Made "basic" and "adding/removing" demos

Now all calls to the jQuery plugin must include the function as the
first parameter: $grid.shuffle('shuffle', 'green');
pull/56/head
Glen Cheney 11 years ago
parent 410762f8e8
commit 3aa94d53f9

@ -4,11 +4,11 @@
<!--[if gte IE 9]><!-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<!--<![endif]-->
<script src="js/jquery.shuffle.js"></script>
<script src="js/prism.js"></script>
<script src="{{ site.url }}/js/jquery.shuffle.js"></script>
<script src="{{ site.url }}/js/prism.js"></script>
{% if page.extraJS && page.extraJS.length %}
{% for src in page.extraJS %}
<script src="js/demos/{{ src }}"></script>
<script src="{{ site.url }}/js/demos/{{ src }}"></script>
{% endfor %}
{% endif %}

@ -1,4 +1,14 @@
{% include head.html %}
{% if page.includeHeader %}
<header class="container-fluid">
<div class="row-fluid">
<div class="span7">
<h1>Shuffle</h1>
<p>Categorize, sort, and filter a responsive grid of items</p>
</div>
</div>
</header>
{% endif %}
<main role="main" id="main" class="language-markup">
{{ content }}
</main>

@ -4,6 +4,33 @@ title: Basic Shuffle Demo
bodyClass: basic
extraJS: [ "homepage.js" ]
---
<ul>
<li>Use the one from the main homepage demo</li>
</ul>
<div class="container-fluid">
<div class="row-fluid">
<h1>Masonry with a sizer</h1>
<hr>
</div>
</div>
<div class="container-fluid">
<div id="grid" class="row-fluid shuffle--container shuffle--fluid">
{% for item in site.items %}
{% assign item = item %}
{% include picture-item.html %}
{% endfor %}
<div class="span3 shuffle__sizer"></div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<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>
</div>

@ -1,108 +0,0 @@
---
layout: default
title: Shuffle Minimal Demo
bodyClass: null
extraJS: [ "minimal.js" ]
---
<style>
#grid {
outline: 1px solid rgb(255, 255, 255);
outline: 1px solid rgba(255, 255, 255, .7);
}
.simple-item {
width: 33.33333%; /* 3 per row */
}
.simple-item img {
max-width: 100%;
}
/* Spacing Exmaple */
.spacing #grid {
padding: 10px;
}
.spacing .simple-item {
width: 306px;
margin: 10px;
}
/* add some space to the bottom of the document */
.spacer {
padding-bottom: 150px;
}
</style>
<div class="container container-main">
<section>
<h2>Minimal</h2>
<button class="js-spacing">Add some space</button>
<div class="filter clearfix">
<p class="lfloat label">Filter:</p>
<ul class="filter-options control-group lfloat">
<li data-group="all" class="active">Most Recent</li>
<li data-group="wallpaper">Wallpapers</li>
<li data-group="graphics">Graphic Design</li>
<li data-group="photography">Photography</li>
<li data-group="3d">3D Renders</li>
</ul>
</div>
<div id="grid">
<div class="simple-item" data-groups='["photography"]'>
<img src="img/baseball.png" alt="" />
<div><a href="img/originals/baseball.jpg">Photography</a></div>
</div>
<div class="simple-item" data-groups='["wallpaper", "3d"]'>
<img src="img/tennis-ball.png" alt="" />
<div><a href="#">3D Render, Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["3d", "wallpaper"]'>
<img src="img/imac.png" alt="" />
<div><a href="#">3D Render, Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["graphics"]'>
<img src="img/master-chief.png" alt="" />
<div><a href="#">Graphic Design</a></div>
</div>
<div class="simple-item" data-groups='["3d", "wallpaper"]'>
<img src="img/es-blue.png" alt="" />
<div><a href="#">3D Render, Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["photography"]'>
<img src="img/pumpkin.png" alt="" />
<div><a href="#">Photography</a></div>
</div>
<div class="simple-item" data-groups='["3d", "wallpaper"]'>
<img src="img/vestride-red.png" alt="" />
<div><a href="#">3D Render, Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["graphics"]'>
<img src="img/newegg.png" alt="" />
<div><a href="#">Motion Graphics</a></div>
</div>
<div class="simple-item" data-groups='["wallpaper"]'>
<img src="img/eightfoldarc.png" alt="" />
<div><a href="#">Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["photography"]'>
<img src="img/ground.png" alt=""/>
<div><a href="img/originals/baseball.jpg">Photography</a></div>
</div>
<div class="simple-item" data-groups='["wallpaper"]'>
<img src="img/grassy-hills.png" alt="" />
<div><a href="#">Wallpaper</a></div>
</div>
<div class="simple-item" data-groups='["3d", "wallpaper"]'>
<img src="img/vestride-classy.png" alt="" />
<div><a href="#">3D Render, Wallpaper</a></div>
</div>
</div>
</section>
</div>
<div class="spacer"></div>

@ -0,0 +1,84 @@
---
layout: default
title: Shuffle Adding and Removing Elements Demo
bodyClass: null
extraJS: [ "adding-removing.js" ]
---
<style>
/* Styles for shuffle */
.container {
counter-reset: boxes;
}
.box {
position: relative;
width: 18%;
margin-left: 2.5%;
height: 100px;
margin-top: 20px;
float: left;
background: #E74C3C;
counter-increment: boxes;
}
.box::before {
content: counter(boxes);
position: absolute;
color: white;
top: .5em;
left: .5em;
}
.box.shuffle-item,
.box:first-child {
margin-left: 0;
}
.w2 {
width: 38.5%;
}
.w3 {
width: 59%;
}
.h2 {
height: 220px;
}
</style>
<section class="container">
<div class="row">
<h1 class="span12">Adding and Removing Items</h1>
</div>
</section>
<section class="container">
<button id="randomize">Randomize</button>
<button id="add">Add 5 Boxes</button>
<button id="remove">Remove Some Boxes</button>
</section>
<section class="container">
<div id="my-shuffle" class="items">
<div class="box"></div>
<div class="box h2 w2"></div>
<div class="box"></div>
<div class="box"></div>
<div class="box w2"></div>
<div class="box"></div>
</div>
</section>
<section class="container">
<div class="row">
<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>

@ -33,7 +33,12 @@ nav > a {
}
.filter__search {
margin: 5px 0;
}
.sort-options {
margin-top: 10px;
}

@ -1535,6 +1535,12 @@ nav > a {
.filter__label {
margin: 0 0 3px; }
.filter__search {
margin: 5px 0; }
.sort-options {
margin-top: 10px; }
.btn-group:before, .btn-group:after {
content: " ";
display: table; }

@ -3,16 +3,8 @@ layout: default
title: jQuery Shuffle Plugin
bodyClass: home
extraJS: [ "homepage.js" ]
includeHeader: true
---
<header class="container-fluid">
<div class="row-fluid">
<div class="span7">
<h1>Shuffle</h1>
<p>Categorize, sort, and filter a responsive grid of items</p>
</div>
</div>
</header>
<section id="downloads">
<div class="container-fluid">
<h2>Downloads</h2>
@ -30,25 +22,30 @@ extraJS: [ "homepage.js" ]
</div>
<div class="container-fluid filter">
<div class="row-fluid">
<p class="filter__label">Filter:</p>
<div class="filter-options btn-group">
<button class="btn btn--filter" data-group="wallpaper">Wallpapers</button>
<button class="btn btn--filter" data-group="graphics">Graphic Design</button>
<button class="btn btn--filter" data-group="photography">Photography</button>
<button class="btn btn--filter" data-group="3d">3D Renders</button>
</div>
<input class="filter__search js-shuffle-search" type="search" placeholder="Search..." />
</div>
<div class="row-fluid">
<p class="filter__label">Sort:</p>
<div class="sort-options btn-group">
<button class="btn btn--sort" data-sort class="active">Default</button>
<button class="btn btn--sort" data-sort="title">Title</button>
<button class="btn btn--sort" data-sort="date-created">Date Created</button>
<div class="span9">
<p class="filter__label">Filter:</p>
<div class="filter-options btn-group">
<button class="btn btn--filter" data-group="wallpaper">Wallpapers</button>
<button class="btn btn--filter" data-group="graphics">Graphic Design</button>
<button class="btn btn--filter" data-group="photography">Photography</button>
<button class="btn btn--filter" data-group="3d">3D Renders</button>
</div>
</div>
<div class="span3">
<div class="pusll-right">
<p class="filter__label">Sort:</p>
<select class="sort-options">
<option value>Default</option>
<option value="title">Title</option>
<option value="date-created">Date Created</option>
</select>
</div>
</div>
<input class="filter__search js-shuffle-search" type="search" placeholder="Search..." />
</div>
</div>

@ -0,0 +1,137 @@
window.Manipulator = (function($) {
'use strict';
var Manipulator = function( element ) {
var self = this;
self.$el = $( element );
self.init();
};
Manipulator.prototype.init = function() {
var self = this;
self.initShuffle();
self.setupEvents();
};
// Column width and gutter width options can be functions
Manipulator.prototype.initShuffle = function() {
this.$el.shuffle({
itemSelector: '.box',
speed: 250,
easing: 'ease',
columnWidth: function( containerWidth ) {
// .box's have a width of 18%
return 0.18 * containerWidth;
},
gutterWidth: function( containerWidth ) {
// .box's have a margin-left of 2.5%
return 0.025 * containerWidth;
}
});
// Shuffle is stored in the elements data with jQuery.
// You can access the class instance here
this.shuffle = this.$el.data('shuffle');
};
Manipulator.prototype.setupEvents = function() {
var self = this;
$('#add').on('click', $.proxy( self.onAddClick, self ));
$('#randomize').on('click', $.proxy( self.onRandomize, self ));
$('#remove').on('click', $.proxy( self.onRemoveClick, self ));
};
Manipulator.prototype.onAddClick = function() {
// Creating random elements. You could use an
// ajax request or clone elements instead
var self = this,
itemsToCreate = 5,
frag = document.createDocumentFragment(),
grid = self.$el[0],
items = [],
$items,
classes = ['w2', 'h2', 'w3'],
box, i, random, randomClass;
for (i = 0; i < itemsToCreate; i++) {
random = Math.random();
box = document.createElement('div');
box.className = 'box';
// Randomly add a class
if ( random > 0.8 ) {
randomClass = Math.floor( Math.random() * 3 );
box.className = box.className + ' ' + classes[ randomClass ];
}
items.push( box );
frag.appendChild( box );
}
grid.appendChild( frag );
$items = $(items);
// Tell shuffle items have been appended.
// It expects a jQuery object as the parameter.
self.shuffle.appended( $items );
// or
// self.$el.shuffle('appended', $items );
};
Manipulator.prototype.getRandomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
// Randomly choose some elements to remove
Manipulator.prototype.onRemoveClick = function() {
var self = this,
total = self.shuffle.visibleItems,
numberToRemove = Math.min( 3, total ),
indexesToRemove = [],
i = 0,
$collection = $();
// None left
if ( !total ) {
return;
}
// This has the possibility to choose the same index for more than
// one in the array, meaning sometimes less than 3 will be removed
for ( ; i < numberToRemove; i++ ) {
indexesToRemove.push( self.getRandomInt( 0, total - 1 ) );
}
// Make a jQuery collection out of the index selections
$.each(indexesToRemove, function(i, index) {
$collection = $collection.add( self.shuffle.$items.eq( index ) );
});
// Tell shuffle to remove them
self.shuffle.remove( $collection );
// or
// self.$el.shuffle('remove', $collection);
};
Manipulator.prototype.onRandomize = function() {
var self = this,
sortObj = {
randomize: true
};
self.shuffle.sort( sortObj );
// or
// self.$el.shuffle('sort', sortObj);
};
return Manipulator;
}(jQuery));
$(document).ready(function() {
new window.Manipulator( document.getElementById('my-shuffle') );
});

@ -43,7 +43,7 @@ var DEMO = (function( $ ) {
$this.toggleClass('active');
// Filter elements
$grid.shuffle( group );
$grid.shuffle( 'shuffle', group );
});
$btns = null;
@ -51,15 +51,11 @@ var DEMO = (function( $ ) {
setupSorting = function() {
// Sorting options
$('.sort-options button').on('click', function() {
$('.sort-options').on('change', function() {
var $this = $(this),
sort = $this.data('sort'),
sort = this.value,
opts = {};
// Hide current label, show current label in title
$('.sort-options .active').removeClass('active');
$this.addClass('active');
// We're given the element wrapped in jQuery
if (sort === 'date-created') {
opts = {
@ -84,7 +80,7 @@ var DEMO = (function( $ ) {
// Advanced filtering
$('.js-shuffle-search').on('keyup change', function() {
var val = this.value.toLowerCase();
$grid.shuffle(function($el, shuffle) {
$grid.shuffle('shuffle', function($el, shuffle) {
// Only search elements in the current group
if (shuffle.group !== 'all' && $.inArray(shuffle.group, $el.data('groups')) === -1) {

@ -1,41 +0,0 @@
$(document).ready(function() {
// Set up button clicks
$('.filter-options li').on('click', function() {
var $this = $(this),
$grid = $('#grid');
// Hide current label, show current label in title
$('.filter-options .active').removeClass('active');
$this.addClass('active');
// Filter elements
$grid.shuffle($this.data('group'));
});
// instantiate the plugin
$('#grid').shuffle();
// Add space button
$('.js-spacing').on('click', function() {
var $body = $(document.body);
$body.toggleClass('spacing');
if ( $body.hasClass('spacing') ) {
$(this).text('Remove the spacing');
$('#grid')
.shuffle('destroy')
// you can hide the initial transition if you want
.shuffle({
showInitialTransition: false
});
} else {
$(this).text('Add some space');
$('#grid')
.shuffle('destroy')
.shuffle();
}
});
});

@ -155,8 +155,7 @@ Shuffle.prototype = {
// Add classes and invalidate styles
self._addClasses();
// Set up css for transitions and set initial css for each item
self.$container[0].style[ self.transitionName ] = 'height ' + self.speed + 'ms ' + self.easing;
// Set initial css for each item
self._initItems();
// Bind resize events (http://stackoverflow.com/questions/1852751/window-resize-event-firing-in-internet-explorer)
@ -189,6 +188,7 @@ Shuffle.prototype = {
if ( self.supported ) {
setTimeout(function() {
self._setTransitions();
self.$container[0].style[ self.transitionName ] = 'height ' + self.speed + 'ms ' + self.easing;
}, 0);
}
},
@ -352,9 +352,11 @@ Shuffle.prototype = {
return element;
},
_setTransitions : function() {
_setTransitions : function( $items ) {
var self = this;
self.$items.each(function() {
$items = $items || self.$items;
$items.each(function() {
self._setTransition( this );
});
return self;
@ -803,6 +805,7 @@ Shuffle.prototype = {
$newItems.addClass('shuffle-item');
self._initItems( $newItems );
self._setTransitions( $newItems );
self.$items = self._getItems();
// Hide all items
@ -1065,27 +1068,8 @@ $.fn.shuffle = function( opts ) {
$this.data('shuffle', shuffle);
}
// If passed a string, lets decide what to do with it. Or they've provided a function to filter by
if ( $.isFunction(opts) ) {
shuffle.shuffle.apply( shuffle, args );
// Key should be an object with propreties reversed and by.
} else if (typeof opts === 'string') {
switch( opts ) {
case 'sort':
case 'destroy':
case 'update':
case 'appended':
case 'enable':
case 'disable':
case 'layout':
case 'remove':
shuffle[ opts ].apply( shuffle, args );
break;
default:
shuffle.shuffle( opts );
break;
}
if ( typeof opts === 'string' && shuffle[ opts ] ) {
shuffle[ opts ].apply( shuffle, args );
}
});
};

Loading…
Cancel
Save