2016-03-18 15:23:23 +01:00
|
|
|
/* 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 (factory) {
|
|
|
|
if (typeof define === 'function' && define.amd) {
|
|
|
|
define(["./kute.js"], function(KUTE){ factory(KUTE); return KUTE; });
|
|
|
|
} else if(typeof module == "object" && typeof require == "function") {
|
|
|
|
var KUTE = require("./kute.js");
|
|
|
|
module.exports = factory(KUTE);
|
|
|
|
} else if ( typeof window.KUTE !== 'undefined' ) {
|
|
|
|
factory();
|
|
|
|
} else {
|
|
|
|
throw new Error("Text-Plugin requires KUTE.js.");
|
|
|
|
}
|
|
|
|
}( function () {
|
2016-09-03 17:35:49 +02:00
|
|
|
var K = window.KUTE, DOM = K.dom, PP = K.pp, number = K.Interpolate.number,
|
2016-03-18 15:23:23 +01:00
|
|
|
_s = String("abcdefghijklmnopqrstuvwxyz").split(""), // lowercase
|
|
|
|
_S = String("abcdefghijklmnopqrstuvwxyz".toUpperCase()).split(""), // uppercase
|
|
|
|
_sb = String("~!@#$%^&*()_+{}[];'<>,./?\=-").split(""), // symbols
|
|
|
|
_n = String("0123456789").split(""), // numeric
|
|
|
|
_a = _s.concat(_S,_n), // alpha numeric
|
|
|
|
_all = _a.concat(_sb), // all caracters
|
2016-09-03 17:35:49 +02:00
|
|
|
random = Math.random, floor = Math.floor, min = Math.min;
|
2016-03-18 15:23:23 +01:00
|
|
|
|
|
|
|
K.prS['text'] = K.prS['number'] = function(l,p,v){
|
|
|
|
return l.innerHTML;
|
|
|
|
}
|
|
|
|
|
2016-09-03 17:35:49 +02:00
|
|
|
PP['text'] = function(p,v,l) {
|
|
|
|
if ( !( 'text' in DOM ) ) {
|
|
|
|
DOM['text'] = function(l,p,a,b,v,o) {
|
|
|
|
var tp = tp || o.textChars === 'alpha' ? _s // textChars is alpha
|
|
|
|
: o.textChars === 'upper' ? _S // textChars is numeric
|
|
|
|
: o.textChars === 'numeric' ? _n // textChars is numeric
|
|
|
|
: o.textChars === 'alphanumeric' ? _a // textChars is alphanumeric
|
|
|
|
: o.textChars === 'symbols' ? _sb // textChars is symbols
|
|
|
|
: o.textChars ? o.textChars.split('') // textChars is a custom text
|
|
|
|
: _s, ll = tp.length,
|
|
|
|
t = tp[floor((random() * ll))], ix = '', tx = '', fi = a.substring(0), f = b.substring(0);
|
2016-03-18 15:23:23 +01:00
|
|
|
|
2016-09-03 17:35:49 +02:00
|
|
|
// use string.replace(/<\/?[^>]+(>|$)/g, "") to strip HTML tags while animating ?
|
|
|
|
ix = a !== '' ? fi.substring(fi.length,floor(min(v * fi.length, fi.length))) : ''; // initial text, A value
|
|
|
|
tx = f.substring(0,floor(min(v * f.length, f.length))); // end text, B value
|
|
|
|
l.innerHTML = v < 1 ? tx + t + ix : b;
|
2016-03-18 15:23:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2016-09-03 17:35:49 +02:00
|
|
|
PP['number'] = function(p,v,l) {
|
|
|
|
if ( !( 'number' in DOM ) ) {
|
|
|
|
DOM['number'] = function(l,p,a,b,v) {
|
|
|
|
l.innerHTML = parseInt( number(a, b, v));
|
2016-03-18 15:23:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return parseInt(v) || 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}));
|