forked from thednp/kute.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkute-text.js
71 lines (63 loc) · 2.92 KB
/
kute-text.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
/* KUTE.js - The Light Tweening Engine
* package - KUTE.js Text Plugin
* desc - adds the tween numbers incremental and cool string writing/scrambling
* by dnp_theme & @dalisoft
* Licensed under MIT-License
*/
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['kute.js'], factory);
} else if(typeof module == 'object' && typeof require == 'function') {
module.exports = factory(require('kute.js'));
} else if ( typeof root.KUTE !== 'undefined' ) {
factory(root.KUTE);
} else {
throw new Error("Text-Plugin require KUTE.js.");
}
}(this, function (KUTE) {
'use strict';
var g = typeof global !== 'undefined' ? global : window, // connect to KUTE object and global
K = KUTE, DOM = K.dom, prepareStart = K.prepareStart,
parseProperty = K.parseProperty, number = g.Interpolate.number,
defaultOptions = K.defaultOptions;
// let's go with the plugin
var _string = String("abcdefghijklmnopqrstuvwxyz").split(""), // lowercase
_stringUppercase = String("abcdefghijklmnopqrstuvwxyz".toUpperCase()).split(""), // uppercase
_symbols = String("~!@#$%^&*()_+{}[];'<>,./?\=-").split(""), // symbols
_numeric = String("0123456789").split(""), // numeric
_alphanumeric = _string.concat(_stringUppercase,_numeric), // alpha numeric
_all = _alphanumeric.concat(_symbols), // all caracters
random = Math.random, min = Math.min;
defaultOptions.textChars = 'alpha'; // set default textChars tween option since 1.6.1
prepareStart.text = prepareStart.number = function(p,v){
return this.element.innerHTML;
}
parseProperty.text = function(p,v) {
if ( !( 'text' in DOM ) ) {
DOM.text = function(l,p,a,b,v,o) {
var tp = tp || o.textChars === 'alpha' ? _string // textChars is alpha
: o.textChars === 'upper' ? _stringUppercase // textChars is numeric
: o.textChars === 'numeric' ? _numeric // textChars is numeric
: o.textChars === 'alphanumeric' ? _alphanumeric // textChars is alphanumeric
: o.textChars === 'symbols' ? _symbols // textChars is symbols
: o.textChars ? o.textChars.split('') // textChars is a custom text
: _string, ll = tp.length,
t = tp[(random() * ll)>>0], ix = '', tx = '', fi = a.substring(0), f = b.substring(0);
// use string.replace(/<\/?[^>]+(>|$)/g, "") to strip HTML tags while animating ? this is definatelly a smart TO DO
ix = a !== '' ? fi.substring(fi.length, min(v * fi.length, fi.length)>>0 ) : ''; // initial text, A value
tx = f.substring(0, min(v * f.length, f.length)>>0 ); // end text, B value
l.innerHTML = v < 1 ? tx + t + ix : b;
}
}
return v;
}
parseProperty['number'] = function(p,v,l) {
if ( !( 'number' in DOM ) ) {
DOM.number = function(l,p,a,b,v) {
l.innerHTML = number(a, b, v)>>0;
}
}
return parseInt(v) || 0;
}
return this;
}));