Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     .directive( 'shift', [ '$animate', function( $animate ){
  2.         return {
  3.             restrict    : 'A',
  4.             priority    : '400',
  5.             terminal    : true,
  6.             transclude  : 'element',
  7.             link        : function( $scope, $element, $attrs, ctrl, $transclude ) {
  8.                 var
  9.                     child = open();
  10.  
  11.                 $scope.$watch( $attrs.shift, function( curr, prev ) {
  12.                     if ( curr === prev ) {
  13.                         return;
  14.                     }
  15.                     shift();
  16.                 });
  17.  
  18.                 function shift(){
  19.                     close( child );
  20.                     child = open();
  21.                 }
  22.  
  23.                 function open(){
  24.                     var child = {};
  25.                     child.scope = $scope.$new();
  26.                     $transclude( child.scope, function( clone ){
  27.                         child.element = clone;
  28.                         child.element.addClass( 'ng-shift ng-shift-enter' );
  29.                         $animate.enter( clone, $element.parent(), $element );
  30.                     });
  31.                     return child;
  32.                 }
  33.  
  34.                 function close( child ){
  35.                     if ( child.element ) {
  36.                         child.element.removeClass( 'ng-shift-enter' );
  37.                         child.element.addClass( 'ng-shift-leave' );
  38.                         $animate.leave( child.element );
  39.                         delete child.element;
  40.                     }
  41.                     if ( child.scope ) {
  42.                         child.scope.$destroy();
  43.                         delete child.scope;
  44.                     }
  45.                 }
  46.             }
  47.         }
  48.     }]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement