/* KUTE.js - The Light Tweening Engine * by dnp_theme * Licensed under MIT-License */ (function (factory) { if (typeof define === 'function' && define.amd) { define([], factory); // AMD. Register as an anonymous module. } else if (typeof exports == 'object') { module.exports = factory(); // Node, not strict CommonJS } else { // Browser globals window.KUTE = window.KUTE || factory(); } }( function () { "use strict"; var K = K || {}, _tws = [], _t = null, getPrefix = function() { //returns browser prefix var div = document.createElement('div'), i = 0, pf = ['Moz', 'moz', 'Webkit', 'webkit', 'O', 'o', 'Ms', 'ms'], pl = pf.length, s = ['MozTransform', 'mozTransform', 'WebkitTransform', 'webkitTransform', 'OTransform', 'oTransform', 'MsTransform', 'msTransform']; for (i; i < pl; i++) { if (s[i] in div.style) { return pf[i]; } } div = null; }, property = function(p){ // returns prefixed property | property var r = (!(p in document.body.style)) ? true : false, f = getPrefix(); // is prefix required for property | prefix return r ? f + (p.charAt(0).toUpperCase() + p.slice(1)) : p; }, selector = function(el,multi){ // a selector utility var nl; if (multi){ nl = typeof el === 'object' ? el : document.querySelectorAll(el); } else { nl = typeof el === 'object' ? el : /^#/.test(el) ? document.getElementById(el.replace('#','')) : document.querySelector(el); } if (nl === null && el !== 'window') throw new TypeError('Element not found or incorrect selector: '+el); return nl; }, trueDimendion = function (d,p) { //true dimension returns { v = value, u = unit } var x = parseInt(d) || 0, mu = ['px','%','deg','rad','em','rem','vh','vw'], l = mu.length, y = getU(); function getU() { var u,i=0; for (i;i 0) { if ( w._r < 9999 ) { w._r--; } // we have to make it stop somewhere, infinity is too damn much if (w._y) { w.reversed = !w.reversed; w.rvs(); } // handle yoyo w._sT = (w._y && !w.reversed) ? t + w._rD : t; //set the right time for delay return true; } else { if (w._cC) { w._cC.call(); } w.scrollOut(); // unbind preventing scroll when scroll tween finished // start animating chained tweens var i = 0, ctl = w._cT.length; for (i; i < ctl; i++) { w._cT[i].start(w._sT + w._dr); } //stop ticking when finished w.close(); return false; } } return true; }, // applies the transform origin and perspective perspective = function (l,w) { if ( w._to !== undefined ) { l.style[_pfto] = w._to; } // element transform origin if ( w._ppo !== undefined ) { l.style[_pfo] = w._ppo; } // element perspective origin if ( w._ppp !== undefined ) { l.parentNode.style[_pfp] = w._ppp + 'px'; } // parent perspective if ( w._pppo !== undefined ) { l.parentNode.style[_pfo] = w._pppo; } // parent perspective origin }, //more internals getAll = function () { return _tws; }, removeAll = function () { _tws = []; }, add = function (tw) { _tws.push(tw); }, remove = function (tw) { var i = _tws.indexOf(tw); if (i !== -1) { _tws.splice(i, 1); }}, stop = function () { _t && _caf(_t); _t = null; }, // process properties for _vE and _vS or one of them preparePropertiesObject = function (e, s, l) { var i, pl = arguments.length, _st = []; pl = pl > 2 ? 2 : pl; for (i=0; i 0) { self._r = self.repeat; } if (self._y && self.reversed===true) { self.rvs(); self.reversed = false; } self.playing = false; },64) } }, // the multi elements Tween constructs TweensTO = function (els, vE, o) { // .to this.tweens = []; var i, tl = els.length, _o = []; for ( i = 0; i < tl; i++ ) { _o[i] = o || {}; o.delay = o.delay || 0; _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; this.tweens.push( to(els[i], vE, _o[i]) ); } }, TweensFT = function (els, vS, vE, o) { // .fromTo this.tweens = []; var i, tl = els.length, _o = []; for ( i = 0; i < tl; i++ ) { _o[i] = o || {}; o.delay = o.delay || 0; _o[i].delay = i>0 ? o.delay + (o.offset||0) : o.delay; this.tweens.push( fromTo(els[i], vS, vE, _o[i]) ); } }; var ws = TweensTO.prototype = TweensFT.prototype; ws.start = function(t){ t = t || window.performance.now(); var i, tl = this.tweens.length; for ( i = 0; i < tl; i++ ) { this.tweens[i].start(t); } return this; } ws.stop = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].stop(); } return this; } ws.pause = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].pause(); } return this; } ws.chain = function(){ this.tweens[this.tweens.length-1]._cT = arguments; return this; } ws.play = ws.resume = function(){ for ( var i = 0; i < this.tweens.length; i++ ) { this.tweens[i].play(); } return this; } var start = function (t) { // move functions that use the ticker outside the prototype to be in the same scope with it this.scrollIn(); perspective(this._el,this); // apply the perspective and transform origin if ( this._rpr ) { this.stack(); } // on start we reprocess the valuesStart for TO() method for ( var e in this._vE ) { this._vSR[e] = this._vS[e]; } // now it's a good time to start add(this); this.playing = true; this.paused = false; this._sCF = false; this._sT = t || window.performance.now(); this._sT += this._dl; if (!this._sCF) { if (this._sC) { this._sC.call(); } this._sCF = true; } if (!_t) _tk(); return this; }, play = function () { if (this.paused && this.playing) { this.paused = false; if (this._rC !== null) { this._rC.call(); } this._sT += window.performance.now() - this._pST; add(this); if (!_t) _tk(); // restart ticking if stopped } return this; }; Tween.prototype.start = start; Tween.prototype.play = Tween.prototype.resume = play; K = { // export core methods to public for plugins property: property, getPrefix: getPrefix, selector: selector, pe : pe, // utils to: to, fromTo: fromTo, allTo: allTo, allFromTo: allFromTo, // main methods Interpolate: {number: number, unit: unit, color: color }, // interpolators ?? move array & coords to svg and leave color dom: DOM, // DOM manipulation pp: parseProperty, prS: prepareStart, // init truD: trueDimendion, truC: trueColor, rth: rgbToHex, htr: hexToRGB, gCS: getComputedStyle, // property parsing Easing: easing, Tween: Tween, TweensTO: TweensTO, TweensFT: TweensFT // constructors }; return K; }));