@@ -42,7 +42,7 @@ <h1>AniJS demo</h1>
42
42
</ div >
43
43
44
44
< div >
45
- < h4 data-anijs =" if: added, do: swing animated, on: $gridstack " > Widget added</ h4 >
45
+ < h4 > Widget added</ h4 >
46
46
</ div >
47
47
48
48
< br />
@@ -57,9 +57,14 @@ <h4 data-anijs="if: added, do: swing animated, on: $gridstack">Widget added</h4>
57
57
$ ( '.grid-stack' ) . gridstack ( ) ;
58
58
var self = this ;
59
59
this . grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
60
- AniJS . run ( ) ;
61
- self . gridstackNotifier = AniJS . getNotifier ( 'gridstack' ) ;
62
60
$ ( '.grid-stack' ) . on ( 'added' , function ( event , items ) {
61
+ // add anijs data to gridstack item
62
+ for ( var i = 0 ; i < items . length ; i ++ ) {
63
+ $ ( items [ i ] . el [ 0 ] ) . attr ( 'data-anijs' , 'if: added, do: swing animated, after: $removeAnimations, on: $gridstack' ) ;
64
+ }
65
+ AniJS . run ( ) ;
66
+ self . gridstackNotifier = AniJS . getNotifier ( 'gridstack' ) ;
67
+ // fire added event!
63
68
self . gridstackNotifier . dispatchEvent ( 'added' ) ;
64
69
} ) ;
65
70
$ ( '#add-widget' ) . click ( function ( ) {
@@ -68,8 +73,15 @@ <h4 data-anijs="if: added, do: swing animated, on: $gridstack">Widget added</h4>
68
73
69
74
function addNewWidget ( ) {
70
75
var grid = $ ( '.grid-stack' ) . data ( 'gridstack' ) ;
71
- grid . addWidget ( $ ( '<div class="grid-stack-item-content"></div>' ) , 0 , 0 , Math . floor ( 1 + 3 * Math . random ( ) ) , Math . floor ( 1 + 3 * Math . random ( ) ) , true ) ;
76
+ grid . addWidget ( $ ( '<div><div class="grid-stack-item-content"></div ></div>' ) , 0 , 0 , Math . floor ( 1 + 3 * Math . random ( ) ) , Math . floor ( 1 + 3 * Math . random ( ) ) , true ) ;
72
77
}
78
+
79
+ var animationHelper = AniJS . getHelper ( ) ;
80
+
81
+ //Defining removeAnimations to remove existing animations
82
+ animationHelper . removeAnimations = function ( e , animationContext ) {
83
+ $ ( '.grid-stack-item' ) . attr ( 'data-anijs' , '' ) ;
84
+ } ;
73
85
} ) ;
74
86
</ script >
75
87
</ body >
0 commit comments