var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
seg.b=cp1=seg.a+(seg.c-seg.a)*0.6;//instead of placing b on a exactly, we move it inline with c so that if the user specifies an ease like Back.easeIn or Elastic.easeIn which goes BEYOND the beginning, it will do so smoothly.
}
seg.da=p2-p1;
seg.ca=cp2-p1;
seg.ba=cp1-p1;
if(quad){
qb=cubicToQuadratic(p1,cp1,cp2,p2);
a.splice(ii,1,qb[0],qb[1],qb[2],qb[3]);
ii+=4;
}else{
ii++;
}
cp1=m2;
}
seg=a[ii];
seg.b=cp1;
seg.c=cp1+(seg.d-cp1)*0.4;//instead of placing c on d exactly, we move it inline with b so that if the user specifies an ease like Back.easeOut or Elastic.easeOut which goes BEYOND the end, it will do so smoothly.
values[i][p]=prepend[p]+Number(tmp.charAt(0)+tmp.substr(2));//accommodate relative values. Do it inline instead of breaking it out into a function for speed reasons
//check to see if the last and first values are identical (well, within 0.05). If so, make seamless by appending the second element to the very end of the values array and the 2nd-to-last element to the very beginning (we'll remove those segments later)
if(values.length>1){
last=values[values.length-1];
seamless=true;
i=props.length;
while(--i>-1){
p=props[i];
if(Math.abs(first[p]-last[p])>0.05){//build in a tolerance of +/-0.05 to accommodate rounding errors.
seamless=false;
break;
}
}
if(seamless){
values=values.concat();//duplicate the array to avoid contaminating the original which the user may be reusing for other tweens
_calculateControlPoints(a,curviness,quadratic,basic,_corProps[p]);//this method requires that _parseAnchors() and _setSegmentRatios() ran first so that _r1, _r2, and _r3 values are populated for all properties
this._startRatio=tween.vars.runBackwards?1:0;//we determine the starting ratio when the tween inits which is always 0 unless the tween has runBackwards:true (indicating it's a from() tween) in which case it's 1.
returntrue;
},
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
v[p]=e[p];//duplicate the vars object because we need to alter some things which would cause problems if the user plans to reuse the same vars object for another tween.
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
this.setRatio=CSSPlugin.prototype.setRatio;//speed optimization (avoid prototype lookup on this "hot" method)
},
_globals=_gsScope._gsDefine.globals,
_hasPriority,//turns true whenever a CSSPropTween instance is created that has a priority other than 0. This helps us discern whether or not we should spend the time organizing the linked list or not after a CSSPlugin's _onInitTween() method is called.
_suffixMap,//we set this in _onInitTween() each time as a way to have a persistent variable we can use in other methods like _parse() without having to pass it around as a parameter and we keep _parse() decoupled from a particular CSSPlugin instance
_cs,//computed style (we store this in a shared variable to conserve memory and make minification tighter
_overwriteProps,//alias to the currently instantiating CSSPlugin's _overwriteProps array. We use this closure in order to avoid having to pass a reference around from method to method and aid in minification.
_specialProps={},
p=CSSPlugin.prototype=newTweenPlugin("css");
p.constructor=CSSPlugin;
CSSPlugin.version="2.1.0";
CSSPlugin.API=2;
CSSPlugin.defaultTransformPerspective=0;
CSSPlugin.defaultSkewType="compensated";
CSSPlugin.defaultSmoothOrigin=true;
p="px";//we'll reuse the "p" variable to keep file size down
_valuesExp=/(?:\+=|\-=|\-|\b)[\d\-\.]+[a-zA-Z0-9]*(?:%|\b)/gi,//finds all the values that begin with numbers or += or -= and then a number. Includes suffixes. We use this to split complex values apart like "1px 5px 20px rgb(255,102,51)"
_NaNExp=/(?![+-]?\d*\.?\d+|[+-]|e[+-]\d+)[^0-9]/g,//also allows scientific notation and doesn't kill the leading -/+ in -= and +=
_suffixExp=/(?:\d|\-|\+|=|#|\.)*/g,
_opacityExp=/opacity *= *([^)]*)/i,
_opacityValExp=/opacity:([^;]*)/i,
_alphaFilterExp=/alpha\(opacity *=.+?\)/i,
_rgbhslExp=/^(rgb|hsl)/,
_capsExp=/([A-Z])/g,
_camelExp=/-([a-z])/gi,
_urlExp=/(^(?:url\(\"|url\())|(?:(\"\))$|\)$)/gi,//for pulling out urls from url(...) or url("...") strings (some browsers wrap urls in quotes, some don't when reporting things like backgroundImage)
_internals=CSSPlugin._internals={_specialProps:_specialProps},//provides a hook to a few internal methods that we need to access from inside other plugins
_agent=(_gsScope.navigator||{}).userAgent||"",
_autoRound,
_reqSafariFix,//we won't apply the Safari transform fix until we actually come across a tween that affects a transform property (to maintain best performance).
_isSafari,
_isFirefox,//Firefox has a bug that causes 3D transformed elements to randomly disappear unless a repaint is forced after each update on each element.
_isSafariLT6,//Safari (and Android 4 which uses a flavor of Safari) has a bug that prevents changes to "top" and "left" properties from rendering properly if changed on the same frame as a transform UNLESS we set the element's WebkitBackfaceVisibility to hidden (weird, I know). Doing this for Android 3 and earlier seems to actually cause other problems, though (fun!)
_ieVers,
_supportsOpacity=(function(){//we set _isSafari, _ieVers, _isFirefox, and _supportsOpacity all in one function here to reduce file size slightly, especially in the minified version.
_log=function(s){//for logging messages, but in a way that won't throw errors in old versions of IE.
if(_gsScope.console){
console.log(s);
}
},
_target,//when initting a CSSPlugin, we set this variable so that we can access it from within many other functions without having to pass it around as params
_index,//when initting a CSSPlugin, we set this variable so that we can access it from within many other functions without having to pass it around as params
_prefixCSS="",//the non-camelCase vendor prefix like "-o-", "-moz-", "-ms-", or "-webkit-"
_prefix="",//camelCase vendor prefix like "O", "ms", "Webkit", or "Moz".
// @private feed in a camelCase property name like "transform" and it will check to see if it is valid as-is or if it needs a vendor prefix. It returns the corrected camelCase property name (i.e. "WebkitTransform" or "MozTransform" or "transform" or null if no such property is found, like if the browser is IE8 or before, "transform" won't be found at all)
return_computedStyleScope.getComputedStyle(e);//to avoid errors in Microsoft Edge, we need to call getComputedStyle() from a specific scope, typically window.
if(!_supportsOpacity)if(p==="opacity"){//several versions of IE don't use the standard "opacity" property - they use things like filter:alpha(opacity=50), so we parse that here.
if(p==="lineHeight"&&!sfx){//special case of when a simple lineHeight (without a unit) is used. Set it to the value, read back the computed value, and then revert.
if(_getStyle(node,"display").indexOf("flex")!==-1){//Edge and IE11 have a bug that causes offsetWidth to report as 0 if the container has display:flex and the child is position:relative. Switching to position: absolute solves it.
style.position="absolute";
}
cache=node._gsCache;
time=TweenLite.ticker.frame;
if(cache&&horiz&&cache.time===time){//performance optimization: we record the width of elements along with the ticker frame so that we can quickly get it again on the same tick (seems relatively safe to assume it wouldn't change on the same tick)
_calculateOffset=_internals.calculateOffset=function(t,p,cs){//for figuring out "top" or "left" in px when it's "auto". We need to factor in margin with the offsetLeft/offsetTop
// @private returns at object containing ALL of the style properties in camelCase and their associated values.
_getAllStyles=function(t,cs){
vars={},
i,tr,p;
if((cs=cs||_getComputedStyle(t,null))){
if((i=cs.length)){
while(--i>-1){
p=cs[i];
if(p.indexOf("-transform")===-1||_transformPropCSS===p){//Some webkit browsers duplicate transform values, one non-prefixed and one prefixed ("transform" and "WebkitTransform"), so we must weed out the extra one here.
}else{//some browsers behave differently - cs.length is always 0, so we must do a for...in loop.
for(iincs){
if(i.indexOf("Transform")===-1||_transformProp===i){//Some webkit browsers duplicate transform values, one non-prefixed and one prefixed ("transform" and "WebkitTransform"), so we must weed out the extra one here.
s[i]=cs[i];
}
}
}
}elseif((cs=t.currentStyle||t.style)){
for(iincs){
if(typeof(i)==="string"&&s[i]===undefined){
s[i.replace(_camelExp,_camelFunc)]=cs[i];
}
}
}
if(!_supportsOpacity){
s.opacity=_getIEOpacity(t);
}
tr=_getTransform(t,cs,false);
s.rotation=tr.rotation;
s.skewX=tr.skewX;
s.scaleX=tr.scaleX;
s.scaleY=tr.scaleY;
s.x=tr.x;
s.y=tr.y;
if(_supports3D){
s.z=tr.z;
s.rotationX=tr.rotationX;
s.rotationY=tr.rotationY;
s.scaleZ=tr.scaleZ;
}
if(s.filters){
deletes.filters;
}
returns;
},
// @private analyzes two style objects (as returned by _getAllStyles()) and only looks for differences between them that contain tweenable values (like a number or color). It returns an object with a "difs" property which refers to an object containing only those isolated properties and values for tweening, and a "firstMPT" property which refers to the first MiniPropTween instance in a linked list that recorded all the starting values of the different properties so that we can revert to them at the end or beginning of the tween - we don't want the cascading to get messed up. The forceLookup parameter is an optional generic object with properties that should be forced into the results - this is necessary for className tweens that are overwriting others because imagine a scenario where a rollover/rollout adds/removes a class and the user swipes the mouse over the target SUPER fast, thus nothing actually changed yet and the subsequent comparison of the properties would indicate they match (especially when px rounding is taken into consideration), thus no tweening is necessary even though it SHOULD tween and remove those properties after the tween (otherwise the inline styles will contaminate things). See the className SpecialProp code for details.
difs[p]=(val==="auto"&&(p==="left"||p==="top"))?_calculateOffset(t,p):((val===""||val==="auto"||val==="none")&&typeof(s1[p])==="string"&&s1[p].replace(_NaNExp,"")!=="")?0:val;//if the ending value is defaulting ("" or "auto"), we check the starting value and if it can be parsed into a number (a string which could have a suffix too, like 700px), then we swap in 0 for "" or "auto" so that things actually tween.
if(style[p]!==undefined){//for className tweens, we must remember which properties already existed inline - the ones that didn't should be removed when the tween isn't in progress because they were only introduced to facilitate the transition between classes.
// @private Parses position-related complex strings like "top left" or "50px 10px" or "70% 20%", etc. which are used for things like transformOrigin or backgroundPosition. Optionally decorates a supplied object (recObj) with the following properties: "ox" (offsetX), "oy" (offsetY), "oxp" (if true, "ox" is a percentage not a pixel value), and "oxy" (if true, "oy" is a percentage not a pixel value)
if(x==="center"||(isNaN(parseFloat(x))&&(x+"").indexOf("=")===-1)){//remember, the user could flip-flop the values and say "bottom center" or "center bottom", etc. "center" is ambiguous because it could be used to describe horizontal or vertical, hence the isNaN(). If there's an "=" sign in the value, it's relative.
*@privateTranslatesstringslike"40deg"or"40"or40rad" or "+=40deg" or "270_short" or "-90_cw" or "+=45_ccw"toanumericradianangle.Ofcourseastarting/defaultvaluemustbefedintoosothatrelativevaluescanbecalculatedproperly.
if(v.charAt(v.length-1)===","){//sometimes a trailing comma is included and we should chop it off (typically from a comma-delimited list of values like a textShadow:"2px 2px 2px blue, 5px 5px 5px rgb(255,0,0)" - in this example "blue," has a trailing comma. We could strip it out inside parseComplex() but we'd need to do it to the beginning and ending values plus it wouldn't provide protection from other potential scenarios like if the user passes in a similar value.
v=v.substr(0,v.length-1);
}
if(_colorLookup[v]){
a=_colorLookup[v];
}elseif(v.charAt(0)==="#"){
if(v.length===4){//for shorthand like #9F0
r=v.charAt(1);
g=v.charAt(2);
b=v.charAt(3);
v="#"+r+r+g+g+b+b;
}
v=parseInt(v.substr(1),16);
a=[v>>16,(v>>8)&255,v&255];
}elseif(v.substr(0,3)==="hsl"){
a=wasHSL=v.match(_numExp);
if(!toHSL){
h=(Number(a[0])%360)/360;
s=Number(a[1])/100;
l=Number(a[2])/100;
g=(l<=0.5)?l*(s+1):l+s-l*s;
r=l*2-g;
if(a.length>3){
a[3]=Number(a[3]);
}
a[0]=_hue(h+1/3,r,g);
a[1]=_hue(h,r,g);
a[2]=_hue(h-1/3,r,g);
}elseif(v.indexOf("=")!==-1){//if relative values are found, just return the raw strings with the relative prefixes in place.
_colorExp="(?:\\b(?:(?:rgb|rgba|hsl|hsla)\\(.+?\\))|\\B#(?:[0-9a-f]{3}){1,2}\\b";//we'll dynamically build this Regular Expression to conserve file size. After building it, it will be able to find rgb(), rgba(), # (hexadecimal), and named color values like red, blue, purple, etc.
// @private used when other plugins must tween values first, like BezierPlugin or ThrowPropsPlugin, etc. That plugin's setRatio() gets called first so that the values are updated, and then we loop through the MiniPropTweens which handle copying the values into their appropriate slots so that they can then be applied correctly in the main CSSPlugin setRatio() method. Remember, we typically create a proxy object that has a bunch of uniquely-named properties that we feed to the sub-plugin and it does its magic normally, and then we must interpret those values and apply them to the css because often numbers must get combined/concatenated, suffixes added, etc. to work with css, like boxShadow could have 4 values plus a color.
d.autoRotate.rotation=d.mod?d.mod.call(this._tween,proxy.rotation,this.t,this._tween):proxy.rotation;//special case for ModifyPlugin to hook into an auto-rotating bezier
}
//at the end, we must set the CSSPropTween's "e" (end) value dynamically here because that's what is used in the final setRatio() method. Same for "b" at the beginning.
*@privateMostotherplugins(likeBezierPluginandThrowPropsPluginandothers)canonlytweennumericvalues,butCSSPluginmustaccommodatespecialvaluesthathaveabunchofextradata(likeasuffixorstringsbetweennumericvalues,etc.).Forexample,boxShadowhasvalueslike"10px 10px 20px 30px rgb(255,0,0)"whichwouldutterlyconfuseotherplugins.Thismethodallowsustosplitthatdataapartandgrabonlythenumericdataandattachittouniquely-namedpropertiesofagenericproxyobject({})sothatwecanfeedthattovirtuallyanyplugintohavethenumberstweened.However,wemustalsokeeptrackofwhichpropertiesfromtheproxygowithwhichCSSPropTweenvaluesandinstances.SowecreatealinkedlistofMiniPropTweens.Eachonerecordsatarget(theoriginalCSSPropTween),property(like"s"or"xn1"or"xn2")thatwe're tweening and the unique property name that was used for the proxy (like "boxShadow_xn1" and "boxShadow_xn2") and whether or not they need to be rounded. That way, in the _setPluginRatio() method we can simply copy the values over from the proxy to the CSSPropTween instance(s). Then, when the main CSSPlugin setRatio() method runs and applies the CSSPropTween values accordingly, they'reupdatednicely.Sotheexternalplugintweensthenumbers,_setPluginRatio()copiesthemover,andsetRatio()actsnormally,applyingcss-specificvaluestotheelement.
*-xfirst:Thefirstinstanceofanysub-CSSPropTweensthataretweeningpropertiesofthisinstance.Forexample,wemaysplitupaboxShadowtweensothatthere's a main CSSPropTween of type:1 that has various xs* and xn* values associated with the h-shadow, v-shadow, blur, color, etc. Then we spawn a CSSPropTween for each of those that has a higher priority and runs BEFORE the main CSSPropTween so that the values are all set by the time it needs to re-assemble them. The xfirst gives us an easy way to identify the first one in that chain which typically ends at the main one (because they'reallprependetothelinkedlist)
*-data:ArbitrarydatathatneedstobestoredwiththeCSSPropTween.Typicallyifwe're going to have a plugin handle the tweening of a complex-value tween, we create a generic object that stores the END values that we'retweeningtoandtheCSSPropTween'sxs1,xs2,etc.havethestartingvalues.Westorethatobjectasdata.Thatway,wecansimplypassthatobjecttothepluginandusetheCSSPropTweenasthetarget.
*-setRatio:Onlyusedfortype:2tweensthatrequirecustomfunctionality.Inthiscase,wecalltheCSSPropTween's setRatio() method and pass the ratio each time the tween updates. This isn'tquiteasefficientasdoingthingsdirectlyintheCSSPlugin's setRatio() method, but it'sveryconvenientandflexible.
this.type=type||0;//0 = normal tween, -1 = non-tweening (in which case xs0 will be applied to the target's property, like tp.t[tp.p] = tp.xs0), 1 = complex-value SpecialProp, 2 = custom setRatio() that does all the work
if(pr){
this.pr=pr;
_hasPriority=true;
}
this.b=(b===undefined)?s:b;
this.e=(e===undefined)?s+c:e;
if(next){
this._next=next;
next._prev=this;
}
},
_addNonTweeningNumericPT=function(target,prop,start,end,next,overwriteProp){//cleans up some code redundancies and helps minification. Just a fast way to add a NUMERIC non-tweening CSSPropTween
*sp.parseComplex(element,"boxShadow","5px 10px 20px rgb(255,102,51)","0px 0px 0px red",true,"0px 0px 0px rgb(0,0,0,0)",pt);
*Itwillwalkthroughthebeginningandendingvalues(whichshouldbeinthesameformatwiththesamenumberandtypeofvalues)andfigureoutwhichpartsarenumbers,whatstringsseparatethenumeric/tweenablevalues,andthencreatetheCSSPropTweensaccordingly.Ifapluginisdefined,nochildCSSPropTweenswillbecreated.Instead,theendingvalueswillbestoredinthe"data"propertyofthereturnedCSSPropTweenlike:{s:-5,xn1:-10,xn2:-20,xn3:255,xn4:0,xn5:0}sothatitcanbefedtoanyotherpluginandit'll be plain numeric tweens but the recomposition of the complex value will be handled inside CSSPlugin'ssetRatio().
temp=ev;//original string value so we can look for any prefix later.
bv=_parseColor(bv,useHSL);
ev=_parseColor(ev,useHSL);
hasAlpha=(bv.length+ev.length>6);
if(hasAlpha&&!_supportsOpacity&&ev[3]===0){//older versions of IE don't support rgba(), so if the destination alpha is 0, just use "transparent" for the end color
pt["xs"+pt.l]+=pt.l?" transparent":"transparent";
pt.e=pt.e.split(ea[i]).join("transparent");
}else{
if(!_supportsOpacity){//old versions of IE don't support rgba().
_colorExp.lastIndex=0;//otherwise the test() on the RegExp could move the lastIndex and taint future results.
}else{
bnums=bv.match(_numExp);//gets each group of numbers in the beginning value string and drops them into an array
//if no number is found, treat it as a non-tweening value and just append the string to the current xs.
if(!bnums){
pt["xs"+pt.l]+=(pt.l||pt["xs"+pt.l])?" "+ev:ev;
//loop through all the numbers that are found and construct the extra values on the pt.
}else{
enums=ev.match(_relNumExp);//get each group of numbers in the end value string and drop them into an array. We allow relative values too, like +=50 or -=.5
if(!enums||enums.length!==bnums.length){
//DEBUG: _log("mismatched formatting detected on " + p + " (" + b + " vs " + e + ")");
if(!c)if(l!==0&&!pt.plugin){//typically we'll combine non-changing values right into the xs to optimize performance, but we don't combine them when there's a plugin that will be tweening the values because it may depend on the values being split apart, like for a bezier, if a value doesn't change between the first and second iteration but then it does on the 3rd, we'll run into trouble because there's no xn slot for that value!
pt["xs"+l]+=s+(sfx||"");
returnpt;
}
pt.l++;
pt.type=pt.setRatio?2:1;
pt["xs"+pt.l]=sfx||"";
if(l>0){
pt.data["xn"+l]=s+c;
pt.rxp["xn"+l]=r;//round extra property (we need to tap into this in the _parseToProxy() method)
pt.xfirst.xs0=0;//just to ensure that the property stays numeric which helps modern browsers speed up processing. Remember, in the setRatio() method, we do pt.t[pt.p] = val + pt.xs0 so if pt.xs0 is "" (the default), it'll cast the end value as a string. When a property is a number sometimes and a string sometimes, it prevents the compiler from locking in the data type, slowing things down slightly.
//shortcut for creating a new SpecialProp that can accept multiple properties as a comma-delimited list (helps minification). dflt can be an array for multiple values (we don't do a comma-delimited list because the default value may contain commas, like rect(0px,0px,0px,0px)). We attach this method to the SpecialProp class/object instead of using a private _createSpecialProp() method so that we can tap into it externally if necessary, like from another plugin.
options={parser:defaults};//to make backwards compatible with older versions of BezierPlugin and ThrowPropsPlugin
}
vara=p.split(","),
d=options.defaultValue,
i,temp;
defaults=defaults||[d];
for(i=0;i<a.length;i++){
options.prefix=(i===0&&options.prefix);
options.defaultValue=defaults[i]||d;
temp=newSpecialProp(a[i],options);
}
},
//creates a placeholder special prop for a plugin so that the property gets caught the first time a tween of it is attempted, and at that time it makes the plugin register itself, thus taking over for all future tweens of that property. This allows us to not mandate that things load in a particular order and it also allows us to log() an error that informs the user when they attempt to tween an external plugin-related property without loading its .js file.
//if this SpecialProp's value can contain a comma-delimited list of values (like boxShadow or textShadow), we must parse them in a special way, and look for a keyword (like "inset" for boxShadow) and ensure that the beginning and ending BOTH have it if the end defines it as such. We also must ensure that there are an equal number of values specified (we can't tween 1 boxShadow to 3 for example)
CSSPlugin.useSVGTransformAttr=true;//Safari and Firefox both have some rendering bugs when applying CSS transforms to SVG elements, so default to using the "transform" attribute instead (users can override this).
//Some browsers (like Firefox and IE) don't honor transform-origin properly in SVG elements, so we need to manually adjust the matrix accordingly. We feature detect here rather than always doing the conversion for certain browsers because they may fix the problem at some point in the future.
//IE and Android stock don't support CSS transforms on SVG elements, so we must write them to the "transform" attribute. We populate this variable in the _parseTransform() method, and only if/when we come across an SVG element
force=(width===rect.getBoundingClientRect().width&&!(_isFirefox&&_supports3D));//note: Firefox fails the test even though it does support CSS transforms in 3D. Since we can't push 3D stuff into the transform attribute, we force Firefox to pass the test here (as long as it does truly support 3D).
xOriginOld=tm.xOrigin;//record the original values before we alter them.
yOriginOld=tm.yOrigin;
}
if(!absolute||(v=absolute.split(" ")).length<2){
b=e.getBBox();
if(b.x===0&&b.y===0&&b.width+b.height===0){//some browsers (like Firefox) misreport the bounds if the element has zero width and height (it just assumes it's at x:0, y:0), thus we need to manually grab the position in that case.
if(absolute&&m!==_identity2DMatrix){//if svgOrigin is being set, we must invert the matrix and determine where the absolute point is, factoring in the current transforms. Otherwise, the svgOrigin would be based on the element's non-transformed position on the canvas.
a=m[0];
b=m[1];
c=m[2];
d=m[3];
tx=m[4];
ty=m[5];
determinant=(a*d-b*c);
if(determinant){//if it's zero (like if scaleX and scaleY are zero), skip it to avoid errors with dividing by zero.
//originally, we simply adjusted the x and y values, but that would cause problems if, for example, you created a rotational tween part-way through an x/y tween. Managing the offset in a separate variable gives us ultimate flexibility.
//tm.x -= x - (x * m[0] + y * m[2]);
//tm.y -= y - (x * m[1] + y * m[3]);
tm.xOffset+=(x*m[0]+y*m[2])-x;
tm.yOffset+=(x*m[1]+y*m[3])-y;
}else{
tm.xOffset=tm.yOffset=0;
}
}
if(!skipRecord){
e.setAttribute("data-svg-origin",v.join(" "));
}
},
_getBBoxHack=function(swapIfPossible){//works around issues in some browsers (like Firefox) that don't correctly report getBBox() on SVG elements inside a <defs> element and/or <mask>. We try creating an SVG, adding it to the documentElement and toss the element in there so that it's definitely part of the rendering tree, then grab the bbox and if it works, we actually swap out the original getBBox() method for our own that does these extra steps whenever getBBox is needed. This helps ensure that performance is optimal (only do all these extra steps when absolutely necessary...most elements don't need it).
returne.getBBox();//Firefox throws errors if you try calling getBBox() on an SVG element that's not rendered (like in a <symbol> or <defs>). https://bugzilla.mozilla.org/show_bug.cgi?id=612118
}catch(error){
return_getBBoxHack.call(e,true);
}
},
_isSVG=function(e){//reports if the element is an SVG on which getBBox() actually works
//for older versions of IE, we need to interpret the filter portion that is in the format: progid:DXImageTransform.Microsoft.Matrix(M11=6.123233995736766e-17, M12=-1, M21=1, M22=6.123233995736766e-17, sizingMethod='auto expand') Notice that we need to swap b and c compared to a normal matrix.
if(_transformProp&&isDefault&&!e.offsetParent){//note: if offsetParent is null, that means the element isn't in the normal document flow, like if it has display:none or one of its ancestors has display:none). Firefox returns null for getComputedStyle() if the element is in an iframe that has display:none. https://bugzilla.mozilla.org/show_bug.cgi?id=548397
//browsers don't report transforms accurately unless the element is in the DOM and has a display value that's not "none". Firefox and Microsoft browsers have a partial bug where they'll report transforms even if display:none BUT not any percentage-based values like translate(-50%, 8px) will be reported as if it's translate(0, 8px).
n=style.display;
style.display="block";
parent=e.parentNode;
if(!parent||!e.offsetParent){
dec=1;//flag
nextSibling=e.nextSibling;
_docElement.appendChild(e);//we must add it to the DOM in order to get values properly
if(isDefault&&(style[_transformProp]+"").indexOf("matrix")!==-1){//some browsers (like Chrome 40) don't correctly report transforms that are applied inline on an SVG element (they don't get included in the computed style), so we double-check here and accept matrix values
s=style[_transformProp];
isDefault=0;
}
m=e.getAttribute("transform");
if(isDefault&&m){
m=e.transform.baseVal.consolidate().matrix;//ensures that even complex values like "translate(50,60) rotate(135,0,0)" are parsed because it mashes it into a matrix.
//split the matrix values out into an array (m for matrix)
m=(s||"").match(_numExp)||[];
i=m.length;
while(--i>-1){
n=Number(m[i]);
m[i]=(dec=n-(n|=0))?((dec*rnd+(dec<0?-0.5:0.5))|0)/rnd+n:n;//convert strings to Numbers and round to 5 decimal places to avoid issues with tiny numbers. Roughly 20x faster than Number.toFixed(). We also must make sure to round before dividing so that values like 0.9999999999 become 1 to avoid glitches in browser rendering and interpretation of flipped/rotated 3D matrices. And don't just multiply the number by rnd, floor it, and then divide by rnd because the bitwise operations max out at a 32-bit signed integer, thus it could get clipped at a relatively low value (like 22,000.00000 for example).
returnt._gsTransform;//if the element already has a _gsTransform, use that. Note: some browsers don't accurately return the calculated style for the transform (particularly for SVG), so it's almost always safest to just use the values we've already applied rather than re-parsing things.
invX=(tm.scaleX<0),//in order to interpret things properly, we need to know if the user applied a negative scaleX previously so that we can adjust the rotation and skewX accordingly. Otherwise, if we always interpret a flipped matrix as affecting scaleY and the user only wants to tween the scaleX on multiple sequential tweens, it would keep the negative scaleY without that being the user's intent.
//we'll only look at these position-related 6 variables first because if x/y/z all match, it's relatively safe to assume we don't need to re-parse everything which risks losing important rotational information (like rotationX:180 plus rotationY:180 would look the same as rotation:180 - there's no way to know for sure which direction was taken based solely on the matrix3d() values)
vara11=m[0],a21=m[1],a31=m[2],a41=m[3],
a12=m[4],a22=m[5],a32=m[6],a42=m[7],
a13=m[8],a23=m[9],a33=m[10],
a14=m[12],a24=m[13],a34=m[14],
a43=m[11],
angle=Math.atan2(a32,a33),
t1,t2,t3,t4,cos,sin;
//we manually compensate for non-zero z component of transformOrigin to work around bugs in Safari
if(tm.zOrigin){
a34=-tm.zOrigin;
a14=a13*a34-m[12];
a24=a23*a34-m[13];
a34=a33*a34+tm.zOrigin-m[14];
}
//note for possible future consolidation: rotationX: Math.atan2(a32, a33), rotationY: Math.atan2(-a31, Math.sqrt(a33 * a33 + a32 * a32)), rotation: Math.atan2(a21, a11), skew: Math.atan2(a12, a22). However, it doesn't seem to be quite as reliable as the full-on backwards rotation procedure.
tm.rotationX=angle*_RAD2DEG;
//rotationX
if(angle){
cos=Math.cos(-angle);
sin=Math.sin(-angle);
t1=a12*cos+a13*sin;
t2=a22*cos+a23*sin;
t3=a32*cos+a33*sin;
a13=a12*-sin+a13*cos;
a23=a22*-sin+a23*cos;
a33=a32*-sin+a33*cos;
a43=a42*-sin+a43*cos;
a12=t1;
a22=t2;
a32=t3;
}
//rotationY
angle=Math.atan2(-a31,a33);
tm.rotationY=angle*_RAD2DEG;
if(angle){
cos=Math.cos(-angle);
sin=Math.sin(-angle);
t1=a11*cos-a13*sin;
t2=a21*cos-a23*sin;
t3=a31*cos-a33*sin;
a23=a21*sin+a23*cos;
a33=a31*sin+a33*cos;
a43=a41*sin+a43*cos;
a11=t1;
a21=t2;
a31=t3;
}
//rotationZ
angle=Math.atan2(a21,a11);
tm.rotation=angle*_RAD2DEG;
if(angle){
cos=Math.cos(angle);
sin=Math.sin(angle);
t1=a11*cos+a21*sin;
t2=a12*cos+a22*sin;
t3=a13*cos+a23*sin;
a21=a21*cos-a11*sin;
a22=a22*cos-a12*sin;
a23=a23*cos-a13*sin;
a11=t1;
a12=t2;
a13=t3;
}
if(tm.rotationX&&Math.abs(tm.rotationX)+Math.abs(tm.rotation)>359.9){//when rotationY is set, it will often be parsed as 180 degrees different than it should be, and rotationX and rotation both being 180 (it looks the same), so we adjust for that here.
tm.scaleY*=1/Math.cos(angle);//by default, we compensate the scale based on the skew so that the element maintains a similar proportion when skewed, so we have to alter the scaleY here accordingly to match the default (non-adjusted) skewing that CSS does (stretching more and more as it skews).
}elseif((!_supports3D||parse||!m.length||tm.x!==m[4]||tm.y!==m[5]||(!tm.rotationX&&!tm.rotationY))){//sometimes a 6-element matrix is returned even when we performed 3D transforms, like if rotationX and rotationY are 180. In cases like this, we still need to honor the 3D transforms. If we just rely on the 2D info, it could affect how the data is interpreted, like scaleY might get set to -1 or rotation could get offset by 180 degrees. For example, do a TweenLite.to(element, 1, {css:{rotationX:180, rotationY:180}}) and then later, TweenLite.to(element, 1, {css:{rotationX:0}}) and without this conditional logic in place, it'd jump to a state of being unrotated when the 2nd tween starts. Then again, we need to honor the fact that the user COULD alter the transforms outside of CSSPlugin, like by manually applying new css, so we try to sense that by looking at x and y because if those changed, we know the changes were made outside CSSPlugin and we force a reinterpretation of the matrix values. Also, in Webkit browsers, if the element's "display" is "none", its calculated style value will always return empty, so if we've already recorded the values in the _gsTransform object, we'll just rely on those.
vark=(m.length>=6),
a=k?m[0]:1,
b=m[1]||0,
c=m[2]||0,
d=k?m[3]:1;
tm.x=m[4]||0;
tm.y=m[5]||0;
scaleX=Math.sqrt(a*a+b*b);
scaleY=Math.sqrt(d*d+c*c);
rotation=(a||b)?Math.atan2(b,a)*_RAD2DEG:tm.rotation||0;//note: if scaleX is 0, we cannot accurately measure rotation. Same for skewX with a scaleY of 0. Therefore, we default to the previously recorded value (or zero if that doesn't exist).
//some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 0 in these cases. The conditional logic here is faster than calling Math.abs(). Also, browsers tend to render a SLIGHTLY rotated object in a fuzzy way, so we need to snap to exactly 0 when appropriate.
t._gsTransform=tm;//record to the object's _gsTransform which we use so that tweens can control individual properties independently (we need all the properties to accurately recompose the matrix in the setRatio() method)
if(tm.svg){//if we're supposed to apply transforms to the SVG element's "transform" attribute, make sure there aren't any CSS transforms applied or they'll override the attribute ones. Also clear the transform attribute if we're using CSS, just to be clean.
TweenLite.delayedCall(0.001,function(){//if we apply this right away (before anything has rendered), we risk there being no transforms for a brief moment and it also interferes with adjusting the transformOrigin in a tween with immediateRender:true (it'd try reading the matrix and it wouldn't have the appropriate data in place because we just removed it).
//for setting 2D transforms in IE6, IE7, and IE8 (must use a "filter" to emulate the behavior of modern day browser transforms)
_setIETransformRatio=function(v){
vart=this.data,//refers to the element's _gsTransform object
ang=-t.rotation*_DEG2RAD,
skew=ang+t.skewX*_DEG2RAD,
rnd=100000,
a=((Math.cos(ang)*t.scaleX*rnd)|0)/rnd,
b=((Math.sin(ang)*t.scaleX*rnd)|0)/rnd,
c=((Math.sin(skew)*-t.scaleY*rnd)|0)/rnd,
d=((Math.cos(skew)*t.scaleY*rnd)|0)/rnd,
style=this.t.style,
cs=this.t.currentStyle,
filters,val;
if(!cs){
return;
}
val=b;//just for swapping the variables an inverting them (reused "val" to avoid creating another variable in memory). IE's filter matrix uses a non-standard matrix configuration (angle goes the opposite way, and b and c are reversed and inverted)
b=-c;
c=-val;
filters=cs.filter;
style.filter="";//remove filters so that we can accurately measure offsetWidth/offsetHeight
style.filter=m+" "+filters;//we must always put the transform/matrix FIRST (before alpha(opacity=xx)) to avoid an IE bug that slices part of the object when rotation is applied with alpha.
}
//at the end or beginning of the tween, if the matrix is normal (1, 0, 0, 1) and opacity is 100 (or doesn't exist), remove the filter to improve browser performance.
//we must set the margins AFTER applying the filter in order to avoid some bugs in IE8 that could (in rare scenarios) cause them to be ignored intermittently (vibration).
if(!clip){
varmult=(_ieVers<8)?1:-1,//in Internet Explorer 7 and before, the box model is broken, causing the browser to treat the width/height of the actual rotated filtered image as the width/height of the box itself, but Microsoft corrected that in IE8. We must use a negative offset in IE8 on the right/bottom
dif=(i<2)?-t.ieOffsetX:-t.ieOffsetY;//if another tween is controlling a margin, we cannot only apply the difference in the ieOffsets, so we essentially zero-out the dx and dy here in that case. We record the margin(s) later so that we can keep comparing them, making this code very flexible.
if(skewY){//for performance reasons, we combine all skewing into the skewX and rotation values. Remember, a skewY of 10 degrees looks the same as a rotation of 10 degrees plus a skewX of 10 degrees.
skewX+=skewY;
angle+=skewY;
}
//check to see if we should render as 2D (and SVGs must use 2D when _useSVGTransformAttr is true)
if(((((v===1||v===0)&&force3D==="auto"&&(this.tween._totalTime===this.tween._totalDuration||!this.tween._totalTime))||!force3D)&&!z&&!perspective&&!rotationY&&!rotationX&&sz===1)||(_useSVGTransformAttr&&isSVG)||!_supports3D){//on the final render (which could be 0 for a from tween), if there are no 3D aspects, render in 2D to free up memory and improve performance especially on mobile devices. Check the tween's totalTime/totalDuration too in order to make sure it doesn't happen between repeats if it's a repeating tween.
//2D
if(angle||skewX||isSVG){
angle*=_DEG2RAD;
skew=skewX*_DEG2RAD;
rnd=100000;
a11=Math.cos(angle)*sx;
a21=Math.sin(angle)*sx;
a12=Math.sin(angle-skew)*-sy;
a22=Math.cos(angle-skew)*sy;
if(skew&&t.skewType==="simple"){//by default, we compensate skewing on the other axis to make it look more natural, but you can set the skewType to "simple" to use the uncompensated skewing that CSS does
if(_useSVGTransformAttr&&(t.xPercent||t.yPercent)){//The SVG spec doesn't support percentage-based translation in the "transform" attribute, so we merge it into the matrix to simulate it.
//some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 5 decimal places.
if(_isFirefox){//Firefox has a bug (at least in v25) that causes it to render the transparent part of 32-bit PNG images as black when displayed inside an iframe and the 3D scale is very small and doesn't change sufficiently enough between renders (like if you use a Power4.easeInOut to scale from 0 to 1 where the beginning values only change a tiny amount to begin the tween before accelerating). In this case, we force the scale to be 0.00002 instead which is visually the same but works around the Firefox issue.
min=0.0001;
if(sx<min&&sx>-min){
sx=sz=0.00002;
}
if(sy<min&&sy>-min){
sy=sz=0.00002;
}
if(perspective&&!t.z&&!t.rotationX&&!t.rotationY){//Firefox has a bug that causes elements to have an odd super-thin, broken/dotted black border on elements that have a perspective set but aren't utilizing 3D space (no rotationX, rotationY, or z).
perspective=0;
}
}
if(angle||skewX){
angle*=_DEG2RAD;
cos=a11=Math.cos(angle);
sin=a21=Math.sin(angle);
if(skewX){
angle-=skewX*_DEG2RAD;
cos=Math.cos(angle);
sin=Math.sin(angle);
if(t.skewType==="simple"){//by default, we compensate skewing on the other axis to make it look more natural, but you can set the skewType to "simple" to use the uncompensated skewing that CSS does
t1=Math.tan((skewX-skewY)*_DEG2RAD);
t1=Math.sqrt(1+t1*t1);
cos*=t1;
sin*=t1;
if(t.skewY){
t1=Math.tan(skewY*_DEG2RAD);
t1=Math.sqrt(1+t1*t1);
a11*=t1;
a21*=t1;
}
}
}
a12=-sin;
a22=cos;
}elseif(!rotationY&&!rotationX&&sz===1&&!perspective&&!isSVG){//if we're only translating and/or 2D scaling, this is faster...
z=0;//don't use string because we calculate perspective later and need the number.
}
}
//optimized way of concatenating all the values into a string. If we do it all in one shot, it's slower because of the way browsers have to create temp strings and the way it affects memory. If we do it piece-by-piece with +=, it's a bit slower too. We found that doing it in these sized chunks works best overall:
if(cssp._lastParsedTransform===vars){returnpt;}//only need to parse the transform once, and only if the browser supports it.
cssp._lastParsedTransform=vars;
varscaleFunc=(vars.scale&&typeof(vars.scale)==="function")?vars.scale:0;//if there's a function-based "scale" value, swap in the resulting numeric value temporarily. Otherwise, if it's called for both scaleX and scaleY independently, they may not match (like if the function uses Math.random()).
if(orig&&typeof(orig)==="string"&&_transformProp){//for values like transform:"rotate(60deg) scale(0.5, 0.8)"
copy=_tempDiv.style;//don't use the original target because it might be SVG in which case some browsers don't report computed style correctly.
copy[_transformProp]=orig;
copy.display="block";//if display is "none", the browser often refuses to report the transform properties correctly.
copy.position="absolute";
if(orig.indexOf("%")!==-1){//%-based translations will fail unless we set the width/height to match the original target...
copy.width=_getStyle(t,"width");
copy.height=_getStyle(t,"height");
}
_doc.body.appendChild(_tempDiv);
m2=_getTransform(_tempDiv,null,false);
if(m1.skewType==="simple"){//the default _getTransform() reports the skewX/scaleY as if skewType is "compensated", thus we need to adjust that here if skewType is "simple".
m2.scaleY*=Math.cos(m2.skewX*_DEG2RAD);
}
if(m1.svg){//if it's an SVG element, x/y part of the matrix will be affected by whatever we use as the origin and the offsets, so compensate here...
x=m1.xOrigin;
y=m1.yOrigin;
m2.x-=m1.xOffset;
m2.y-=m1.yOffset;
if(v.transformOrigin||v.svgOrigin){//if this tween is altering the origin, we must factor that in here. The actual work of recording the transformOrigin values and setting up the PropTween is done later (still inside this function) so we cannot leave the changes intact here - we only want to update the x/y accordingly.
pt.e=endRotations[p];//directional rotations typically have compensated values during the tween, but we need to make sure they end at exactly what the user requested
}
pt.xs0=0;//ensures the value stays numeric in setRatio()
x=m1.xOffset;//when we change the origin, in order to prevent things from jumping we adjust the x/y so we must record those here so that we can create PropTweens for them and flip them at the same time as the origin
pt=_addNonTweeningNumericPT(m1,"xOrigin",(originalGSTransform?m1:m2).xOrigin,m2.xOrigin,pt,transformOriginString);//note: if there wasn't a transformOrigin defined yet, just start with the destination one; it's wasteful otherwise, and it causes problems with fromTo() tweens. For example, TweenLite.to("#wheel", 3, {rotation:180, transformOrigin:"50% 50%", delay:1}); TweenLite.fromTo("#wheel", 3, {scale:0.5, transformOrigin:"50% 50%"}, {scale:1, delay:2}); would cause a jump when the from values revert at the beginning of the 2nd tween.
orig="0px 0px";//certain browsers (like firefox) completely botch transform-origin, so we must remove it to prevent it from contaminating transforms. We manage it ourselves with xOrigin and yOrigin
}
if(orig||(_supports3D&&has3D&&m1.zOrigin)){//if anything 3D is happening and there's a transformOrigin with a z component that's non-zero, we must ensure that the transformOrigin's z-component is set to 0 so that we can manually do those calculations to get around Safari bugs. Even if the user didn't specifically define a "transformOrigin" in this particular tween (maybe they did it via css directly).
m1.zOrigin=((orig.length>2)?parseFloat(orig[2]):copy)||0;//Safari doesn't handle the z part of transformOrigin correctly, so we'll manually handle it in the _set3DTransformRatio() method.
pt.xs0=pt.e=orig[0]+" "+(orig[1]||"50%")+" 0px";//we must define a z value of 0px specifically otherwise iOS 5 Safari will stick with the old one (if one was defined)!
pt=newCSSPropTween(m1,"zOrigin",0,0,pt,-1,pt.n);//we must create a CSSPropTween for the _gsTransform.zOrigin so that it gets reset properly at the beginning if the tween runs backward (as opposed to just setting m1.zOrigin here)
pt.b=copy;
pt.xs0=pt.e=m1.zOrigin;
}else{
pt.xs0=pt.e=orig;
}
//for older versions of IE (6-8), we need to manually calculate things inside the setRatio() function. We record origin x and y (ox and oy) and whether or not the values are percentages (oxp and oyp).
}else{
_parsePosition(orig+"",m1);
}
}
if(hasChange){
cssp._transformType=(!(m1.svg&&_useSVGTransformAttr)&&(has3D||this._transformType===3))?3:2;//quicker than calling cssp._enableTransforms();
for(i=0;i<props.length;i++){//if we're dealing with percentages, we must convert things separately for the horizontal and vertical axis!
if(this.p.indexOf("border")){//older browsers used a prefix
props[i]=_checkPropPrefix(props[i]);
}
bs=bs2=_getStyle(t,props[i],_cs,false,"0px");
if(bs.indexOf(" ")!==-1){
bs2=bs.split(" ");
bs=bs2[0];
bs2=bs2[1];
}
es=es2=ea1[i];
bn=parseFloat(bs);
bsfx=bs.substr((bn+"").length);
rel=(es.charAt(1)==="=");
if(rel){
en=parseInt(es.charAt(0)+"1",10);
es=es.substr(2);
en*=parseFloat(es);
esfx=es.substr((en+"").length-(en<0?1:0))||"";
}else{
en=parseFloat(es);
esfx=es.substr((en+"").length);
}
if(esfx===""){
esfx=_suffixMap[p]||bsfx;
}
if(esfx!==bsfx){
hn=_convertToPixels(t,"borderLeft",bn,bsfx);//horizontal number (we use a bogus "borderLeft" property just because the _convertToPixels() method searches for the keywords "Left", "Right", "Top", and "Bottom" to determine of it's a horizontal or vertical property, and we need "border" in the name so that it knows it should measure relative to the element itself, not its parent.
vn=_convertToPixels(t,"borderTop",bn,bsfx);//vertical number
bs=this.format(((cs)?_ieVers?cs.getPropertyValue(bp+"-x")+" "+cs.getPropertyValue(bp+"-y"):cs.getPropertyValue(bp):t.currentStyle.backgroundPositionX+" "+t.currentStyle.backgroundPositionY)||"0 0"),//Internet Explorer doesn't report background-position correctly - we must query background-position-x and background-position-y and combine them (even in IE10). Before IE9, we must do the same with the currentStyle object and use camelCase
return(v.substr(0,2)==="co")?v:_parsePosition(v.indexOf(" ")===-1?v+" "+v:v);//if set to something like "100% 100%", Safari typically reports the computed style as just "100%" (no 2nd value), but we should ensure that there are two values, so copy the first one. Otherwise, it'd be interpreted as "100% 0" (wrong). Also remember that it could be "cover" or "contain" which we can't tween but should be able to set.
if(_ieVers<9){//IE8 and earlier don't report a "clip" value in the currentStyle - instead, the values are split apart into clipTop, clipRight, clipBottom, and clipLeft. Also, in IE7 and earlier, the values inside rect() are space-delimited, not comma-delimited.
_registerComplexSpecialProp("autoRound,strictUnits",{parser:function(t,e,p,cssp,pt){returnpt;}});//just so that we can ignore these properties (not tween them)
_registerComplexSpecialProp("borderWidth",{parser:_getEdgeParser("borderTopWidth,borderRightWidth,borderBottomWidth,borderLeftWidth")});//Firefox doesn't pick up on borderWidth set in style sheets (only inline).
if(val===100){//for older versions of IE that need to use a filter to apply opacity, we should remove the filter if opacity hits 1 in order to improve performance, but make sure there isn't a transform (matrix) or gradient in the filters.
skip=(!_getStyle(this.data,"filter"));//if a class is applied that has an alpha filter, it will take effect (we don't want that), so re-apply our alpha filter in that case. We must first remove it and then check.
}else{
t.filter=filters.replace(_alphaFilterExp,"");
skip=true;
}
}
if(!skip){
if(this.xn1){
t.filter=filters=filters||("alpha(opacity="+val+")");//works around bug in IE7/8 that prevents changes to "visibility" from being applied properly if the filter is changed to a different alpha on the same frame.
}
if(filters.indexOf("pacity")===-1){//only used if browser doesn't support the standard opacity style property (IE 7 and 8). We omit the "O" to avoid case-sensitivity issues
if(val!==0||!this.xn1){//bugs in IE7/8 won't render the filter properly if opacity is ADDED on the same frame/render as "visibility" changes (this.xn1 is 1 if this tween is an "autoAlpha" tween)
t.filter=filters+" alpha(opacity="+val+")";//we round the value because otherwise, bugs in IE7/8 can prevent "visibility" changes from being applied properly.
if(isAutoAlpha&&b===1&&_getStyle(t,"visibility",_cs)==="hidden"&&e!==0){//if visibility is initially set to "hidden", we should interpret that as intent to make opacity 0 (a convenience)
pt.xn1=isAutoAlpha?1:0;//we need to record whether or not this is an autoAlpha so that in the setRatio(), we know to duplicate the setting of the alpha in order to work around a bug in IE7 and IE8 that prevents changes to "visibility" from taking effect if the filter is changed to a different alpha(opacity) at the same time. Setting it to the SAME value first, then the new value works around the IE7/8 bug.
style.zoom=1;//helps correct an IE issue.
pt.type=2;
pt.b="alpha(opacity="+pt.s+")";
pt.e="alpha(opacity="+(pt.s+pt.c)+")";
pt.data=t;
pt.plugin=plugin;
pt.setRatio=_setIEOpacityRatio;
}
if(isAutoAlpha){//we have to create the "visibility" PropTween after the opacity one in the linked list so that they run in the order that works properly in IE8 and earlier
if(p.substr(0,2)==="ms"||p.substr(0,6)==="webkit"){//Microsoft and some Webkit browsers don't conform to the standard of capitalizing the first prefix character, so we adjust so that when we prefix the caps with a dash, it's correct (otherwise it'd be "ms-transform" instead of "-ms-transform" for IE9, for example)
varb=t.getAttribute("class")||"",//don't use t.className because it doesn't work consistently on SVG elements; getAttribute("class") and setAttribute("class", value") is more reliable.
//if there's a className tween already operating on the target, force it to its end so that the necessary inline styles are removed and the class name is applied before we determine the end state (we don't want inline styles interfering that were there just for class-specific values)
cnpt=t._gsClassPT;
if(cnpt){
cnptLookup={};
mpt=cnpt.data;//first MiniPropTween which stores the inline styles - we need to force these so that the inline styles don't contaminate things. Otherwise, there's a small chance that a tween could start and the inline values match the destination values and they never get cleaned.
t.style.cssText=cssText;//we recorded cssText before we swapped classes and ran _getAllStyles() because in cases when a className tween is overwritten, we remove all the related tweening properties from that class change (otherwise class-specific stuff can't override properties we've directly set on the target's style object due to specificity).
pt=pt.xfirst=cssp.parse(t,difData.difs,pt,plugin);//we record the CSSPropTween as the xfirst so that we can handle overwriting propertly (if "className" gets overwritten, we must kill all the properties associated with the className part of the tween, so we can loop through from xfirst to the pt itself)
returnpt;
}});
var_setClearPropsRatio=function(v){
if(v===1||v===0)if(this.data._totalTime===this.data._totalDuration&&this.data.data!=="isFromStart"){//this.data refers to the tween. Only clear at the END of the tween (remember, from() tweens make the ratio go from 1 to 0, so we can't just check that and if the tween is the zero-duration one that's created internally to render the starting values in a from() tween, ignore that because otherwise, for example, 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).
vars=this.t.style,
transformParse=_specialProps.transform.parse,
a,p,i,clearTransform,transform;
if(this.e==="all"){
s.cssText="";
clearTransform=true;
}else{
a=this.e.split(" ").join("").split(",");
i=a.length;
while(--i>-1){
p=a[i];
if(_specialProps[p]){
if(_specialProps[p].parse===transformParse){
clearTransform=true;
}else{
p=(p==="transformOrigin")?_transformOriginProp:_specialProps[p].p;//ensures that special properties use the proper browser-specific property name, like "scaleX" might be "-webkit-transform" or "boxShadow" might be "-moz-box-shadow"
//gets called when the tween renders for the first time. This kicks everything off, recording start/end values, etc.
p._onInitTween=function(target,vars,tween,index){
if(!target.nodeType){//css is only for dom elements
returnfalse;
}
this._target=_target=target;
this._tween=tween;
this._vars=vars;
_index=index;
_autoRound=vars.autoRound;
_hasPriority=false;
_suffixMap=vars.suffixMap||CSSPlugin.suffixMap;
_cs=_getComputedStyle(target,"");
_overwriteProps=this._overwriteProps;
varstyle=target.style,
v,pt,pt2,first,last,next,zIndex,tpt,threeD;
if(_reqSafariFix)if(style.zIndex===""){
v=_getStyle(target,"zIndex",_cs);
if(v==="auto"||v===""){
//corrects a bug in [non-Android] Safari that prevents it from repainting elements in their new positions if they don't have a zIndex set. We also can't just apply this inside _parseTransform() because anything that's moved in any way (like using "left" or "top" instead of transforms like "x" and "y") can be affected, so it is best to ensure that anything that's tweening has a z-index. Setting "WebkitPerspective" to a non-zero value worked too except that on iOS Safari things would flicker randomly. Plus zIndex is less memory-intensive.
this._addLazySet(style,"zIndex",0);
}
}
if(typeof(vars)==="string"){
first=style.cssText;
v=_getAllStyles(target,_cs);
style.cssText=first+";"+vars;
v=_cssDif(target,v,_getAllStyles(target)).difs;
if(!_supportsOpacity&&_opacityValExp.test(vars)){
v.opacity=parseFloat(RegExp.$1);
}
vars=v;
style.cssText=first;
}
if(vars.className){//className tweens will combine any differences they find in the css with the vars that are passed in, so {className:"myClass", scale:0.5, left:20} would work.
// 1) [non-Android] Safari skips rendering changes to "top" and "left" that are made on the same frame/render as a transform update.
// 2) iOS Safari sometimes neglects to repaint elements in their new positions. Setting "WebkitPerspective" to a non-zero value worked too except that on iOS Safari things would flicker randomly.
// 3) Safari sometimes displayed odd artifacts when tweening the transform (or WebkitTransform) property, like ghosts of the edges of the element remained. Definitely a browser bug.
//Note: we allow the user to override the auto-setting by defining WebkitBackfaceVisibility in the vars of the tween.
tpt.pr=-1;//ensures that the transforms get applied after the components are updated.
_overwriteProps.pop();//we don't want to force the overwrite of all "transform" tweens of the target - we only care about individual transform properties like scaleX, rotation, etc. The CSSPropTween constructor automatically adds the property to _overwriteProps which is why we need to pop() here.
}
if(_hasPriority){
//reorders the linked list in order of pr (priority)
while(pt){
next=pt._next;
pt2=first;
while(pt2&&pt2.pr>pt.pr){
pt2=pt2._next;
}
if((pt._prev=pt2?pt2._prev:last)){
pt._prev._next=pt;
}else{
first=pt;
}
if((pt._next=pt2)){
pt2._prev=pt;
}else{
last=pt;
}
pt=next;
}
this._firstPT=first;
}
returntrue;
};
p.parse=function(target,vars,pt,plugin){
varstyle=target.style,
p,sp,bn,en,bs,es,bsfx,esfx,isStr,rel;
for(pinvars){
es=vars[p];//ending value string
sp=_specialProps[p];//SpecialProp lookup.
if(typeof(es)==="function"&&!(sp&&sp.allowFunc)){
es=es(_index,_target);
}
if(sp){
pt=sp.parse(target,es,p,this,pt,plugin,vars);
}elseif(p.substr(0,2)==="--"){//for tweening CSS variables (which always start with "--"). To maximize performance and simplicity, we bypass CSSPlugin altogether and just add a normal property tween to the tween instance itself.
if(p==="color"||p==="fill"||p==="stroke"||p.indexOf("Color")!==-1||(isStr&&_rgbhslExp.test(es))){//Opera uses background: to define color sometimes in addition to backgroundColor:
bsfx=(bn||bn===0)?bs.substr((bn+"").length):"";//remember, bs could be non-numeric like "normal" for fontWeight, so we should default to a blank suffix in that case.
if(bs===""||bs==="auto"){
if(p==="width"||p==="height"){
bn=_getDimension(target,p,_cs);
bsfx="px";
}elseif(p==="left"||p==="top"){
bn=_calculateOffset(target,p,_cs);
bsfx="px";
}else{
bn=(p!=="opacity")?0:1;
bsfx="";
}
}
rel=(isStr&&es.charAt(1)==="=");
if(rel){
en=parseInt(es.charAt(0)+"1",10);
es=es.substr(2);
en*=parseFloat(es);
esfx=es.replace(_suffixExp,"");
}else{
en=parseFloat(es);
esfx=isStr?es.replace(_suffixExp,""):"";
}
if(esfx===""){
esfx=(pin_suffixMap)?_suffixMap[p]:bsfx;//populate the end suffix, prioritizing the map, then if none is found, use the beginning suffix.
}
es=(en||en===0)?(rel?en+bn:en)+esfx:vars[p];//ensures that any += or -= prefixes are taken care of. Record the end value before normalizing the suffix because we always want to end the tween on exactly what they intended even if it doesn't match the beginning value's suffix.
//if the beginning/ending suffixes don't match, normalize them...
if(bsfx!==esfx)if(esfx!==""||p==="lineHeight")if(en||en===0)if(bn){//note: if the beginning value (bn) is 0, we don't need to convert units!
bn=_convertToPixels(target,p,bn,bsfx);
if(esfx==="%"){
bn/=_convertToPixels(target,p,100,"%")/100;
if(vars.strictUnits!==true){//some browsers report only "px" values instead of allowing "%" with getComputedStyle(), so we assume that if we're tweening to a %, we should start there too unless strictUnits:true is defined. This approach is particularly useful for responsive designs that use from() tweens.
esfx="px";//we don't use bsfx after this, so we don't need to set it to px too.
}
if(rel)if(en||en===0){
es=(en+bn)+esfx;//the changes we made affect relative calculations, so adjust the end value here.
}
}
if(rel){
en+=bn;
}
if((bn||bn===0)&&(en||en===0)){//faster than isNaN(). Also, previously we required en !== bn but that doesn't really gain much performance and it prevents _parseToProxy() from working properly if beginning and ending values match but need to get tweened by an external plugin anyway. For example, a bezier tween where the target starts at left:0 and has these points: [{left:50},{left:0}] wouldn't work properly because when parsing the last point, it'd match the first (current) one and a non-tweening CSSPropTween would be recorded when we actually need a normal tween (type:0) so that things get updated during the tween properly.
pt.xs0=(es==="none"&&(p==="display"||p.indexOf("Style")!==-1))?bs:es;//intermediate value should typically be set immediately (end value) except for "display" or things like borderTopStyle, borderBottomStyle, etc. which should use the beginning value during the tween.
//DEBUG: _log("non-tweening value "+p+": "+pt.xs0);
}
}
}
if(plugin)if(pt&&!pt.plugin){
pt.plugin=plugin;
}
}
returnpt;
};
//gets called every time the tween updates, passing the new ratio (typically a value between 0 and 1, but not always (for example, if an Elastic.easeOut is used, the value can jump above 1 mid-tween). It will always start and 0 and end at 1.
p.setRatio=function(v){
varpt=this._firstPT,
min=0.000001,
val,str,i;
//at the end of the tween, we set the values to exactly what we received in order to make sure non-tweening values (like "position" or "float" or whatever) are set and so that if the beginning/ending suffixes (units) didn't match and we normalized to px, the value that the user passed in is used here. We check to see if the tween is at its beginning in case it's a from() tween in which case the ratio will actually go from 1 to 0 over the course of the tween (backwards).
}elseif(pt.setRatio){//custom setRatio() for things like SpecialProps, external plugins, etc.
pt.setRatio(v);
}
pt=pt._next;
}
//if the tween is reversed all the way back to the beginning, we need to restore the original values which may have different units (like % instead of px or em or whatever).
}else{
while(pt){
if(pt.type!==2){
pt.t[pt.p]=pt.b;
}else{
pt.setRatio(v);
}
pt=pt._next;
}
}
};
/**
*@private
*Forcesrenderingofthetarget's transforms (rotation, scale, etc.) whenever the CSSPlugin'ssetRatio()iscalled.
this._transform=this._transform||_getTransform(this._target,_cs,true);//ensures that the element has a _gsTransform property with the appropriate values.
this.data._linkCSSP(this,this._next,null,true);//we purposefully keep this._next even though it'd make sense to null it, but this is a performance optimization, as this happens during the while (pt) {} loop in setRatio() at the bottom of which it sets pt = pt._next, so if we null it, the linked list will be broken in that loop.
};
/** @private Gives us a way to set a value on the first render (and only the first render). **/
remove=true;//just to prevent resetting this._firstPT 5 lines down in case pt._next is null. (optimized for speed)
}
if(prev){
prev._next=pt;
}elseif(!remove&&this._firstPT===null){
this._firstPT=pt;
}
pt._next=next;
pt._prev=prev;
}
returnpt;
};
p._mod=function(lookup){
varpt=this._firstPT;
while(pt){
if(typeof(lookup[pt.p])==="function"){//only gets called by RoundPropsPlugin (ModifyPlugin manages all the rendering internally for CSSPlugin properties that need modification). Remember, we handle rounding a bit differently in this plugin for performance reasons, leveraging "r" as an indicator that the value should be rounded internally.
pt.r=lookup[pt.p];
}
pt=pt._next;
}
};
//we need to make sure that if alpha or autoAlpha is killed, opacity is too. And autoAlpha affects the "visibility" property.
p._kill=function(lookup){
varcopy=lookup,
pt,p,xfirst;
if(lookup.autoAlpha||lookup.alpha){
copy={};
for(pinlookup){//copy the lookup so that we're not changing the original which may be passed elsewhere.
copy[p]=lookup[p];
}
copy.opacity=1;
if(copy.autoAlpha){
copy.visibility=1;
}
}
if(lookup.className&&(pt=this._classNamePT)){//for className tweens, we need to kill any associated CSSPropTweens too; a linked list starts at the className's "xfirst".
xfirst=pt.xfirst;
if(xfirst&&xfirst._prev){
this._linkCSSP(xfirst._prev,pt._next,xfirst._prev._prev);//break off the prev
*-Wecan't just create new independent tweens because otherwise, what happens if the original/parent tween is reversed or pause or dropped into a TimelineLite for tight control? You'dexpectthattween'sbehaviortoaffectalltheothers.
*-Analyzingeverystylepropertyofeverychildbeforeandafterthetweenisanexpensiveoperationwhentherearemanychildren,sothisbehaviorshouldn't be imposed on all className tweens by default, especially since it'sprobablyrarethatthisextrafunctionalityisneeded.
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
selector=(pseudo?"":",")+selector.split("::").join(":").toLowerCase()+",";//note: old versions of IE report tag name selectors as upper case, so we just change everything to lowercase.
if(pseudo){
a=[];
}
while(--i>-1){
//Firefox may throw insecure operation errors when css is loaded from other domains, so try/catch.
try{
curSS=ss[i][ruleProp];
if(!curSS){
continue;
}
j=curSS.length;
}catch(e){
console.log(e);
continue;
}
while(--j>-1){
cs=curSS[j];
if(cs.selectorText&&(","+cs.selectorText.split("::").join(":").toLowerCase()+",").indexOf(selector)!==-1){//note: IE adds an extra ":" to pseudo selectors, so .myClass:after becomes .myClass::after, so we need to strip the extra one out.
if(pseudo){
a.push(cs.style);
}else{
returncs.style;
}
}
}
}
returna;
};
// @private gets called when the tween renders for the first time. This kicks everything off, recording start/end values, etc.
CSSPlugin.prototype._onInitTween.call(this,div,value,tween);//we just offload all the work to the regular CSSPlugin and then copy the cssText back over to the rule in the setRatio() method. This allows us to have all of the updates to CSSPlugin automatically flow through to CSSRulePlugin instead of having to maintain both
returntrue;
};
// @private gets called every time the tween updates, passing the new ratio (typically a value between 0 and 1, but not always (for example, if an Elastic.easeOut is used, the value can jump above 1 mid-tween). It will always start and 0 and end at 1.
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
if(v.charAt(v.length-1)===","){//sometimes a trailing comma is included and we should chop it off (typically from a comma-delimited list of values like a textShadow:"2px 2px 2px blue, 5px 5px 5px rgb(255,0,0)" - in this example "blue," has a trailing comma. We could strip it out inside parseComplex() but we'd need to do it to the beginning and ending values plus it wouldn't provide protection from other potential scenarios like if the user passes in a similar value.
v=v.substr(0,v.length-1);
}
if(_colorLookup[v]){
a=_colorLookup[v];
}elseif(v.charAt(0)==="#"){
if(v.length===4){//for shorthand like #9F0
r=v.charAt(1);
g=v.charAt(2);
b=v.charAt(3);
v="#"+r+r+g+g+b+b;
}
v=parseInt(v.substr(1),16);
a=[v>>16,(v>>8)&255,v&255];
}elseif(v.substr(0,3)==="hsl"){
a=wasHSL=v.match(_numExp);
if(!toHSL){
h=(Number(a[0])%360)/360;
s=Number(a[1])/100;
l=Number(a[2])/100;
g=(l<=0.5)?l*(s+1):l+s-l*s;
r=l*2-g;
if(a.length>3){
a[3]=Number(a[3]);
}
a[0]=_hue(h+1/3,r,g);
a[1]=_hue(h,r,g);
a[2]=_hue(h-1/3,r,g);
}elseif(v.indexOf("=")!==-1){//if relative values are found, just return the raw strings with the relative prefixes in place.
_colorExp="(?:\\b(?:(?:rgb|rgba|hsl|hsla)\\(.+?\\))|\\B#(?:[0-9a-f]{3}){1,2}\\b",//we'll dynamically build this Regular Expression to conserve file size. After building it, it will be able to find rgb(), rgba(), # (hexadecimal), and named color values like red, blue, purple, etc.
ColorPropsPlugin=_gsScope._gsDefine.plugin({
propName:"colorProps",
version:"1.5.3",
priority:-1,
API:2,
global:true,
//called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
//called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
init:function(target,value,tween){
vari=value.length,
a=this.a=[],
start,end;
this.target=target;
this._mod=0;
if(!i){
returnfalse;
}
while(--i>-1){
start=target[i];
end=value[i];
if(start!==end){
a.push({i:i,s:start,c:end-start});
}
}
returntrue;
},
mod:function(lookup){
if(typeof(lookup.endArray)==="function"){
this._mod=lookup.endArray;
}
},
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
var_cssRatioSetter=function(pt,cssp,mod){//Takes an individual CSSPropTween and converts it into a type:2 that has a setRatio that does everything the regular CSSPlugin.setRatio() method does but applying the mod() too. We do this to keep the main CSSPlugin.setRatio() as fast as possible (the vast majority of times, no mod() will be necessary)
hasBezier=(lookup.rotation&&cssp._overwriteProps.join("").indexOf("bezier")!==-1);//when a Bezier tween is applying autoRotation, it's a very special case we need to handle differently.
//called when the tween renders for the first time. This is where initial values should be recorded and any setup routines should run.
init:function(target,value,tween){
this._tween=tween;
this._vars=value;
returntrue;
},
initAll:function(){
vartween=this._tween,
lookup=this._vars,
mpt=this,
pt=tween._firstPT,
val,next;
//initAll() gets called for each and every ModifiersPlugin instance in a tween, so if there are multiple targets, there will be multiple instances. Since we're ripping through the whole tween (and all the PropTweens), we only need to run this code ONCE. So we're setting a toggle on the first PropTween that just tells us if we've done it already. We don't set it on the tween instance because if it gets invalidated, we don't want to have to track this property and reset it. PropTweens get blown away when a tween is invalidated.
if(pt._modInitted){
returnfalse;
}else{
pt._modInitted=1;
}
while(pt){
next=pt._next;//record here, because it may get removed
val=lookup[pt.n];
if(pt.pg){
if(pt.t._propName==="css"){//handle CSSPlugin uniquely (for performance, due to the fact that the values almost always are a concatenation of numbers and strings, like suffixes, and we don't want to slow down the regular CSSPlugin setRatio() performance with conditional checks for if the value needs to be modded, so we pull any modding prop out and change it to a type:2 one that simply calls a setRatio() method where we encapsulate the modding and update all together. That way, it says in the main CSSProp linked list and just has some custom logic applied to it inside its setRatio())
_modCSS(lookup,pt.t);
}elseif(pt.t!==mpt){//don't run modProps on modProps :)
*@return{(array|number)}Anarraycontainingred,green,andblue(andoptionallyalpha)inthatorder,oriftheformatparameterwas"hsl",thearraywillcontainhue,saturationandlightness(andoptionallyalpha)inthatorder.Orif"format"isdefinedas"number",it'll return a number like 0xFF0000. Always numbers unless there'sarelativeprefixfoundinanhsl()orhsla()stringand"format"is"hsl".
*/
_parseColor=function(v,format){
vartoHSL=(format==="hsl"),
a,r,g,b,h,s,l,max,min,d,wasHSL;
if(!v){
a=_colorLookup.black;
}elseif(typeof(v)==="number"){
a=[v>>16,(v>>8)&255,v&255];
}else{
if(v.charAt(v.length-1)===","){//sometimes a trailing comma is included and we should chop it off (typically from a comma-delimited list of values like a textShadow:"2px 2px 2px blue, 5px 5px 5px rgb(255,0,0)" - in this example "blue," has a trailing comma. We could strip it out inside parseComplex() but we'd need to do it to the beginning and ending values plus it wouldn't provide protection from other potential scenarios like if the user passes in a similar value.
_colorExp="(?:\\b(?:(?:rgb|rgba|hsl|hsla)\\(.+?\\))|\\B#(?:[0-9a-f]{3}){1,2}\\b",//we'll dynamically build this Regular Expression to conserve file size. After building it, it will be able to find rgb(), rgba(), # (hexadecimal), and named color values like red, blue, purple, etc.
_addColorMatrixFilterCacheTween=function(p,pg,cache,vars){//we cache the ColorMatrixFilter components in a _gsColorMatrixFilter object attached to the target object so that it's easy to grab the current value at any time.
//to improve performance, when a color is sensed, we hijack the setRatio() method of the plugin instance with a new function that this method spits back. This is a special method that handles parsing color values on-the-fly and turns them into numeric values which PixiJS requires. In other words, instead of "rgb(255, 0, 0)", PixiJS wants 0xFF0000. This also works with hsl() values.
_buildColorSetter=function(tween,plugin){
varsetRatio=plugin.setRatio,//save the original (super) setRatio() function
if(func.graphics){//in order for PixiJS to actually redraw GraphicsData, we've gotta increment the "dirty" and "clearDirty" values. If we don't do this, the values will be tween properly, but not rendered.
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
//parses a color (like #9F0, #FF9900, or rgb(255,51,153)) into an array with 3 elements for red, green, and blue. Also handles rgba() values (splits into array of 4 elements of course)
//parses the transform values for an element, returning an object with x, y, scaleX, scaleY, rotation, skewX, and skewY properties. Note: by default (for performance reasons), all skewing is combined into skewX and rotation but skewY still has a place in the transform object so that we can record how much of the skew is attributed to skewX vs skewY. Remember, a skewY of 10 looks the same as a rotation of 10 and skewX of -10.
_getTransform=function(t,rec){
vars=t.matrix,
min=0.000001,
a=s.a,
b=s.b,
c=s.c,
d=s.d,
m=rec?t._gsTransform||{skewY:0}:{skewY:0},
invX=(m.scaleX<0);//in order to interpret things properly, we need to know if the user applied a negative scaleX previously so that we can adjust the rotation and skewX accordingly. Otherwise, if we always interpret a flipped matrix as affecting scaleY and the user only wants to tween the scaleX on multiple sequential tweens, it would keep the negative scaleY without that being the user's intent.
m.tx=s.e-(m.ox||0);//ox is the offset x that we record in setRatio() whenever we apply a custom transform that might use a pivot point. Remember, s.e and s.f get affected by things like scale. For example, imagine an object whose top left corner is at 100,100 and then we scale it up to 300% using the center as the pivot point - that corner would now be very different even though to the user, they didn't intend to change/tween the x/y position per se. Therefore, we record whatever offsets we make so that we can compensate when reading the values back.
m.ty=s.f-(m.oy||0);//oy is the offset y (see note above)
m.scaleX=Math.sqrt(a*a+b*b);
m.scaleY=Math.sqrt(d*d+c*c);
m.rotation=(a||b)?Math.atan2(b,a):m.rotation||0;//note: if scaleX is 0, we cannot accurately measure rotation. Same for skewX with a scaleY of 0. Therefore, we default to the previously recorded value (or zero if that doesn't exist).
//some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 0 in these cases. The conditional logic here is faster than calling Math.abs().
t._gsTransform=m;//record to the object's _gsTransform which we use so that tweens can control individual properties independently (we need all the properties to accurately recompose the matrix in the setRatio() method)
//takes a value and a default number, checks if the value is relative, null, or numeric and spits back a normalized number accordingly. Primarily used in the _parseTransform() function.
//translates strings like "40deg" or "40" or 40rad" or "+=40deg" to a numeric radian angle, optionally relative to a default value (if "+=" or "-=" prefix is found)
//Some of these properties are in place in order to conform with the standard PropTweens in TweenPlugins so that overwriting and roundProps occur properly. For example, f and r may seem unnecessary here, but they enable other functionality.
if((s||s===0)&&(v||v===0)&&(pt.c=(rel?v:v-s))){//faster than isNaN(). Also, we set pt.c (change) here because if it's 0, we'll just treat it like a non-tweening value. can't do (v !== start) because if it's a relative value and the CHANGE is identical to the START, the condition will fail unnecessarily.
pt.s=s;
}else{
pt.type=-1;
pt.i=value[p];//intermediate value is typically the same as the end value.
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
//apply transform values like x, y, scaleX, scaleY, rotation, skewX, or skewY. We do these after looping through all the PropTweens because those are where the changes are made to scaleX/scaleY/rotation/skewX/skewY/x/y.
if(this._transform){
pt=this._transform;//to improve speed and reduce size, reuse the pt variable as an alias to the _transform property
varang=pt.rotation,
skew=ang-pt.skewX,
a=Math.cos(ang)*pt.scaleX,
b=Math.sin(ang)*pt.scaleX,
c=Math.sin(skew)*-pt.scaleY,
d=Math.cos(skew)*pt.scaleY,
min=0.000001,
pxl=this._pxl,
pyl=this._pyl;
//some browsers have a hard time with very small values like 2.4492935982947064e-16 (notice the "e-" towards the end) and would render the object slightly off. So we round to 0 in these cases for both b and c. The conditional logic here is faster than calling Math.abs().
pt.ox=this._pxg-(pxl*a+pyl*c);//we must record the offset x/y that we're making from the regular tx/ty (matrix.e and f) so that we can correctly interpret positional data in _getTransform(). See note there on tx and ox.
//compares the beginning x, y, scaleX, scaleY, rotation, and skewX properties with the ending ones and adds PropTweens accordingly wherever necessary. We must tween them individually (rather than just tweening the matrix values) so that elgant overwriting can occur, like if one tween is controlling scaleX, scaleY, and rotation and then another one starts mid-tween that is trying to control the scaleX only - this tween should continue tweening scaleY and rotation.
p._parseTransform=function(t,v){
if(this._transform){return;}//only need to parse the transform once, and only if the browser supports it.
//note: for performance reasons, we combine all skewing into the skewX and rotation values, ignoring skewY but we must still record it so that we can discern how much of the overall skew is attributed to skewX vs. skewY. Otherwise, if the skewY would always act relative (tween skewY to 10deg, for example, multiple times and if we always combine things into skewX, we can't remember that skewY was 10 from last time). Remember, a skewY of 10 degrees looks the same as a rotation of 10 degrees plus a skewX of -10 degrees.
//don't allow rotation/skew values to be a SUPER small decimal because when they're translated back to strings for setting the css property, the browser reports them in a funky way, like 1-e7. Of course we could use toFixed() to resolve that issue but that hurts performance quite a bit with all those function calls on every frame, plus it is virtually impossible to discern values that small visually (nobody will notice changing a rotation of 0.0000001 to 0, so the performance improvement is well worth it).
if(m2.skewY<min)if(m2.skewY>-min){
m2.skewY=0;
}
if(m2.skewX<min)if(m2.skewX>-min){
m2.skewX=0;
}
if(m2.rotation<min)if(m2.rotation>-min){
m2.rotation=0;
}
pivot=v.localPivot||v.globalPivot;
if(typeof(pivot)==="string"){
copy=pivot.split(",");
dx=Number(copy[0]);
dy=Number(copy[1]);
}elseif(typeof(pivot)==="object"){
dx=Number(pivot.x);
dy=Number(pivot.y);
}elseif(v.localPivot){
copy=t.getBBox(true);
dx=copy.width/2;
dy=copy.height/2;
}else{
copy=t.getBBox();
dx=copy.x+copy.width/2;
dy=copy.y+copy.height/2;
}
if(v.localPivot){
mtx=t.matrix;
dx+=t.attr("x");
dy+=t.attr("y");
this._pxl=dx;
this._pyl=dy;
this._pxg=dx*mtx.a+dy*mtx.c+mtx.e-m1.tx;
this._pyg=dx*mtx.b+dy*mtx.d+mtx.f-m1.ty;
}else{
mtx=t.matrix.invert();
this._pxl=dx*mtx.a+dy*mtx.c+mtx.e;
this._pyl=dx*mtx.b+dy*mtx.d+mtx.f;
this._pxg=dx-m1.tx;
this._pyg=dy-m1.ty;
}
}elseif(typeof(v)==="string"){//for values like transform:"rotate(60deg) scale(0.5, 0.8)"
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
_getRoundFunc=function(v){//pass in 0.1 get a function that'll round to the nearest tenth, or 5 to round to the closest 5, or 0.001 to the closest 1000th, etc.
varp=v<1?Math.pow(10,(v+"").length-2):1;//to avoid floating point math errors (like 24 * 0.1 == 2.4000000000000004), we chop off at a specific number of decimal places (much faster than toFixed()
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
_buildGetter=function(e,axis){//pass in an element and an axis ("x" or "y") and it'll return a getter function for the scroll position of that element (like scrollTop or scrollLeft, although if the element is the window, it'll use the pageXOffset/pageYOffset or the documentElement's scrollTop/scrollLeft or document.body's. Basically this streamlines things and makes a very fast getter across browsers.
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
if(this.x<0){//can't scroll to a position less than 0! Might happen if someone uses a Back.easeOut or Elastic.easeOut when scrolling back to the top of the page (for example)
this.x=0;
}
if(this.y<0){
this.y=0;
}
if(this._autoKill){
//note: iOS has a bug that throws off the scroll by several pixels, so we need to check if it's within 7 pixels of the previous one that we set instead of just looking for an exact match.
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
propName:"yourCustomProperty",//the name of the property that will get intercepted and handled by this plugin (obviously change it to whatever you want, typically it is camelCase starting with lowercase).
priority:0,//the priority in the rendering pipeline (0 by default). A priority of -1 would mean this plugin will run after all those with 0 or greater. A priority of 1 would get run before 0, etc. This only matters when a plugin relies on other plugins finishing their work before it runs (or visa-versa)
API:2,//the API should stay 2 - it just gives us a way to know the method/property structure so that if in the future we change to a different TweenPlugin architecture, we can identify this plugin's structure.
version:"1.0.0",//your plugin's version number
overwriteProps:["yourCustomProperty"],//an array of property names whose tweens should be overwritten by this plugin. For example, if you create a "scale" plugin that handles both "scaleX" and "scaleY", the overwriteProps would be ["scaleX","scaleY"] so that if there's a scaleX or scaleY tween in-progress when a new "scale" tween starts (using this plugin), it would overwrite the scaleX or scaleY tween.
//now, just for kicks, we'll record the starting "alpha" value and amount of change so that we can manage this manually rather than _addTween() (again, totally fictitious, just for an example)
this._alphaStart=target.alpha;
this._alphaChange=value.alpha-target.alpha;
//always return true unless we want to scrap the plugin and have the value treated as a normal property tween (very uncommon)
//[optional] - called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.). If you're using this._super._addTween() for all your tweens and you don't need to do anything special on each frame besides updating those values, you can omit this "set" function altogether.
set:function(ratio){
//since we used _addTween() inside init function, it created some property tweens that we'll update by calling the parent prototype's setRatio() (otherwise, the property tweens wouldn't get their values updated). this._super refers to the TweenPlugin prototype from which the plugin inherits (not that you need to worry about that).
var_gsScope=(typeof(module)!=="undefined"&&module.exports&&typeof(global)!=="undefined")?global:this||window;//helps ensure compatibility with AMD/RequireJS and CommonJS/Node
if((character.charCodeAt(0)>=_emojiStart&&character.charCodeAt(0)<=_emojiEnd)||(text.charCodeAt(i+1)>=0xFE00&&text.charCodeAt(i+1)<=0xFE0F)){//special emoji characters use 2 or 4 unicode characters that we must keep together.
//called each time the values should be updated, and the ratio gets passed as the only parameter (typically it's a value between 0 and 1, but it can exceed those when using an ease like Elastic.easeOut or Back.easeOut, etc.)
returnexistingModule;//in case the core set of classes is already loaded, don't instantiate twice.
}
var_namespace=function(ns){
vara=ns.split("."),
p=_globals,i;
for(i=0;i<a.length;i++){
p[a[i]]=p=p[a[i]]||{};
}
returnp;
},
gs=_namespace("com.greensock"),
_tinyNum=0.00000001,
_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()
varb=[],
l=a.length,
i;
for(i=0;i!==l;b.push(a[i++])){}
returnb;
},
_emptyFunc=function(){},
_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)
*vargs=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.
*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(...)
_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.)
//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).
//create all the standard eases like Linear, Quad, Cubic, Quart, Quint, Strong, Power0, Power1, Power2, Power3, and Power4 (each with easeIn, easeOut, and easeInOut)
//now try to determine the requestAnimationFrame and cancelAnimationFrame functions and if none are found, we'll use a setTimeout()/clearTimeout() polyfill.
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.
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.
return(_lagThreshold<1/_tinyNum);
}
_lagThreshold=threshold||(1/_tinyNum);//zero should be interpreted as basically unlimited
}elseif(_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().
//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.
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.
//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.
var_checkTimeout=function(){
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.
_ticker.wake();
}
vart=setTimeout(_checkTimeout,2000);
if(t.unref){
// 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.
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);
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.
this._uncache(false);
}
//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.
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.
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.
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.
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.
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).
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()
this._propLookup=[];
this._siblings=[];
for(i=0;i<targets.length;i++){
targ=targets[i];
if(!targ){
targets.splice(i--,1);
continue;
}elseif(typeof(targ)==="string"){
targ=targets[i--]=TweenLite.selector(targ);//in case it's an array of strings
if(typeof(targ)==="string"){
targets.splice(i+1,1);//to avoid an endless loop (can't imagine why the selector would return a string, but just in case)
}
continue;
}elseif(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.
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)
this.render(Math.min(0,-this._delay));//in case delay is negative
}
},true),
_isSelector=function(v){
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.
},
_autoCSS=function(vars,target){
varcss={},
p;
for(pinvars){
if(!_reservedProps[p]&&(!(pintarget)||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.
css[p]=vars[p];
deletevars[p];
}
}
vars.css=css;
};
p=TweenLite.prototype=newAnimation();
p.constructor=TweenLite;
p.kill()._gc=false;
//----TweenLite defaults, overwrite management, and root updates ----------------------------------------------------
}elseif(val<min)if(val>-min&&!pt.blob){//prevents issues with converting very small numbers to strings in the browser
val=0;
}
if(!pt.f){
pt.t[pt.p]=val;
}elseif(pt.fp){
pt.t[pt.p](pt.fp,val);
}else{
pt.t[pt.p](val);
}
pt=pt._next;
}
},
_blobRound=function(v){
return(((v*1000)|0)/1000)+"";
},
//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("")).
_blobDif=function(start,end,filter,pt){
vara=[],
charIndex=0,
s="",
color=0,
startNums,endNums,num,i,l,nonNumbers,currentNum;
a.start=start;
a.end=end;
start=a[0]=start+"";//ensure values are strings
end=a[1]=end+"";
if(filter){
filter(a);//pass an array with the starting and ending values and let the filter do whatever it needs to the values.
start=a[0];
end=a[1];
}
a.length=0;
startNums=start.match(_numbersExp)||[];
endNums=end.match(_numbersExp)||[];
if(pt){
pt._next=null;
pt.blob=1;
a._firstPT=a._applyPT=pt;//apply last in the linked list (which means inserting it first)
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.
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!
//note: we don't set _prev because we'll never need to remove individual PropTweens from this list.
}
charIndex+=currentNum.length;
}
s+=end.substr(charIndex);
if(s){
a.push(s);
}
a.setRatio=_setRatio;
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).
a.end=null;
}
returna;
},
//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.
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.
}else{
pt.s=parseFloat(s);
if(!isRelative){
pt.c=(parseFloat(end)-pt.s)||0;
}
}
}
if(pt.c){//only add it to the linked list if there's a change.
if((pt._next=this._firstPT)){
pt._next._prev=pt;
}
this._firstPT=pt;
returnpt;
}
},
_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.
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".
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.
//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)
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
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.
startAt.kill();
}
startVars={};
for(pinv.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);
startVars[p]=v.startAt[p];
}
startVars.data="isStart";
startVars.overwrite=false;
startVars.immediateRender=true;
startVars.lazy=(immediate&&v.lazy!==false);
startVars.startAt=startVars.delay=null;//no nesting of startAt objects allowed (otherwise it could cause an infinite loop).
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()).
}elseif(dur!==0){
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.
}
}
}elseif(v.runBackwards&&dur!==0){
//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)
if(startAt){
startAt.render(-1,true);
startAt.kill();
this._startAt=null;
}else{
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
immediate=false;
}
pt={};
for(pinv){//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.
if(!_reservedProps[p]||p==="autoCSS"){
pt[p]=v[p];
}
}
pt.overwrite=0;
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.
pt.lazy=(immediate&&v.lazy!==false);
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)
this._startAt=TweenLite.to(this.target,0,pt);
if(!immediate){
this._startAt._init();//ensures that the initial values are recorded
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.
TweenLite._onPluginEvent("_onInitAllProps",this);//reorders the array in order of priority. Uses a static TweenPlugin method in order to minimize file size in TweenLite
}
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.
_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)
}
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.
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)
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.
}
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.
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.
time=0;
}
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.
force=true;
if(prevRawPrevTime>_tinyNum){
callback="onReverseComplete";
}
}
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.
}
}elseif(time<_tinyNum){//to work around occasional floating point math artifacts, round super small values to 0.
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.
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.
}
}
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.
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 overwriting 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.
//_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.
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.
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.
}
if(prevTime===0){
if(self._startAt){
if(time>=0){
self._startAt.render(time,true,force);
}elseif(!callback){
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.
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.
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.
if(callback)if(!self._gc||force){//check _gc because there's a chance that kill() could be called in an onUpdate
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.
self._startAt.render(time,true,force);
}
if(isComplete){
if(self._timeline.autoRemoveChildren){
self._enabled(false,false);
}
self._active=false;
}
if(!suppressEvents&&self.vars[callback]){
self._callback(callback);
}
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 scenario, but possible nonetheless.
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)
if((killed||!vars)&&!_onOverwrite(this,overwritingTween,target,killed)){//if the onOverwrite returned false, that means the user wants to override the overwriting (cancel it).
returnfalse;
}
}
for(pinkillProps){
if((pt=propLookup[p])){
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.
if(pt.f){
pt.t[pt.p](pt.s);
}else{
pt.t[pt.p]=pt.s;
}
changed=true;
}
if(pt.pg&&pt.t._kill(killProps)){
changed=true;//some plugins need to be notified so they can perform cleanup tasks first
}
if(!pt.pg||pt.t._overwriteProps.length===0){
if(pt._prev){
pt._prev._next=pt._next;
}elseif(pt===this._firstPT){
this._firstPT=pt._next;
}
if(pt._next){
pt._next._prev=pt._prev;
}
pt._next=pt._prev=null;
}
deletepropLookup[p];
}
if(record){
overwrittenProps[p]=1;
}
}
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.
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)
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.
if(pt.f===2){
pt.t._applyPT.m=val;
}else{
pt.m=val;
}
}
pt=pt._next;
}
};
TweenLite._onPluginEvent=function(type,tween){
varpt=tween._firstPT,
changed,pt2,first,last,next;
if(type==="_onInitAllProps"){
//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.
//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.
//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.