vendor/assets/javascripts/packery.pkgd.js in packery-rails-1.4.1 vs vendor/assets/javascripts/packery.pkgd.js in packery-rails-1.4.2

- old
+ new

@@ -1,7 +1,7 @@ /*! - * Packery PACKAGED v1.4.1 + * Packery PACKAGED v1.4.2 * bin-packing layout library * * Licensed GPLv3 for open source use * or Flickity Commercial License for commercial use * @@ -1720,18 +1720,23 @@ Item.prototype.getPosition = function() { var style = getStyle( this.element ); var layoutOptions = this.layout.options; var isOriginLeft = layoutOptions.isOriginLeft; var isOriginTop = layoutOptions.isOriginTop; - var x = parseInt( style[ isOriginLeft ? 'left' : 'right' ], 10 ); - var y = parseInt( style[ isOriginTop ? 'top' : 'bottom' ], 10 ); + var xValue = style[ isOriginLeft ? 'left' : 'right' ]; + var yValue = style[ isOriginTop ? 'top' : 'bottom' ]; + var x = parseInt( xValue, 10 ); + var y = parseInt( yValue, 10 ); + // convert percent to pixels + var layoutSize = this.layout.size; + x = xValue.indexOf('%') != -1 ? ( x / 100 ) * layoutSize.width : x; + y = yValue.indexOf('%') != -1 ? ( y / 100 ) * layoutSize.height : y; // clean up 'auto' or other non-integer values x = isNaN( x ) ? 0 : x; y = isNaN( y ) ? 0 : y; // remove padding from measurement - var layoutSize = this.layout.size; x -= isOriginLeft ? layoutSize.paddingLeft : layoutSize.paddingRight; y -= isOriginTop ? layoutSize.paddingTop : layoutSize.paddingBottom; this.position.x = x; this.position.y = y; @@ -1747,43 +1752,41 @@ var xPadding = layoutOptions.isOriginLeft ? 'paddingLeft' : 'paddingRight'; var xProperty = layoutOptions.isOriginLeft ? 'left' : 'right'; var xResetProperty = layoutOptions.isOriginLeft ? 'right' : 'left'; var x = this.position.x + layoutSize[ xPadding ]; - // set in percentage - x = layoutOptions.percentPosition && !layoutOptions.isHorizontal ? - ( ( x / layoutSize.width ) * 100 ) + '%' : x + 'px'; - style[ xProperty ] = x; + // set in percentage or pixels + style[ xProperty ] = this.getXValue( x ); // reset other property style[ xResetProperty ] = ''; // y var yPadding = layoutOptions.isOriginTop ? 'paddingTop' : 'paddingBottom'; var yProperty = layoutOptions.isOriginTop ? 'top' : 'bottom'; var yResetProperty = layoutOptions.isOriginTop ? 'bottom' : 'top'; var y = this.position.y + layoutSize[ yPadding ]; - // set in percentage - y = layoutOptions.percentPosition && layoutOptions.isHorizontal ? - ( ( y / layoutSize.height ) * 100 ) + '%' : y + 'px'; - style[ yProperty ] = y; + // set in percentage or pixels + style[ yProperty ] = this.getYValue( y ); // reset other property style[ yResetProperty ] = ''; this.css( style ); this.emitEvent( 'layout', [ this ] ); }; +Item.prototype.getXValue = function( x ) { + var layoutOptions = this.layout.options; + return layoutOptions.percentPosition && !layoutOptions.isHorizontal ? + ( ( x / this.layout.size.width ) * 100 ) + '%' : x + 'px'; +}; -// transform translate function -var translate = is3d ? - function( x, y ) { - return 'translate3d(' + x + 'px, ' + y + 'px, 0)'; - } : - function( x, y ) { - return 'translate(' + x + 'px, ' + y + 'px)'; - }; +Item.prototype.getYValue = function( y ) { + var layoutOptions = this.layout.options; + return layoutOptions.percentPosition && layoutOptions.isHorizontal ? + ( ( y / this.layout.size.height ) * 100 ) + '%' : y + 'px'; +}; Item.prototype._transitionTo = function( x, y ) { this.getPosition(); // get current x & y from top/left @@ -1804,25 +1807,36 @@ } var transX = x - curX; var transY = y - curY; var transitionStyle = {}; - // flip cooridinates if origin on right or bottom - var layoutOptions = this.layout.options; - transX = layoutOptions.isOriginLeft ? transX : -transX; - transY = layoutOptions.isOriginTop ? transY : -transY; - transitionStyle.transform = translate( transX, transY ); + transitionStyle.transform = this.getTranslate( transX, transY ); this.transition({ to: transitionStyle, onTransitionEnd: { transform: this.layoutPosition }, isCleaning: true }); }; +Item.prototype.getTranslate = function( x, y ) { + // flip cooridinates if origin on right or bottom + var layoutOptions = this.layout.options; + x = layoutOptions.isOriginLeft ? x : -x; + y = layoutOptions.isOriginTop ? y : -y; + x = this.getXValue( x ); + y = this.getYValue( y ); + + if ( is3d ) { + return 'translate3d(' + x + ', ' + y + ', 0)'; + } + + return 'translate(' + x + ', ' + y + ')'; +}; + // non transition + transform support Item.prototype.goTo = function( x, y ) { this.setPosition( x, y ); this.layoutPosition(); }; @@ -1898,32 +1912,40 @@ this.isTransitioning = true; }; -var itemTransitionProperties = transformProperty && ( utils.toDashed( transformProperty ) + - ',opacity' ); +// dash before all cap letters, including first for +// WebkitTransform => -webkit-transform +function toDashedAll( str ) { + return str.replace( /([A-Z])/g, function( $1 ) { + return '-' + $1.toLowerCase(); + }); +} +var transitionProps = 'opacity,' + + toDashedAll( vendorProperties.transform || 'transform' ); + Item.prototype.enableTransition = function(/* style */) { - // only enable if not already transitioning - // bug in IE10 were re-setting transition style will prevent - // transitionend event from triggering + // HACK changing transitionProperty during a transition + // will cause transition to jump if ( this.isTransitioning ) { return; } - // make transition: foo, bar, baz from style object - // TODO uncomment this bit when IE10 bug is resolved - // var transitionValue = []; + // make `transition: foo, bar, baz` from style object + // HACK un-comment this when enableTransition can work + // while a transition is happening + // var transitionValues = []; // for ( var prop in style ) { // // dash-ify camelCased properties like WebkitTransition - // transitionValue.push( toDash( prop ) ); + // prop = vendorProperties[ prop ] || prop; + // transitionValues.push( toDashedAll( prop ) ); // } // enable transition styles - // HACK always enable transform,opacity for IE10 this.css({ - transitionProperty: itemTransitionProperties, + transitionProperty: transitionProps, transitionDuration: this.layout.options.transitionDuration }); // listen for transition end event this.element.addEventListener( transitionEndEvent, this, false ); }; @@ -2122,11 +2144,11 @@ return Item; })); /*! - * Outlayer v1.4.0 + * Outlayer v1.4.1 * the brains and guts of a layout library * MIT license */ ( function( window, factory ) { @@ -2537,11 +2559,11 @@ * @param {Array} items - Outlayer.Items */ Outlayer.prototype._emitCompleteOnItems = function( eventName, items ) { var _this = this; function onComplete() { - _this.emitEvent( eventName + 'Complete', [ items ] ); + _this.dispatchEvent( eventName + 'Complete', null, [ items ] ); } var count = items.length; if ( !items || !count ) { onComplete(); @@ -2561,10 +2583,36 @@ var item = items[i]; item.once( eventName, tick ); } }; +/** + * emits events via eventEmitter and jQuery events + * @param {String} type - name of event + * @param {Event} event - original event + * @param {Array} args - extra arguments + */ +Outlayer.prototype.dispatchEvent = function( type, event, args ) { + // add original event to arguments + var emitArgs = event ? [ event ].concat( args ) : args; + this.emitEvent( type, emitArgs ); + + if ( jQuery ) { + // set this.$element + this.$element = this.$element || jQuery( this.element ); + if ( event ) { + // create jQuery event + var $event = jQuery.Event( event ); + $event.type = type; + this.$element.trigger( $event, args ); + } else { + // just trigger with type if no event available + this.$element.trigger( type, args ); + } + } +}; + // -------------------------- ignore & stamps -------------------------- // /** * keep item in collection, but do not lay it out @@ -3530,11 +3578,11 @@ return Item; })); /*! - * Packery v1.4.1 + * Packery v1.4.2 * bin-packing layout library * * Licensed GPLv3 for open source use * or Flickity Commercial License for commercial use * @@ -3617,17 +3665,27 @@ _this.itemDragEnd( this.element ); } }; this.handleUIDraggable = { - start: function handleUIDraggableStart( event ) { + start: function handleUIDraggableStart( event, ui ) { + // HTML5 may trigger dragstart, dismiss HTML5 dragging + if ( !ui ) { + return; + } _this.itemDragStart( event.currentTarget ); }, drag: function handleUIDraggableDrag( event, ui ) { + if ( !ui ) { + return; + } _this.itemDragMove( event.currentTarget, ui.position.left, ui.position.top ); }, - stop: function handleUIDraggableStop( event ) { + stop: function handleUIDraggableStop( event, ui ) { + if ( !ui ) { + return; + } _this.itemDragEnd( event.currentTarget ); } }; }; @@ -3849,11 +3907,11 @@ function tick() { ticks++; if ( ticks != 2 ) { return; } - _this.emitEvent( 'fitComplete', [ item ] ); + _this.dispatchEvent( 'fitComplete', null, [ item ] ); } // when item is laid out item.on( 'layout', function() { tick(); return true; @@ -3994,10 +4052,10 @@ // only sort when item moved _this.sortItemsByPosition(); // emit item drag event now that everything is done if ( itemNeedsPositioning ) { - _this.emitEvent( 'dragItemPositioned', [ item ] ); + _this.dispatchEvent( 'dragItemPositioned', null, [ item ] ); } // listen once return true; }; };