Added images loaded demo, alias for columnWidth in shuffle options as `sizer`

Also added an image demo without images loaded to see the difference.
Converted bootstrap breakpoints to ems.
More work on the nav.
Optionally include prism per post now
pull/56/head
Glen Cheney 11 years ago
parent 17644ce7f0
commit 2b99fb1343

@ -1,7 +1,23 @@
<nav class="site-nav collapsed" id="nav" role="primary">
<div class="js-tray site-nav__tray">
<div class="container-fluid">
<div class="container-fluid site-nav__tray-inner">
<h3 class="site-nav__title">Shuffle.js</h3>
<div class="row-fluid">
<div class="">
<a href="/">Home</a>
</div>
<div class="">
<a href="https://github.com/Vestride/Shuffle">GitHub Repo</a>
</div>
<div class="">
<a href="https://twitter.com/Vestride">@Vestride</a>
</div>
</div>
<h3 class="site-nav__title">Demos</h3>
<div class="row-fluid">
{% for post in site.demos %}
<div class="span3 figure-wrap">
@ -18,6 +34,7 @@
</div>
</div>
</div>
<div class="site-nav__band">
<div class="container-fluid">
<button class="js-nav-toggle pull-right" data-close-label="Close Nav">Open Nav</button>

@ -8,14 +8,16 @@
<!-- Shuffle! -->
<script src="{{ site.url }}/js/jquery.shuffle.js"></script>
{% if page.prism %}
<!-- Syntax highlighting via Prism -->
<script src="{{ site.url }}/js/prism.js"></script>
{% endif %}
<!-- Make the nav work -->
<script src="{{ site.url }}/js/page.js"></script>
{% if page.extraJS && page.extraJS.length %}
{% for src in page.extraJS %}
<script src="{{ site.url }}/js/demos/{{ src }}"></script>
<script src="{{ site.url }}/js/{{ src }}"></script>
{% endfor %}
{% endif %}

@ -2,7 +2,7 @@
layout: default
title: Basic Shuffle Demo
bodyClass: basic
extraJS: [ "homepage.js" ]
extraJS: [ "demos/homepage.js" ]
---
<div class="container-fluid">
<div class="row-fluid">

@ -2,7 +2,7 @@
layout: default
title: Shuffle Adaptive Demo
bodyClass: null
extraJS: [ "gallery.js" ]
extraJS: [ "demos/gallery.js" ]
extraCSS: [ "/css/gallery.css" ]
---

@ -1,9 +1,76 @@
---
layout: default
title: Shuffle Responsive Demo
bodyClass: null
extraJS: []
title: Using images with imagesloaded.js
extraJS: [ "imagesloaded.pkgd.js", "demos/images.js"]
prism: true
---
<ul>
<li>Will be <strong><em>fully responsive</em></strong></li>
</ul>
<div class="container-fluid">
<h2>Images!</h2>
<p>You can encounter problems when shuffle item dimensions depend on images. <a href="{% post_url demos/2013-06-29-image-problems %}">Like this demo</a>. There are three good solutions to this.</p>
<ol>
<li>Set an explicit height on <code>.shuffle-item</code>s like the <a href="{% post_url demos/2013-05-01-basic %}">basic demo</a>.</li>
<li>Similar to number 1, make the height of the image container a percentage of the width. This can be seen in the nav above with the <code>div.keep-ratio</code>. Note: if you want to support IE, you'll need another element inside that <code>div.keep-ratio</code> which is positioned absolute with top/right/bottom/left all zero.</li>
<li>Get notified when images load (this page). In this case, I'm using <a href="http://desandro.github.io/imagesloaded/">Desandro's images loaded plugin</a></li>
</ol>
</div>
<style>
.shuffle-wrap {
position: relative;
}
.shuffle--images {
position: relative;
visibility: hidden;
}
.shuffle--images.images-loaded {
visibility: visible;
}
.shuffle--images .img-item {
margin-top: 10px;
margin-left: 0;
}
.shuffle--images .img-item img {
width: 100%;
}
.loader {
position: absolute;
top: 50%;
left: 50%;
margin-top: -16px;
margin-left: -16px;
}
</style>
<div class="container-fluid shuffle-wrap">
<img id="loader" class="loader" alt="Loading..." src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAzMDAgMzAwIgogICAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4xIj4KICA8cGF0aCBkPSJNIDE1MCwwCiAgICAgICAgICAgYSAxNTAsMTUwIDAgMCwxIDEwNi4wNjYsMjU2LjA2NgogICAgICAgICAgIGwgLTM1LjM1NSwtMzUuMzU1CiAgICAgICAgICAgYSAtMTAwLC0xMDAgMCAwLDAgLTcwLjcxMSwtMTcwLjcxMSB6IgogICAgICAgIGZpbGw9IiMzZDdmZTYiPgogICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiBhdHRyaWJ1dGVUeXBlPSJYTUwiCiAgICAgICAgICAgdHlwZT0icm90YXRlIiBmcm9tPSIwIDE1MCAxNTAiIHRvPSIzNjAgMTUwIDE1MCIKICAgICAgICAgICBiZWdpbj0iMHMiIGR1cj0iMXMiIGZpbGw9ImZyZWV6ZSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIC8+CiAgPC9wYXRoPgo8L3N2Zz4K" />
<div class="shuffle--images row-fluid">
{% for item in site.items %}
<figure class="js-item img-item span3 m-span3">
<img src="{{ site.url }}/img/{{ item.img }}" alt="{{item.title}}"/>
<figcaption>{{ item.groups }}</figcaption>
</figure>
{% endfor %}
<div class="span3 m-span3" id="js-sizer"></div>
</div>
</div>
<section>
<div class="container">
<h2>Another section</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</section>

@ -2,7 +2,7 @@
layout: default
title: Shuffle Adding and Removing Elements Demo
bodyClass: null
extraJS: [ "adding-removing.js" ]
extraJS: [ "demos/adding-removing.js" ]
---
<style>

@ -0,0 +1,52 @@
---
layout: default
title: Image based items
extraJS: [ "demos/images-broken.js"]
---
<div class="container-fluid">
<h2>This probably looks broken.</h2>
<p>Demo in which shuffle item dimensions are based on images without a fix. <a href="{% post_url demos/2013-05-03-images %}">See here</a> for a solution.</p>
<p>Resize the window and it'll fix itself.</p>
</div>
<style>
.shuffle--images {
position: relative;
}
.shuffle--images .img-item {
margin-top: 10px;
margin-left: 0;
}
.shuffle--images .img-item img {
width: 100%;
}
</style>
<div class="container-fluid">
<div class="shuffle--images row-fluid">
{% for item in site.items %}
<figure class="js-item img-item span3 m-span3">
<img src="{{ site.url }}/img/{{ item.img }}" alt="{{item.title}}"/>
<figcaption>{{ item.groups }}</figcaption>
</figure>
{% endfor %}
<div class="span3 m-span3" id="js-sizer"></div>
</div>
</div>
<section>
<div class="container">
<h2>Another section</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
</section>

@ -311,11 +311,8 @@
.container-fluid:after {
clear: both;
}
@media (max-width: 767px) {
body {
padding-left: 20px;
padding-right: 20px;
}
@media (max-width: 47.9375em) {
.navbar-fixed-top,
.navbar-fixed-bottom,
.navbar-static-top {
@ -408,7 +405,7 @@
top: 20px;
}
}
@media (max-width: 480px) {
@media (max-width: 30em) {
.nav-collapse {
-webkit-transform: translate3d(0, 0, 0);
}
@ -459,7 +456,7 @@
position: static;
}
}
@media (min-width: 768px) and (max-width: 979px) {
@media (min-width: 48em) and (max-width: 61.1875em) {
.row {
margin-left: -20px;
*zoom: 1;
@ -799,7 +796,7 @@
width: 28px;
}
}
@media (min-width: 1200px) {
@media (min-width: 75em) {
.row {
margin-left: -30px;
*zoom: 1;

@ -1,5 +1,10 @@
@import "variables";
* {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
pre {
max-height: 30em;
}
@ -30,6 +35,14 @@ ul ul {
.site-nav {
.site-nav__title {
color: white;
&:first-child {
margin-top: 0;
}
}
.site-nav__tray {
transition: .2s;
overflow: hidden;
@ -37,6 +50,10 @@ ul ul {
background-color: $wetAsphalt;
}
.site-nav__tray-inner {
padding: 30px 0;
}
&.collapsed .site-nav__tray {
height: 0;
}
@ -45,6 +62,14 @@ ul ul {
margin-left: 0;
}
.figure-wrap > a {
display: block;
}
.figure-wrap figcaption {
margin-top: .5em;
}
}
nav > a {

@ -17,6 +17,14 @@
height: 40px;
padding: 0;
}
label {
cursor: pointer;
}
}
.shape-up {
position: relative;
}
.shape {

@ -19,6 +19,25 @@ $itemHeight: 220px;
height: ($itemHeight * 2) + $pictureGutter; /* 2x the height + 1 gutter */
}
// Ehh, i should really use something other than span6 to target this...
&.span6:not(.picture-item--h2) {
.picture-item__details {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: #333;
background-color: rgba(black, .6);
color: white;
}
.picture-item__description {
display: none;
}
}
img {
display: block;
width: 100%;

@ -11,6 +11,13 @@
height: 40px;
padding: 0;
}
.filter-group label {
cursor: pointer;
}
.shape-up {
position: relative;
}
.shape {
margin-left: 0;

@ -15,6 +15,18 @@
height: 464px;
/* 2x the height + 1 gutter */
}
.picture-item.span6:not(.picture-item--h2) .picture-item__details {
position: absolute;
bottom: 0;
left: 0;
width: 100%;
background-color: #333;
background-color: rgba(0, 0, 0, 0.6);
color: white;
}
.picture-item.span6:not(.picture-item--h2) .picture-item__description {
display: none;
}
.picture-item img {
display: block;
width: 100%;

@ -823,12 +823,7 @@ h4 {
clear: both;
}
@media (max-width: 767px) {
body {
padding-left: 20px;
padding-right: 20px;
}
@media (max-width: 47.9375em) {
.navbar-fixed-top,
.navbar-fixed-bottom,
.navbar-static-top {
@ -937,7 +932,7 @@ h4 {
top: 20px;
}
}
@media (max-width: 480px) {
@media (max-width: 30em) {
.nav-collapse {
-webkit-transform: translate3d(0, 0, 0);
}
@ -999,7 +994,7 @@ h4 {
position: static;
}
}
@media (min-width: 768px) and (max-width: 979px) {
@media (min-width: 48em) and (max-width: 61.1875em) {
.row {
margin-left: -20px;
*zoom: 1;
@ -1423,7 +1418,7 @@ h4 {
width: 28px;
}
}
@media (min-width: 1200px) {
@media (min-width: 75em) {
.row {
margin-left: -30px;
*zoom: 1;
@ -1886,6 +1881,11 @@ h4 {
width: 100%;
}
}
* {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
pre {
max-height: 30em;
}
@ -1913,18 +1913,33 @@ ul ul {
list-style-type: circle;
}
.site-nav .site-nav__title {
color: white;
}
.site-nav .site-nav__title:first-child {
margin-top: 0;
}
.site-nav .site-nav__tray {
transition: .2s;
overflow: hidden;
height: 300px;
background-color: #34495e;
}
.site-nav .site-nav__tray-inner {
padding: 30px 0;
}
.site-nav.collapsed .site-nav__tray {
height: 0;
}
.site-nav .figure-wrap:nth-child(4n + 1) {
margin-left: 0;
}
.site-nav .figure-wrap > a {
display: block;
}
.site-nav .figure-wrap figcaption {
margin-top: .5em;
}
nav > a {
display: block;

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 201 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

@ -2,8 +2,9 @@
layout: default
title: jQuery Shuffle Plugin
bodyClass: home
extraJS: [ "homepage.js" ]
extraJS: [ "demos/homepage.js" ]
includeHeader: true
prism: true
---
<section id="downloads">
<div class="container-fluid">

@ -0,0 +1,22 @@
var ImageDemo = (function( $ ) {
var $shuffle = $('.shuffle--images'),
sizer = document.getElementById('js-sizer'),
init = function() {
$shuffle.shuffle({
sizer: sizer,
itemSelector: '.js-item'
});
};
return {
init: init
};
}( jQuery ));
$(document).ready(function() {
ImageDemo.init();
});

@ -0,0 +1,54 @@
// For this demo, shuffle won't be initialized until
// all the images have finished loading.
// Another approach would be to initialize shuffle on document
// ready and as imagesLoaded reports back progress, call shuffle.layout()
// imagesLoade: https://github.com/desandro/imagesloaded
var ImageDemo = (function( $, imagesLoaded ) {
var $shuffle = $('.shuffle--images'),
$imgs = $shuffle.find('img'),
$loader = $('#loader'),
sizer = document.getElementById('js-sizer'),
imgLoad,
init = function() {
// Create a new imagesLoaded instance
imgLoad = new imagesLoaded( $imgs.get() );
// Listen for when all images are done
// will be executed even if some images fail
imgLoad.on( 'always', onAllImagesFinished );
},
onAllImagesFinished = function( instance ) {
if ( window.console && window.console.log ) {
console.log( instance );
}
// Hide loader
$loader.addClass('hidden');
// Adds visibility: visible;
$shuffle.addClass('images-loaded');
// Initialize shuffle
$shuffle.shuffle({
sizer: sizer,
itemSelector: '.js-item'
});
};
return {
init: init
};
}( jQuery, window.imagesLoaded ));
$(document).ready(function() {
ImageDemo.init();
});

@ -0,0 +1,744 @@
/*!
* imagesLoaded PACKAGED v3.0.2
* JavaScript is all like "You images are done yet or what?"
*/
/*!
* EventEmitter v4.1.0 - git.io/ee
* Oliver Caldwell
* MIT license
* @preserve
*/
(function (exports) {
// Place the script in strict mode
'use strict';
/**
* Class for managing events.
* Can be extended to provide event functionality in other classes.
*
* @class Manages event registering and emitting.
*/
function EventEmitter() {}
// Shortcuts to improve speed and size
// Easy access to the prototype
var proto = EventEmitter.prototype,
nativeIndexOf = Array.prototype.indexOf ? true : false;
/**
* Finds the index of the listener for the event in it's storage array.
*
* @param {Function} listener Method to look for.
* @param {Function[]} listeners Array of listeners to search through.
* @return {Number} Index of the specified listener, -1 if not found
* @api private
*/
function indexOfListener(listener, listeners) {
// Return the index via the native method if possible
if (nativeIndexOf) {
return listeners.indexOf(listener);
}
// There is no native method
// Use a manual loop to find the index
var i = listeners.length;
while (i--) {
// If the listener matches, return it's index
if (listeners[i] === listener) {
return i;
}
}
// Default to returning -1
return -1;
}
/**
* Fetches the events object and creates one if required.
*
* @return {Object} The events storage object.
* @api private
*/
proto._getEvents = function () {
return this._events || (this._events = {});
};
/**
* Returns the listener array for the specified event.
* Will initialise the event object and listener arrays if required.
* Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
* Each property in the object response is an array of listener functions.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Function[]|Object} All listener functions for the event.
*/
proto.getListeners = function (evt) {
// Create a shortcut to the storage object
// Initialise it if it does not exists yet
var events = this._getEvents(),
response,
key;
// Return a concatenated array of all matching events if
// the selector is a regular expression.
if (typeof evt === 'object') {
response = {};
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
response[key] = events[key];
}
}
}
else {
response = events[evt] || (events[evt] = []);
}
return response;
};
/**
* Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
*
* @param {String|RegExp} evt Name of the event to return the listeners from.
* @return {Object} All listener functions for an event in an object.
*/
proto.getListenersAsObject = function (evt) {
var listeners = this.getListeners(evt),
response;
if (listeners instanceof Array) {
response = {};
response[evt] = listeners;
}
return response || listeners;
};
/**
* Adds a listener function to the specified event.
* The listener will not be added if it is a duplicate.
* If the listener returns true then it will be removed after it is called.
* If you pass a regular expression as the event name then the listener will be added to all events that match it.
*
* @param {String|RegExp} evt Name of the event to attach the listener to.
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListener = function (evt, listener) {
var listeners = this.getListenersAsObject(evt),
key;
for (key in listeners) {
if (listeners.hasOwnProperty(key) &&
indexOfListener(listener, listeners[key]) === -1) {
listeners[key].push(listener);
}
}
// Return the instance of EventEmitter to allow chaining
return this;
};
/**
* Alias of addListener
*/
proto.on = proto.addListener;
/**
* Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
* You need to tell it what event names should be matched by a regex.
*
* @param {String} evt Name of the event to create.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvent = function (evt) {
this.getListeners(evt);
return this;
};
/**
* Uses defineEvent to define multiple events.
*
* @param {String[]} evts An array of event names to define.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.defineEvents = function (evts)
{
for (var i = 0; i < evts.length; i += 1) {
this.defineEvent(evts[i]);
}
return this;
};
/**
* Removes a listener function from the specified event.
* When passed a regular expression as the event name, it will remove the listener from all events that match it.
*
* @param {String|RegExp} evt Name of the event to remove the listener from.
* @param {Function} listener Method to remove from the event.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListener = function (evt, listener) {
var listeners = this.getListenersAsObject(evt),
index,
key;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
index = indexOfListener(listener, listeners[key]);
if (index !== -1) {
listeners[key].splice(index, 1);
}
}
}
// Return the instance of EventEmitter to allow chaining
return this;
};
/**
* Alias of removeListener
*/
proto.off = proto.removeListener;
/**
* Adds listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
* You can also pass it a regular expression to add the array of listeners to all events that match it.
* Yeah, this function does quite a bit. That's probably a bad thing.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.addListeners = function (evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(false, evt, listeners);
};
/**
* Removes listeners in bulk using the manipulateListeners method.
* If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be removed.
* You can also pass it a regular expression to remove the listeners from all events that match it.
*
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeListeners = function (evt, listeners) {
// Pass through to manipulateListeners
return this.manipulateListeners(true, evt, listeners);
};
/**
* Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
* The first argument will determine if the listeners are removed (true) or added (false).
* If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
* You can also pass it an event name and an array of listeners to be added/removed.
* You can also pass it a regular expression to manipulate the listeners of all events that match it.
*
* @param {Boolean} remove True if you want to remove listeners, false if you want to add.
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
* @param {Function[]} [listeners] An optional array of listener functions to add/remove.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.manipulateListeners = function (remove, evt, listeners) {
// Initialise any required variables
var i,
value,
single = remove ? this.removeListener : this.addListener,
multiple = remove ? this.removeListeners : this.addListeners;
// If evt is an object then pass each of it's properties to this method
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
for (i in evt) {
if (evt.hasOwnProperty(i) && (value = evt[i])) {
// Pass the single listener straight through to the singular method
if (typeof value === 'function') {
single.call(this, i, value);
}
else {
// Otherwise pass back to the multiple function
multiple.call(this, i, value);
}
}
}
}
else {
// So evt must be a string
// And listeners must be an array of listeners
// Loop over it and pass each one to the multiple method
i = listeners.length;
while (i--) {
single.call(this, evt, listeners[i]);
}
}
// Return the instance of EventEmitter to allow chaining
return this;
};
/**
* Removes all listeners from a specified event.
* If you do not specify an event then all listeners will be removed.
* That means every event will be emptied.
* You can also pass a regex to remove all events that match it.
*
* @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.removeEvent = function (evt) {
var type = typeof evt,
events = this._getEvents(),
key;
// Remove different things depending on the state of evt
if (type === 'string') {
// Remove all listeners for the specified event
delete events[evt];
}
else if (type === 'object') {
// Remove all events matching the regex.
for (key in events) {
if (events.hasOwnProperty(key) && evt.test(key)) {
delete events[key];
}
}
}
else {
// Remove all listeners in all events
delete this._events;
}
// Return the instance of EventEmitter to allow chaining
return this;
};
/**
* Emits an event of your choice.
* When emitted, every listener attached to that event will be executed.
* If you pass the optional argument array then those arguments will be passed to every listener upon execution.
* Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
* So they will not arrive within the array on the other side, they will be separate.
* You can also pass a regular expression to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {Array} [args] Optional array of arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emitEvent = function (evt, args) {
var listeners = this.getListenersAsObject(evt),
i,
key,
response;
for (key in listeners) {
if (listeners.hasOwnProperty(key)) {
i = listeners[key].length;
while (i--) {
// If the listener returns true then it shall be removed from the event
// The function is executed either with a basic call or an apply if there is an args array
response = args ? listeners[key][i].apply(null, args) : listeners[key][i]();
if (response === true) {
this.removeListener(evt, listeners[key][i]);
}
}
}
}
// Return the instance of EventEmitter to allow chaining
return this;
};
/**
* Alias of emitEvent
*/
proto.trigger = proto.emitEvent;
/**
* Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
* As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
*
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
* @param {...*} Optional additional arguments to be passed to each listener.
* @return {Object} Current instance of EventEmitter for chaining.
*/
proto.emit = function (evt) {
var args = Array.prototype.slice.call(arguments, 1);
return this.emitEvent(evt, args);
};
// Expose the class either via AMD or the global object
if (typeof define === 'function' && define.amd) {
define(function () {
return EventEmitter;
});
}
else {
exports.EventEmitter = EventEmitter;
}
}(this));
/*!
* eventie v1.0.3
* event binding helper
* eventie.bind( elem, 'click', myFn )
* eventie.unbind( elem, 'click', myFn )
*/
/*jshint browser: true, undef: true, unused: true */
/*global define: false */
( function( window ) {
'use strict';
var docElem = document.documentElement;
var bind = function() {};
if ( docElem.addEventListener ) {
bind = function( obj, type, fn ) {
obj.addEventListener( type, fn, false );
};
} else if ( docElem.attachEvent ) {
bind = function( obj, type, fn ) {
obj[ type + fn ] = fn.handleEvent ?
function() {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement;
fn.handleEvent.call( fn, event );
} :
function() {
var event = window.event;
// add event.target
event.target = event.target || event.srcElement;
fn.call( obj, event );
};
obj.attachEvent( "on" + type, obj[ type + fn ] );
};
}
var unbind = function() {};
if ( docElem.removeEventListener ) {
unbind = function( obj, type, fn ) {
obj.removeEventListener( type, fn, false );
};
} else if ( docElem.detachEvent ) {
unbind = function( obj, type, fn ) {
obj.detachEvent( "on" + type, obj[ type + fn ] );
try {
delete obj[ type + fn ];
} catch ( err ) {
// can't delete window object properties
obj[ type + fn ] = undefined;
}
};
}
var eventie = {
bind: bind,
unbind: unbind
};
// transport
if ( typeof define === 'function' && define.amd ) {
// AMD
define( eventie );
} else {
// browser global
window.eventie = eventie;
}
})( this );
/*!
* imagesLoaded v3.0.2
* JavaScript is all like "You images are done yet or what?"
*/
( function( window ) {
'use strict';
var $ = window.jQuery;
var console = window.console;
var hasConsole = typeof console !== 'undefined';
// -------------------------- helpers -------------------------- //
// extend objects
function extend( a, b ) {
for ( var prop in b ) {
a[ prop ] = b[ prop ];
}
return a;
}
var objToString = Object.prototype.toString;
function isArray( obj ) {
return objToString.call( obj ) === '[object Array]';
}
// turn element or nodeList into an array
function makeArray( obj ) {
var ary = [];
if ( isArray( obj ) ) {
// use object if already an array
ary = obj;
} else if ( typeof obj.length === 'number' ) {
// convert nodeList to array
for ( var i=0, len = obj.length; i < len; i++ ) {
ary.push( obj[i] );
}
} else {
// array of single index
ary.push( obj );
}
return ary;
}
// -------------------------- -------------------------- //
function defineImagesLoaded( EventEmitter, eventie ) {
/**
* @param {Array, Element, NodeList, String} elem
* @param {Object or Function} options - if function, use as callback
* @param {Function} onAlways - callback function
*/
function ImagesLoaded( elem, options, onAlways ) {
// coerce ImagesLoaded() without new, to be new ImagesLoaded()
if ( !( this instanceof ImagesLoaded ) ) {
return new ImagesLoaded( elem, options );
}
// use elem as selector string
if ( typeof elem === 'string' ) {
elem = document.querySelectorAll( elem );
}
this.elements = makeArray( elem );
this.options = extend( {}, this.options );
if ( typeof options === 'function' ) {
onAlways = options;
} else {
extend( this.options, options );
}
if ( onAlways ) {
this.on( 'always', onAlways );
}
this.getImages();
if ( $ ) {
// add jQuery Deferred object
this.jqDeferred = new $.Deferred();
}
// HACK check async to allow time to bind listeners
var _this = this;
setTimeout( function() {
_this.check();
});
}
ImagesLoaded.prototype = new EventEmitter();
ImagesLoaded.prototype.options = {};
ImagesLoaded.prototype.getImages = function() {
this.images = [];
// filter & find items if we have an item selector
for ( var i=0, len = this.elements.length; i < len; i++ ) {
var elem = this.elements[i];
// filter siblings
if ( elem.nodeName === 'IMG' ) {
this.addImage( elem );
}
// find children
var childElems = elem.querySelectorAll('img');
// concat childElems to filterFound array
for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
var img = childElems[j];
this.addImage( img );
}
}
};
/**
* @param {Image} img
*/
ImagesLoaded.prototype.addImage = function( img ) {
var loadingImage = new LoadingImage( img );
this.images.push( loadingImage );
};
ImagesLoaded.prototype.check = function() {
var _this = this;
var checkedCount = 0;
var length = this.images.length;
this.hasAnyBroken = false;
// complete if no images
if ( !length ) {
this.complete();
return;
}
function onConfirm( image, message ) {
if ( _this.options.debug && hasConsole ) {
console.log( 'confirm', image, message );
}
_this.progress( image );
checkedCount++;
if ( checkedCount === length ) {
_this.complete();
}
return true; // bind once
}
for ( var i=0; i < length; i++ ) {
var loadingImage = this.images[i];
loadingImage.on( 'confirm', onConfirm );
loadingImage.check();
}
};
ImagesLoaded.prototype.progress = function( image ) {
this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
this.emit( 'progress', this, image );
if ( this.jqDeferred ) {
this.jqDeferred.notify( this, image );
}
};
ImagesLoaded.prototype.complete = function() {
var eventName = this.hasAnyBroken ? 'fail' : 'done';
this.isComplete = true;
this.emit( eventName, this );
this.emit( 'always', this );
if ( this.jqDeferred ) {
var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve';
this.jqDeferred[ jqMethod ]( this );
}
};
// -------------------------- jquery -------------------------- //
if ( $ ) {
$.fn.imagesLoaded = function( options, callback ) {
var instance = new ImagesLoaded( this, options, callback );
return instance.jqDeferred.promise( $(this) );
};
}
// -------------------------- -------------------------- //
var cache = {};
function LoadingImage( img ) {
this.img = img;
}
LoadingImage.prototype = new EventEmitter();
LoadingImage.prototype.check = function() {
// first check cached any previous images that have same src
var cached = cache[ this.img.src ];
if ( cached ) {
this.useCached( cached );
return;
}
// add this to cache
cache[ this.img.src ] = this;
// If complete is true and browser supports natural sizes,
// try to check for image status manually.
if ( this.img.complete && this.img.naturalWidth !== undefined ) {
// report based on naturalWidth
this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
return;
}
// If none of the checks above matched, simulate loading on detached element.
var proxyImage = this.proxyImage = new Image();
eventie.bind( proxyImage, 'load', this );
eventie.bind( proxyImage, 'error', this );
proxyImage.src = this.img.src;
};
LoadingImage.prototype.useCached = function( cached ) {
if ( cached.isConfirmed ) {
this.confirm( cached.isLoaded, 'cached was confirmed' );
} else {
var _this = this;
cached.on( 'confirm', function( image ) {
_this.confirm( image.isLoaded, 'cache emitted confirmed' );
return true; // bind once
});
}
};
LoadingImage.prototype.confirm = function( isLoaded, message ) {
this.isConfirmed = true;
this.isLoaded = isLoaded;
this.emit( 'confirm', this, message );
};
// trigger specified handler for event type
LoadingImage.prototype.handleEvent = function( event ) {
var method = 'on' + event.type;
if ( this[ method ] ) {
this[ method ]( event );
}
};
LoadingImage.prototype.onload = function() {
this.confirm( true, 'onload' );
this.unbindProxyEvents();
};
LoadingImage.prototype.onerror = function() {
this.confirm( false, 'onerror' );
this.unbindProxyEvents();
};
LoadingImage.prototype.unbindProxyEvents = function() {
eventie.unbind( this.proxyImage, 'load', this );
eventie.unbind( this.proxyImage, 'error', this );
};
// ----- ----- //
return ImagesLoaded;
}
// -------------------------- transport -------------------------- //
if ( typeof define === 'function' && define.amd ) {
// AMD
define( [
'eventEmitter',
'eventie'
],
defineImagesLoaded );
} else {
// browser global
window.imagesLoaded = defineImagesLoaded(
window.EventEmitter,
window.eventie
);
}
})( window );

@ -224,6 +224,12 @@ Shuffle.prototype = {
// If the columnWidth property is a function, then the grid is fluid
self.isFluid = self.columnWidth && typeof self.columnWidth === 'function';
// Column width is the default setting and sizer is not (meaning passed in)
// Assume they meant column width to be the sizer
if ( self.columnWidth === 0 && self.sizer !== null ) {
self.columnWidth = self.sizer;
}
// If column width is a string, treat is as a selector and search for the
// sizer element within the outermost container
if ( typeof self.columnWidth === 'string' ) {
@ -1024,6 +1030,7 @@ Shuffle.options = {
speed : 250, // Transition/animation speed (milliseconds)
easing : 'ease-out', // css easing function to use
itemSelector: '', // e.g. '.gallery-item'
sizer: null,
gutterWidth : 0, // a static number or function that tells the plugin how wide the gutters between columns are (in pixels)
columnWidth : 0,// a static number or function that returns a number which tells the plugin how wide the columns are (in pixels)
showInitialTransition : false, // If set to false, the shuffle-items will only have a transition applied to them after the first layout
@ -1037,7 +1044,6 @@ Shuffle.options = {
// Not overrideable
Shuffle.settings = {
sizer: null,
$sizer: null,
useSizer: false,
itemCss : { // default CSS for each item

@ -2,11 +2,14 @@
This is a large improvement to shuffle. Most notably, the ability for [masonry](http://masonry.desandro.com) layouts. Other additions include adding/removing items, enabling/disabling, multiple instances on a page, and more!
## Todos
* Make demo with images loaded plugin
## Todo before launch
* Update index code examples
* Credit Jake with photos
* Solve margin top issue
* init with a sort
* Horizontal layout
* Custom animations
* Consistent naming of public vs private functions
## Other improvements
* Use Deferred objects for callbacks
* Custom animations
* Horizontal layout

Loading…
Cancel
Save