Skip to content

Commit

Permalink
Update Outlayer v1.4.1; Add jQuery events
Browse files Browse the repository at this point in the history
+ tick version 3.3.1
+ Safari layout and transition fixes; Fixes #698
+ add fluid sandbox
+ README cdnjs; link to raw github; complete Initialize
  • Loading branch information
desandro committed Jul 2, 2015
1 parent b9f4eb1 commit 1e9d697
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 60 deletions.
55 changes: 39 additions & 16 deletions README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,65 @@ _Cascading grid layout library_

Masonry works by placing elements in optimal position based on available vertical space, sort of like a mason fitting stones in a wall. You’ve probably seen it in use all over the Internet.

For complete docs and demos, see [masonry.desandro.com](http://masonry.desandro.com) or [masonryjs.com](http://masonryjs.com) if you're lazy.
See [masonry.desandro.com](http://masonry.desandro.com) for complete docs and demos.

## Install

A packaged source file includes everything you need to use Masonry.
### Download

+ [masonry.pkgd.min.js](dist/masonry.pkgd.min.js)
+ [masonry.pkgd.js](dist/masonry.pkgd.js)
+ [masonry.pkgd.js](https://github.com/desandro/masonry/raw/master/dist/masonry.pkgd.js) un-minified, or
+ [masonry.pkgd.min.js](https://github.com/desandro/masonry/raw/master/dist/masonry.pkgd.min.js) minified

Or, if you're cool with the command line...
### CDN

Install with [Bower](http://bower.io): `bower install masonry`
Link directly to [Masonry files on cdnjs](https://cdnjs.com/libraries/masonry).

``` html
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.1/masonry.pkgd.js"></script>
<!-- or -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/masonry/3.3.1/masonry.pkgd.min.js"></script>
```

### Package managers

Bower: `bower install masonry --save`

[npm](https://www.npmjs.com/package/masonry-layout): `npm install masonry-layout --save`

[Install with npm](https://www.npmjs.org/package/masonry-layout) `npm install masonry-layout`

## Initialize

### In JavaScript
With jQuery

``` js
$('.grid').masonry({
// options...
itemSelector: '.grid-item',
columnWidth: 200
});
```

With vanilla JavaScript

``` js
var container = document.querySelector('#container');
var msnry = new Masonry( container, {
// vanilla JS
var grid = document.querySelector('.grid');
var msnry = new Masonry( grid, {
// options...
itemSelector: '.item',
itemSelector: '.grid-item',
columnWidth: 200
});
```

### In HTML
With HTML

Add a class of `js-masonry` to your element. Options can be set in JSON in `data-masonry-options`.

``` html
<div class="js-masonry" data-masonry-options='{ "itemSelector": ".item", "columnWidth": 200 }'>
<div class="item"></div>
<div class="item"></div>
<div class="grid js-masonry"
data-masonry-options='{ "itemSelector": ".grid-item", "columnWidth": 200 }'>
<div class="grid-item"></div>
<div class="grid-item"></div>
...
</div>
```
Expand All @@ -50,4 +73,4 @@ Masonry is released under the [MIT license](http://desandro.mit-license.org). Ha

* * *

Copyright :copyright: 2015 David DeSandro
Copyright 2015 David DeSandro
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "masonry",
"version": "3.3.0",
"version": "3.3.1",
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

### v3.3.1

+ Updated Outlayer v1.4.1
+ Added jQuery events
+ Fixed Safari layout and transition bugs. Fixed [#698](https://github.com/desandro/masonry/issues/698)

## v3.3.0

+ Added `percentPosition` option. Fixed [#574](https://github.com/desandro/masonry/issues/574)
Expand Down
126 changes: 87 additions & 39 deletions dist/masonry.pkgd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry PACKAGED v3.3.0
* Masonry PACKAGED v3.3.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down Expand Up @@ -1633,14 +1633,19 @@ Item.prototype.getPosition = function() {
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;

Expand All @@ -1660,10 +1665,8 @@ Item.prototype.layoutPosition = function() {
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 ] = '';

Expand All @@ -1673,26 +1676,26 @@ Item.prototype.layoutPosition = function() {
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 ) {
Expand All @@ -1717,11 +1720,7 @@ Item.prototype._transitionTo = function( x, y ) {
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,
Expand All @@ -1732,6 +1731,21 @@ Item.prototype._transitionTo = function( x, y ) {
});
};

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 );
Expand Down Expand Up @@ -1811,28 +1825,36 @@ Item.prototype._transition = function( args ) {

};

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
Expand Down Expand Up @@ -2035,7 +2057,7 @@ return Item;
}));

/*!
* Outlayer v1.4.0
* Outlayer v1.4.1
* the brains and guts of a layout library
* MIT license
*/
Expand Down Expand Up @@ -2450,7 +2472,7 @@ Outlayer.prototype._setContainerMeasure = function( measure, isWidth ) {
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;
Expand All @@ -2474,6 +2496,32 @@ Outlayer.prototype._emitCompleteOnItems = function( eventName, items ) {
}
};

/**
* 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 -------------------------- //


Expand Down Expand Up @@ -2936,7 +2984,7 @@ return Outlayer;


/*!
* Masonry v3.3.0
* Masonry v3.3.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down
4 changes: 2 additions & 2 deletions dist/masonry.pkgd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion masonry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry v3.3.0
* Masonry v3.3.1
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "masonry-layout",
"version": "3.3.0",
"version": "3.3.1",
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
Expand Down
Loading

0 comments on commit 1e9d697

Please sign in to comment.