Skip to content

Commit

Permalink
πŸ›  add stagger option; πŸ‘· build v4.1.0
Browse files Browse the repository at this point in the history
+ ⬆️ Outlayer v2.1.0 for stagger option
+ πŸ“¦ ^ dependencies
+ πŸ“ README.mdown -> .md
+ πŸ›  Fix vendor CSS properties. Fixes #834
+ 🍹 Fix gulp version task
  • Loading branch information
desandro committed Apr 27, 2016
1 parent 641f7f0 commit af5f63c
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 47 deletions.
4 changes: 2 additions & 2 deletions README.mdown β†’ README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ See [masonry.desandro.com](http://masonry.desandro.com) for complete docs and de
Link directly to Masonry files on [npmcdn](https://npmcdn.com/).

``` html
<script src="https://npmcdn.com/masonry-layout@4.0/dist/masonry.pkgd.js"></script>
<script src="https://npmcdn.com/masonry-layout@4.1/dist/masonry.pkgd.js"></script>
<!-- or -->
<script src="https://npmcdn.com/masonry-layout@4.0/dist/masonry.pkgd.min.js"></script>
<script src="https://npmcdn.com/masonry-layout@4.1/dist/masonry.pkgd.min.js"></script>
```

### Package managers
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
"get-size": "~2.0.2",
"outlayer": "~2.0.0"
"get-size": "^2.0.2",
"outlayer": "^2.1.0"
},
"devDependencies": {
"jquery-bridget": "~2.0.0",
Expand Down
119 changes: 83 additions & 36 deletions dist/masonry.pkgd.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry PACKAGED v4.0.0
* Masonry PACKAGED v4.1.0
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down Expand Up @@ -152,7 +152,7 @@ return jQueryBridget;
}));

/**
* EvEmitter v1.0.1
* EvEmitter v1.0.2
* Lil' event emitter
* MIT License
*/
Expand Down Expand Up @@ -206,8 +206,8 @@ proto.once = function( eventName, listener ) {
// set once flag
// set onceEvents hash
var onceEvents = this._onceEvents = this._onceEvents || {};
// set onceListeners array
var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || [];
// set onceListeners object
var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
// set flag
onceListeners[ listener ] = true;

Expand Down Expand Up @@ -485,7 +485,7 @@ return getSize;
// universal module definition
if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'matches-selector/matches-selector',factory );
define( 'desandro-matches-selector/matches-selector',factory );
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS
module.exports = factory();
Expand Down Expand Up @@ -526,21 +526,20 @@ return getSize;
}));

/**
* Fizzy UI utils v2.0.0
* Fizzy UI utils v2.0.1
* MIT license
*/

/*jshint browser: true, undef: true, unused: true, strict: true */

( function( window, factory ) {
/*global define: false, module: false, require: false */
'use strict';
// universal module definition
/*jshint strict: false */ /*globals define, module, require */

if ( typeof define == 'function' && define.amd ) {
// AMD
define( 'fizzy-ui-utils/utils',[
'matches-selector/matches-selector'
'desandro-matches-selector/matches-selector'
], function( matchesSelector ) {
return factory( window, matchesSelector );
});
Expand Down Expand Up @@ -775,28 +774,24 @@ return utils;
'ev-emitter/ev-emitter',
'get-size/get-size'
],
function( EvEmitter, getSize ) {
return factory( window, EvEmitter, getSize );
}
factory
);
} else if ( typeof module == 'object' && module.exports ) {
// CommonJS - Browserify, Webpack
module.exports = factory(
window,
require('ev-emitter'),
require('get-size')
);
} else {
// browser global
window.Outlayer = {};
window.Outlayer.Item = factory(
window,
window.EvEmitter,
window.getSize
);
}

}( window, function factory( window, EvEmitter, getSize ) {
}( window, function factory( EvEmitter, getSize ) {
'use strict';

// ----- helpers ----- //
Expand Down Expand Up @@ -824,13 +819,14 @@ var transitionEndEvent = {
transition: 'transitionend'
}[ transitionProperty ];

// cache all vendor properties
var vendorProperties = [
transformProperty,
transitionProperty,
transitionProperty + 'Duration',
transitionProperty + 'Property'
];
// cache all vendor properties that could have vendor prefix
var vendorProperties = {
transform: transformProperty,
transition: transitionProperty,
transitionDuration: transitionProperty + 'Duration',
transitionProperty: transitionProperty + 'Property',
transitionDelay: transitionProperty + 'Delay'
};

// -------------------------- Item -------------------------- //

Expand Down Expand Up @@ -1044,7 +1040,7 @@ proto._nonTransition = function( args ) {
* @param {Boolean} isCleaning - removes transition styles after transition
* @param {Function} onTransitionEnd - callback
*/
proto._transition = function( args ) {
proto.transition = function( args ) {
// redirect to nonTransition if no transition duration
if ( !parseFloat( this.layout.options.transitionDuration ) ) {
this._nonTransition( args );
Expand Down Expand Up @@ -1090,8 +1086,7 @@ function toDashedAll( str ) {
});
}

var transitionProps = 'opacity,' +
toDashedAll( vendorProperties.transform || 'transform' );
var transitionProps = 'opacity,' + toDashedAll( transformProperty );

proto.enableTransition = function(/* style */) {
// HACK changing transitionProperty during a transition
Expand All @@ -1109,17 +1104,19 @@ proto.enableTransition = function(/* style */) {
// prop = vendorProperties[ prop ] || prop;
// transitionValues.push( toDashedAll( prop ) );
// }
// munge number to millisecond, to match stagger
var duration = this.layout.options.transitionDuration;
duration = typeof duration == 'number' ? duration + 'ms' : duration;
// enable transition styles
this.css({
transitionProperty: transitionProps,
transitionDuration: this.layout.options.transitionDuration
transitionDuration: duration,
transitionDelay: this.staggerDelay || 0
});
// listen for transition end event
this.element.addEventListener( transitionEndEvent, this, false );
};

proto.transition = Item.prototype[ transitionProperty ? '_transition' : '_nonTransition' ];

// ----- events ----- //

proto.onwebkitTransitionEnd = function( event ) {
Expand Down Expand Up @@ -1188,14 +1185,22 @@ proto._removeStyles = function( style ) {

var cleanTransitionStyle = {
transitionProperty: '',
transitionDuration: ''
transitionDuration: '',
transitionDelay: ''
};

proto.removeTransitionStyles = function() {
// remove transition
this.css( cleanTransitionStyle );
};

// ----- stagger ----- //

proto.stagger = function( delay ) {
delay = isNaN( delay ) ? 0 : delay;
this.staggerDelay = delay + 'ms';
};

// ----- show/hide/remove ----- //

// remove element from DOM
Expand Down Expand Up @@ -1311,7 +1316,7 @@ return Item;
}));

/*!
* Outlayer v2.0.0
* Outlayer v2.1.0
* the brains and guts of a layout library
* MIT license
*/
Expand Down Expand Up @@ -1660,23 +1665,36 @@ proto._getItemLayoutPosition = function( /* item */ ) {
* @param {Array} queue
*/
proto._processLayoutQueue = function( queue ) {
queue.forEach( function( obj ) {
this._positionItem( obj.item, obj.x, obj.y, obj.isInstant );
this.updateStagger();
queue.forEach( function( obj, i ) {
this._positionItem( obj.item, obj.x, obj.y, obj.isInstant, i );
}, this );
};

// set stagger from option in milliseconds number
proto.updateStagger = function() {
var stagger = this.options.stagger;
if ( stagger === null || stagger === undefined ) {
this.stagger = 0;
return;
}
this.stagger = getMilliseconds( stagger );
return this.stagger;
};

/**
* Sets position of item in DOM
* @param {Outlayer.Item} item
* @param {Number} x - horizontal position
* @param {Number} y - vertical position
* @param {Boolean} isInstant - disables transitions
*/
proto._positionItem = function( item, x, y, isInstant ) {
proto._positionItem = function( item, x, y, isInstant, i ) {
if ( isInstant ) {
// if not transition, just set CSS
item.goTo( x, y );
} else {
item.stagger( i * this.stagger );
item.moveTo( x, y );
}
};
Expand Down Expand Up @@ -2020,7 +2038,9 @@ proto.reveal = function( items ) {
if ( !items || !items.length ) {
return;
}
items.forEach( function( item ) {
var stagger = this.updateStagger();
items.forEach( function( item, i ) {
item.stagger( i * stagger );
item.reveal();
});
};
Expand All @@ -2034,7 +2054,9 @@ proto.hide = function( items ) {
if ( !items || !items.length ) {
return;
}
items.forEach( function( item ) {
var stagger = this.updateStagger();
items.forEach( function( item, i ) {
item.stagger( i * stagger );
item.hide();
});
};
Expand Down Expand Up @@ -2199,6 +2221,31 @@ function subclass( Parent ) {
return SubClass;
}

// ----- helpers ----- //

// how many milliseconds are in each unit
var msUnits = {
ms: 1,
s: 1000
};

// munge time-like parameter into millisecond number
// '0.4s' -> 40
function getMilliseconds( time ) {
if ( typeof time == 'number' ) {
return time;
}
var matches = time.match( /(^\d*\.?\d*)(\w*)/ );
var num = matches && matches[1];
var unit = matches && matches[2];
if ( !num.length ) {
return 0;
}
num = parseFloat( num );
var mult = msUnits[ unit ] || 1;
return num * mult;
}

// ----- fin ----- //

// back in global
Expand All @@ -2209,7 +2256,7 @@ return Outlayer;
}));

/*!
* Masonry v4.0.0
* Masonry v4.1.0
* 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.

4 changes: 3 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ gulp.task( 'uglify', [ 'requirejs' ], function() {
// set version in source files

var minimist = require('minimist');
var gutil = require('gulp-util');
var chalk = require('chalk');

// use gulp version -t 1.2.3
gulp.task( 'version', function() {
Expand All @@ -120,7 +122,7 @@ gulp.task( 'version', function() {
.pipe( gulp.dest('.') );
// replace CDN links in README
var minorVersion = version.match( /^\d\.\d+/ )[0];
gulp.src('README.mdown')
gulp.src('README.md')
.pipe( replace( /masonry\-layout@\d\.\d+/g, 'masonry-layout@' + minorVersion ))
.pipe( gulp.dest('.') );
});
Expand Down
2 changes: 1 addition & 1 deletion masonry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* Masonry v4.0.0
* Masonry v4.1.0
* Cascading grid layout library
* http://masonry.desandro.com
* MIT License
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "masonry-layout",
"version": "4.0.0",
"version": "4.1.0",
"description": "Cascading grid layout library",
"main": "masonry.js",
"dependencies": {
"get-size": "~2.0.2",
"outlayer": "~2.0.0"
"get-size": "^2.0.2",
"outlayer": "^2.1.0"
},
"devDependencies": {
"chalk": "^1.1.1",
Expand Down

0 comments on commit af5f63c

Please sign in to comment.