Guest User

Untitled

a guest
Jul 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.38 KB | None | 0 0
  1. diff --git a/frameworks/animation/core.js b/frameworks/animation/core.js
  2. index e78cfd8..4151ff6 100644
  3. --- a/frameworks/animation/core.js
  4. +++ b/frameworks/animation/core.js
  5. @@ -59,7 +59,7 @@ SC.Animatable = {
  6.  
  7. // properties that adjust should relay to style
  8. _styleProperties: [ "opacity", "display" ],
  9. - _layoutStyles: ["left", "right", "top", "bottom", "width", "height", "centerX", "centerY"],
  10. + _layoutStyles: 'width height top bottom marginLeft marginTop left right zIndex minWidth maxWidth minHeight maxHeight'.w(),
  11.  
  12. // we cache this dictionary so we don't generate a new one each time we make
  13. // a new animation. It is used so we can start the animations in orderβ€”
  14. @@ -69,6 +69,8 @@ SC.Animatable = {
  15. // and, said animation order
  16. _animationOrder: ["top", "left", "bottom", "right", "width", "height", "centerX", "centerY", "opacity", "display"],
  17.  
  18. + _transitionCallbacks: {},
  19. +
  20.  
  21. initMixin: function()
  22. {
  23. @@ -110,6 +112,18 @@ SC.Animatable = {
  24. this._last_transition_css = ""; // to keep from re-setting unnecessarily
  25. this._disableAnimation = 0; // calls to disableAnimation add one; enableAnimation remove one.
  26. },
  27. +
  28. + didCreateLayer: function(){
  29. + SC.Event.add(this.get('layer'), "webkitTransitionEnd", this, this.transitionEnd);
  30. + SC.Event.add(this.get('layer'), "transitionend", this, this.transitionEnd);
  31. + return sc_super();
  32. + },
  33. +
  34. + willDestroyLayer: function(){
  35. + SC.Event.remove(this.get('layer'), "webkitTransitionEnd", this, this.transitionEnd);
  36. + SC.Event.remove(this.get('layer'), "transitionend", this, this.transitionEnd);
  37. + return sc_super();
  38. + },
  39.  
  40. /**
  41. Stops all animations on the layer when this occurs by calling resetAnimation.
  42. @@ -191,7 +205,16 @@ SC.Animatable = {
  43. // call base with whatever is leftover
  44. return this;
  45. },
  46. -
  47. +
  48. +
  49. + transitionEnd: function(evt){
  50. + var propertyName = evt.originalEvent.propertyName;
  51. + callback = this._transitionCallbacks[propertyName];
  52. +
  53. + if(callback) SC.Animatable.runCallback(callback);
  54. + },
  55. +
  56. +
  57. /**
  58. Returns the current set of styles and layout according to JavaScript transitions.
  59.  
  60. @@ -377,6 +400,15 @@ SC.Animatable = {
  61. // the transition is already set up.
  62. // we can just set it as part of the starting point
  63. startingPoint[i] = newStyle[i];
  64. +
  65. + if (this.transitions[i].action){
  66. + this._transitionCallbacks[i] = {
  67. + source: this,
  68. + target: (this.transitions[i].target || this),
  69. + action: this.transitions[i].action
  70. + };
  71. + };
  72. +
  73. continue;
  74. }
  75.  
  76. @@ -425,6 +457,14 @@ SC.Animatable = {
  77. a.style = layer.style;
  78. a.holder = this;
  79.  
  80. + if (this.transitions[i].action){
  81. + a.callback = {
  82. + source: this,
  83. + target: (this.transitions[i].target || this),
  84. + action: this.transitions[i].action
  85. + };
  86. + };
  87. +
  88. timing = this.transitions[i].timing || SC.Animatable.defaultTimingFunction;
  89. if (timing && SC.typeOf(timing) != SC.T_STRING) a.timingFunction = timing;
  90.  
  91. @@ -688,6 +728,7 @@ SC.Animatable = {
  92. if (t < e) SC.Animatable.addTimer(this);
  93. else {
  94. this.going = false;
  95. + if(this.callback) SC.Animatable.runCallback(this.callback);
  96. this.styles = null;
  97. this.layer = null;
  98. }
  99. @@ -715,6 +756,7 @@ SC.Animatable = {
  100. this.style[this.property] = this.endValue;
  101.  
  102. this.going = false;
  103. + if(this.callback) SC.Animatable.runCallback(this.callback);
  104. this.styles = null;
  105. this.layer = null;
  106. },
  107. @@ -765,6 +807,7 @@ SC.Animatable = {
  108. if (t < e) SC.Animatable.addTimer(this);
  109. else {
  110. this.going = false;
  111. + if(this.callback) SC.Animatable.runCallback(this.callback);
  112. this.styles = null;
  113. this.layer = null;
  114. }
  115. @@ -819,6 +862,7 @@ SC.Animatable = {
  116. if (t < e) SC.Animatable.addTimer(this);
  117. else {
  118. this.going = false;
  119. + if(this.callback) SC.Animatable.runCallback(this.callback);
  120. this.styles = null;
  121. this.layer = null;
  122. }
  123. @@ -943,7 +987,38 @@ SC.mixin(SC.Animatable, {
  124. SC.Animatable.stats.set("lastFPS", SC.Animatable._ticks / (time_diff / 1000));
  125. loop.end();
  126. }
  127. + },
  128. +
  129. + runCallback: function(callback){
  130. + var typeOfAction = SC.typeOf(callback.action);
  131. +
  132. + // if the action is a function, just try to call it.
  133. + if (typeOfAction == SC.T_FUNCTION) {
  134. + callback.action.call(callback.target);
  135. +
  136. + // otherwise, action should be a string. If it has a period, treat it
  137. + // like a property path.
  138. + } else if (typeOfAction === SC.T_STRING) {
  139. + if (callback.action.indexOf('.') >= 0) {
  140. + var path = callback.action.split('.') ;
  141. + var property = path.pop() ;
  142. +
  143. + var target = SC.objectForPropertyPath(path, window) ;
  144. + var action = target.get ? target.get(property) : target[property];
  145. + if (action && SC.typeOf(action) == SC.T_FUNCTION) {
  146. + action.call(target);
  147. + } else {
  148. + throw 'SC.Animator could not find a function at %@'.fmt(callback.action) ;
  149. + }
  150. +
  151. + // otherwise, try to execute action direction on target or send down
  152. + // responder chain.
  153. + } else {
  154. + SC.RootResponder.responder.sendAction(callback.action, callback.target);
  155. + }
  156. + }
  157. }
  158. +
  159. });
Add Comment
Please, Sign In to add comment