1
1
/*!
2
- * Packery PACKAGED v1.4.1
2
+ * Packery PACKAGED v1.4.2
3
3
* bin-packing layout library
4
4
*
5
5
* Licensed GPLv3 for open source use
@@ -1722,14 +1722,19 @@ Item.prototype.getPosition = function() {
1722
1722
var layoutOptions = this . layout . options ;
1723
1723
var isOriginLeft = layoutOptions . isOriginLeft ;
1724
1724
var isOriginTop = layoutOptions . isOriginTop ;
1725
- var x = parseInt ( style [ isOriginLeft ? 'left' : 'right' ] , 10 ) ;
1726
- var y = parseInt ( style [ isOriginTop ? 'top' : 'bottom' ] , 10 ) ;
1725
+ var xValue = style [ isOriginLeft ? 'left' : 'right' ] ;
1726
+ var yValue = style [ isOriginTop ? 'top' : 'bottom' ] ;
1727
+ var x = parseInt ( xValue , 10 ) ;
1728
+ var y = parseInt ( yValue , 10 ) ;
1729
+ // convert percent to pixels
1730
+ var layoutSize = this . layout . size ;
1731
+ x = xValue . indexOf ( '%' ) != - 1 ? ( x / 100 ) * layoutSize . width : x ;
1732
+ y = yValue . indexOf ( '%' ) != - 1 ? ( y / 100 ) * layoutSize . height : y ;
1727
1733
1728
1734
// clean up 'auto' or other non-integer values
1729
1735
x = isNaN ( x ) ? 0 : x ;
1730
1736
y = isNaN ( y ) ? 0 : y ;
1731
1737
// remove padding from measurement
1732
- var layoutSize = this . layout . size ;
1733
1738
x -= isOriginLeft ? layoutSize . paddingLeft : layoutSize . paddingRight ;
1734
1739
y -= isOriginTop ? layoutSize . paddingTop : layoutSize . paddingBottom ;
1735
1740
@@ -1749,10 +1754,8 @@ Item.prototype.layoutPosition = function() {
1749
1754
var xResetProperty = layoutOptions . isOriginLeft ? 'right' : 'left' ;
1750
1755
1751
1756
var x = this . position . x + layoutSize [ xPadding ] ;
1752
- // set in percentage
1753
- x = layoutOptions . percentPosition && ! layoutOptions . isHorizontal ?
1754
- ( ( x / layoutSize . width ) * 100 ) + '%' : x + 'px' ;
1755
- style [ xProperty ] = x ;
1757
+ // set in percentage or pixels
1758
+ style [ xProperty ] = this . getXValue ( x ) ;
1756
1759
// reset other property
1757
1760
style [ xResetProperty ] = '' ;
1758
1761
@@ -1762,26 +1765,26 @@ Item.prototype.layoutPosition = function() {
1762
1765
var yResetProperty = layoutOptions . isOriginTop ? 'bottom' : 'top' ;
1763
1766
1764
1767
var y = this . position . y + layoutSize [ yPadding ] ;
1765
- // set in percentage
1766
- y = layoutOptions . percentPosition && layoutOptions . isHorizontal ?
1767
- ( ( y / layoutSize . height ) * 100 ) + '%' : y + 'px' ;
1768
- style [ yProperty ] = y ;
1768
+ // set in percentage or pixels
1769
+ style [ yProperty ] = this . getYValue ( y ) ;
1769
1770
// reset other property
1770
1771
style [ yResetProperty ] = '' ;
1771
1772
1772
1773
this . css ( style ) ;
1773
1774
this . emitEvent ( 'layout' , [ this ] ) ;
1774
1775
} ;
1775
1776
1777
+ Item . prototype . getXValue = function ( x ) {
1778
+ var layoutOptions = this . layout . options ;
1779
+ return layoutOptions . percentPosition && ! layoutOptions . isHorizontal ?
1780
+ ( ( x / this . layout . size . width ) * 100 ) + '%' : x + 'px' ;
1781
+ } ;
1776
1782
1777
- // transform translate function
1778
- var translate = is3d ?
1779
- function ( x , y ) {
1780
- return 'translate3d(' + x + 'px, ' + y + 'px, 0)' ;
1781
- } :
1782
- function ( x , y ) {
1783
- return 'translate(' + x + 'px, ' + y + 'px)' ;
1784
- } ;
1783
+ Item . prototype . getYValue = function ( y ) {
1784
+ var layoutOptions = this . layout . options ;
1785
+ return layoutOptions . percentPosition && layoutOptions . isHorizontal ?
1786
+ ( ( y / this . layout . size . height ) * 100 ) + '%' : y + 'px' ;
1787
+ } ;
1785
1788
1786
1789
1787
1790
Item . prototype . _transitionTo = function ( x , y ) {
@@ -1806,11 +1809,7 @@ Item.prototype._transitionTo = function( x, y ) {
1806
1809
var transX = x - curX ;
1807
1810
var transY = y - curY ;
1808
1811
var transitionStyle = { } ;
1809
- // flip cooridinates if origin on right or bottom
1810
- var layoutOptions = this . layout . options ;
1811
- transX = layoutOptions . isOriginLeft ? transX : - transX ;
1812
- transY = layoutOptions . isOriginTop ? transY : - transY ;
1813
- transitionStyle . transform = translate ( transX , transY ) ;
1812
+ transitionStyle . transform = this . getTranslate ( transX , transY ) ;
1814
1813
1815
1814
this . transition ( {
1816
1815
to : transitionStyle ,
@@ -1821,6 +1820,21 @@ Item.prototype._transitionTo = function( x, y ) {
1821
1820
} ) ;
1822
1821
} ;
1823
1822
1823
+ Item . prototype . getTranslate = function ( x , y ) {
1824
+ // flip cooridinates if origin on right or bottom
1825
+ var layoutOptions = this . layout . options ;
1826
+ x = layoutOptions . isOriginLeft ? x : - x ;
1827
+ y = layoutOptions . isOriginTop ? y : - y ;
1828
+ x = this . getXValue ( x ) ;
1829
+ y = this . getYValue ( y ) ;
1830
+
1831
+ if ( is3d ) {
1832
+ return 'translate3d(' + x + ', ' + y + ', 0)' ;
1833
+ }
1834
+
1835
+ return 'translate(' + x + ', ' + y + ')' ;
1836
+ } ;
1837
+
1824
1838
// non transition + transform support
1825
1839
Item . prototype . goTo = function ( x , y ) {
1826
1840
this . setPosition ( x , y ) ;
@@ -1900,28 +1914,36 @@ Item.prototype._transition = function( args ) {
1900
1914
1901
1915
} ;
1902
1916
1903
- var itemTransitionProperties = transformProperty && ( utils . toDashed ( transformProperty ) +
1904
- ',opacity' ) ;
1917
+ // dash before all cap letters, including first for
1918
+ // WebkitTransform => -webkit-transform
1919
+ function toDashedAll ( str ) {
1920
+ return str . replace ( / ( [ A - Z ] ) / g, function ( $1 ) {
1921
+ return '-' + $1 . toLowerCase ( ) ;
1922
+ } ) ;
1923
+ }
1924
+
1925
+ var transitionProps = 'opacity,' +
1926
+ toDashedAll ( vendorProperties . transform || 'transform' ) ;
1905
1927
1906
1928
Item . prototype . enableTransition = function ( /* style */ ) {
1907
- // only enable if not already transitioning
1908
- // bug in IE10 were re-setting transition style will prevent
1909
- // transitionend event from triggering
1929
+ // HACK changing transitionProperty during a transition
1930
+ // will cause transition to jump
1910
1931
if ( this . isTransitioning ) {
1911
1932
return ;
1912
1933
}
1913
1934
1914
- // make transition: foo, bar, baz from style object
1915
- // TODO uncomment this bit when IE10 bug is resolved
1916
- // var transitionValue = [];
1935
+ // make `transition: foo, bar, baz` from style object
1936
+ // HACK un-comment this when enableTransition can work
1937
+ // while a transition is happening
1938
+ // var transitionValues = [];
1917
1939
// for ( var prop in style ) {
1918
1940
// // dash-ify camelCased properties like WebkitTransition
1919
- // transitionValue.push( toDash( prop ) );
1941
+ // prop = vendorProperties[ prop ] || prop;
1942
+ // transitionValues.push( toDashedAll( prop ) );
1920
1943
// }
1921
1944
// enable transition styles
1922
- // HACK always enable transform,opacity for IE10
1923
1945
this . css ( {
1924
- transitionProperty : itemTransitionProperties ,
1946
+ transitionProperty : transitionProps ,
1925
1947
transitionDuration : this . layout . options . transitionDuration
1926
1948
} ) ;
1927
1949
// listen for transition end event
@@ -2124,7 +2146,7 @@ return Item;
2124
2146
} ) ) ;
2125
2147
2126
2148
/*!
2127
- * Outlayer v1.4.0
2149
+ * Outlayer v1.4.1
2128
2150
* the brains and guts of a layout library
2129
2151
* MIT license
2130
2152
*/
@@ -2539,7 +2561,7 @@ Outlayer.prototype._setContainerMeasure = function( measure, isWidth ) {
2539
2561
Outlayer . prototype . _emitCompleteOnItems = function ( eventName , items ) {
2540
2562
var _this = this ;
2541
2563
function onComplete ( ) {
2542
- _this . emitEvent ( eventName + 'Complete' , [ items ] ) ;
2564
+ _this . dispatchEvent ( eventName + 'Complete' , null , [ items ] ) ;
2543
2565
}
2544
2566
2545
2567
var count = items . length ;
@@ -2563,6 +2585,32 @@ Outlayer.prototype._emitCompleteOnItems = function( eventName, items ) {
2563
2585
}
2564
2586
} ;
2565
2587
2588
+ /**
2589
+ * emits events via eventEmitter and jQuery events
2590
+ * @param {String } type - name of event
2591
+ * @param {Event } event - original event
2592
+ * @param {Array } args - extra arguments
2593
+ */
2594
+ Outlayer . prototype . dispatchEvent = function ( type , event , args ) {
2595
+ // add original event to arguments
2596
+ var emitArgs = event ? [ event ] . concat ( args ) : args ;
2597
+ this . emitEvent ( type , emitArgs ) ;
2598
+
2599
+ if ( jQuery ) {
2600
+ // set this.$element
2601
+ this . $element = this . $element || jQuery ( this . element ) ;
2602
+ if ( event ) {
2603
+ // create jQuery event
2604
+ var $event = jQuery . Event ( event ) ;
2605
+ $event . type = type ;
2606
+ this . $element . trigger ( $event , args ) ;
2607
+ } else {
2608
+ // just trigger with type if no event available
2609
+ this . $element . trigger ( type , args ) ;
2610
+ }
2611
+ }
2612
+ } ;
2613
+
2566
2614
// -------------------------- ignore & stamps -------------------------- //
2567
2615
2568
2616
@@ -3532,7 +3580,7 @@ return Item;
3532
3580
} ) ) ;
3533
3581
3534
3582
/*!
3535
- * Packery v1.4.1
3583
+ * Packery v1.4.2
3536
3584
* bin-packing layout library
3537
3585
*
3538
3586
* Licensed GPLv3 for open source use
@@ -3619,13 +3667,23 @@ Packery.prototype._create = function() {
3619
3667
} ;
3620
3668
3621
3669
this . handleUIDraggable = {
3622
- start : function handleUIDraggableStart ( event ) {
3670
+ start : function handleUIDraggableStart ( event , ui ) {
3671
+ // HTML5 may trigger dragstart, dismiss HTML5 dragging
3672
+ if ( ! ui ) {
3673
+ return ;
3674
+ }
3623
3675
_this . itemDragStart ( event . currentTarget ) ;
3624
3676
} ,
3625
3677
drag : function handleUIDraggableDrag ( event , ui ) {
3678
+ if ( ! ui ) {
3679
+ return ;
3680
+ }
3626
3681
_this . itemDragMove ( event . currentTarget , ui . position . left , ui . position . top ) ;
3627
3682
} ,
3628
- stop : function handleUIDraggableStop ( event ) {
3683
+ stop : function handleUIDraggableStop ( event , ui ) {
3684
+ if ( ! ui ) {
3685
+ return ;
3686
+ }
3629
3687
_this . itemDragEnd ( event . currentTarget ) ;
3630
3688
}
3631
3689
} ;
@@ -3851,7 +3909,7 @@ Packery.prototype._bindFitEvents = function( item ) {
3851
3909
if ( ticks != 2 ) {
3852
3910
return ;
3853
3911
}
3854
- _this . emitEvent ( 'fitComplete' , [ item ] ) ;
3912
+ _this . dispatchEvent ( 'fitComplete' , null , [ item ] ) ;
3855
3913
}
3856
3914
// when item is laid out
3857
3915
item . on ( 'layout' , function ( ) {
@@ -3996,7 +4054,7 @@ Packery.prototype._getDragEndLayoutComplete = function( elem, item ) {
3996
4054
3997
4055
// emit item drag event now that everything is done
3998
4056
if ( itemNeedsPositioning ) {
3999
- _this . emitEvent ( 'dragItemPositioned' , [ item ] ) ;
4057
+ _this . dispatchEvent ( 'dragItemPositioned' , null , [ item ] ) ;
4000
4058
}
4001
4059
// listen once
4002
4060
return true ;
0 commit comments