1/*! 2* VERSION: 2.1.3 3* DATE: 2019-05-17 4* UPDATES AND DOCS AT: http://greensock.com 5* 6* @license Copyright (c) 2008-2019, GreenSock. All rights reserved. 7* This work is subject to the terms at http://greensock.com/standard-license or for 8* Club GreenSock members, the software agreement that was issued with your membership. 9* 10* @author: Jack Doyle, [email protected] 11*/ 12// jshint ignore: start 13(function(window, moduleName) { 14 15 "use strict"; 16 var _exports = {}, 17 _doc = window.document, 18 _globals = window.GreenSockGlobals = window.GreenSockGlobals || window, 19 existingModule = _globals[moduleName]; 20 if (existingModule) { 21 if (typeof(module) !== "undefined" && module.exports) { //node 22 module.exports = existingModule; 23 } 24 return existingModule; //in case the core set of classes is already loaded, don't instantiate twice. 25 } 26 var _namespace = function(ns) { 27 var a = ns.split("."), 28 p = _globals, i; 29 for (i = 0; i < a.length; i++) { 30 p[a[i]] = p = p[a[i]] || {}; 31 } 32 return p; 33 }, 34 gs = _namespace("com.greensock"), 35 _tinyNum = 0.00000001, 36 _slice = function(a) { //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll() 37 var b = [], 38 l = a.length, 39 i; 40 for (i = 0; i !== l; b.push(a[i++])) {} 41 return b; 42 }, 43 _emptyFunc = function() {}, 44 _isArray = (function() { //works around issues in iframe environments where the Array global isn't shared, thus if the object originates in a different window/iframe, "(obj instanceof Array)" will evaluate false. We added some speed optimizations to avoid Object.prototype.toString.call() unless it's absolutely necessary because it's VERY slow (like 20x slower) 45 var toString = Object.prototype.toString, 46 array = toString.call([]); 47 return function(obj) { 48 return obj != null && (obj instanceof Array || (typeof(obj) === "object" && !!obj.push && toString.call(obj) === array)); 49 }; 50 }()), 51 a, i, p, _ticker, _tickerActive, 52 _defLookup = {}, 53 54 /** 55 * @constructor 56 * Defines a GreenSock class, optionally with an array of dependencies that must be instantiated first and passed into the definition. 57 * This allows users to load GreenSock JS files in any order even if they have interdependencies (like CSSPlugin extends TweenPlugin which is 58 * inside TweenLite.js, but if CSSPlugin is loaded first, it should wait to run its code until TweenLite.js loads and instantiates TweenPlugin 59 * and then pass TweenPlugin to CSSPlugin's definition). This is all done automatically and internally. 60 * 61 * Every definition will be added to a "com.greensock" global object (typically window, but if a window.GreenSockGlobals object is found, 62 * it will go there as of v1.7). For example, TweenLite will be found at window.com.greensock.TweenLite and since it's a global class that should be available anywhere, 63 * it is ALSO referenced at window.TweenLite. However some classes aren't considered global, like the base com.greensock.core.Animation class, so 64 * those will only be at the package like window.com.greensock.core.Animation. Again, if you define a GreenSockGlobals object on the window, everything 65 * gets tucked neatly inside there instead of on the window directly. This allows you to do advanced things like load multiple versions of GreenSock 66 * files and put them into distinct objects (imagine a banner ad uses a newer version but the main site uses an older one). In that case, you could 67 * sandbox the banner one like: 68 * 69 * <script> 70 * var gs = window.GreenSockGlobals = {}; //the newer version we're about to load could now be referenced in a "gs" object, like gs.TweenLite.to(...). Use whatever alias you want as long as it's unique, "gs" or "banner" or whatever. 71 * </script> 72 * <script src="js/greensock/v1.7/TweenMax.js"></script> 73 * <script> 74 * window.GreenSockGlobals = window._gsQueue = window._gsDefine = null; //reset it back to null (along with the special _gsQueue variable) so that the next load of TweenMax affects the window and we can reference things directly like TweenLite.to(...) 75 * </script> 76 * <script src="js/greensock/v1.6/TweenMax.js"></script> 77 * <script> 78 * gs.TweenLite.to(...); //would use v1.7 79 * TweenLite.to(...); //would use v1.6 80 * </script> 81 * 82 * @param {!string} ns The namespace of the class definition, leaving off "com.greensock." as that's assumed. For example, "TweenLite" or "plugins.CSSPlugin" or "easing.Back". 83 * @param {!Array.<string>}
83 dependencies An array of dependencies (described as their namespaces minus "com.greensock." prefix). For example ["TweenLite","plugins.TweenPlugin","core.Animation"] 84 * @param {!function():Object} func The function that should be called and passed the resolved dependencies which will return the actual class for this definition. 85 * @param {boolean=} global If true, the class will be added to the global scope (typically window unless you define a window.GreenSockGlobals object) 86 */ 87 Definition = function(ns, dependencies, func, global) { 88 this.sc = (_defLookup[ns]) ? _defLookup[ns].sc : []; //subclasses 89 _defLookup[ns] = this; 90 this.gsClass = null; 91 this.func = func; 92 var _classes = []; 93 this.check = function(init) { 94 var i = dependencies.length, 95 missing = i, 96 cur, a, n, cl; 97 while (--i > -1) { 98 if ((cur = _defLookup[dependencies[i]] || new Definition(dependencies[i], [])).gsClass) { 99 _classes[i] = cur.gsClass; 100 missing--; 101 } else if (init) { 102 cur.sc.push(this); 103 } 104 } 105 if (missing === 0 && func) { 106 a = ("com.greensock." + ns).split("."); 107 n = a.pop(); 108 cl = _namespace(a.join("."))[n] = this.gsClass = func.apply(func, _classes); 109 110 //exports to multiple environments 111 if (global) { 112 _globals[n] = _exports[n] = cl; //provides a way to avoid global namespace pollution. By default, the main classes like TweenLite, Power1, Strong, etc. are added to window unless a GreenSockGlobals is defined. So if you want to have things added to a custom object instead, just do something like window.GreenSockGlobals = {} before loading any GreenSock files. You can even set up an alias like window.GreenSockGlobals = windows.gs = {} so that you can access everything like gs.TweenLite. Also remember that ALL classes are added to the window.com.greensock object (in their respective packages, like com.greensock.easing.Power1, com.greensock.TweenLite, etc.) 113 if (typeof(module) !== "undefined" && module.exports) { //node 114 if (ns === moduleName) { 115 module.exports = _exports[moduleName] = cl; 116 for (i in _exports) { 117 cl[i] = _exports[i]; 118 } 119 } else if (_exports[moduleName]) { 120 _exports[moduleName][n] = cl; 121 } 122 } else if (typeof(define) === "function" && define.amd){ //AMD 123 define((window.GreenSockAMDPath ? window.GreenSockAMDPath + "/" : "") + ns.split(".").pop(), [], function() { return cl; }); 124 } 125 } 126 for (i = 0; i < this.sc.length; i++) { 127 this.sc[i].check(); 128 } 129 } 130 }; 131 this.check(true); 132 }, 133 134 //used to create Definition instances (which basically registers a class that has dependencies). 135 _gsDefine = window._gsDefine = function(ns, dependencies, func, global) { 136 return new Definition(ns, dependencies, func, global); 137 }, 138 139 //a quick way to create a class that doesn't have any dependencies. Returns the class, but first registers it in the GreenSock namespace so that other classes can grab it (other classes might be dependent on the class). 140 _class = gs._class = function(ns, func, global) { 141 func = func || function() {}; 142 _gsDefine(ns, [], function(){ return func; }, global); 143 return func; 144 }; 145 146 _gsDefine.globals = _globals; 147 148 149 150/* 151* ---------------------------------------------------------------- 152* Ease 153* ---------------------------------------------------------------- 154*/ 155 var _baseParams = [0, 0, 1, 1], 156 Ease = _class("easing.Ease", function(func, extraParams, type, power) { 157 this._func = func; 158 this._type = type || 0; 159 this._power = power || 0; 160 this._params = extraParams ? _baseParams.concat(extraParams) : _baseParams; 161 }, true), 162 _easeMap = Ease.map = {}, 163 _easeReg = Ease.register = function(ease, names, types, create) { 164 var na = names.split(","), 165 i = na.length, 166 ta = (types || "easeIn,easeOut,easeInOut").split(","), 167 e, name, j, type; 168 while (--i > -1) { 169 name = na[i]; 170 e = create ? _class("easing."+name, null, true) : gs.easing[name] || {}; 171 j = ta.length; 172 while (--j > -1) { 173 type = ta[j]; 174 _easeMap[name + "." + type] = _easeMap[type + name] = e[type] = ease.getRatio ? ease : ease[type] || new ease(); 175 } 176 } 177 }; 178 179 p = Ease.prototype; 180 p._calcEnd = false; 181 p.getRatio = function(p) { 182 if (this._func) { 183 this._params[0] = p; 184 return this._func.apply(null, this._params); 185 } 186 var t = this._type, 187 pw = this._power,
188 r = (t === 1) ? 1 - p : (t === 2) ? p : (p < 0.5) ? p * 2 : (1 - p) * 2; 189 if (pw === 1) { 190 r *= r; 191 } else if (pw === 2) { 192 r *= r * r; 193 } else if (pw === 3) { 194 r *= r * r * r; 195 } else if (pw === 4) { 196 r *= r * r * r * r; 197 } 198 return (t === 1) ? 1 - r : (t === 2) ? r : (p < 0.5) ? r / 2 : 1 - (r / 2); 199 }; 200 201 //create all the standard eases like Linear, Quad, Cubic, Quart, Quint, Strong, Power0, Power1, Power2, Power3, and Power4 (each with easeIn, easeOut, and easeInOut) 202 a = ["Linear","Quad","Cubic","Quart","Quint,Strong"]; 203 i = a.length; 204 while (--i > -1) { 205 p = a[i]+",Power"+i; 206 _easeReg(new Ease(null,null,1,i), p, "easeOut", true); 207 _easeReg(new Ease(null,null,2,i), p, "easeIn" + ((i === 0) ? ",easeNone" : "")); 208 _easeReg(new Ease(null,null,3,i), p, "easeInOut"); 209 } 210 _easeMap.linear = gs.easing.Linear.easeIn; 211 _easeMap.swing = gs.easing.Quad.easeInOut; //for jQuery folks 212 213 214/* 215* ---------------------------------------------------------------- 216* EventDispatcher 217* ---------------------------------------------------------------- 218*/ 219 var EventDispatcher = _class("events.EventDispatcher", function(target) { 220 this._listeners = {}; 221 this._eventTarget = target || this; 222 }); 223 p = EventDispatcher.prototype; 224 225 p.addEventListener = function(type, callback, scope, useParam, priority) { 226 priority = priority || 0; 227 var list = this._listeners[type], 228 index = 0, 229 listener, i; 230 if (this === _ticker && !_tickerActive) { 231 _ticker.wake(); 232 } 233 if (list == null) { 234 this._listeners[type] = list = []; 235 } 236 i = list.length; 237 while (--i > -1) { 238 listener = list[i]; 239 if (listener.c === callback && listener.s === scope) { 240 list.splice(i, 1); 241 } else if (index === 0 && listener.pr < priority) { 242 index = i + 1; 243 } 244 } 245 list.splice(index, 0, {c:callback, s:scope, up:useParam, pr:priority}); 246 }; 247 248 p.removeEventListener = function(type, callback) { 249 var list = this._listeners[type], i; 250 if (list) { 251 i = list.length; 252 while (--i > -1) { 253 if (list[i].c === callback) { 254 list.splice(i, 1); 255 return; 256 } 257 } 258 } 259 }; 260 261 p.dispatchEvent = function(type) { 262 var list = this._listeners[type], 263 i, t, listener; 264 if (list) { 265 i = list.length; 266 if (i > 1) { 267 list = list.slice(0); //in case addEventListener() is called from within a listener/callback (otherwise the index could change, resulting in a skip) 268 } 269 t = this._eventTarget; 270 while (--i > -1) { 271 listener = list[i]; 272 if (listener) { 273 if (listener.up) { 274 listener.c.call(listener.s || t, {type:type, target:t}); 275 } else { 276 listener.c.call(listener.s || t); 277 } 278 } 279 } 280 } 281 }; 282 283 284/* 285* ---------------------------------------------------------------- 286* Ticker 287* ---------------------------------------------------------------- 288*/ 289 var _reqAnimFrame = window.requestAnimationFrame, 290 _cancelAnimFrame = window.cancelAnimationFrame, 291 _getTime = Date.now || function() {return new Date().getTime();}, 292 _lastUpdate = _getTime(); 293 294 //now try to determine the requestAnimationFrame and cancelAnimationFrame functions and if none are found, we'll use a setTimeout()/clearTimeout() polyfill. 295 a = ["ms","moz","webkit","o"]; 296 i = a.length; 297 while (--i > -1 && !_reqAnimFrame) { 298 _reqAnimFrame = window[a[i] + "RequestAnimationFrame"]; 299 _cancelAnimFrame = window[a[i] + "CancelAnimationFrame"] || window[a[i] + "CancelRequestAnimationFrame"]; 300 } 301 302 _class("Ticker", function(fps, useRAF) { 303 var _self = this, 304 _startTime = _getTime(), 305 _useRAF = (useRAF !== false && _reqAnimFrame) ? "auto" : false, 306 _lagThreshold = 500, 307 _adjustedLag = 33, 308 _tickWord = "tick", //helps reduce gc burden 309 _fps, _req, _id, _gap, _nextTime, 310 _tick = function(manual) { 311 var elapsed = _getTime() - _lastUpdate, 312 overlap, dispatch; 313 if (elapsed > _lagThreshold) { 314 _startTime += elapsed - _adjustedLag; 315 } 316 _lastUpdate += elapsed; 317 _self.time = (_lastUpdate - _startTime) / 1000; 318 overlap = _self.time - _nextTime; 319 if (!_fps || overlap > 0 || manual === true) { 320 _self.frame++; 321 _nextTime += overlap + (overlap >= _gap ? 0.004 : _gap - overlap); 322 dispatch = true; 323 } 324 if (manual !== true) { //make sure the request is made before we dispatch the "tick" event so that timing is maintained. Otherwise, if processing the "tick" requires a bunch of time (like 15ms) and we're using a setTimeout() that's based on 16.7ms, it'd technically take 31.7ms between frames otherwise. 325 _id = _req(_tick); 326 }
327 if (dispatch) { 328 _self.dispatchEvent(_tickWord); 329 } 330 }; 331 332 EventDispatcher.call(_self); 333 _self.time = _self.frame = 0; 334 _self.tick = function() { 335 _tick(true); 336 }; 337 338 _self.lagSmoothing = function(threshold, adjustedLag) { 339 if (!arguments.length) { //if lagSmoothing() is called with no arguments, treat it like a getter that returns a boolean indicating if it's enabled or not. This is purposely undocumented and is for internal use. 340 return (_lagThreshold < 1 / _tinyNum); 341 } 342 _lagThreshold = threshold || (1 / _tinyNum); //zero should be interpreted as basically unlimited 343 _adjustedLag = Math.min(adjustedLag, _lagThreshold, 0); 344 }; 345 346 _self.sleep = function() { 347 if (_id == null) { 348 return; 349 } 350 if (!_useRAF || !_cancelAnimFrame) { 351 clearTimeout(_id); 352 } else { 353 _cancelAnimFrame(_id); 354 } 355 _req = _emptyFunc; 356 _id = null; 357 if (_self === _ticker) { 358 _tickerActive = false; 359 } 360 }; 361 362 _self.wake = function(seamless) { 363 if (_id !== null) { 364 _self.sleep(); 365 } else if (seamless) { 366 _startTime += -_lastUpdate + (_lastUpdate = _getTime()); 367 } else if (_self.frame > 10) { //don't trigger lagSmoothing if we're just waking up, and make sure that at least 10 frames have elapsed because of the iOS bug that we work around below with the 1.5-second setTimout(). 368 _lastUpdate = _getTime() - _lagThreshold + 5; 369 } 370 _req = (_fps === 0) ? _emptyFunc : (!_useRAF || !_reqAnimFrame) ? function(f) { return setTimeout(f, ((_nextTime - _self.time) * 1000 + 1) | 0); } : _reqAnimFrame; 371 if (_self === _ticker) { 372 _tickerActive = true; 373 } 374 _tick(2); 375 }; 376 377 _self.fps = function(value) { 378 if (!arguments.length) { 379 return _fps; 380 } 381 _fps = value; 382 _gap = 1 / (_fps || 60); 383 _nextTime = this.time + _gap; 384 _self.wake(); 385 }; 386 387 _self.useRAF = function(value) { 388 if (!arguments.length) { 389 return _useRAF; 390 } 391 _self.sleep(); 392 _useRAF = value; 393 _self.fps(_fps); 394 }; 395 _self.fps(fps); 396 397 //a bug in iOS 6 Safari occasionally prevents the requestAnimationFrame from working initially, so we use a 1.5-second timeout that automatically falls back to setTimeout() if it senses this condition. 398 setTimeout(function() { 399 if (_useRAF === "auto" && _self.frame < 5 && (_doc || {}).visibilityState !== "hidden") { 400 _self.useRAF(false); 401 } 402 }, 1500); 403 }); 404 405 p = gs.Ticker.prototype = new gs.events.EventDispatcher(); 406 p.constructor = gs.Ticker; 407 408 409/* 410* ---------------------------------------------------------------- 411* Animation 412* ---------------------------------------------------------------- 413*/ 414 var Animation = _class("core.Animation", function(duration, vars) { 415 this.vars = vars = vars || {}; 416 this._duration = this._totalDuration = duration || 0; 417 this._delay = Number(vars.delay) || 0; 418 this._timeScale = 1; 419 this._active = !!vars.immediateRender; 420 this.data = vars.data; 421 this._reversed = !!vars.reversed; 422 423 if (!_rootTimeline) { 424 return; 425 } 426 if (!_tickerActive) { //some browsers (like iOS 6 Safari) shut down JavaScript execution when the tab is disabled and they [occasionally] neglect to start up requestAnimationFrame again when returning - this code ensures that the engine starts up again properly. 427 _ticker.wake(); 428 } 429 430 var tl = this.vars.useFrames ? _rootFramesTimeline : _rootTimeline; 431 tl.add(this, tl._time); 432 433 if (this.vars.paused) { 434 this.paused(true); 435 } 436 }); 437 438 _ticker = Animation.ticker = new gs.Ticker(); 439 p = Animation.prototype; 440 p._dirty = p._gc = p._initted = p._paused = false; 441 p._totalTime = p._time = 0; 442 p._rawPrevTime = -1; 443 p._next = p._last = p._onUpdate = p._timeline = p.timeline = null; 444 p._paused = false; 445 446 447 //some browsers (like iOS) occasionally drop the requestAnimationFrame event when the user switches to a different tab and then comes back again, so we use a 2-second setTimeout() to sense if/when that condition occurs and then wake() the ticker. 448 var _checkTimeout = function() { 449 if (_tickerActive && _getTime() - _lastUpdate > 2000 && ((_doc || {}).visibilityState !== "hidden" || !_ticker.lagSmoothing())) { //note: if the tab is hidden, we should still wake if lagSmoothing has been disabled. 450 _ticker.wake(); 451 } 452 var t = setTimeout(_checkTimeout, 2000); 453 if (t.unref) { 454 // allows a node process to exit even if the timeoutâs callback hasn't been invoked. Without it, the node process could hang as this function is called every two seconds. 455 t.unref(); 456 } 457 };
458 _checkTimeout(); 459 460 461 p.play = function(from, suppressEvents) { 462 if (from != null) { 463 this.seek(from, suppressEvents); 464 } 465 return this.reversed(false).paused(false); 466 }; 467 468 p.pause = function(atTime, suppressEvents) { 469 if (atTime != null) { 470 this.seek(atTime, suppressEvents); 471 } 472 return this.paused(true); 473 }; 474 475 p.resume = function(from, suppressEvents) { 476 if (from != null) { 477 this.seek(from, suppressEvents); 478 } 479 return this.paused(false); 480 }; 481 482 p.seek = function(time, suppressEvents) { 483 return this.totalTime(Number(time), suppressEvents !== false); 484 }; 485 486 p.restart = function(includeDelay, suppressEvents) { 487 return this.reversed(false).paused(false).totalTime(includeDelay ? -this._delay : 0, (suppressEvents !== false), true); 488 }; 489 490 p.reverse = function(from, suppressEvents) { 491 if (from != null) { 492 this.seek((from || this.totalDuration()), suppressEvents); 493 } 494 return this.reversed(true).paused(false); 495 }; 496 497 p.render = function() { 498 //stub - we override this method in subclasses. 499 }; 500 501 p.invalidate = function() { 502 this._time = this._totalTime = 0; 503 this._initted = this._gc = false; 504 this._rawPrevTime = -1; 505 if (this._gc || !this.timeline) { 506 this._enabled(true); 507 } 508 return this; 509 }; 510 511 p.isActive = function() { 512 var tl = this._timeline, //the 2 root timelines won't have a _timeline; they're always active. 513 startTime = this._startTime, 514 rawTime; 515 return (!tl || (!this._gc && !this._paused && tl.isActive() && (rawTime = tl.rawTime(true)) >= startTime && rawTime < startTime + this.totalDuration() / this._timeScale - _tinyNum)); 516 }; 517 518 p._enabled = function (enabled, ignoreTimeline) { 519 if (!_tickerActive) { 520 _ticker.wake(); 521 } 522 this._gc = !enabled; 523 this._active = this.isActive(); 524 if (ignoreTimeline !== true) { 525 if (enabled && !this.timeline) { 526 this._timeline.add(this, this._startTime - this._delay); 527 } else if (!enabled && this.timeline) { 528 this._timeline._remove(this, true); 529 } 530 } 531 return false; 532 }; 533 534 535 p._kill = function() { 536 return this._enabled(false, false); 537 }; 538 539 p.kill = function(vars, target) { 540 this._kill(vars, target); 541 return this; 542 }; 543 544 p._uncache = function(includeSelf) { 545 var tween = includeSelf ? this : this.timeline; 546 while (tween) { 547 tween._dirty = true; 548 tween = tween.timeline; 549 } 550 return this; 551 }; 552 553 p._swapSelfInParams = function(params) { 554 var i = params.length, 555 copy = params.concat(); 556 while (--i > -1) { 557 if (params[i] === "{self}") { 558 copy[i] = this; 559 } 560 } 561 return copy; 562 }; 563 564 p._callback = function(type) { 565 var v = this.vars, 566 callback = v[type], 567 params = v[type + "Params"], 568 scope = v[type + "Scope"] || v.callbackScope || this, 569 l = params ? params.length : 0; 570 switch (l) { //speed optimization; call() is faster than apply() so use it when there are only a few parameters (which is by far most common). Previously we simply did var v = this.vars; v[type].apply(v[type + "Scope"] || v.callbackScope || this, v[type + "Params"] || _blankArray); 571 case 0: callback.call(scope); break; 572 case 1: callback.call(scope, params[0]); break; 573 case 2: callback.call(scope, params[0], params[1]); break; 574 default: callback.apply(scope, params); 575 } 576 }; 577 578//----Animation getters/setters -------------------------------------------------------- 579 580 p.eventCallback = function(type, callback, params, scope) { 581 if ((type || "").substr(0,2) === "on") { 582 var v = this.vars; 583 if (arguments.length === 1) { 584 return v[type]; 585 } 586 if (callback == null) { 587 delete v[type]; 588 } else { 589 v[type] = callback; 590 v[type + "Params"] = (_isArray(params) && params.join("").indexOf("{self}") !== -1) ? this._swapSelfInParams(params) : params; 591 v[type + "Scope"] = scope; 592 } 593 if (type === "onUpdate") { 594 this._onUpdate = callback; 595 } 596 } 597 return this; 598 }; 599 600 p.delay = function(value) { 601 if (!arguments.length) { 602 return this._delay; 603 } 604 if (this._timeline.smoothChildTiming) { 605 this.startTime( this._startTime + value - this._delay ); 606 }
607 this._delay = value; 608 return this; 609 }; 610 611 p.duration = function(value) { 612 if (!arguments.length) { 613 this._dirty = false; 614 return this._duration; 615 } 616 this._duration = this._totalDuration = value; 617 this._uncache(true); //true in case it's a TweenMax or TimelineMax that has a repeat - we'll need to refresh the totalDuration. 618 if (this._timeline.smoothChildTiming) if (this._time > 0) if (this._time < this._duration) if (value !== 0) { 619 this.totalTime(this._totalTime * (value / this._duration), true); 620 } 621 return this; 622 }; 623 624 p.totalDuration = function(value) { 625 this._dirty = false; 626 return (!arguments.length) ? this._totalDuration : this.duration(value); 627 }; 628 629 p.time = function(value, suppressEvents) { 630 if (!arguments.length) { 631 return this._time; 632 } 633 if (this._dirty) { 634 this.totalDuration(); 635 } 636 return this.totalTime((value > this._duration) ? this._duration : value, suppressEvents); 637 }; 638 639 p.totalTime = function(time, suppressEvents, uncapped) { 640 if (!_tickerActive) { 641 _ticker.wake(); 642 } 643 if (!arguments.length) { 644 return this._totalTime; 645 } 646 if (this._timeline) { 647 if (time < 0 && !uncapped) { 648 time += this.totalDuration(); 649 } 650 if (this._timeline.smoothChildTiming) { 651 if (this._dirty) { 652 this.totalDuration(); 653 } 654 var totalDuration = this._totalDuration, 655 tl = this._timeline; 656 if (time > totalDuration && !uncapped) { 657 time = totalDuration; 658 } 659 this._startTime = (this._paused ? this._pauseTime : tl._time) - ((!this._reversed ? time : totalDuration - time) / this._timeScale); 660 if (!tl._dirty) { //for performance improvement. If the parent's cache is already dirty, it already took care of marking the ancestors as dirty too, so skip the function call here. 661 this._uncache(false); 662 } 663 //in case any of the ancestor timelines had completed but should now be enabled, we should reset their totalTime() which will also ensure that they're lined up properly and enabled. Skip for animations that are on the root (wasteful). Example: a TimelineLite.exportRoot() is performed when there's a paused tween on the root, the export will not complete until that tween is unpaused, but imagine a child gets restarted later, after all [unpaused] tweens have completed. The startTime of that child would get pushed out, but one of the ancestors may have completed. 664 if (tl._timeline) { 665 while (tl._timeline) { 666 if (tl._timeline._time !== (tl._startTime + tl._totalTime) / tl._timeScale) { 667 tl.totalTime(tl._totalTime, true); 668 } 669 tl = tl._timeline; 670 } 671 } 672 } 673 if (this._gc) { 674 this._enabled(true, false); 675 } 676 if (this._totalTime !== time || this._duration === 0) { 677 if (_lazyTweens.length) { 678 _lazyRender(); 679 } 680 this.render(time, suppressEvents, false); 681 if (_lazyTweens.length) { //in case rendering caused any tweens to lazy-init, we should render them because typically when someone calls seek() or time() or progress(), they expect an immediate render. 682 _lazyRender(); 683 } 684 } 685 } 686 return this; 687 }; 688 689 p.progress = p.totalProgress = function(value, suppressEvents) { 690 var duration = this.duration(); 691 return (!arguments.length) ? (duration ? this._time / duration : this.ratio) : this.totalTime(duration * value, suppressEvents); 692 }; 693 694 p.startTime = function(value) { 695 if (!arguments.length) { 696 return this._startTime; 697 } 698 if (value !== this._startTime) { 699 this._startTime = value; 700 if (this.timeline) if (this.timeline._sortChildren) { 701 this.timeline.add(this, value - this._delay); //ensures that any necessary re-sequencing of Animations in the timeline occurs to make sure the rendering order is correct. 702 } 703 } 704 return this; 705 }; 706 707 p.endTime = function(includeRepeats) { 708 return this._startTime + ((includeRepeats != false) ? this.totalDuration() : this.duration()) / this._timeScale; 709 }; 710 711 p.timeScale = function(value) { 712 if (!arguments.length) { 713 return this._timeScale; 714 } 715 var pauseTime, t; 716 value = value || _tinyNum; //can't allow zero because it'll throw the math off
717 if (this._timeline && this._timeline.smoothChildTiming) { 718 pauseTime = this._pauseTime; 719 t = (pauseTime || pauseTime === 0) ? pauseTime : this._timeline.totalTime(); 720 this._startTime = t - ((t - this._startTime) * this._timeScale / value); 721 } 722 this._timeScale = value; 723 t = this.timeline; 724 while (t && t.timeline) { //must update the duration/totalDuration of all ancestor timelines immediately in case in the middle of a render loop, one tween alters another tween's timeScale which shoves its startTime before 0, forcing the parent timeline to shift around and shiftChildren() which could affect that next tween's render (startTime). Doesn't matter for the root timeline though. 725 t._dirty = true; 726 t.totalDuration(); 727 t = t.timeline; 728 } 729 return this; 730 }; 731 732 p.reversed = function(value) { 733 if (!arguments.length) { 734 return this._reversed; 735 } 736 if (value != this._reversed) { 737 this._reversed = value; 738 this.totalTime(((this._timeline && !this._timeline.smoothChildTiming) ? this.totalDuration() - this._totalTime : this._totalTime), true); 739 } 740 return this; 741 }; 742 743 p.paused = function(value) { 744 if (!arguments.length) { 745 return this._paused; 746 } 747 var tl = this._timeline, 748 raw, elapsed; 749 if (value != this._paused) if (tl) { 750 if (!_tickerActive && !value) { 751 _ticker.wake(); 752 } 753 raw = tl.rawTime();
754 elapsed = raw - this._pauseTime; 755 if (!value && tl.smoothChildTiming) { 756 this._startTime += elapsed; 757 this._uncache(false); 758 } 759 this._pauseTime = value ? raw : null; 760 this._paused = value; 761 this._active = this.isActive(); 762 if (!value && elapsed !== 0 && this._initted && this.duration()) { 763 raw = tl.smoothChildTiming ? this._totalTime : (raw - this._startTime) / this._timeScale; 764 this.render(raw, (raw === this._totalTime), true); //in case the target's properties changed via some other tween or manual update by the user, we should force a render. 765 } 766 } 767 if (this._gc && !value) { 768 this._enabled(true, false); 769 } 770 return this; 771 }; 772 773 774/* 775* ---------------------------------------------------------------- 776* SimpleTimeline 777* ---------------------------------------------------------------- 778*/ 779 var SimpleTimeline = _class("core.SimpleTimeline", function(vars) { 780 Animation.call(this, 0, vars); 781 this.autoRemoveChildren = this.smoothChildTiming = true; 782 }); 783 784 p = SimpleTimeline.prototype = new Animation(); 785 p.constructor = SimpleTimeline; 786 p.kill()._gc = false; 787 p._first = p._last = p._recent = null; 788 p._sortChildren = false; 789 790 p.add = p.insert = function(child, position) { 791 var prevTween, st; 792 child._startTime = Number(position || 0) + child._delay; 793 if (child._paused) if (this !== child._timeline) { //we only adjust the _pauseTime if it wasn't in this timeline already. Remember, sometimes a tween will be inserted again into the same timeline when its startTime is changed so that the tweens in the TimelineLite/Max are re-ordered properly in the linked list (so everything renders in the proper order). 794 child._pauseTime = this.rawTime() - (child._timeline.rawTime() - child._pauseTime); 795 } 796 if (child.timeline) { 797 child.timeline._remove(child, true); //removes from existing timeline so that it can be properly added to this one. 798 } 799 child.timeline = child._timeline = this; 800 if (child._gc) { 801 child._enabled(true, true); 802 } 803 prevTween = this._last; 804 if (this._sortChildren) { 805 st = child._startTime; 806 while (prevTween && prevTween._startTime > st) { 807 prevTween = prevTween._prev; 808 } 809 } 810 if (prevTween) { 811 child._next = prevTween._next; 812 prevTween._next = child; 813 } else { 814 child._next = this._first; 815 this._first = child; 816 } 817 if (child._next) { 818 child._next._prev = child; 819 } else { 820 this._last = child; 821 } 822 child._prev = prevTween; 823 this._recent = child; 824 if (this._timeline) { 825 this._uncache(true); 826 } 827 return this; 828 }; 829 830 p._remove = function(tween, skipDisable) { 831 if (tween.timeline === this) { 832 if (!skipDisable) { 833 tween._enabled(false, true); 834 } 835 836 if (tween._prev) { 837 tween._prev._next = tween._next; 838 } else if (this._first === tween) { 839 this._first = tween._next; 840 } 841 if (tween._next) { 842 tween._next._prev = tween._prev; 843 } else if (this._last === tween) { 844 this._last = tween._prev; 845 } 846 tween._next = tween._prev = tween.timeline = null; 847 if (tween === this._recent) { 848 this._recent = this._last; 849 } 850 851 if (this._timeline) { 852 this._uncache(true); 853 } 854 } 855 return this; 856 }; 857 858 p.render = function(time, suppressEvents, force) { 859 var tween = this._first, 860 next; 861 this._totalTime = this._time = this._rawPrevTime = time; 862 while (tween) { 863 next = tween._next; //record it here because the value could change after rendering... 864 if (tween._active || (time >= tween._startTime && !tween._paused && !tween._gc)) { 865 if (!tween._reversed) { 866 tween.render((time - tween._startTime) * tween._timeScale, suppressEvents, force); 867 } else { 868 tween.render(((!tween._dirty) ? tween._totalDuration : tween.totalDuration()) - ((time - tween._startTime) * tween._timeScale), suppressEvents, force); 869 } 870 } 871 tween = next; 872 } 873 }; 874 875 p.rawTime = function() { 876 if (!_tickerActive) { 877 _ticker.wake(); 878 } 879 return this._totalTime; 880 }; 881 882/* 883* ---------------------------------------------------------------- 884* TweenLite 885* ---------------------------------------------------------------- 886*/ 887 var TweenLite = _class("TweenLite", function(target, duration, vars) { 888 Animation.call(this, duration, vars); 889 this.render = TweenLite.prototype.render; //speed optimization (avoid prototype lookup on this "hot" method) 890 891 if (target == null) { 892 throw "Cannot tween a null target."; 893 } 894 895 this.target = target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target; 896 897 var isSelector = (target.jquery || (target.length && target !== window && target[0] && (target[0] === window || (target[0].nodeType && target[0].style && !target.nodeType)))),
898 overwrite = this.vars.overwrite, 899 i, targ, targets; 900 901 this._overwrite = overwrite = (overwrite == null) ? _overwriteLookup[TweenLite.defaultOverwrite] : (typeof(overwrite) === "number") ? overwrite >> 0 : _overwriteLookup[overwrite]; 902 903 if ((isSelector || target instanceof Array || (target.push && _isArray(target))) && typeof(target[0]) !== "number") { 904 this._targets = targets = _slice(target); //don't use Array.prototype.slice.call(target, 0) because that doesn't work in IE8 with a NodeList that's returned by querySelectorAll() 905 this._propLookup = []; 906 this._siblings = []; 907 for (i = 0; i < targets.length; i++) { 908 targ = targets[i]; 909 if (!targ) { 910 targets.splice(i--, 1); 911 continue; 912 } else if (typeof(targ) === "string") { 913 targ = targets[i--] = TweenLite.selector(targ); //in case it's an array of strings 914 if (typeof(targ) === "string") { 915 targets.splice(i+1, 1); //to avoid an endless loop (can't imagine why the selector would return a string, but just in case) 916 } 917 continue; 918 } else if (targ.length && targ !== window && targ[0] && (targ[0] === window || (targ[0].nodeType && targ[0].style && !targ.nodeType))) { //in case the user is passing in an array of selector objects (like jQuery objects), we need to check one more level and pull things out if necessary. Also note that <select> elements pass all the criteria regarding length and the first child having style, so we must also check to ensure the target isn't an HTML node itself. 919 targets.splice(i--, 1); 920 this._targets = targets = targets.concat(_slice(targ)); 921 continue; 922 } 923 this._siblings[i] = _register(targ, this, false); 924 if (overwrite === 1) if (this._siblings[i].length > 1) { 925 _applyOverwrite(targ, this, null, 1, this._siblings[i]); 926 } 927 } 928 929 } else { 930 this._propLookup = {}; 931 this._siblings = _register(target, this, false); 932 if (overwrite === 1) if (this._siblings.length > 1) { 933 _applyOverwrite(target, this, null, 1, this._siblings); 934 } 935 } 936 if (this.vars.immediateRender || (duration === 0 && this._delay === 0 && this.vars.immediateRender !== false)) { 937 this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render) 938 this.render(Math.min(0, -this._delay)); //in case delay is negative 939 } 940 }, true), 941 _isSelector = function(v) { 942 return (v && v.length && v !== window && v[0] && (v[0] === window || (v[0].nodeType && v[0].style && !v.nodeType))); //we cannot check "nodeType" if the target is window from within an iframe, otherwise it will trigger a security error in some browsers like Firefox. 943 }, 944 _autoCSS = function(vars, target) { 945 var css = {}, 946 p; 947 for (p in vars) { 948 if (!_reservedProps[p] && (!(p in target) || p === "transform" || p === "x" || p === "y" || p === "width" || p === "height" || p === "className" || p === "border") && (!_plugins[p] || (_plugins[p] && _plugins[p]._autoCSS))) { //note: <img> elements contain read-only "x" and "y" properties. We should also prioritize editing css width/height rather than the element's properties. 949 css[p] = vars[p]; 950 delete vars[p]; 951 } 952 } 953 vars.css = css; 954 }; 955 956 p = TweenLite.prototype = new Animation(); 957 p.constructor = TweenLite; 958 p.kill()._gc = false; 959 960//----TweenLite defaults, overwrite management, and root updates ---------------------------------------------------- 961 962 p.ratio = 0; 963 p._firstPT = p._targets = p._overwrittenProps = p._startAt = null; 964 p._notifyPluginsOfEnabled = p._lazy = false; 965 966 TweenLite.version = "2.1.3"; 967 TweenLite.defaultEase = p._ease = new Ease(null, null, 1, 1); 968 TweenLite.defaultOverwrite = "auto"; 969 TweenLite.ticker = _ticker; 970 TweenLite.autoSleep = 120; 971 TweenLite.lagSmoothing = function(threshold, adjustedLag) { 972 _ticker.lagSmoothing(threshold, adjustedLag); 973 }; 974 975 TweenLite.selector = window.$ || window.jQuery || function(e) { 976 var selector = window.$ || window.jQuery; 977 if (selector) { 978 TweenLite.selector = selector; 979 return selector(e); 980 } 981 if (!_doc) { //in some dev environments (like Angular 6), GSAP gets loaded before the document is defined! So re-query it here if/when necessary. 982 _doc = window.document; 983 } 984 return (!_doc) ? e : (_doc.querySelectorAll ? _doc.querySelectorAll(e) : _doc.getElementById((e.charAt(0) === "#") ? e.substr(1) : e)); 985 }; 986 987 var _lazyTweens = [], 988 _lazyLookup = {}, 989 _numbersExp = /(?:(-|-=|\+=)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig, 990 _relExp = /[\+-]=-?[\.\d]/, 991 //_nonNumbersExp = /(?:([\-+](?!(\d|=)))|[^\d\-+=e]|(e(?![\-+][\d])))+/ig, 992 _setRatio = function(v) { 993 var pt = this._firstPT, 994 min = 0.000001, 995 val; 996 while (pt) { 997 val = !pt.blob ? pt.c * v + pt.s : (v === 1 && this.end != null) ? this.end : v ? this.join("") : this.start; 998 if (pt.m) { 999 val = pt.m.call(this._tween, val, this._target || pt.t, this._tween); 1000 } else if (val < min) if (val >
1000 -min && !pt.blob) { //prevents issues with converting very small numbers to strings in the browser 1001 val = 0; 1002 } 1003 if (!pt.f) { 1004 pt.t[pt.p] = val; 1005 } else if (pt.fp) { 1006 pt.t[pt.p](pt.fp, val); 1007 } else { 1008 pt.t[pt.p](val); 1009 } 1010 pt = pt._next; 1011 } 1012 }, 1013 _blobRound = function(v) { 1014 return (((v * 1000) | 0) / 1000) + ""; 1015 }, 1016 //compares two strings (start/end), finds the numbers that are different and spits back an array representing the whole value but with the changing values isolated as elements. For example, "rgb(0,0,0)" and "rgb(100,50,0)" would become ["rgb(", 0, ",", 50, ",0)"]. Notice it merges the parts that are identical (performance optimization). The array also has a linked list of PropTweens attached starting with _firstPT that contain the tweening data (t, p, s, c, f, etc.). It also stores the starting value as a "start" property so that we can revert to it if/when necessary, like when a tween rewinds fully. If the quantity of numbers differs between the start and end, it will always prioritize the end value(s). The pt parameter is optional - it's for a PropTween that will be appended to the end of the linked list and is typically for actually setting the value after all of the elements have been updated (with array.join("")). 1017 _blobDif = function(start, end, filter, pt) { 1018 var a = [], 1019 charIndex = 0, 1020 s = "", 1021 color = 0, 1022 startNums, endNums, num, i, l, nonNumbers, currentNum; 1023 a.start = start; 1024 a.end = end; 1025 start = a[0] = start + ""; //ensure values are strings 1026 end = a[1] = end + ""; 1027 if (filter) { 1028 filter(a); //pass an array with the starting and ending values and let the filter do whatever it needs to the values. 1029 start = a[0]; 1030 end = a[1]; 1031 } 1032 a.length = 0; 1033 startNums = start.match(_numbersExp) || []; 1034 endNums = end.match(_numbersExp) || []; 1035 if (pt) { 1036 pt._next = null; 1037 pt.blob = 1; 1038 a._firstPT = a._applyPT = pt; //apply last in the linked list (which means inserting it first) 1039 } 1040 l = endNums.length; 1041 for (i = 0; i < l; i++) { 1042 currentNum = endNums[i]; 1043 nonNumbers = end.substr(charIndex, end.indexOf(currentNum, charIndex)-charIndex); 1044 s += (nonNumbers || !i) ? nonNumbers : ","; //note: SVG spec allows omission of comma/space when a negative sign is wedged between two numbers, like 2.5-5.3 instead of 2.5,-5.3 but when tweening, the negative value may switch to positive, so we insert the comma just in case. 1045 charIndex += nonNumbers.length; 1046 if (color) { //sense rgba() values and round them. 1047 color = (color + 1) % 5; 1048 } else if (nonNumbers.substr(-5) === "rgba(") { 1049 color = 1; 1050 } 1051 if (currentNum === startNums[i] || startNums.length <= i) { 1052 s += currentNum; 1053 } else { 1054 if (s) { 1055 a.push(s); 1056 s = ""; 1057 } 1058 num = parseFloat(startNums[i]); 1059 a.push(num); 1060 a._firstPT = {_next: a._firstPT, t:a, p: a.length-1, s:num, c:((currentNum.charAt(1) === "=") ? parseInt(currentNum.charAt(0) + "1", 10) * parseFloat(currentNum.substr(2)) : (parseFloat(currentNum) - num)) || 0, f:0, m:(color && color < 4) ? Math.round : _blobRound}; //limiting to 3 decimal places and casting as a string can really help performance when array.join() is called! 1061 //note: we don't set _prev because we'll never need to remove individual PropTweens from this list. 1062 } 1063 charIndex += currentNum.length; 1064 } 1065 s += end.substr(charIndex); 1066 if (s) { 1067 a.push(s); 1068 } 1069 a.setRatio = _setRatio; 1070 if (_relExp.test(end)) { //if the end string contains relative values, delete it so that on the final render (in _setRatio()), we don't actually set it to the string with += or -= characters (forces it to use the calculated value). 1071 a.end = null; 1072 } 1073 return a; 1074 }, 1075 //note: "funcParam" is only necessary for function-based getters/setters that require an extra parameter like getAttribute("width") and setAttribute("width", value). In this example, funcParam would be "width". Used by AttrPlugin for example. 1076 _addPropTween = function(target, prop, start, end, overwriteProp, mod, funcParam, stringFilter, index) { 1077 if (typeof(end) === "function") { 1078 end = end(index || 0, target); 1079 } 1080 var type = typeof(target[prop]), 1081 getterName = (type !== "function") ? "" : ((prop.indexOf("set") || typeof(target["get" + prop.substr(3)]) !== "function") ? prop : "get" + prop.substr(3)), 1082 s = (start !== "get") ? start : !getterName ? target[prop] : funcParam ? target[getterName](funcParam) : target[getterName](), 1083 isRelative = (typeof(end) === "string" && end.charAt(1) === "="), 1084 pt = {t:target, p:prop, s:s, f:(type === "function"), pg:0, n:overwriteProp || prop, m:(!mod ? 0 : (typeof(mod) === "function") ? mod : Math.round), pr:0, c:isRelative ? parseInt(end.charAt(0) + "1", 10) * parseFloat(end.substr(2)) : (parseFloat(end) - s) || 0}, 1085 blob; 1086 1087 if (typeof(s) !== "number" || (typeof(end) !== "number" && !isRelative)) { 1088 if (funcParam || isNaN(s) || (!isRelative && isNaN(end)) || typeof(s) === "boolean" || typeof(end) === "boolean") { 1089 //a blob (string that has multiple numbers in it) 1090 pt.fp = funcParam; 1091 blob = _blobDif(s, (isRelative ? (parseFloat(pt.s) + pt.c) + (pt.s + "").replace(/[0-9\-\.]/g, "") : end), stringFilter || TweenLite.defaultStringFilter, pt); 1092 pt = {t: blob, p: "setRatio", s: 0, c: 1, f: 2, pg: 0, n: overwriteProp || prop, pr: 0, m: 0}; //"2" indicates it's a Blob property tween. Needed for RoundPropsPlugin for example. 1093 } else { 1094 pt.s = parseFloat(s); 1095 if (!isRelative) { 1096 pt.c = (parseFloat(end) - pt.s) || 0; 1097 } 1098 } 1099 } 1100 if (pt.c) { //only add it to the linked list if there's a change. 1101 if ((pt._next = this._firstPT)) { 1102 pt._next._prev = pt; 1103 } 1104 this._firstPT = pt; 1105 return pt; 1106 } 1107 }, 1108 _internals = TweenLite._internals = {isArray:_isArray, isSelector:_isSelector, lazyTweens:_lazyTweens, blobDif:_blobDif}, //gives us a way to expose certain private values to other GreenSock classes without contaminating tha main TweenLite object. 1109 _plugins = TweenLite._plugins = {}, 1110 _tweenLookup = _internals.tweenLookup = {}, 1111 _tweenLookupNum = 0, 1112 _reservedProps = _internals.reservedProps = {ease:1, delay:1, overwrite:1, onComplete:1, onCompleteParams:1, onCompleteScope:1, useFrames:1, runBackwards:1, startAt:1, onUp
1112date:1, onUpdateParams:1, onUpdateScope:1, onStart:1, onStartParams:1, onStartScope:1, onReverseComplete:1, onReverseCompleteParams:1, onReverseCompleteScope:1, onRepeat:1, onRepeatParams:1, onRepeatScope:1, easeParams:1, yoyo:1, immediateRender:1, repeat:1, repeatDelay:1, data:1, paused:1, reversed:1, autoCSS:1, lazy:1, onOverwrite:1, callbackScope:1, stringFilter:1, id:1, yoyoEase:1, stagger:1}, 1113 _overwriteLookup = {none:0, all:1, auto:2, concurrent:3, allOnStart:4, preexisting:5, "true":1, "false":0}, 1114 _rootFramesTimeline = Animation._rootFramesTimeline = new SimpleTimeline(), 1115 _rootTimeline = Animation._rootTimeline = new SimpleTimeline(), 1116 _nextGCFrame = 30, 1117 _lazyRender = _internals.lazyRender = function() { 1118 var l = _lazyTweens.length, 1119 i, tween; 1120 _lazyLookup = {}; 1121 for (i = 0; i < l; i++) { 1122 tween = _lazyTweens[i]; 1123 if (tween && tween._lazy !== false) { 1124 tween.render(tween._lazy[0], tween._lazy[1], true); 1125 tween._lazy = false; 1126 } 1127 } 1128 _lazyTweens.length = 0; 1129 }; 1130 1131 _rootTimeline._startTime = _ticker.time; 1132 _rootFramesTimeline._startTime = _ticker.frame; 1133 _rootTimeline._active = _rootFramesTimeline._active = true; 1134 setTimeout(_lazyRender, 1); //on some mobile devices, there isn't a "tick" before code runs which means any lazy renders wouldn't run before the next official "tick". 1135 1136 Animation._updateRoot = TweenLite.render = function() { 1137 var i, a, p; 1138 if (_lazyTweens.length) { //if code is run outside of the requestAnimationFrame loop, there may be tweens queued AFTER the engine refreshed, so we need to ensure any pending renders occur before we refresh again. 1139 _lazyRender(); 1140 } 1141 _rootTimeline.render((_ticker.time - _rootTimeline._startTime) * _rootTimeline._timeScale, false, false); 1142 _rootFramesTimeline.render((_ticker.frame - _rootFramesTimeline._startTime) * _rootFramesTimeline._timeScale, false, false); 1143 if (_lazyTweens.length) { 1144 _lazyRender(); 1145 } 1146 if (_ticker.frame >= _nextGCFrame) { //dump garbage every 120 frames or whatever the user sets TweenLite.autoSleep to 1147 _nextGCFrame = _ticker.frame + (parseInt(TweenLite.autoSleep, 10) || 120); 1148 for (p in _tweenLookup) { 1149 a = _tweenLookup[p].tweens; 1150 i = a.length; 1151 while (--i > -1) { 1152 if (a[i]._gc) { 1153 a.splice(i, 1); 1154 } 1155 } 1156 if (a.length === 0) { 1157 delete _tweenLookup[p]; 1158 } 1159 } 1160 //if there are no more tweens in the root timelines, or if they're all paused, make the _timer sleep to reduce load on the CPU slightly 1161 p = _rootTimeline._first; 1162 if (!p || p._paused) if (TweenLite.autoSleep && !_rootFramesTimeline._first && _ticker._listeners.tick.length === 1) { 1163 while (p && p._paused) { 1164 p = p._next; 1165 } 1166 if (!p) { 1167 _ticker.sleep(); 1168 } 1169 } 1170 } 1171 }; 1172 1173 _ticker.addEventListener("tick", Animation._updateRoot); 1174 1175 var _register = function(target, tween, scrub) { 1176 var id = target._gsTweenID, a, i; 1177 if (!_tweenLookup[id || (target._gsTweenID = id = "t" + (_tweenLookupNum++))]) { 1178 _tweenLookup[id] = {target:target, tweens:[]}; 1179 } 1180 if (tween) { 1181 a = _tweenLookup[id].tweens; 1182 a[(i = a.length)] = tween; 1183 if (scrub) { 1184 while (--i > -1) { 1185 if (a[i] === tween) { 1186 a.splice(i, 1); 1187 } 1188 } 1189 } 1190 } 1191 return _tweenLookup[id].tweens; 1192 }, 1193 _onOverwrite = function(overwrittenTween, overwritingTween, target, killedProps) { 1194 var func = overwrittenTween.vars.onOverwrite, r1, r2; 1195 if (func) { 1196 r1 = func(overwrittenTween, overwritingTween, target, killedProps); 1197 } 1198 func = TweenLite.onOverwrite; 1199 if (func) { 1200 r2 = func(overwrittenTween, overwritingTween, target, killedProps); 1201 } 1202 return (r1 !== false && r2 !== false); 1203 }, 1204 _applyOverwrite = function(target, tween, props, mode, siblings) { 1205 var i, changed, curTween, l; 1206 if (mode === 1 || mode >= 4) { 1207 l = siblings.length; 1208 for (i = 0; i < l; i++) { 1209 if ((curTween = siblings[i]) !== tween) { 1210 if (!curTween._gc) { 1211 if (curTween._kill(null, target, tween)) { 1212 changed = true; 1213 } 1214 } 1215 } else if (mode === 5) { 1216 break; 1217 } 1218 } 1219 return changed; 1220 } 1221 //NOTE: Add tiny amount to overcome floating point errors that can cause the startTime to be VERY slightly off (when a tween's time() is set for example) 1222 var startTime = tween._startTime + _tinyNum, 1223 overlaps = [], 1224 oCount = 0, 1225 zeroDur = (tween._duration === 0), 1226 globalStart; 1227 i = siblings.length; 1228 while (--i > -1) { 1229 if ((curTween = siblings[i]) === tween || curTween._gc || curTween._paused) { 1230 //ignore 1231 } else if (curTween._timeline !== tween._timeline) { 1232 globalStart = globalStart || _checkOverlap(tween, 0, zeroDur); 1233 if (_checkOverlap(curTween, globalStart, zeroDur) === 0) { 1234 overlaps[oCount++] = curTween; 1235 } 1236 } else if (curTween._startTime <= startTime) if (curTween._startTime + curTween.totalDuration() / curTween._timeScale > startTime) if (!((zeroDur || !curTween._initted) && startTime - curTween._startTime <= _tinyNum * 2)) { 1237 overlaps[oCount++] = curTween; 1238 } 1239 } 1240 1241 i = oCount; 1242 while (--i > -1) { 1243 curTween = overlaps[i]; 1244 l = curTween._firstPT; //we need to discern if there were property tweens originally; if they all get removed in the next line's _kill() call, the tween should be killed. See https://github.com/greensock/GreenSock-JS/issues/278 1245 if (mode === 2) if (curTween._kill(props, target, tween)) { 1246 changed = true; 1247 } 1248 if (mode !== 2 || (!curTween._firstPT && curTween._initted && l)) { 1249 if (mode !== 2 && !_onOverwrite(curTween, tween)) { 1250 continue; 1251 } 1252 if (curTween._enabled(false, false)) { //if all property tweens have been overwritten, kill the tween. 1253 changed = true; 1254 } 1255 } 1256 } 1257 return changed; 1258 }, 1259 _checkOverlap = function(tween, reference, zeroDur) { 1260 var tl = tween._timeline, 1261 ts = tl._timeScale, 1262 t = tween._startTime; 1263 while (tl._timeline) { 1264 t += tl._startTime; 1265 ts *= tl._timeScale; 1266 if (tl._paused) { 1267 return -100; 1268 } 1269 tl = tl._timeline; 1270 } 1271 t /= ts; 1272 return (t > reference) ? t - reference : ((zeroDur && t === reference) || (!tween._initted && t - reference < 2 * _tinyNum)) ? _tinyNum : ((t += tween.totalDuration() / tween._timeScale / ts) > reference + _tinyNum) ? 0 : t - reference - _tinyNum; 1273 }; 1274 1275 1276//---- TweenLite instance methods ----------------------------------------------------------------------------- 1277 1278 p._init = function() { 1279 var v = this.vars, 1280 op = this._overwrittenProps, 1281 dur = this._duration, 1282 immediate = !!v.immediateRender, 1283 ease = v.ease, 1284 startAt = this._startAt, 1285 i, initPlugins, pt, p, startVars, l; 1286 if (v.startAt) { 1287 if (startAt) { 1288 startAt.render(-1, true); //if we've run a startAt previously (when the tween instantiated), we should revert it so that the values re-instantiate correctly particularly for relative tweens. Without this, a TweenLite.fromTo(obj, 1, {x:"+=100"}, {x:"-=100"}), for example, would actually jump to +=200 because the startAt would run twice, doubling the relative change. 1289 startAt.kill(); 1290 } 1291 startVars = {}; 1292 for (p in v.startAt) { //copy the properties/values into a new object to avoid collisions, like var to = {x:0}, from = {x:500}; timeline.fromTo(e, 1, from, to).fromTo(e, 1, to, from); 1293 startVars[p] = v.startAt[p]; 1294 } 1295 startVars.data = "isStart"; 1296 startVars.overwrite = false; 1297 startVars.immediateRender = true; 1298 startVars.lazy = (immediate && v.lazy !== false);
1299 startVars.startAt = startVars.delay = null; //no nesting of startAt objects allowed (otherwise it could cause an infinite loop). 1300 startVars.onUpdate = v.onUpdate; 1301 startVars.onUpdateParams = v.onUpdateParams; 1302 startVars.onUpdateScope = v.onUpdateScope || v.callbackScope || this; 1303 this._startAt = TweenLite.to(this.target || {}, 0, startVars); 1304 if (immediate) { 1305 if (this._time > 0) { 1306 this._startAt = null; //tweens that render immediately (like most from() and fromTo() tweens) shouldn't revert when their parent timeline's playhead goes backward past the startTime because the initial render could have happened anytime and it shouldn't be directly correlated to this tween's startTime. Imagine setting up a complex animation where the beginning states of various objects are rendered immediately but the tween doesn't happen for quite some time - if we revert to the starting values as soon as the playhead goes backward past the tween's startTime, it will throw things off visually. Reversion should only happen in TimelineLite/Max instances where immediateRender was false (which is the default in the convenience methods like from()). 1307 } else if (dur !== 0) { 1308 return; //we skip initialization here so that overwriting doesn't occur until the tween actually begins. Otherwise, if you create several immediateRender:true tweens of the same target/properties to drop into a TimelineLite or TimelineMax, the last one created would overwrite the first ones because they didn't get placed into the timeline yet before the first render occurs and kicks in overwriting. 1309 } 1310 } 1311 } else if (v.runBackwards && dur !== 0) { 1312 //from() tweens must be handled uniquely: their beginning values must be rendered but we don't want overwriting to occur yet (when time is still 0). Wait until the tween actually begins before doing all the routines like overwriting. At that time, we should render at the END of the tween to ensure that things initialize correctly (remember, from() tweens go backwards) 1313 if (startAt) { 1314 startAt.render(-1, true); 1315 startAt.kill(); 1316 this._startAt = null; 1317 } else { 1318 if (this._time !== 0) { //in rare cases (like if a from() tween runs and then is invalidate()-ed), immediateRender could be true but the initial forced-render gets skipped, so there's no need to force the render in this context when the _time is greater than 0 1319 immediate = false; 1320 } 1321 pt = {}; 1322 for (p in v) { //copy props into a new object and skip any reserved props, otherwise onComplete or onUpdate or onStart could fire. We should, however, permit autoCSS to go through. 1323 if (!_reservedProps[p] || p === "autoCSS") { 1324 pt[p] = v[p]; 1325 } 1326 } 1327 pt.overwrite = 0; 1328 pt.data = "isFromStart"; //we tag the tween with as "isFromStart" so that if [inside a plugin] we need to only do something at the very END of a tween, we have a way of identifying this tween as merely the one that's setting the beginning values for a "from()" tween. For example, clearProps in CSSPlugin should only get applied at the very END of a tween and without this tag, from(...{height:100, clearProps:"height", delay:1}) would wipe the height at the beginning of the tween and after 1 second, it'd kick back in. 1329 pt.lazy = (immediate && v.lazy !== false); 1330 pt.immediateRender = immediate; //zero-duration tweens render immediately by default, but if we're not specifically instructed to render this tween immediately, we should skip this and merely _init() to record the starting values (rendering them immediately would push them to completion which is wasteful in that case - we'd have to render(-1) immediately after) 1331 this._startAt = TweenLite.to(this.target, 0, pt); 1332 if (!immediate) { 1333 this._startAt._init(); //ensures that the initial values are recorded 1334 this._startAt._enabled(false); //no need to have the tween render on the next cycle. Disable it because we'll always manually control the renders of the _startAt tween. 1335 if (this.vars.immediateRender) { 1336 this._startAt = null; 1337 } 1338 } else if (this._time === 0) { 1339 return; 1340 } 1341 } 1342 } 1343 this._ease = ease = (!ease) ? TweenLite.defaultEase : (ease instanceof Ease) ? ease : (typeof(ease) === "function") ? new Ease(ease, v.easeParams) : _easeMap[ease] || TweenLite.defaultEase; 1344 if (v.easeParams instanceof Array && ease.config) { 1345 this._ease = ease.config.apply(ease, v.easeParams); 1346 } 1347 this._easeType = this._ease._type; 1348 this._easePower = this._ease._power; 1349 this._firstPT = null; 1350 1351 if (this._targets) { 1352 l = this._targets.length; 1353 for (i = 0; i < l; i++) { 1354 if ( this._initProps( this._targets[i], (this._propLookup[i] = {}), this._siblings[i], (op ? op[i] : null), i) ) { 1355 initPlugins = true; 1356 } 1357 } 1358 } else { 1359 initPlugins = this._initProps(this.target, this._propLookup, this._siblings, op, 0); 1360 } 1361 1362 if (initPlugins) { 1363 TweenLite._onPluginEvent("_onInitAllProps", this); //reorders the array in order of priority. Uses a static TweenPlugin method in order to minimize file size in TweenLite 1364 } 1365 if (op) if (!this._firstPT) if (typeof(this.target) !== "function") { //if all tweening properties have been overwritten, kill the tween. If the target is a function, it's probably a delayedCall so let it live. 1366 this._enabled(false, false); 1367 } 1368 if (v.runBackwards) { 1369 pt = this._firstPT; 1370 while (pt) { 1371 pt.s += pt.c; 1372 pt.c = -pt.c; 1373 pt = pt._next; 1374 } 1375 } 1376 this._onUpdate = v.onUpdate; 1377 this._initted = true; 1378 }; 1379 1380 p._initProps = function(target, propLookup, siblings, overwrittenProps, index) { 1381 var p, i, initPlugins, plugin, pt, v; 1382 if (target == null) { 1383 return false; 1384 } 1385 if (_lazyLookup[target._gsTweenID]) { 1386 _lazyRender(); //if other tweens of the same target have recently initted but haven't rendered yet, we've got to force the render so that the starting values are correct (imagine populating a timeline with a bunch of sequential tweens and then jumping to the end) 1387 } 1388 1389 if (!this.vars.css) if (target.style) if (target !== window && target.nodeType) if (_plugins.css) if (this.vars.autoCSS !== false) { //it's so common to use TweenLite/Max to animate the css of DOM elements, we assume that if the target is a DOM element, that's what is intended (a convenience so that users don't have to wrap things in css:{}, although we still recommend it for a slight performance boost and better specificity). Note: we cannot check "nodeType" on the window inside an iframe. 1390 _autoCSS(this.vars, target); 1391 } 1392 for (p in this.vars) { 1393 v = this.vars[p]; 1394 if (_reservedProps[p]) { 1395 if (v) if ((v instanceof Array) || (v.push && _isArray(v))) if (v.join("").indexOf("{self}") !== -1) { 1396 this.vars[p] = v = this._swapSelfInParams(v, this); 1397 } 1398 1399 } else if (_plugins[p] && (plugin = new _plugins[p]())._onInitTween(target, this.vars[p], this, index)) { 1400 1401 //t - target [object] 1402 //p - property [string] 1403 //s - start [number] 1404 //c - change [number] 1405 //f - isFunction [boolean] 1406 //n - name [string] 1407 //pg - isPlugin [boolean] 1408 //pr - priority [number] 1409 //m - mod [function | 0] 1410 this._firstPT = pt = {_next:this._firstPT, t:plugin, p:"setRatio", s:0, c:1, f:1, n:p, pg:1, pr:plugin._priority, m:0};
1411 i = plugin._overwriteProps.length; 1412 while (--i > -1) { 1413 propLookup[plugin._overwriteProps[i]] = this._firstPT; 1414 } 1415 if (plugin._priority || plugin._onInitAllProps) { 1416 initPlugins = true; 1417 } 1418 if (plugin._onDisable || plugin._onEnable) { 1419 this._notifyPluginsOfEnabled = true; 1420 } 1421 if (pt._next) { 1422 pt._next._prev = pt; 1423 } 1424 1425 } else { 1426 propLookup[p] = _addPropTween.call(this, target, p, "get", v, p, 0, null, this.vars.stringFilter, index); 1427 } 1428 } 1429 1430 if (overwrittenProps) if (this._kill(overwrittenProps, target)) { //another tween may have tried to overwrite properties of this tween before init() was called (like if two tweens start at the same time, the one created second will run first) 1431 return this._initProps(target, propLookup, siblings, overwrittenProps, index); 1432 } 1433 if (this._overwrite > 1) if (this._firstPT) if (siblings.length > 1) if (_applyOverwrite(target, this, propLookup, this._overwrite, siblings)) { 1434 this._kill(propLookup, target); 1435 return this._initProps(target, propLookup, siblings, overwrittenProps, index); 1436 } 1437 if (this._firstPT) if ((this.vars.lazy !== false && this._duration) || (this.vars.lazy && !this._duration)) { //zero duration tweens don't lazy render by default; everything else does. 1438 _lazyLookup[target._gsTweenID] = true; 1439 } 1440 return initPlugins; 1441 }; 1442 1443 p.render = function(time, suppressEvents, force) { 1444 var self = this, 1445 prevTime = self._time, 1446 duration = self._duration, 1447 prevRawPrevTime = self._rawPrevTime, 1448 isComplete, callback, pt, rawPrevTime; 1449 if (time >= duration - _tinyNum && time >= 0) { //to work around occasional floating point math artifacts. 1450 self._totalTime = self._time = duration; 1451 self.ratio = self._ease._calcEnd ? self._ease.getRatio(1) : 1; 1452 if (!self._reversed ) { 1453 isComplete = true; 1454 callback = "onComplete"; 1455 force = (force || self._timeline.autoRemoveChildren); //otherwise, if the animation is unpaused/activated after it's already finished, it doesn't get removed from the parent timeline. 1456 } 1457 if (duration === 0) if (self._initted || !self.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered. 1458 if (self._startTime === self._timeline._duration) { //if a zero-duration tween is at the VERY end of a timeline and that timeline renders at its end, it will typically add a tiny bit of cushion to the render time to prevent rounding errors from getting in the way of tweens rendering their VERY end. If we then reverse() that timeline, the zero-duration tween will trigger its onReverseComplete even though technically the playhead didn't pass over it again. It's a very specific edge case we must accommodate. 1459 time = 0; 1460 } 1461 if (prevRawPrevTime < 0 || (time <= 0 && time >= -_tinyNum) || (prevRawPrevTime === _tinyNum && self.data !== "isPause")) if (prevRawPrevTime !== time) { //note: when this.data is "isPause", it's a callback added by addPause() on a timeline that we should not be triggered when LEAVING its exact start time. In other words, tl.addPause(1).play(1) shouldn't pause. 1462 force = true; 1463 if (prevRawPrevTime > _tinyNum) { 1464 callback = "onReverseComplete"; 1465 } 1466 } 1467 self._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient. 1468 } 1469 1470 } else if (time < _tinyNum) { //to work around occasional floating point math artifacts, round super small values to 0. 1471 self._totalTime = self._time = 0; 1472 self.ratio = self._ease._calcEnd ? self._ease.getRatio(0) : 0; 1473 if (prevTime !== 0 || (duration === 0 && prevRawPrevTime > 0)) { 1474 callback = "onReverseComplete"; 1475 isComplete = self._reversed; 1476 } 1477 if (time > -_tinyNum) { 1478 time = 0; 1479 } else if (time < 0) { 1480 self._active = false; 1481 if (duration === 0) if (self._initted || !self.vars.lazy || force) { //zero-duration tweens are tricky because we must discern the momentum/direction of time in order to determine whether the starting values should be rendered or the ending values. If the "playhead" of its timeline goes past the zero-duration tween in the forward direction or lands directly on it, the end values should be rendered, but if the timeline's "playhead" moves past it in the backward direction (from a postitive time to a negative time), the starting values must be rendered. 1482 if (prevRawPrevTime >= 0 && !(prevRawPrevTime === _tinyNum && self.data === "isPause")) { 1483 force = true; 1484 } 1485 self._rawPrevTime = rawPrevTime = (!suppressEvents || time || prevRawPrevTime === time) ? time : _tinyNum; //when the playhead arrives at EXACTLY time 0 (right on top) of a zero-duration tween, we need to discern if events are suppressed so that when the playhead moves again (next time), it'll trigger the callback. If events are NOT suppressed, obviously the callback would be triggered in this render. Basically, the callback should fire either when the playhead ARRIVES or LEAVES this exact spot, not both. Imagine doing a timeline.seek(0) and there's a callback that sits at 0. Since events are suppressed on that seek() by default, nothing will fire, but when the playhead moves off of that position, the callback should fire. This behavior is what people intuitively expect. We set the _rawPrevTime to be a precise tiny number to indicate this scenario rather than using another property/variable which would increase memory usage. This technique is less readable, but more efficient. 1486 } 1487 } 1488 if (!self._initted || (self._startAt && self._startAt.progress())) { //if we render the very beginning (time == 0) of a fromTo(), we must force the render (normal tweens wouldn't need to render at a time of 0 when the prevTime was also 0). This is also mandatory to make sure overwriting kicks in immediately. Also, we check progress() because if startAt has already rendered at its end, we should force a render at its beginning. Otherwise, if you put the playhead directly on top of where a fromTo({immediateRender:false}) starts, and then move it backwards, the from() won't revert its values. 1489 force = true; 1490 } 1491 } else { 1492 self._totalTime = self._time = time; 1493 1494 if (self._easeType) { 1495 var r = time / duration, type = self._easeType, pow = self._easePower; 1496 if (type === 1 || (type === 3 && r >= 0.5)) { 1497 r = 1 - r; 1498 } 1499 if (type === 3) { 1500 r *= 2; 1501 } 1502 if (pow === 1) { 1503 r *= r; 1504 } else if (pow === 2) { 1505 r *= r * r; 1506 } else if (pow === 3) { 1507 r *= r * r * r; 1508 } else if (pow === 4) { 1509 r *= r * r * r * r; 1510 } 1511 self.ratio = (type === 1) ? 1 - r : (type === 2) ? r : (time / duration < 0.5) ? r / 2 : 1 - (r / 2); 1512 } else { 1513 self.ratio = self._ease.getRatio(time / duration); 1514 } 1515 } 1516 1517 if (self._time === prevTime && !force) { 1518 return; 1519 } else if (!self._initted) { 1520 self._init(); 1521 if (!self._initted || self._gc) { //immediateRender tweens typically won't initialize until the playhead advances (_time is greater than 0) in order to ensure that over
1521writing occurs properly. Also, if all of the tweening properties have been overwritten (which would cause _gc to be true, as set in _init()), we shouldn't continue otherwise an onStart callback could be called for example. 1522 return; 1523 } else if (!force && self._firstPT && ((self.vars.lazy !== false && self._duration) || (self.vars.lazy && !self._duration))) { 1524 self._time = self._totalTime = prevTime; 1525 self._rawPrevTime = prevRawPrevTime; 1526 _lazyTweens.push(self); 1527 self._lazy = [time, suppressEvents]; 1528 return; 1529 } 1530 //_ease is initially set to defaultEase, so now that init() has run, _ease is set properly and we need to recalculate the ratio. Overall this is faster than using conditional logic earlier in the method to avoid having to set ratio twice because we only init() once but renderTime() gets called VERY frequently. 1531 if (self._time && !isComplete) { 1532 self.ratio = self._ease.getRatio(self._time / duration); 1533 } else if (isComplete && self._ease._calcEnd) { 1534 self.ratio = self._ease.getRatio((self._time === 0) ? 0 : 1); 1535 } 1536 } 1537 if (self._lazy !== false) { //in case a lazy render is pending, we should flush it because the new render is occurring now (imagine a lazy tween instantiating and then immediately the user calls tween.seek(tween.duration()), skipping to the end - the end render would be forced, and then if we didn't flush the lazy render, it'd fire AFTER the seek(), rendering it at the wrong time. 1538 self._lazy = false; 1539 } 1540 if (!self._active) if (!self._paused && self._time !== prevTime && time >= 0) { 1541 self._active = true; //so that if the user renders a tween (as opposed to the timeline rendering it), the timeline is forced to re-render and align it with the proper time/frame on the next rendering cycle. Maybe the tween already finished but the user manually re-renders it as halfway done. 1542 } 1543 if (prevTime === 0) { 1544 if (self._startAt) { 1545 if (time >= 0) { 1546 self._startAt.render(time, true, force); 1547 } else if (!callback) { 1548 callback = "_dummyGS"; //if no callback is defined, use a dummy value just so that the condition at the end evaluates as true because _startAt should render AFTER the normal render loop when the time is negative. We could handle this in a more intuitive way, of course, but the render loop is the MOST important thing to optimize, so this technique allows us to avoid adding extra conditional logic in a high-frequency area. 1549 } 1550 } 1551 if (self.vars.onStart) if (self._time !== 0 || duration === 0) if (!suppressEvents) { 1552 self._callback("onStart"); 1553 } 1554 } 1555 pt = self._firstPT; 1556 while (pt) { 1557 if (pt.f) { 1558 pt.t[pt.p](pt.c * self.ratio + pt.s); 1559 } else { 1560 pt.t[pt.p] = pt.c * self.ratio + pt.s; 1561 } 1562 pt = pt._next; 1563 } 1564 1565 if (self._onUpdate) { 1566 if (time < 0) if (self._startAt && time !== -0.0001) { //if the tween is positioned at the VERY beginning (_startTime 0) of its parent timeline, it's illegal for the playhead to go back further, so we should not render the recorded startAt values. 1567 self._startAt.render(time, true, force); //note: for performance reasons, we tuck this conditional logic inside less traveled areas (most tweens don't have an onUpdate). We'd just have it at the end before the onComplete, but the values should be updated before any onUpdate is called, so we ALSO put it here and then if it's not called, we do so later near the onComplete. 1568 } 1569 if (!suppressEvents) if (self._time !== prevTime || isComplete || force) { 1570 self._callback("onUpdate"); 1571 } 1572 } 1573 if (callback) if (!self._gc || force) { //check _gc because there's a chance that kill() could be called in an onUpdate 1574 if (time < 0 && self._startAt && !self._onUpdate && time !== -0.0001) { //-0.0001 is a special value that we use when looping back to the beginning of a repeated TimelineMax, in which case we shouldn't render the _startAt values. 1575 self._startAt.render(time, true, force); 1576 } 1577 if (isComplete) { 1578 if (self._timeline.autoRemoveChildren) { 1579 self._enabled(false, false); 1580 } 1581 self._active = false; 1582 } 1583 if (!suppressEvents && self.vars[callback]) { 1584 self._callback(callback); 1585 } 1586 if (duration === 0 && self._rawPrevTime === _tinyNum && rawPrevTime !== _tinyNum) { //the onComplete or onReverseComplete could trigger movement of the playhead and for zero-duration tweens (which must discern direction) that land directly back on their start time, we don't want to fire again on the next render. Think of several addPause()'s in a timeline that forces the playhead to a certain spot, but what if it's already paused and another tween is tweening the "time" of the timeline? Each time it moves [forward] past that spot, it would move back, and since suppressEvents is true, it'd reset _rawPrevTime to _tinyNum so that when it begins again, the callback would fire (so ultimately it could bounce back and forth during that tween). Again, this is a very uncommon sce
1586nario, but possible nonetheless. 1587 self._rawPrevTime = 0; 1588 } 1589 } 1590 }; 1591 1592 p._kill = function(vars, target, overwritingTween) { 1593 if (vars === "all") { 1594 vars = null; 1595 } 1596 if (vars == null) if (target == null || target === this.target) { 1597 this._lazy = false; 1598 return this._enabled(false, false); 1599 } 1600 target = (typeof(target) !== "string") ? (target || this._targets || this.target) : TweenLite.selector(target) || target; 1601 var simultaneousOverwrite = (overwritingTween && this._time && overwritingTween._startTime === this._startTime && this._timeline === overwritingTween._timeline), 1602 firstPT = this._firstPT, 1603 i, overwrittenProps, p, pt, propLookup, changed, killProps, record, killed; 1604 if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") { 1605 i = target.length; 1606 while (--i > -1) { 1607 if (this._kill(vars, target[i], overwritingTween)) { 1608 changed = true; 1609 } 1610 } 1611 } else { 1612 if (this._targets) { 1613 i = this._targets.length; 1614 while (--i > -1) { 1615 if (target === this._targets[i]) { 1616 propLookup = this._propLookup[i] || {}; 1617 this._overwrittenProps = this._overwrittenProps || []; 1618 overwrittenProps = this._overwrittenProps[i] = vars ? this._overwrittenProps[i] || {} : "all"; 1619 break; 1620 } 1621 } 1622 } else if (target !== this.target) { 1623 return false; 1624 } else { 1625 propLookup = this._propLookup; 1626 overwrittenProps = this._overwrittenProps = vars ? this._overwrittenProps || {} : "all"; 1627 } 1628 1629 if (propLookup) { 1630 killProps = vars || propLookup; 1631 record = (vars !== overwrittenProps && overwrittenProps !== "all" && vars !== propLookup && (typeof(vars) !== "object" || !vars._tempKill)); //_tempKill is a super-secret way to delete a particular tweening property but NOT have it remembered as an official overwritten property (like in BezierPlugin) 1632 if (overwritingTween && (TweenLite.onOverwrite || this.vars.onOverwrite)) { 1633 for (p in killProps) { 1634 if (propLookup[p]) { 1635 if (!killed) { 1636 killed = []; 1637 } 1638 killed.push(p); 1639 } 1640 } 1641 if ((killed || !vars) && !_onOverwrite(this, overwritingTween, target, killed)) { //if the onOverwrite returned false, that means the user wants to override the overwriting (cancel it). 1642 return false; 1643 } 1644 } 1645 1646 for (p in killProps) { 1647 if ((pt = propLookup[p])) { 1648 if (simultaneousOverwrite) { //if another tween overwrites this one and they both start at exactly the same time, yet this tween has already rendered once (for example, at 0.001) because it's first in the queue, we should revert the values to where they were at 0 so that the starting values aren't contaminated on the overwriting tween. 1649 if (pt.f) { 1650 pt.t[pt.p](pt.s); 1651 } else { 1652 pt.t[pt.p] = pt.s; 1653 } 1654 changed = true; 1655 } 1656 if (pt.pg && pt.t._kill(killProps)) { 1657 changed = true; //some plugins need to be notified so they can perform cleanup tasks first 1658 } 1659 if (!pt.pg || pt.t._overwriteProps.length === 0) { 1660 if (pt._prev) { 1661 pt._prev._next = pt._next; 1662 } else if (pt === this._firstPT) { 1663 this._firstPT = pt._next; 1664 } 1665 if (pt._next) { 1666 pt._next._prev = pt._prev; 1667 } 1668 pt._next = pt._prev = null; 1669 } 1670 delete propLookup[p]; 1671 } 1672 if (record) { 1673 overwrittenProps[p] = 1; 1674 } 1675 } 1676 if (!this._firstPT && this._initted && firstPT) { //if all tweening properties are killed, kill the tween. Without this line, if there's a tween with multiple targets and then you killTweensOf() each target individually, the tween would technically still remain active and fire its onComplete even though there aren't any more properties tweening. 1677 this._enabled(false, false); 1678 } 1679 } 1680 } 1681 return changed; 1682 }; 1683 1684 p.invalidate = function() { 1685 if (this._notifyPluginsOfEnabled) { 1686 TweenLite._onPluginEvent("_onDisable", this); 1687 } 1688 var t = this._time; 1689 this._firstPT = this._overwrittenProps = this._startAt = this._onUpdate = null; 1690 this._notifyPluginsOfEnabled = this._active = this._lazy = false; 1691 this._propLookup = (this._targets) ? {} : []; 1692 Animation.prototype.invalidate.call(this); 1693 if (this.vars.immediateRender) { 1694 this._time = -_tinyNum; //forces a render without having to set the render() "force" parameter to true because we want to allow lazying by default (using the "force" parameter always forces an immediate full render) 1695 this.render(t, false, this.vars.lazy !== false); 1696 } 1697 return this; 1698 }; 1699 1700 p._enabled = function(enabled, ignoreTimeline) { 1701 if (!_tickerActive) { 1702 _ticker.wake(); 1703 } 1704 if (enabled && this._gc) { 1705 var targets = this._targets, 1706 i; 1707 if (targets) { 1708 i = targets.length; 1709 while (--i > -1) { 1710 this._siblings[i] = _register(targets[i], this, true); 1711 } 1712 } else { 1713 this._siblings = _register(this.target, this, true); 1714 } 1715 } 1716 Animation.prototype._enabled.call(this, enabled, ignoreTimeline); 1717 if (this._notifyPluginsOfEnabled) if (this._firstPT) { 1718 return TweenLite._onPluginEvent((enabled ? "_onEnable" : "_onDisable"), this); 1719 } 1720 return false; 1721 }; 1722 1723 1724//----TweenLite static methods ----------------------------------------------------- 1725 1726 TweenLite.to = function(target, duration, vars) { 1727 return new TweenLite(target, duration, vars); 1728 }; 1729 1730 TweenLite.from = function(target, duration, vars) { 1731 vars.runBackwards = true; 1732 vars.immediateRender = (vars.immediateRender != false); 1733 return new TweenLite(target, duration, vars); 1734 }; 1735 1736 TweenLite.fromTo = function(target, duration, fromVars, toVars) { 1737 toVars.startAt = fromVars; 1738 toVars.immediateRender = (toVars.immediateRender != false && fromVars.immediateRender != false); 1739 return new TweenLite(target, duration, toVars); 1740 }; 1741 1742 TweenLite.delayedCall = function(delay, callback, params, scope, useFrames) { 1743 return new TweenLite(callback, 0, {delay:delay, onComplete:callback, onCompleteParams:params, callbackScope:scope, onReverseComplete:callback, onReverseCompleteParams:params, immediateRender:false, lazy:false, useFrames:useFrames, overwrite:0}); 1744 }; 1745 1746 TweenLite.set = function(target, vars) { 1747 return new TweenLite(target, 0, vars); 1748 }; 1749 1750 TweenLite.getTweensOf = function(target, onlyActive) { 1751 if (target == null) { return []; } 1752 target = (typeof(target) !== "string") ? target : TweenLite.selector(target) || target; 1753 var i, a, j, t; 1754 if ((_isArray(target) || _isSelector(target)) && typeof(target[0]) !== "number") { 1755 i = target.length; 1756 a = []; 1757 while (--i > -1) { 1758 a = a.concat(TweenLite.getTweensOf(target[i], onlyActive)); 1759 } 1760 i = a.length; 1761 //now get rid of any duplicates (tweens of arrays of objects could cause duplicates) 1762 while (--i > -1) { 1763 t = a[i]; 1764 j = i; 1765 while (--j > -1) { 1766 if (t === a[j]) { 1767 a.splice(i, 1); 1768 } 1769 } 1770 } 1771 } else if (target._gsTweenID) { 1772 a = _register(target).concat(); 1773 i = a.length; 1774 while (--i > -1) { 1775 if (a[i]._gc || (onlyActive && !a[i].isActive())) { 1776 a.splice(i, 1); 1777 } 1778 } 1779 } 1780 return a || []; 1781 }; 1782 1783 TweenLite.killTweensOf = TweenLite.killDelayedCallsTo = function(target, onlyActive, vars) { 1784 if (typeof(onlyActive) === "object") { 1785 vars = onlyActive; //for backwards compatibility (before "onlyActive" parameter was inserted) 1786 onlyActive = false; 1787 } 1788 var a = TweenLite.getTweensOf(target, onlyActive), 1789 i = a.length; 1790 while (--i > -1) { 1791 a[i]._kill(vars, target); 1792 } 1793 }; 1794 1795 1796 1797/* 1798* ---------------------------------------------------------------- 1799* TweenPlugin (could easily be split out as a separate file/class, but included for ease of use (so that people don't need to include another script call before loading plugins which is easy to forget) 1800* ---------------------------------------------------------------- 1801*/ 1802 var TweenPlugin = _class("plugins.TweenPlugin", function(props, priority) { 1803 this._overwriteProps = (props || "").split(","); 1804 this._propName = this._overwriteProps[0]; 1805 this._priority = priority || 0; 1806 this._super = TweenPlugin.prototype; 1807 }, true); 1808 1809 p = TweenPlugin.prototype; 1810 TweenPlugin.version = "1.19.0"; 1811 TweenPlugin.API = 2; 1812 p._firstPT = null; 1813 p._addTween = _addPropTween; 1814 p.setRatio = _setRatio; 1815 1816 p._kill = function(lookup) { 1817 var a = this._overwriteProps, 1818 pt = this._firstPT, 1819 i; 1820 if (lookup[this._propName] != null) { 1821 this._overwriteProps = []; 1822 } else { 1823 i = a.length; 1824 while (--i > -1) { 1825 if (lookup[a[i]] != null) { 1826 a.splice(i, 1); 1827 } 1828 } 1829 } 1830 while (pt) { 1831 if (lookup[pt.n] != null) { 1832 if (pt._next) { 1833 pt._next._prev = pt._prev; 1834 } 1835 if (pt._prev) { 1836 pt._prev._next = pt._next; 1837 pt._prev = null; 1838 } else if (this._firstPT === pt) { 1839 this._firstPT = pt._next; 1840 } 1841 } 1842 pt = pt._next; 1843 } 1844 return false; 1845 }; 1846
1847 p._mod = p._roundProps = function(lookup) { 1848 var pt = this._firstPT, 1849 val; 1850 while (pt) { 1851 val = lookup[this._propName] || (pt.n != null && lookup[ pt.n.split(this._propName + "_").join("") ]); 1852 if (val && typeof(val) === "function") { //some properties that are very plugin-specific add a prefix named after the _propName plus an underscore, so we need to ignore that extra stuff here. 1853 if (pt.f === 2) { 1854 pt.t._applyPT.m = val; 1855 } else { 1856 pt.m = val; 1857 } 1858 } 1859 pt = pt._next; 1860 } 1861 }; 1862 1863 TweenLite._onPluginEvent = function(type, tween) { 1864 var pt = tween._firstPT, 1865 changed, pt2, first, last, next; 1866 if (type === "_onInitAllProps") { 1867 //sorts the PropTween linked list in order of priority because some plugins need to render earlier/later than others, like MotionBlurPlugin applies its effects after all x/y/alpha tweens have rendered on each frame. 1868 while (pt) { 1869 next = pt._next; 1870 pt2 = first; 1871 while (pt2 && pt2.pr > pt.pr) { 1872 pt2 = pt2._next; 1873 } 1874 if ((pt._prev = pt2 ? pt2._prev : last)) { 1875 pt._prev._next = pt; 1876 } else { 1877 first = pt; 1878 } 1879 if ((pt._next = pt2)) { 1880 pt2._prev = pt; 1881 } else { 1882 last = pt; 1883 } 1884 pt = next; 1885 } 1886 pt = tween._firstPT = first; 1887 } 1888 while (pt) { 1889 if (pt.pg) if (typeof(pt.t[type]) === "function") if (pt.t[type]()) { 1890 changed = true; 1891 } 1892 pt = pt._next; 1893 } 1894 return changed; 1895 }; 1896 1897 TweenPlugin.activate = function(plugins) { 1898 var i = plugins.length; 1899 while (--i > -1) { 1900 if (plugins[i].API === TweenPlugin.API) { 1901 _plugins[(new plugins[i]())._propName] = plugins[i]; 1902 } 1903 } 1904 return true; 1905 }; 1906 1907 //provides a more concise way to define plugins that have no dependencies besides TweenPlugin and TweenLite, wrapping common boilerplate stuff into one function (added in 1.9.0). You don't NEED to use this to define a plugin - the old way still works and can be useful in certain (rare) situations. 1908 _gsDefine.plugin = function(config) { 1909 if (!config || !config.propName || !config.init || !config.API) { throw "illegal plugin definition."; } 1910 var propName = config.propName, 1911 priority = config.priority || 0, 1912 overwriteProps = config.overwriteProps, 1913 map = {init:"_onInitTween", set:"setRatio", kill:"_kill", round:"_mod", mod:"_mod", initAll:"_onInitAllProps"}, 1914 Plugin = _class("plugins." + propName.charAt(0).toUpperCase() + propName.substr(1) + "Plugin", 1915 function() { 1916 TweenPlugin.call(this, propName, priority); 1917 this._overwriteProps = overwriteProps || []; 1918 }, (config.global === true)), 1919 p = Plugin.prototype = new TweenPlugin(propName), 1920 prop; 1921 p.constructor = Plugin; 1922 Plugin.API = config.API; 1923 for (prop in map) { 1924 if (typeof(config[prop]) === "function") { 1925 p[map[prop]] = config[prop]; 1926 } 1927 } 1928 Plugin.version = config.version; 1929 TweenPlugin.activate([Plugin]); 1930 return Plugin; 1931 }; 1932 1933 1934 //now run through all the dependencies discovered and if any are missing, log that to the console as a warning. This is why it's best to have TweenLite load last - it can check all the dependencies for you. 1935 a = window._gsQueue; 1936 if (a) { 1937 for (i = 0; i < a.length; i++) { 1938 a[i](); 1939 } 1940 for (p in _defLookup) { 1941 if (!_defLookup[p].func) { 1942 window.console.log("GSAP encountered missing dependency: " + p); 1943 } 1944 } 1945 } 1946 1947 _tickerActive = false; //ensures that the first official animation forces a ticker.tick() to update the time when it is instantiated 1948 1949})((typeof(module) !== "undefined" && module.exports && typeof(global) !== "undefined") ? global : this || window, "TweenLite");
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.