typedJS 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b50c14bce234cefbe5af68b9f21c62840705101e
4
+ data.tar.gz: d6059fd0603d24e5d368b66143ffb993725ccfe1
5
+ SHA512:
6
+ metadata.gz: 0b4c90cc0bdd83a90a6e85f16c38db2c748edb23a958001313ebe851eb05d5817d4d5991b288f65c0c804eee5e9aa5e1814cad196630ab917cb9bf997b6b8018
7
+ data.tar.gz: b593f7e2041ff046905d441644d3c16ca6c745b1959ee3e4bc07b64246a1d4e11456576e9a764a5cf1992a9cc0bee01e72fc8096f0828f1e243e7db80d1bd67c
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in typedJS.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Amit
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,40 @@
1
+ # TypedJS
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'typedJS'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install typedJS
20
+
21
+ ## Usage
22
+
23
+ In your JavaScript manifest (e.g. application.js)
24
+
25
+ //= require typed
26
+
27
+
28
+ In your Stylesheet manifest (e.g. application.js)
29
+
30
+ //= require blink
31
+
32
+ TODO: Write usage instructions here
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/[my-github-username]/typedJS/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require "typedJS/version"
2
+
3
+ module TypedJS
4
+ # Your code goes here...
5
+ class Engine < ::Rails::Engine; end
6
+ end
@@ -0,0 +1,3 @@
1
+ module TypedJS
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'typedJS/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "typedJS"
8
+ spec.version = TypedJS::VERSION
9
+ spec.authors = ["Amit"]
10
+ spec.email = ["gudeamit148@gmail.com"]
11
+ spec.summary = %q{This gem allows to users to simulate typing animation for some text}
12
+ spec.description = %q{This gem allows to users to simulate typing animation for some text}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
File without changes
@@ -0,0 +1,421 @@
1
+ // The MIT License (MIT)
2
+
3
+ // Typed.js | Copyright (c) 2014 Matt Boldt | www.mattboldt.com
4
+
5
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ // of this software and associated documentation files (the "Software"), to deal
7
+ // in the Software without restriction, including without limitation the rights
8
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ // copies of the Software, and to permit persons to whom the Software is
10
+ // furnished to do so, subject to the following conditions:
11
+
12
+ // The above copyright notice and this permission notice shall be included in
13
+ // all copies or substantial portions of the Software.
14
+
15
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ // THE SOFTWARE.
22
+
23
+
24
+
25
+
26
+ ! function($) {
27
+
28
+ "use strict";
29
+
30
+ var Typed = function(el, options) {
31
+
32
+ // chosen element to manipulate text
33
+ this.el = $(el);
34
+
35
+ // options
36
+ this.options = $.extend({}, $.fn.typed.defaults, options);
37
+
38
+ // attribute to type into
39
+ this.isInput = this.el.is('input');
40
+ this.attr = this.options.attr;
41
+
42
+ // show cursor
43
+ this.showCursor = this.isInput ? false : this.options.showCursor;
44
+
45
+ // text content of element
46
+ this.elContent = this.attr ? this.el.attr(this.attr) : this.el.text()
47
+
48
+ // html or plain text
49
+ this.contentType = this.options.contentType;
50
+
51
+ // typing speed
52
+ this.typeSpeed = this.options.typeSpeed;
53
+
54
+ // add a delay before typing starts
55
+ this.startDelay = this.options.startDelay;
56
+
57
+ // backspacing speed
58
+ this.backSpeed = this.options.backSpeed;
59
+
60
+ // amount of time to wait before backspacing
61
+ this.backDelay = this.options.backDelay;
62
+
63
+ // input strings of text
64
+ this.strings = this.options.strings;
65
+
66
+ // character number position of current string
67
+ this.strPos = 0;
68
+
69
+ // current array position
70
+ this.arrayPos = 0;
71
+
72
+ // number to stop backspacing on.
73
+ // default 0, can change depending on how many chars
74
+ // you want to remove at the time
75
+ this.stopNum = 0;
76
+
77
+ // Looping logic
78
+ this.loop = this.options.loop;
79
+ this.loopCount = this.options.loopCount;
80
+ this.curLoop = 0;
81
+
82
+ // for stopping
83
+ this.stop = false;
84
+
85
+ // custom cursor
86
+ this.cursorChar = this.options.cursorChar;
87
+
88
+ // shuffle the strings
89
+ this.shuffle = this.options.shuffle;
90
+ // the order of strings
91
+ this.sequence = [];
92
+
93
+ // All systems go!
94
+ this.build();
95
+ };
96
+
97
+ Typed.prototype = {
98
+
99
+ constructor: Typed
100
+
101
+ ,
102
+ init: function() {
103
+ // begin the loop w/ first current string (global self.string)
104
+ // current string will be passed as an argument each time after this
105
+ var self = this;
106
+ self.timeout = setTimeout(function() {
107
+ for (var i=0;i<self.strings.length;++i) self.sequence[i]=i;
108
+
109
+ // shuffle the array if true
110
+ if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
111
+
112
+ // Start typing
113
+ self.typewrite(self.strings[self.sequence[self.arrayPos]], self.strPos);
114
+ }, self.startDelay);
115
+ }
116
+
117
+ ,
118
+ build: function() {
119
+ // Insert cursor
120
+ if (this.showCursor === true) {
121
+ this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
122
+ this.el.after(this.cursor);
123
+ }
124
+ this.init();
125
+ }
126
+
127
+ // pass current string state to each function, types 1 char per call
128
+ ,
129
+ typewrite: function(curString, curStrPos) {
130
+ // exit when stopped
131
+ if (this.stop === true) {
132
+ return;
133
+ }
134
+
135
+ // varying values for setTimeout during typing
136
+ // can't be global since number changes each time loop is executed
137
+ var humanize = Math.round(Math.random() * (100 - 30)) + this.typeSpeed;
138
+ var self = this;
139
+
140
+ // ------------- optional ------------- //
141
+ // backpaces a certain string faster
142
+ // ------------------------------------ //
143
+ // if (self.arrayPos == 1){
144
+ // self.backDelay = 50;
145
+ // }
146
+ // else{ self.backDelay = 500; }
147
+
148
+ // contain typing function in a timeout humanize'd delay
149
+ self.timeout = setTimeout(function() {
150
+ // check for an escape character before a pause value
151
+ // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
152
+ // single ^ are removed from string
153
+ var charPause = 0;
154
+ var substr = curString.substr(curStrPos);
155
+ if (substr.charAt(0) === '^') {
156
+ var skip = 1; // skip atleast 1
157
+ if (/^\^\d+/.test(substr)) {
158
+ substr = /\d+/.exec(substr)[0];
159
+ skip += substr.length;
160
+ charPause = parseInt(substr);
161
+ }
162
+
163
+ // strip out the escape character and pause value so they're not printed
164
+ curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
165
+ }
166
+
167
+ if (self.contentType === 'html') {
168
+ // skip over html tags while typing
169
+ var curChar = curString.substr(curStrPos).charAt(0)
170
+ if (curChar === '<' || curChar === '&') {
171
+ var tag = '';
172
+ var endTag = '';
173
+ if (curChar === '<') {
174
+ endTag = '>'
175
+ } else {
176
+ endTag = ';'
177
+ }
178
+ while (curString.substr(curStrPos).charAt(0) !== endTag) {
179
+ tag += curString.substr(curStrPos).charAt(0);
180
+ curStrPos++;
181
+ }
182
+ curStrPos++;
183
+ tag += endTag;
184
+ }
185
+ }
186
+
187
+ // timeout for any pause after a character
188
+ self.timeout = setTimeout(function() {
189
+ if (curStrPos === curString.length) {
190
+ // fires callback function
191
+ self.options.onStringTyped(self.arrayPos);
192
+
193
+ // is this the final string
194
+ if (self.arrayPos === self.strings.length - 1) {
195
+ // animation that occurs on the last typed string
196
+ self.options.callback();
197
+
198
+ self.curLoop++;
199
+
200
+ // quit if we wont loop back
201
+ if (self.loop === false || self.curLoop === self.loopCount)
202
+ return;
203
+ }
204
+
205
+ self.timeout = setTimeout(function() {
206
+ self.backspace(curString, curStrPos);
207
+ }, self.backDelay);
208
+ } else {
209
+
210
+ /* call before functions if applicable */
211
+ if (curStrPos === 0)
212
+ self.options.preStringTyped(self.arrayPos);
213
+
214
+ // start typing each new char into existing string
215
+ // curString: arg, self.el.html: original text inside element
216
+ var nextString = curString.substr(0, curStrPos + 1);
217
+ if (self.attr) {
218
+ self.el.attr(self.attr, nextString);
219
+ } else {
220
+ if (self.isInput) {
221
+ self.el.val(nextString);
222
+ } else if (self.contentType === 'html') {
223
+ self.el.html(nextString);
224
+ } else {
225
+ self.el.text(nextString);
226
+ }
227
+ }
228
+
229
+ // add characters one by one
230
+ curStrPos++;
231
+ // loop the function
232
+ self.typewrite(curString, curStrPos);
233
+ }
234
+ // end of character pause
235
+ }, charPause);
236
+
237
+ // humanized value for typing
238
+ }, humanize);
239
+
240
+ }
241
+
242
+ ,
243
+ backspace: function(curString, curStrPos) {
244
+ // exit when stopped
245
+ if (this.stop === true) {
246
+ return;
247
+ }
248
+
249
+ // varying values for setTimeout during typing
250
+ // can't be global since number changes each time loop is executed
251
+ var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
252
+ var self = this;
253
+
254
+ self.timeout = setTimeout(function() {
255
+
256
+ // ----- this part is optional ----- //
257
+ // check string array position
258
+ // on the first string, only delete one word
259
+ // the stopNum actually represents the amount of chars to
260
+ // keep in the current string. In my case it's 14.
261
+ // if (self.arrayPos == 1){
262
+ // self.stopNum = 14;
263
+ // }
264
+ //every other time, delete the whole typed string
265
+ // else{
266
+ // self.stopNum = 0;
267
+ // }
268
+
269
+ if (self.contentType === 'html') {
270
+ // skip over html tags while backspacing
271
+ if (curString.substr(curStrPos).charAt(0) === '>') {
272
+ var tag = '';
273
+ while (curString.substr(curStrPos).charAt(0) !== '<') {
274
+ tag -= curString.substr(curStrPos).charAt(0);
275
+ curStrPos--;
276
+ }
277
+ curStrPos--;
278
+ tag += '<';
279
+ }
280
+ }
281
+
282
+ // ----- continue important stuff ----- //
283
+ // replace text with base text + typed characters
284
+ var nextString = curString.substr(0, curStrPos);
285
+ if (self.attr) {
286
+ self.el.attr(self.attr, nextString);
287
+ } else {
288
+ if (self.isInput) {
289
+ self.el.val(nextString);
290
+ } else if (self.contentType === 'html') {
291
+ self.el.html(nextString);
292
+ } else {
293
+ self.el.text(nextString);
294
+ }
295
+ }
296
+
297
+ // if the number (id of character in current string) is
298
+ // less than the stop number, keep going
299
+ if (curStrPos > self.stopNum) {
300
+ // subtract characters one by one
301
+ curStrPos--;
302
+ // loop the function
303
+ self.backspace(curString, curStrPos);
304
+ }
305
+ // if the stop number has been reached, increase
306
+ // array position to next string
307
+ else if (curStrPos <= self.stopNum) {
308
+ self.arrayPos++;
309
+
310
+ if (self.arrayPos === self.strings.length) {
311
+ self.arrayPos = 0;
312
+
313
+ // Shuffle sequence again
314
+ if(self.shuffle) self.sequence = self.shuffleArray(self.sequence);
315
+
316
+ self.init();
317
+ } else
318
+ self.typewrite(self.strings[self.sequence[self.arrayPos]], curStrPos);
319
+ }
320
+
321
+ // humanized value for typing
322
+ }, humanize);
323
+
324
+ }
325
+ /**
326
+ * Shuffles the numbers in the given array.
327
+ * @param {Array} array
328
+ * @returns {Array}
329
+ */
330
+ ,shuffleArray: function(array) {
331
+ var tmp, current, top = array.length;
332
+ if(top) while(--top) {
333
+ current = Math.floor(Math.random() * (top + 1));
334
+ tmp = array[current];
335
+ array[current] = array[top];
336
+ array[top] = tmp;
337
+ }
338
+ return array;
339
+ }
340
+
341
+ // Start & Stop currently not working
342
+
343
+ // , stop: function() {
344
+ // var self = this;
345
+
346
+ // self.stop = true;
347
+ // clearInterval(self.timeout);
348
+ // }
349
+
350
+ // , start: function() {
351
+ // var self = this;
352
+ // if(self.stop === false)
353
+ // return;
354
+
355
+ // this.stop = false;
356
+ // this.init();
357
+ // }
358
+
359
+ // Reset and rebuild the element
360
+ ,
361
+ reset: function() {
362
+ var self = this;
363
+ clearInterval(self.timeout);
364
+ var id = this.el.attr('id');
365
+ this.el.after('<span id="' + id + '"/>')
366
+ this.el.remove();
367
+ if (typeof this.cursor !== 'undefined') {
368
+ this.cursor.remove();
369
+ }
370
+ // Send the callback
371
+ self.options.resetCallback();
372
+ }
373
+
374
+ };
375
+
376
+ $.fn.typed = function(option) {
377
+ return this.each(function() {
378
+ var $this = $(this),
379
+ data = $this.data('typed'),
380
+ options = typeof option == 'object' && option;
381
+ if (!data) $this.data('typed', (data = new Typed(this, options)));
382
+ if (typeof option == 'string') data[option]();
383
+ });
384
+ };
385
+
386
+ $.fn.typed.defaults = {
387
+ strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
388
+ // typing speed
389
+ typeSpeed: 0,
390
+ // time before typing starts
391
+ startDelay: 0,
392
+ // backspacing speed
393
+ backSpeed: 0,
394
+ // shuffle the strings
395
+ shuffle: false,
396
+ // time before backspacing
397
+ backDelay: 500,
398
+ // loop
399
+ loop: false,
400
+ // false = infinite
401
+ loopCount: false,
402
+ // show cursor
403
+ showCursor: true,
404
+ // character for cursor
405
+ cursorChar: "|",
406
+ // attribute to type (null == text)
407
+ attr: null,
408
+ // either html or text
409
+ contentType: 'html',
410
+ // call when done callback function
411
+ callback: function() {},
412
+ // starting callback function before each string
413
+ preStringTyped: function() {},
414
+ //callback for every typed string
415
+ onStringTyped: function() {},
416
+ // callback for reset
417
+ resetCallback: function() {}
418
+ };
419
+
420
+
421
+ }(window.jQuery);
File without changes
@@ -0,0 +1,22 @@
1
+
2
+ .typed-cursor{
3
+ opacity: 1;
4
+ -webkit-animation: blink 0.7s infinite;
5
+ -moz-animation: blink 0.7s infinite;
6
+ animation: blink 0.7s infinite;
7
+ }
8
+ @keyframes blink{
9
+ 0% { opacity:1; }
10
+ 50% { opacity:0; }
11
+ 100% { opacity:1; }
12
+ }
13
+ @-webkit-keyframes blink{
14
+ 0% { opacity:1; }
15
+ 50% { opacity:0; }
16
+ 100% { opacity:1; }
17
+ }
18
+ @-moz-keyframes blink{
19
+ 0% { opacity:1; }
20
+ 50% { opacity:0; }
21
+ 100% { opacity:1; }
22
+ }
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typedJS
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Amit
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: This gem allows to users to simulate typing animation for some text
42
+ email:
43
+ - gudeamit148@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/typedJS.rb
54
+ - lib/typedJS/version.rb
55
+ - typedJS.gemspec
56
+ - vendor/assets/javascripts/.keep
57
+ - vendor/assets/javascripts/typed.js
58
+ - vendor/assets/stylesheets/.keep
59
+ - vendor/assets/stylesheets/blink.css
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: This gem allows to users to simulate typing animation for some text
84
+ test_files: []