-
Notifications
You must be signed in to change notification settings - Fork 25
/
jquery.typetype.js
123 lines (123 loc) · 4.42 KB
/
jquery.typetype.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Generated by CoffeeScript 1.7.1
$.fn.extend({
backspace: function(num, options) {
var settings;
settings = $.extend({
callback: function() {},
keypress: function() {},
t: 100,
e: 0.04
}, options);
return this.each(function() {
var elem;
elem = this;
$(elem).queue(function() {
var append, backsp;
backsp = function(n, fakeparam) {
if (n) {
elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'] = elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'].slice(0, -1);
settings.keypress.call(elem);
setTimeout((function() {
backsp(n - 1, fakeparam);
}), settings.t);
} else {
settings.callback.call(elem);
$(elem).dequeue();
}
};
append = function(fake, fakeyness) {
if (fake) {
elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'] += fake[0];
settings.keypress.call(elem);
setTimeout((function() {
append(fake.slice(1), fakeyness);
}), settings.t);
} else {
fakeyness();
}
};
backsp(num);
});
});
},
typetype: function(txt, options) {
var settings;
settings = $.extend({
callback: function() {},
keypress: function() {},
t: 100,
e: 0.04
}, options);
return this.each(function() {
var elem;
elem = this;
$(elem).queue(function() {
var append, backsp, typeTo;
backsp = function(num, cont) {
if (num) {
elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'] = elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'].slice(0, -1);
settings.keypress.call(elem);
setTimeout((function() {
backsp(num - 1, cont);
}), settings.t);
} else {
cont();
}
};
append = function(str, cont) {
if (str) {
elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'] += str[0];
settings.keypress.call(elem);
setTimeout((function() {
append(str.slice(1), cont);
}), settings.t);
} else {
cont();
}
};
typeTo = function(i) {
var afterErr, r;
afterErr = function() {
return setTimeout((function() {
typeTo(i);
}), Math.random() * settings.t * (txt[i - 1] === txt[i] ? 1.6 : txt[i - 1] === '.' ? 12 : txt[i - 1] === '!' ? 12 : txt[i - 1] === '?' ? 12 : txt[i - 1] === '\n' ? 12 : txt[i - 1] === ',' ? 8 : txt[i - 1] === ';' ? 8 : txt[i - 1] === ':' ? 8 : txt[i - 1] === ' ' ? 3 : 2));
};
r = Math.random() / settings.e;
if (txt.length >= i) {
if (0.3 > r && txt[i - 1] !== txt[i] && txt.length > i + 4) {
append(txt.slice(i, i + 4), (function() {
backsp(4, afterErr);
}));
} else if (0.7 > r && i > 1 && /[A-Z]/.test(txt[i - 2] && txt.length > i + 4)) {
append(txt[i - 1].toUpperCase() + txt.slice(i, i + 4), (function() {
backsp(5, afterErr);
}));
} else if (0.5 > r && txt[i - 1] !== txt[i] && txt.length > i) {
append(txt[i], (function() {
backsp(1, afterErr);
}));
} else if (1.0 > r && txt[i - 1] !== txt[i] && txt.length > i) {
append(txt[i] + txt[i - 1], (function() {
backsp(2, afterErr);
}));
} else if (0.5 > r && /[A-Z]/.test(txt[i])) {
append(txt[i].toLowerCase(), (function() {
backsp(1, afterErr);
}));
} else {
elem[/(np|x)/i.test(elem.tagName) ? 'value' : 'innerHTML'] += txt[i - 1];
settings.keypress.call(elem);
setTimeout((function() {
typeTo(i + 1);
}), Math.random() * settings.t * (txt[i - 1] === txt[i] ? 1.6 : txt[i - 1] === '.' ? 12 : txt[i - 1] === '!' ? 12 : txt[i - 1] === '?' ? 12 : txt[i - 1] === '\n' ? 12 : txt[i - 1] === ',' ? 8 : txt[i - 1] === ';' ? 8 : txt[i - 1] === ':' ? 8 : txt[i - 1] === ' ' ? 3 : 2));
}
} else {
settings.callback.call(elem);
$(elem).dequeue();
}
};
typeTo(1);
});
});
}
});