jquery-typewriter-rails 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +24 -0
- data/lib/jquery/typewriter/rails.rb +10 -0
- data/lib/jquery/typewriter/rails/version.rb +7 -0
- data/vendor/assets/javascripts/jquery.typewriter.js +359 -0
- metadata +122 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Richard Lee
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# jQuery Typewriter for Rails
|
2
|
+
|
3
|
+
[jquery-typewriter](https://github.com/dmrschmidt/jquery-typewriter) is a jQuery plugin written by [Dennis Schmidt](https://github.com/dmrschmidt). The jQuery typewriter allows you to easily add the effect of an old-shool typewriter writing your text to the page.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
Add the following to your `Gemfile`:
|
8
|
+
|
9
|
+
gem 'jquery-typewriter-rails'
|
10
|
+
|
11
|
+
Add the following directive to your JavaScript manifest file (for example, `application.js`):
|
12
|
+
|
13
|
+
//= require jquery.typewriter
|
14
|
+
|
15
|
+
For full documentation please visit [the original documentation site](http://dmrschmidt.github.com/jquery-typewriter/documentation.html) of this plugin.
|
16
|
+
|
17
|
+
|
18
|
+
## Contributing
|
19
|
+
|
20
|
+
1. Fork it
|
21
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
22
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
23
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
24
|
+
5. Create new Pull Request
|
@@ -0,0 +1,359 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery typewriter by Dennis Schmidt
|
3
|
+
* free download at: http://metzeltiger.github.com/jquery-typewriter/
|
4
|
+
*/
|
5
|
+
var DEFAULTS = new Array();
|
6
|
+
DEFAULTS['data-timeout-letter'] = 15;
|
7
|
+
DEFAULTS['data-timeout-wait'] = 100;
|
8
|
+
DEFAULTS['data-iterations'] = 5;
|
9
|
+
|
10
|
+
/*
|
11
|
+
* Returns the desired timeout for the given element (DOM object) and type
|
12
|
+
* (timeout-letter or timeout-wait). These have default values that will be
|
13
|
+
* returned if the given element doesn't have a valid data-timeout-XXX
|
14
|
+
* attribute set.
|
15
|
+
*/
|
16
|
+
function get_value(element, type, default_value) {
|
17
|
+
var timeout = parseInt(element.attr(type));
|
18
|
+
if(isNaN(timeout) || timeout <= 0) { timeout = default_value }
|
19
|
+
return timeout;
|
20
|
+
}
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Wraps an element that is to be filled with text.
|
24
|
+
*/
|
25
|
+
var Typebox = $.Class.create({
|
26
|
+
/*
|
27
|
+
* properties
|
28
|
+
*/
|
29
|
+
_max_waiting : 15,
|
30
|
+
_possible_chars : "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
|
31
|
+
|
32
|
+
/*
|
33
|
+
* Wrap the passed element into a new Typebox.
|
34
|
+
*/
|
35
|
+
initialize: function(element, should_cycle, timeout_letter, timeout_wait,
|
36
|
+
max_iterations) {
|
37
|
+
this._fixed = "";
|
38
|
+
this._current = "";
|
39
|
+
this._position = 0;
|
40
|
+
this._iteration = 0;
|
41
|
+
this._waited = 0;
|
42
|
+
this._started = false;
|
43
|
+
this._element = $(element);
|
44
|
+
this._text = this._element.html();
|
45
|
+
this._in_tag = false;
|
46
|
+
this._element.html('');
|
47
|
+
this._should_cycle = should_cycle;
|
48
|
+
this._max_iterations = max_iterations;
|
49
|
+
this.set_timeouts(timeout_letter, timeout_wait);
|
50
|
+
},
|
51
|
+
|
52
|
+
/*
|
53
|
+
* Sets the timeouts to use.
|
54
|
+
*/
|
55
|
+
set_timeouts: function(timeout_letter, timeout_wait) {
|
56
|
+
this._timeout_letter = get_value(this._element,
|
57
|
+
'data-timeout-letter', timeout_letter);
|
58
|
+
this._timeout_wait = get_value(this._element,
|
59
|
+
'data-timeout-wait', timeout_wait);
|
60
|
+
},
|
61
|
+
|
62
|
+
/*
|
63
|
+
* Returns the current (real) character that is about to be written.
|
64
|
+
*/
|
65
|
+
current_char: function() {
|
66
|
+
return this._text[this._position];
|
67
|
+
},
|
68
|
+
|
69
|
+
/*
|
70
|
+
* Returns a randomly generated character from the list of all possible
|
71
|
+
* characters.
|
72
|
+
*/
|
73
|
+
random_char: function() {
|
74
|
+
var index = Math.floor(Math.random() * this._possible_chars.length);
|
75
|
+
return this._possible_chars.charAt(index);
|
76
|
+
},
|
77
|
+
|
78
|
+
/*
|
79
|
+
* Returns true if the current character should be printed with other
|
80
|
+
* random characters, before actually printing the correct char itself.
|
81
|
+
* This is never the case for special characters, such as whitespaces.
|
82
|
+
*/
|
83
|
+
should_cycle: function() {
|
84
|
+
var should_cycle = this._should_cycle &&
|
85
|
+
(this._iteration < (this._max_iterations - 1)) &&
|
86
|
+
!(this.current_char() == ' ' ||
|
87
|
+
this.current_char() == "\n" ||
|
88
|
+
this.current_char() == "\r");
|
89
|
+
return should_cycle;
|
90
|
+
},
|
91
|
+
|
92
|
+
/*
|
93
|
+
* What to do when we are waiting.
|
94
|
+
*/
|
95
|
+
handle_waiting: function() {
|
96
|
+
var value = '.';
|
97
|
+
this._fixed = this._current;
|
98
|
+
// if waiting is finished, reset the text field
|
99
|
+
if(++this._waited == this._max_waiting) {
|
100
|
+
this._fixed = "";
|
101
|
+
value = '';
|
102
|
+
}
|
103
|
+
return value;
|
104
|
+
},
|
105
|
+
|
106
|
+
/*
|
107
|
+
* What to do when we are writing actual text.
|
108
|
+
*/
|
109
|
+
handle_writing: function() {
|
110
|
+
var value = this.should_cycle()
|
111
|
+
? this.random_char()
|
112
|
+
: this.current_char();
|
113
|
+
this._iteration = (this._iteration + 1) % (this._max_iterations + 1);
|
114
|
+
if(this._iteration == 0) {
|
115
|
+
this._position++;
|
116
|
+
this._fixed = this._current;
|
117
|
+
}
|
118
|
+
return value;
|
119
|
+
},
|
120
|
+
|
121
|
+
/*
|
122
|
+
* Calculates and returns the next character to be displayed.
|
123
|
+
*/
|
124
|
+
get_char: function() {
|
125
|
+
if(this.is_waiting()) {
|
126
|
+
// display dots if in "waiting" mode
|
127
|
+
var value = this.handle_waiting();
|
128
|
+
} else {
|
129
|
+
// display random letter or real character when not waiting
|
130
|
+
var value = this.handle_writing();
|
131
|
+
}
|
132
|
+
return value;
|
133
|
+
},
|
134
|
+
|
135
|
+
/*
|
136
|
+
* Returns true, when currently an HTML tag needs to be written.
|
137
|
+
* Needed to quickly jump over these, to avoid ugliness.
|
138
|
+
*/
|
139
|
+
in_tag: function() {
|
140
|
+
var current = this.current_char();
|
141
|
+
this._in_tag = (this._in_tag || current == '<') && current != '>';
|
142
|
+
return this._in_tag;
|
143
|
+
},
|
144
|
+
|
145
|
+
/*
|
146
|
+
* Quickly writes a tag.
|
147
|
+
*/
|
148
|
+
write_tag: function() {
|
149
|
+
this._current = this._fixed + this.current_char();
|
150
|
+
$(this._element).html(this._current);
|
151
|
+
this._fixed = this._current;
|
152
|
+
this._position++;
|
153
|
+
},
|
154
|
+
|
155
|
+
|
156
|
+
/*
|
157
|
+
* Returns true if this Typebox is finished printing it's text.
|
158
|
+
*/
|
159
|
+
is_done: function() {
|
160
|
+
return this._position >= this._text.length;
|
161
|
+
},
|
162
|
+
|
163
|
+
/*
|
164
|
+
* Returns true if this Typebox is currently in waiting mode.
|
165
|
+
*/
|
166
|
+
is_waiting: function() {
|
167
|
+
return this._element.attr("data-prefill") == "true" &&
|
168
|
+
this._waited < this._max_waiting;
|
169
|
+
},
|
170
|
+
|
171
|
+
/*
|
172
|
+
* Update the Typebox's text with new content.
|
173
|
+
*/
|
174
|
+
update: function() {
|
175
|
+
if(!this.is_done()) {
|
176
|
+
// skip any tags quickly
|
177
|
+
if(this.in_tag()) do { this.write_tag(); } while(this.in_tag())
|
178
|
+
// in case we skipped a tag, we need to verify we're not done again
|
179
|
+
if(!this.is_done()) {
|
180
|
+
this._current = this._fixed + this.get_char();
|
181
|
+
$(this._element).html(this._current);
|
182
|
+
}
|
183
|
+
}
|
184
|
+
this._started = true;
|
185
|
+
return this.is_done();
|
186
|
+
},
|
187
|
+
|
188
|
+
/*
|
189
|
+
* Returns true on the first run.
|
190
|
+
*/
|
191
|
+
is_firstrun: function() {
|
192
|
+
return !this._started;
|
193
|
+
},
|
194
|
+
|
195
|
+
/*
|
196
|
+
* Returns true if the output should be performed after a pause.
|
197
|
+
*/
|
198
|
+
should_pause: function() {
|
199
|
+
return this._element.attr("data-prepause") && this.is_firstrun();
|
200
|
+
},
|
201
|
+
|
202
|
+
/*
|
203
|
+
* Returns the desired interval until the next update should occur.
|
204
|
+
*/
|
205
|
+
get_interval: function() {
|
206
|
+
if(this.should_pause()) {
|
207
|
+
return parseInt(this._element.attr("data-prepause"));
|
208
|
+
} else if(this.is_waiting()) {
|
209
|
+
return this._timeout_wait;
|
210
|
+
} else {
|
211
|
+
return this._timeout_letter;
|
212
|
+
}
|
213
|
+
},
|
214
|
+
|
215
|
+
/*
|
216
|
+
*
|
217
|
+
*/
|
218
|
+
toString: function() {
|
219
|
+
return this._text;
|
220
|
+
},
|
221
|
+
});
|
222
|
+
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Creates a couple of Typeboxes when initiated and manages their filling,
|
226
|
+
* by calling their update methods repetitively.
|
227
|
+
*/
|
228
|
+
var Typewriter = $.Class.create({
|
229
|
+
/*
|
230
|
+
* Constructs a new typewriter for the given DOM Object ID.
|
231
|
+
*/
|
232
|
+
initialize: function(element) {
|
233
|
+
this._started = false;
|
234
|
+
this._box_id = element.id;
|
235
|
+
this._box = $(element);
|
236
|
+
this._parts = [];
|
237
|
+
this._should_cycle = this._box.attr("data-cycling") != "false";
|
238
|
+
this.load_parts();
|
239
|
+
this.autostart();
|
240
|
+
},
|
241
|
+
|
242
|
+
/*
|
243
|
+
* Gets a list of DOM objects with class="typewriter-starter", and
|
244
|
+
* registers those with a value of data-start-typewriter identical to it's
|
245
|
+
* own ID as it's start handlers.
|
246
|
+
* Clicking on any of these items will then start the typewriter.
|
247
|
+
*/
|
248
|
+
register_start_handlers: function(handlers) {
|
249
|
+
var self = this;
|
250
|
+
var box = this._box;
|
251
|
+
handlers.each(function(index, element) {
|
252
|
+
var to_start = $(element).attr("data-start-typewriter");
|
253
|
+
if(to_start == box.attr('id')) {
|
254
|
+
$(element).click(jQuery.proxy(self.start_typing, self));
|
255
|
+
}
|
256
|
+
});
|
257
|
+
},
|
258
|
+
|
259
|
+
/*
|
260
|
+
* Returns true when the typewriter shall start automatically (which is)
|
261
|
+
* the default behaviour, unless overwritten by setting data-autostart
|
262
|
+
* to false.
|
263
|
+
*/
|
264
|
+
shall_autostart: function() {
|
265
|
+
return this._box.attr("data-autostart") != "false";
|
266
|
+
},
|
267
|
+
|
268
|
+
/*
|
269
|
+
* Performs an automatic start unless configured otherwise.
|
270
|
+
* By default this is enabled, but it can be disabled by adding
|
271
|
+
* data-autostart="false" to the main typewriter DOM object
|
272
|
+
* (the one with class 'typewriter').
|
273
|
+
*/
|
274
|
+
autostart: function() {
|
275
|
+
if(this.shall_autostart()) { this.type(); }
|
276
|
+
},
|
277
|
+
|
278
|
+
/*
|
279
|
+
* Creates a Typebox instance from the given DOM object.
|
280
|
+
*/
|
281
|
+
load_part: function(part) {
|
282
|
+
var timeout_letter = get_value(this._box, 'data-timeout-letter',
|
283
|
+
DEFAULTS['data-timeout-letter']);
|
284
|
+
var timeout_wait = get_value(this._box, 'data-timeout-wait',
|
285
|
+
DEFAULTS['data-timeout-wait']);
|
286
|
+
var max_iterations = get_value(this._box, 'data-iterations',
|
287
|
+
DEFAULTS['data-iterations']);
|
288
|
+
this._parts.push(new Typebox(
|
289
|
+
part,
|
290
|
+
this._should_cycle,
|
291
|
+
timeout_letter,
|
292
|
+
timeout_wait,
|
293
|
+
max_iterations)
|
294
|
+
);
|
295
|
+
},
|
296
|
+
|
297
|
+
/*
|
298
|
+
* Loads all the Typebox instances that are available.
|
299
|
+
*/
|
300
|
+
load_parts: function() {
|
301
|
+
var boxes = this._box.find(".typewrite");
|
302
|
+
var parent = this;
|
303
|
+
$.each(boxes, function(index, element) { parent.load_part(element) });
|
304
|
+
},
|
305
|
+
|
306
|
+
/*
|
307
|
+
* Returns the Typebox instance that is currently in update progress.
|
308
|
+
*/
|
309
|
+
get_part: function() {
|
310
|
+
if(this._current_part == null || (this._current_part.is_done() &&
|
311
|
+
this._parts.length > 0))
|
312
|
+
this._current_part = this._parts.shift();
|
313
|
+
return this._current_part;
|
314
|
+
},
|
315
|
+
|
316
|
+
/*
|
317
|
+
* Call this method externally to start the typing. Here we can assure
|
318
|
+
* #type() is only called ONCE, to avoid timing problems.
|
319
|
+
*/
|
320
|
+
start_typing: function() {
|
321
|
+
if(!this._started) {
|
322
|
+
this._started = true;
|
323
|
+
this.type();
|
324
|
+
}
|
325
|
+
},
|
326
|
+
|
327
|
+
/*
|
328
|
+
* Delegates the filling of the Typeboxes to it's respective child
|
329
|
+
* Typebox instances.
|
330
|
+
*/
|
331
|
+
type: function() {
|
332
|
+
this.get_part().update();
|
333
|
+
var timeout = this.get_part().get_interval();
|
334
|
+
window.setTimeout(jQuery.proxy(this.type, this), timeout);
|
335
|
+
},
|
336
|
+
|
337
|
+
/*
|
338
|
+
*
|
339
|
+
*/
|
340
|
+
toString: function() {
|
341
|
+
return this._box_id;
|
342
|
+
}
|
343
|
+
});
|
344
|
+
|
345
|
+
/*
|
346
|
+
* perform some initializations
|
347
|
+
*/
|
348
|
+
$(document).ready(function() {
|
349
|
+
var typewriters = [];
|
350
|
+
var handlers = $(".typewriter-starter");
|
351
|
+
$(".typewriter").each(function(index, element) {
|
352
|
+
var typewriter = new Typewriter(element);
|
353
|
+
// if it does not start on it's own, define a start handler
|
354
|
+
if(!typewriter.shall_autostart()) {
|
355
|
+
typewriter.register_start_handlers(handlers);
|
356
|
+
}
|
357
|
+
typewriters.push(typewriter);
|
358
|
+
});
|
359
|
+
});
|
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jquery-typewriter-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.5
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Richard Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: jquery-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>'
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>'
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.3'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description: The jQuery typewriter allows you to easily add the effect of an old-shool
|
79
|
+
typewriter writing your text to the page.
|
80
|
+
email:
|
81
|
+
- rl@polydice.com
|
82
|
+
executables: []
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- lib/jquery/typewriter/rails/version.rb
|
87
|
+
- lib/jquery/typewriter/rails.rb
|
88
|
+
- vendor/assets/javascripts/jquery.typewriter.js
|
89
|
+
- LICENSE.txt
|
90
|
+
- README.md
|
91
|
+
homepage: https://github.com/polydice/jquery-typewriter-rails
|
92
|
+
licenses:
|
93
|
+
- MIT
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ! '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
segments:
|
105
|
+
- 0
|
106
|
+
hash: 3811699664421706861
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: 3811699664421706861
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: jQuery typewriter text-style plugin wrapped for Rails.
|
122
|
+
test_files: []
|