1 // ==========================================================================
  2 // Project:   SproutCore
  3 // Copyright: @2013 7x7 Software, Inc.
  4 // License:   Licensed under MIT license (see license.js)
  5 // ==========================================================================
  6 
  7 
  8 SC.mixin(SC.View,
  9   /** @scope SC.View */ {
 10 
 11   /** @class
 12 
 13     @extends SC.ViewTransitionProtocol
 14     @see SC.View#animate for other timing functions.
 15     @since Version 1.10
 16   */
 17   SLIDE_IN: {
 18 
 19     layoutProperties: ['top', 'bottom', 'left', 'right', 'height', 'width', 'centerX', 'centerY'],
 20 
 21     /** @private Starts from outside of parent unless inPlace is true. */
 22     setup: function (view, options, inPlace) {
 23       var parentView = view.get('parentView'),
 24         parentFrame,
 25         viewFrame = view.get('borderFrame'),
 26         left,
 27         top;
 28 
 29       if (inPlace) {
 30         // Move from the current position.
 31       } else {
 32         // If there is no parentView, use the window's frame.
 33         if (parentView) {
 34           parentFrame = parentView.get('borderFrame');
 35         } else {
 36           parentFrame = SC.RootResponder.responder.currentWindowSize;
 37         }
 38 
 39         switch (options.direction) {
 40         case 'left':
 41           left = parentFrame.width;
 42           break;
 43         case 'up':
 44           top = parentFrame.height;
 45           break;
 46         case 'down':
 47           top = -viewFrame.height;
 48           break;
 49         default:
 50           left = -viewFrame.width;
 51         }
 52       }
 53 
 54       // Convert to a HW accelerate-able layout.
 55       view.adjust({ centerX: null, centerY: null, bottom: null, left: left || viewFrame.x, right: null, top: top || viewFrame.y, height: viewFrame.height, width: viewFrame.width });
 56     },
 57 
 58     /** @private */
 59     run: function (view, options, finalLayout, finalFrame) {
 60       var key,
 61         value;
 62 
 63       if (options.direction === 'up' || options.direction === 'down') {
 64         key = 'top';
 65         value = finalFrame.y;
 66       } else {
 67         key = 'left';
 68         value = finalFrame.x;
 69       }
 70 
 71       view.animate(key, value, {
 72         delay: options.delay || 0,
 73         duration: options.duration || 0.4,
 74         timing: options.timing || 'ease'
 75       }, function (data) {
 76         if (!data.isCancelled) {
 77           this.didTransitionIn();
 78         }
 79       });
 80     }
 81   },
 82 
 83   /** @class
 84 
 85     @extends SC.ViewTransitionProtocol
 86     @see SC.View#animate for other timing functions.
 87     @since Version 1.10
 88   */
 89   SLIDE_OUT: {
 90 
 91     layoutProperties: ['top', 'bottom', 'left', 'right', 'height', 'width', 'centerX', 'centerY'],
 92 
 93     /** @private Starts from current position. */
 94     setup: function (view, options) {
 95       var viewFrame = view.get('borderFrame'),
 96         left = viewFrame.x,
 97         top = viewFrame.y,
 98         height = viewFrame.height,
 99         width = viewFrame.width;
100 
101       view.adjust({ centerX: null, centerY: null, bottom: null, left: left, right: null, top: top, height: height, width: width });
102     },
103 
104     /** @private */
105     run: function (view, options, finalLayout, finalFrame) {
106       var viewFrame = view.get('borderFrame'),
107         parentView = view.get('parentView'),
108         parentFrame,
109         key, value;
110 
111       // If there is no parentView, use the window's frame.
112       if (parentView) {
113         parentFrame = parentView.get('borderFrame');
114       } else {
115         parentFrame = SC.RootResponder.responder.currentWindowSize;
116       }
117 
118       switch (options.direction) {
119       case 'left':
120         key = 'left';
121         value = -viewFrame.width;
122         break;
123       case 'up':
124         key = 'top';
125         value = -viewFrame.height;
126         break;
127       case 'down':
128         key = 'top';
129         value = parentFrame.height;
130         break;
131       default:
132         key = 'left';
133         value = parentFrame.width;
134       }
135 
136       view.animate(key, value, {
137         delay: options.delay || 0,
138         duration: options.duration || 0.4,
139         timing: options.timing || 'ease'
140       }, function (data) {
141         if (!data.isCancelled) {
142           this.didTransitionOut();
143         }
144       });
145     }
146   }
147 
148 });
149