1
1
/*!
2
- * Packery PACKAGED v2.0 .0
2
+ * Packery PACKAGED v2.1 .0
3
3
* Gapless, draggable grid layouts
4
4
*
5
5
* Licensed GPLv3 for open source use
@@ -827,7 +827,8 @@ var vendorProperties = {
827
827
transform : transformProperty ,
828
828
transition : transitionProperty ,
829
829
transitionDuration : transitionProperty + 'Duration' ,
830
- transitionProperty : transitionProperty + 'Property'
830
+ transitionProperty : transitionProperty + 'Property' ,
831
+ transitionDelay : transitionProperty + 'Delay'
831
832
} ;
832
833
833
834
// -------------------------- Item -------------------------- //
@@ -1106,10 +1107,14 @@ proto.enableTransition = function(/* style */) {
1106
1107
// prop = vendorProperties[ prop ] || prop;
1107
1108
// transitionValues.push( toDashedAll( prop ) );
1108
1109
// }
1110
+ // munge number to millisecond, to match stagger
1111
+ var duration = this . layout . options . transitionDuration ;
1112
+ duration = typeof duration == 'number' ? duration + 'ms' : duration ;
1109
1113
// enable transition styles
1110
1114
this . css ( {
1111
1115
transitionProperty : transitionProps ,
1112
- transitionDuration : this . layout . options . transitionDuration
1116
+ transitionDuration : duration ,
1117
+ transitionDelay : this . staggerDelay || 0
1113
1118
} ) ;
1114
1119
// listen for transition end event
1115
1120
this . element . addEventListener ( transitionEndEvent , this , false ) ;
@@ -1183,14 +1188,22 @@ proto._removeStyles = function( style ) {
1183
1188
1184
1189
var cleanTransitionStyle = {
1185
1190
transitionProperty : '' ,
1186
- transitionDuration : ''
1191
+ transitionDuration : '' ,
1192
+ transitionDelay : ''
1187
1193
} ;
1188
1194
1189
1195
proto . removeTransitionStyles = function ( ) {
1190
1196
// remove transition
1191
1197
this . css ( cleanTransitionStyle ) ;
1192
1198
} ;
1193
1199
1200
+ // ----- stagger ----- //
1201
+
1202
+ proto . stagger = function ( delay ) {
1203
+ delay = isNaN ( delay ) ? 0 : delay ;
1204
+ this . staggerDelay = delay + 'ms' ;
1205
+ } ;
1206
+
1194
1207
// ----- show/hide/remove ----- //
1195
1208
1196
1209
// remove element from DOM
@@ -1306,7 +1319,7 @@ return Item;
1306
1319
} ) ) ;
1307
1320
1308
1321
/*!
1309
- * Outlayer v2.0.1
1322
+ * Outlayer v2.1.0
1310
1323
* the brains and guts of a layout library
1311
1324
* MIT license
1312
1325
*/
@@ -1655,23 +1668,36 @@ proto._getItemLayoutPosition = function( /* item */ ) {
1655
1668
* @param {Array } queue
1656
1669
*/
1657
1670
proto . _processLayoutQueue = function ( queue ) {
1658
- queue . forEach ( function ( obj ) {
1659
- this . _positionItem ( obj . item , obj . x , obj . y , obj . isInstant ) ;
1671
+ this . updateStagger ( ) ;
1672
+ queue . forEach ( function ( obj , i ) {
1673
+ this . _positionItem ( obj . item , obj . x , obj . y , obj . isInstant , i ) ;
1660
1674
} , this ) ;
1661
1675
} ;
1662
1676
1677
+ // set stagger from option in milliseconds number
1678
+ proto . updateStagger = function ( ) {
1679
+ var stagger = this . options . stagger ;
1680
+ if ( stagger === null || stagger === undefined ) {
1681
+ this . stagger = 0 ;
1682
+ return ;
1683
+ }
1684
+ this . stagger = getMilliseconds ( stagger ) ;
1685
+ return this . stagger ;
1686
+ } ;
1687
+
1663
1688
/**
1664
1689
* Sets position of item in DOM
1665
1690
* @param {Outlayer.Item } item
1666
1691
* @param {Number } x - horizontal position
1667
1692
* @param {Number } y - vertical position
1668
1693
* @param {Boolean } isInstant - disables transitions
1669
1694
*/
1670
- proto . _positionItem = function ( item , x , y , isInstant ) {
1695
+ proto . _positionItem = function ( item , x , y , isInstant , i ) {
1671
1696
if ( isInstant ) {
1672
1697
// if not transition, just set CSS
1673
1698
item . goTo ( x , y ) ;
1674
1699
} else {
1700
+ item . stagger ( i * this . stagger ) ;
1675
1701
item . moveTo ( x , y ) ;
1676
1702
}
1677
1703
} ;
@@ -2015,7 +2041,9 @@ proto.reveal = function( items ) {
2015
2041
if ( ! items || ! items . length ) {
2016
2042
return ;
2017
2043
}
2018
- items . forEach ( function ( item ) {
2044
+ var stagger = this . updateStagger ( ) ;
2045
+ items . forEach ( function ( item , i ) {
2046
+ item . stagger ( i * stagger ) ;
2019
2047
item . reveal ( ) ;
2020
2048
} ) ;
2021
2049
} ;
@@ -2029,7 +2057,9 @@ proto.hide = function( items ) {
2029
2057
if ( ! items || ! items . length ) {
2030
2058
return ;
2031
2059
}
2032
- items . forEach ( function ( item ) {
2060
+ var stagger = this . updateStagger ( ) ;
2061
+ items . forEach ( function ( item , i ) {
2062
+ item . stagger ( i * stagger ) ;
2033
2063
item . hide ( ) ;
2034
2064
} ) ;
2035
2065
} ;
@@ -2194,6 +2224,31 @@ function subclass( Parent ) {
2194
2224
return SubClass ;
2195
2225
}
2196
2226
2227
+ // ----- helpers ----- //
2228
+
2229
+ // how many milliseconds are in each unit
2230
+ var msUnits = {
2231
+ ms : 1 ,
2232
+ s : 1000
2233
+ } ;
2234
+
2235
+ // munge time-like parameter into millisecond number
2236
+ // '0.4s' -> 40
2237
+ function getMilliseconds ( time ) {
2238
+ if ( typeof time == 'number' ) {
2239
+ return time ;
2240
+ }
2241
+ var matches = time . match ( / ( ^ \d * \. ? \d * ) ( \w * ) / ) ;
2242
+ var num = matches && matches [ 1 ] ;
2243
+ var unit = matches && matches [ 2 ] ;
2244
+ if ( ! num . length ) {
2245
+ return 0 ;
2246
+ }
2247
+ num = parseFloat ( num ) ;
2248
+ var mult = msUnits [ unit ] || 1 ;
2249
+ return num * mult ;
2250
+ }
2251
+
2197
2252
// ----- fin ----- //
2198
2253
2199
2254
// back in global
@@ -2672,7 +2727,11 @@ proto.positionDropPlaceholder = function() {
2672
2727
} ;
2673
2728
2674
2729
proto . hideDropPlaceholder = function ( ) {
2675
- this . layout . element . removeChild ( this . dropPlaceholder ) ;
2730
+ // only remove once, #333
2731
+ var parent = this . dropPlaceholder . parentNode ;
2732
+ if ( parent ) {
2733
+ parent . removeChild ( this . dropPlaceholder ) ;
2734
+ }
2676
2735
} ;
2677
2736
2678
2737
// ----- ----- //
@@ -2682,7 +2741,7 @@ return Item;
2682
2741
} ) ) ;
2683
2742
2684
2743
/*!
2685
- * Packery v2.0 .0
2744
+ * Packery v2.1 .0
2686
2745
* Gapless, draggable grid layouts
2687
2746
*
2688
2747
* Licensed GPLv3 for open source use
0 commit comments