typedjs-rails 1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 152b78f5bb60e3242995eb246b158e6529a24e52
4
+ data.tar.gz: 5901b61b297e2884c04424437dddb3bd2cf2f31a
5
+ SHA512:
6
+ metadata.gz: 3ba0a9ad3c2114bf283e7810c3f630cf93f2c4ca8122cd4efdd69b1a933c57cffaff111c8ede5a821cf47013c1486dffac38fece998f3b968b445d11d0b3ad79
7
+ data.tar.gz: b491e34335a4adf27934a7963d3b1c18c1431bbb46c2d5f9b93b0ecc41dd714a74c8978791096a989576ac6ea1650814141bba5d22a1949f1525d1773d1b9283
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "http://rubygems.org"
2
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,377 @@
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
+ // All systems go!
89
+ this.build();
90
+ };
91
+
92
+ Typed.prototype = {
93
+
94
+ constructor: Typed
95
+
96
+ ,
97
+ init: function() {
98
+ // begin the loop w/ first current string (global self.string)
99
+ // current string will be passed as an argument each time after this
100
+ var self = this;
101
+ self.timeout = setTimeout(function() {
102
+ // Start typing
103
+ self.typewrite(self.strings[self.arrayPos], self.strPos);
104
+ }, self.startDelay);
105
+ }
106
+
107
+ ,
108
+ build: function() {
109
+ // Insert cursor
110
+ if (this.showCursor === true) {
111
+ this.cursor = $("<span class=\"typed-cursor\">" + this.cursorChar + "</span>");
112
+ this.el.after(this.cursor);
113
+ }
114
+ this.init();
115
+ }
116
+
117
+ // pass current string state to each function, types 1 char per call
118
+ ,
119
+ typewrite: function(curString, curStrPos) {
120
+ // exit when stopped
121
+ if (this.stop === true) {
122
+ return;
123
+ }
124
+
125
+ // varying values for setTimeout during typing
126
+ // can't be global since number changes each time loop is executed
127
+ var humanize = Math.round(Math.random() * (100 - 30)) + this.typeSpeed;
128
+ var self = this;
129
+
130
+ // ------------- optional ------------- //
131
+ // backpaces a certain string faster
132
+ // ------------------------------------ //
133
+ // if (self.arrayPos == 1){
134
+ // self.backDelay = 50;
135
+ // }
136
+ // else{ self.backDelay = 500; }
137
+
138
+ // contain typing function in a timeout humanize'd delay
139
+ self.timeout = setTimeout(function() {
140
+ // check for an escape character before a pause value
141
+ // format: \^\d+ .. eg: ^1000 .. should be able to print the ^ too using ^^
142
+ // single ^ are removed from string
143
+ var charPause = 0;
144
+ var substr = curString.substr(curStrPos);
145
+ if (substr.charAt(0) === '^') {
146
+ var skip = 1; // skip atleast 1
147
+ if (/^\^\d+/.test(substr)) {
148
+ substr = /\d+/.exec(substr)[0];
149
+ skip += substr.length;
150
+ charPause = parseInt(substr);
151
+ }
152
+
153
+ // strip out the escape character and pause value so they're not printed
154
+ curString = curString.substring(0, curStrPos) + curString.substring(curStrPos + skip);
155
+ }
156
+
157
+ if (self.contentType === 'html') {
158
+ // skip over html tags while typing
159
+ if (curString.substr(curStrPos).charAt(0) === '<') {
160
+ var tag = '';
161
+ while (curString.substr(curStrPos).charAt(0) !== '>') {
162
+ tag += curString.substr(curStrPos).charAt(0);
163
+ curStrPos++;
164
+ }
165
+ curStrPos++;
166
+ tag += '>';
167
+ }
168
+ }
169
+
170
+ // timeout for any pause after a character
171
+ self.timeout = setTimeout(function() {
172
+ if (curStrPos === curString.length) {
173
+ // fires callback function
174
+ self.options.onStringTyped(self.arrayPos);
175
+
176
+ // is this the final string
177
+ if (self.arrayPos === self.strings.length - 1) {
178
+ // animation that occurs on the last typed string
179
+ self.options.callback();
180
+
181
+ self.curLoop++;
182
+
183
+ // quit if we wont loop back
184
+ if (self.loop === false || self.curLoop === self.loopCount)
185
+ return;
186
+ }
187
+
188
+ self.timeout = setTimeout(function() {
189
+ self.backspace(curString, curStrPos);
190
+ }, self.backDelay);
191
+ } else {
192
+
193
+ /* call before functions if applicable */
194
+ if (curStrPos === 0)
195
+ self.options.preStringTyped(self.arrayPos);
196
+
197
+ // start typing each new char into existing string
198
+ // curString: arg, self.el.html: original text inside element
199
+ var nextString = self.elContent + curString.substr(0, curStrPos + 1);
200
+ if (self.attr) {
201
+ self.el.attr(self.attr, nextString);
202
+ } else {
203
+ if (self.contentType === 'html') {
204
+ self.el.html(nextString);
205
+ } else {
206
+ self.el.text(nextString);
207
+ }
208
+ }
209
+
210
+ // add characters one by one
211
+ curStrPos++;
212
+ // loop the function
213
+ self.typewrite(curString, curStrPos);
214
+ }
215
+ // end of character pause
216
+ }, charPause);
217
+
218
+ // humanized value for typing
219
+ }, humanize);
220
+
221
+ }
222
+
223
+ ,
224
+ backspace: function(curString, curStrPos) {
225
+ // exit when stopped
226
+ if (this.stop === true) {
227
+ return;
228
+ }
229
+
230
+ // varying values for setTimeout during typing
231
+ // can't be global since number changes each time loop is executed
232
+ var humanize = Math.round(Math.random() * (100 - 30)) + this.backSpeed;
233
+ var self = this;
234
+
235
+ self.timeout = setTimeout(function() {
236
+
237
+ // ----- this part is optional ----- //
238
+ // check string array position
239
+ // on the first string, only delete one word
240
+ // the stopNum actually represents the amount of chars to
241
+ // keep in the current string. In my case it's 14.
242
+ // if (self.arrayPos == 1){
243
+ // self.stopNum = 14;
244
+ // }
245
+ //every other time, delete the whole typed string
246
+ // else{
247
+ // self.stopNum = 0;
248
+ // }
249
+
250
+ if (self.contentType === 'html') {
251
+ // skip over html tags while backspacing
252
+ if (curString.substr(curStrPos).charAt(0) === '>') {
253
+ var tag = '';
254
+ while (curString.substr(curStrPos).charAt(0) !== '<') {
255
+ tag -= curString.substr(curStrPos).charAt(0);
256
+ curStrPos--;
257
+ }
258
+ curStrPos--;
259
+ tag += '<';
260
+ }
261
+ }
262
+
263
+ // ----- continue important stuff ----- //
264
+ // replace text with base text + typed characters
265
+ var nextString = self.elContent + curString.substr(0, curStrPos);
266
+ if (self.attr) {
267
+ self.el.attr(self.attr, nextString);
268
+ } else {
269
+ if (self.contentType === 'html') {
270
+ self.el.html(nextString);
271
+ } else {
272
+ self.el.text(nextString);
273
+ }
274
+ }
275
+
276
+ // if the number (id of character in current string) is
277
+ // less than the stop number, keep going
278
+ if (curStrPos > self.stopNum) {
279
+ // subtract characters one by one
280
+ curStrPos--;
281
+ // loop the function
282
+ self.backspace(curString, curStrPos);
283
+ }
284
+ // if the stop number has been reached, increase
285
+ // array position to next string
286
+ else if (curStrPos <= self.stopNum) {
287
+ self.arrayPos++;
288
+
289
+ if (self.arrayPos === self.strings.length) {
290
+ self.arrayPos = 0;
291
+ self.init();
292
+ } else
293
+ self.typewrite(self.strings[self.arrayPos], curStrPos);
294
+ }
295
+
296
+ // humanized value for typing
297
+ }, humanize);
298
+
299
+ }
300
+
301
+ // Start & Stop currently not working
302
+
303
+ // , stop: function() {
304
+ // var self = this;
305
+
306
+ // self.stop = true;
307
+ // clearInterval(self.timeout);
308
+ // }
309
+
310
+ // , start: function() {
311
+ // var self = this;
312
+ // if(self.stop === false)
313
+ // return;
314
+
315
+ // this.stop = false;
316
+ // this.init();
317
+ // }
318
+
319
+ // Reset and rebuild the element
320
+ ,
321
+ reset: function() {
322
+ var self = this;
323
+ clearInterval(self.timeout);
324
+ var id = this.el.attr('id');
325
+ this.el.after('<span id="' + id + '"/>')
326
+ this.el.remove();
327
+ this.cursor.remove();
328
+ // Send the callback
329
+ self.options.resetCallback();
330
+ }
331
+
332
+ };
333
+
334
+ $.fn.typed = function(option) {
335
+ return this.each(function() {
336
+ var $this = $(this),
337
+ data = $this.data('typed'),
338
+ options = typeof option == 'object' && option;
339
+ if (!data) $this.data('typed', (data = new Typed(this, options)));
340
+ if (typeof option == 'string') data[option]();
341
+ });
342
+ };
343
+
344
+ $.fn.typed.defaults = {
345
+ strings: ["These are the default values...", "You know what you should do?", "Use your own!", "Have a great day!"],
346
+ // typing speed
347
+ typeSpeed: 0,
348
+ // time before typing starts
349
+ startDelay: 0,
350
+ // backspacing speed
351
+ backSpeed: 0,
352
+ // time before backspacing
353
+ backDelay: 500,
354
+ // loop
355
+ loop: false,
356
+ // false = infinite
357
+ loopCount: false,
358
+ // show cursor
359
+ showCursor: true,
360
+ // character for cursor
361
+ cursorChar: "|",
362
+ // attribute to type (null == text)
363
+ attr: null,
364
+ // either html or text
365
+ contentType: 'html',
366
+ // call when done callback function
367
+ callback: function() {},
368
+ // starting callback function before each string
369
+ preStringTyped: function() {},
370
+ //callback for every typed string
371
+ onStringTyped: function() {},
372
+ // callback for reset
373
+ resetCallback: function() {}
374
+ };
375
+
376
+
377
+ }(window.jQuery);
@@ -0,0 +1,2 @@
1
+ require 'typedjs/version'
2
+ require 'typedjs/rails'
@@ -0,0 +1,6 @@
1
+ module Typedjs
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Typedjs
2
+ VERSION = "1.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "typedjs/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "typedjs-rails"
7
+ s.version = "1.0.1"
8
+ s.authors = ["TheDartCode"]
9
+ s.email = ["giorgos@thedartcode.com"]
10
+ s.homepage = "http://www.thedartcode.com/"
11
+ s.summary = %q{Gem for easily adding Typed.js to the Rails Asset Pipeline}
12
+ s.description = %q{Gem that includes Typed.js, in the Rails Asset Pipeline introduced in Rails 3.1}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_dependency "railties", ">= 3.1"
20
+ s.add_development_dependency "bundler", "~> 1.0"
21
+ s.add_development_dependency "rails", ">= 3.1"
22
+ end
23
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: typedjs-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - TheDartCode
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: Gem that includes Typed.js, in the Rails Asset Pipeline introduced in
56
+ Rails 3.1
57
+ email:
58
+ - giorgos@thedartcode.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - Rakefile
65
+ - app/assets/javascripts/typed.js
66
+ - lib/typedjs-rails.rb
67
+ - lib/typedjs/rails.rb
68
+ - lib/typedjs/version.rb
69
+ - typedjs-rails.gemspec
70
+ homepage: http://www.thedartcode.com/
71
+ licenses: []
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.4.5
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Gem for easily adding Typed.js to the Rails Asset Pipeline
93
+ test_files: []