Add bootstrap 3 demo, fix percentage width issue with Shuffle, closes #8.

Update jQuery to 1.11.0/2.1.0
Update Google Analytics
Fix nav highlighting.
pull/56/head
Glen Cheney 10 years ago
parent 648300a8f1
commit b6aa8fe396

@ -43,6 +43,10 @@ demos:
slug: animated
label: Animated viewport entry
screenshot: animated.webp
- url: 'demos/2014-03-08-bootstrap3-grid'
slug: bootstrap3-grid
label: Bootstrap 3 Grid Demo
screenshot: bootstrap3grid.webp
shapes:
- shape: circle

@ -1,5 +1,5 @@
<div class="row-fluid m-row js-demos demo-list">
{% for post in site.demos limit:4 %}
{% for post in site.demos %}
<div class="span3 m-span3 figure-wrap js-demo">
<a href="{{ site.baseurl }}/{{ post.slug }}">
<figure>
@ -12,20 +12,3 @@
</div>
{% endfor %}
</div>
{% if site.demos | size > 4 %}
<div class="row-fluid m-row js-demos demo-list">
{% for post in site.demos limit:4 offset:4 %}
<div class="span3 m-span3 figure-wrap js-demo">
<a href="{{ site.baseurl }}/{{ post.slug }}">
<figure>
<div class="keep-ratio four-three">
<img src="{{ site.baseurl }}/img/demos/{{ post.slug }}.webp" alt="{{ post.label }}" />
</div>
<figcaption>{{ post.label }}</figcaption>
</figure>
</a>
</div>
{% endfor %}
</div>
{% endif %}

@ -43,6 +43,11 @@
<link rel="stylesheet" href="{{ site.baseurl }}{{ href }}" />
{% endfor %}
{% endif %}
{% if page.externalCSS %}
{% for href in page.externalCSS %}
<link rel="stylesheet" href="{{ href }}" />
{% endfor %}
{% endif %}
<!--[if lt IE 9]>
<script src="{{ site.baseurl }}/js/html5shiv.js"></script>

@ -1,8 +1,8 @@
<!--[if lt IE 9]>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<![endif]-->
<!--[if gte IE 9]><!-->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<!--<![endif]-->
<!-- Shuffle! -->
@ -15,6 +15,7 @@
<script>var site_url = "{{ site.baseurl }}";</script>
<script src="{{ site.baseurl }}/js/page.js"></script>
<script src="{{ site.baseurl }}/js/evenheights.js"></script>
{% if page.extraJS && page.extraJS.length %}
{% for src in page.extraJS %}
@ -23,29 +24,5 @@
{% endif %}
{% if site.environment == "production" %}
<script>
// Analytics
var _gaq = [ ['_setAccount', 'UA-39355642-1'], ['_trackPageview'] ];
(function(doc, script) {
'use strict';
var js,
fjs = doc.scripts[0],
frag = doc.createDocumentFragment(),
add = function(url, id) {
if (doc.getElementById(id)) {return;}
js = doc.createElement(script);
js.src = url;
if ( id ) { js.id = id; }
frag.appendChild( js );
};
// Load GA over http, we know it won't be over ssl
add('//www.google-analytics.com/ga.js');
fjs.parentNode.insertBefore(frag, fjs);
}(document, 'script'));
</script>
<script>(function(G,o,O,g,l){G.GoogleAnalyticsObject=O;G[O]||(G[O]=function(){(G[O].q=G[O].q||[]).push(arguments)});G[O].l=+new Date;g=o.createElement('script'),l=o.scripts[0];g.src='//www.google-analytics.com/analytics.js';l.parentNode.insertBefore(g,l)}(this,document,'ga'));ga('create','UA-39355642-1','vestride.github.io');ga('send','pageview')</script>
{% endif %}

@ -0,0 +1,111 @@
---
layout: default
title: Bootstrap 3 Grid Demo
description: Demonstrating how Shuffle can be used with a grid system which uses padding for gutters instead of margins.
image: /demos/bootstrap3grid.jpg
externalCSS: [ "http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" ]
extraJS: [ "demos/bootstrap3grid.js" ]
---
<style>
.table-center-wrap {
width: 100%;
height: 100%;
text-align: center;
}
.demo-description {
margin-bottom: 20px;
}
.grid__brick .grid__brick-inner {
background-color: #F0F0F0;
height: 100px;
border: 1px solid rgba(0, 0, 0, 0.3);
}
.grid__brick:nth-child(n+4) {
margin-top: 15px;
}
@media (max-width: 767px) {
.grid__brick:nth-child(n+3) {
margin-top: 15px;
}
}
.aside {
height: 200px;
background-color: #E0E0E0;
}
.aside + .aside {
margin-top: 10px;
}
</style>
<div class="container-fluid demo-description">
<div class="row">
<div class="col-xs-12">
<h2>Bootstrap 3 Grid</h2>
<p>
On this page, I have added the minified bootstrap css file from the <a href="http://www.bootstrapcdn.com/">NetDNA CDN</a> (which is also why some of the site-styles are being overriden).
<br>
The <a href="http://getbootstrap.com/css/#grid">Bootstrap 3 grid</a> system uses padding for gutters instead of margins. This page demonstrates one way to use Shuffle with these types of grids, as well as showing you don't have to use the full width of the page with Shuffle.
</p>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-9">
<div class="row">
<div id="grid" class="shuffle--container shuffle--fluid">
{% for i in (1..20) %}
<div class="grid__brick col-xs-6 col-sm-4">
<div class="grid__brick-inner">
<div class="table-center-wrap">
<div class="table-center">
{{ i }}
</div>
</div>
</div>
</div>
{% endfor %}
<div class="col-xs-1 shuffle__sizer"></div>
</div>
</div>
</div>
<div class="col-xs-12 col-sm-3">
<aside class="aside table-center-wrap">
<div class="table-center">
Some content on the right.
</div>
</aside>
<aside class="aside table-center-wrap">
<div class="table-center">
Some content on the right.
</div>
</aside>
<aside class="aside table-center-wrap">
<div class="table-center">
Some content on the right.
</div>
</aside>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<div class="col-xs-12">
<h2>Shuffle.js</h2>
<p>{{ site.longDescription }}</p>
</div>
</div>
</div>

@ -88,3 +88,13 @@
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.table-center-wrap {
display: table;
table-layout: fixed;
}
.table-center {
display: table-cell;
vertical-align: middle;
}

@ -101,6 +101,10 @@ nav > a {
}
.demo-list .figure-wrap {
position: relative;
z-index: 1;
}
.demo-list .figure-wrap,
.demo-list .figure-wrap img {
@ -122,6 +126,7 @@ nav > a {
}
.demo-list:hover .figure-wrap:hover {
z-index: 2;
-webkit-transform: scale3d( 1.05, 1.05, 1 );
transform: scale3d( 1.05, 1.05, 1 );
@ -141,6 +146,7 @@ nav > a {
.demo-list .figure-wrap figcaption {
margin-top: .5em;
margin-bottom: 1em;
}

@ -1973,6 +1973,11 @@ nav > a {
margin: 5px 0;
}
.demo-list .figure-wrap {
position: relative;
z-index: 1;
}
.demo-list .figure-wrap,
.demo-list .figure-wrap img {
-webkit-transform: translateZ(0);
@ -1990,6 +1995,7 @@ nav > a {
}
.demo-list:hover .figure-wrap:hover {
z-index: 2;
-webkit-transform: scale3d(1.05, 1.05, 1);
transform: scale3d(1.05, 1.05, 1);
}
@ -2008,6 +2014,7 @@ nav > a {
.demo-list .figure-wrap figcaption {
margin-top: .5em;
margin-bottom: 1em;
}
.filter__label {
@ -2329,3 +2336,13 @@ button:active {
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.table-center-wrap {
display: table;
table-layout: fixed;
}
.table-center {
display: table-cell;
vertical-align: middle;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

@ -24,101 +24,15 @@
* Uses CSS Transforms to filter down a grid of items.
* Dependencies: jQuery 1.9+, Modernizr 2.6.2. Optionally throttle/debounce by Ben Alman
* Inspired by Isotope http://isotope.metafizzy.co/
* Modified 2013-08-19
* Modified 2014-03-08
* @license MIT license
* @author Glen Cheney <cheney.glen@gmail.com>
* @version 2.0.1
* @version 2.0.3
*/
(function($, Modernizr, undefined) {
'use strict';
// You can return `undefined` from the `by` function to revert to DOM order
// This plugin does NOT return a jQuery object. It returns a plain array because
// jQuery sorts everything in DOM order.
$.fn.sorted = function(options) {
var opts = $.extend({}, $.fn.sorted.defaults, options),
arr = this.get(),
revert = false;
if ( !arr.length ) {
return [];
}
if ( opts.randomize ) {
return $.fn.sorted.randomize( arr );
}
// Sort the elements by the opts.by function.
// If we don't have opts.by, default to DOM order
if (opts.by !== $.noop && opts.by !== null && opts.by !== undefined) {
arr.sort(function(a, b) {
// Exit early if we already know we want to revert
if ( revert ) {
return 0;
}
var valA = opts.by($(a)),
valB = opts.by($(b));
// If both values are undefined, use the DOM order
if ( valA === undefined && valB === undefined ) {
revert = true;
return 0;
}
if ( valA === 'sortFirst' || valB === 'sortLast' ) {
return -1;
}
if ( valA === 'sortLast' || valB === 'sortFirst' ) {
return 1;
}
return (valA < valB) ? -1 :
(valA > valB) ? 1 : 0;
});
}
// Revert to the original array if necessary
if ( revert ) {
return this.get();
}
if ( opts.reverse ) {
arr.reverse();
}
return arr;
};
$.fn.sorted.defaults = {
reverse: false, // Use array.reverse() to reverse the results
by: null, // Sorting function
randomize: false // If true, this will skip the sorting and return a randomized order in the array
};
// http://stackoverflow.com/a/962890/373422
$.fn.sorted.randomize = function( array ) {
var top = array.length,
tmp, current;
if ( !top ) {
return array;
}
while ( --top ) {
current = Math.floor( Math.random() * (top + 1) );
tmp = array[ current ];
array[ current ] = array[ top ];
array[ top ] = tmp;
}
return array;
};
// Used for unique instance variables
var id = 0;
@ -453,44 +367,86 @@ Shuffle.prototype = {
return parseFloat( dimension );
},
// Calculate number of columns
// Gets css if using sizer element
_setColumns : function( theContainerWidth ) {
var self = this,
containerWidth = theContainerWidth || self.$container.width(),
gutter = typeof self.gutterWidth === 'function' ?
self.gutterWidth( containerWidth ) :
self.useSizer ?
self._getPreciseDimension( self.sizer, 'marginLeft' ) :
self.gutterWidth,
calculatedColumns;
// use fluid columnWidth function if there
self.colWidth = self.isFluid ? self.columnWidth( containerWidth ) :
// columnWidth option isn't a function, are they using a sizing element?
self.useSizer ? self._getPreciseDimension( self.sizer, 'width' ) :
// if not, how about the explicitly set option?
self.columnWidth ||
// or use the size of the first item
self.$items.outerWidth(true) ||
// if there's no items, use size of container
containerWidth;
_getOuterWidth: function( element, includeMargins ) {
var width = element.offsetWidth;
if (includeMargins) {
var marginLeft = Math.round(parseFloat(element.style.marginLeft)) || 0;
var marginRight = Math.round(parseFloat(element.style.marginRight)) || 0;
width += marginLeft + marginRight;
}
return width;
},
_getColumnSize: function( gutterSize, containerWidth ) {
var size;
// Use fluid columnWidth function if there
if (this.isFluid) {
size = this.columnWidth(containerWidth);
// columnWidth option isn't a function, are they using a sizing element?
} else if (this.useSizer) {
size = this._getPreciseDimension(this.sizer, 'width');
// if not, how about the explicitly set option?
} else if (this.columnWidth) {
size = this.columnWidth;
// or use the size of the first item
} else if (this.$items.length > 0) {
size = this.getOuterWidth(this.$items[0], true);
// if there's no items, use size of container
} else {
size = containerWidth;
}
// Don't let them set a column width of zero.
self.colWidth = self.colWidth || containerWidth;
if ( size === 0 ) {
size = containerWidth;
}
// return Math.round(size + gutterSize);
return size + gutterSize;
},
self.colWidth += gutter;
calculatedColumns = (containerWidth + gutter) / self.colWidth;
_getGutterSize: function(containerWidth) {
var size;
if (this.gutterWidth === 'function') {
size = this.gutterWidth(containerWidth);
} else if (this.useSizer) {
size = this._getPreciseDimension(this.sizer, 'marginLeft');
} else {
size = this.gutterWidth;
}
return size;
},
/**
* Calculate the number of columns to be used. Gets css if using sizer element.
* @param {number} [theContainerWidth] Optionally specify a container width if it's already available.
*/
_setColumns : function( theContainerWidth ) {
var containerWidth = theContainerWidth || this._getOuterWidth(this.$container[0]);
var gutter = this._getGutterSize(containerWidth);
var columnWidth = this._getColumnSize(gutter, containerWidth);
var calculatedColumns = (containerWidth + gutter) / columnWidth;
// Widths given from getComputedStyle are not precise enough...
if ( Math.ceil(calculatedColumns) - calculatedColumns < 0.01 ) {
if ( Math.abs(Math.round(calculatedColumns) - calculatedColumns) < 0.03 ) {
// e.g. calculatedColumns = 11.998876
calculatedColumns = Math.ceil( calculatedColumns );
calculatedColumns = Math.round( calculatedColumns );
}
self.cols = Math.floor( calculatedColumns );
self.cols = Math.max( self.cols, 1 );
self.containerWidth = containerWidth;
this.cols = Math.max( Math.floor(calculatedColumns), 1 );
this.containerWidth = containerWidth;
this.colWidth = columnWidth;
},
/**
@ -525,18 +481,30 @@ Shuffle.prototype = {
fn = fn || self.filterEnd;
self.layoutTransitionEnded = false;
$.each(items, function(index) {
var $this = $(items[index]),
//how many columns does this brick span
colSpan = Math.ceil( $this.outerWidth(true) / self.colWidth );
colSpan = Math.min( colSpan, self.cols );
$.each(items, function(index, item) {
var $this = $(item),
brickWidth = self._getOuterWidth(item, true),
columnSpan = brickWidth / self.colWidth;
// If the difference between the rounded column span number and the
// calculated column span number is really small, round the number to
// make it fit.
if ( Math.abs(Math.round(columnSpan) - columnSpan) < 0.03 ) {
// e.g. columnSpan = 4.0089945390298745
columnSpan = Math.round( columnSpan );
}
// How many columns does this brick span. Ensure it's not more than the
// amount of columns in the whole layout.
var colSpan = Math.min( Math.ceil(columnSpan), self.cols );
// The brick is only one column.
if ( colSpan === 1 ) {
// if brick spans only one column, just like singleMode
self._placeItem( $this, self.colYs, fn, isOnlyPosition, isHide );
// The brick spans more than one column, figure out how many different
// places could this brick fit horizontally
} else {
// brick spans more than one column
// how many different places could this brick fit horizontally
var groupCount = self.cols + 1 - colSpan,
groupY = [],
groupColY,
@ -1070,9 +1038,9 @@ Shuffle.prototype = {
// it can first check if it is actually destroyed and not doing anything
self.destroyed = true;
}
};
// Overrideable options
Shuffle.options = {
group: ALL_ITEMS, // Filter group
@ -1091,6 +1059,7 @@ Shuffle.options = {
supported: CAN_TRANSITION_TRANSFORMS // supports transitions and transforms
};
// Not overrideable
Shuffle.settings = {
$sizer: null,
@ -1128,4 +1097,93 @@ $.fn.shuffle = function( opts ) {
});
};
// You can return `undefined` from the `by` function to revert to DOM order
// This plugin does NOT return a jQuery object. It returns a plain array because
// jQuery sorts everything in DOM order.
$.fn.sorted = function(options) {
var opts = $.extend({}, $.fn.sorted.defaults, options),
arr = this.get(),
revert = false;
if ( !arr.length ) {
return [];
}
if ( opts.randomize ) {
return $.fn.sorted.randomize( arr );
}
// Sort the elements by the opts.by function.
// If we don't have opts.by, default to DOM order
if (opts.by !== $.noop && opts.by !== null && opts.by !== undefined) {
arr.sort(function(a, b) {
// Exit early if we already know we want to revert
if ( revert ) {
return 0;
}
var valA = opts.by($(a)),
valB = opts.by($(b));
// If both values are undefined, use the DOM order
if ( valA === undefined && valB === undefined ) {
revert = true;
return 0;
}
if ( valA === 'sortFirst' || valB === 'sortLast' ) {
return -1;
}
if ( valA === 'sortLast' || valB === 'sortFirst' ) {
return 1;
}
return (valA < valB) ? -1 :
(valA > valB) ? 1 : 0;
});
}
// Revert to the original array if necessary
if ( revert ) {
return this.get();
}
if ( opts.reverse ) {
arr.reverse();
}
return arr;
};
$.fn.sorted.defaults = {
reverse: false, // Use array.reverse() to reverse the results
by: null, // Sorting function
randomize: false // If true, this will skip the sorting and return a randomized order in the array
};
// http://stackoverflow.com/a/962890/373422
$.fn.sorted.randomize = function( array ) {
var top = array.length,
tmp, current;
if ( !top ) {
return array;
}
while ( --top ) {
current = Math.floor( Math.random() * (top + 1) );
tmp = array[ current ];
array[ current ] = array[ top ];
array[ top ] = tmp;
}
return array;
};
})(jQuery, Modernizr);

@ -0,0 +1,22 @@
var DEMO = (function( $ ) {
'use strict';
var init = function() {
var $grid = $('#grid'),
$sizer = $grid.find('.shuffle__sizer');
$grid.shuffle({
itemSelector: '.grid__brick',
sizer: $sizer
});
};
return {
init: init
};
}( jQuery ));
$(document).ready(function() {
DEMO.init();
});

@ -0,0 +1,62 @@
/*!
* jQuery Even Heights plugin
* Author: Glen Cheney
* Modified: 06/26/13
* Dependencies: jQuery 1.2.6+
* Sets a jQuery collection to all be the same height
* If you need to set multiple collection, please use `$.evenHeights( collectionsArray )`
* because it is much faster
*/
(function( $ ) {
'use strict';
function getTallest( $elements ) {
var tallest = 0;
$elements.each(function() {
if ( this.offsetHeight > tallest ) {
tallest = this.offsetHeight;
}
});
return tallest;
}
$.fn.evenHeights = function() {
return this.css( 'height', '' ).css( 'height', getTallest( this ) );
};
/**
* For groups of elements which should be the same height. Using this method
* will create far less style recalculations and layouts.
* @param {Array.<jQuery>} groups Array of jQuery collections.
* @return {Array.<number>} An array containing the pixel value of the
* tallest element for each group.
*/
$.evenHeights = function( groups ) {
var winners = [];
// First, reset the height for every element.
// This is done first, otherwise we dirty the DOM on each loop!
$.each(groups, function( i, $elements ) {
$elements.css( 'height', '' );
});
// Now, measure heights in each group and save the tallest value. Instead of
// setting the height value for the entire group, save it. If it were set,
// the next iteration in the loop would have to recalculate styles in the DOM
$.each(groups, function( i, $elements ) {
winners.push( getTallest( $elements ) );
});
// Lastly, set them all.
$.each(groups, function( i, $elements ) {
$elements.css( 'height', winners[ i ] );
});
return winners;
};
})(window.$);

@ -100,13 +100,20 @@ Modules.Nav = (function( $ ) {
function NavTray( element ) {
this.$el = $( element );
this.isOpen = false;
this.$window = $( window );
this.$trigger = this.$el.find('.js-nav-toggle');
this.$tray = this.$el.find('.js-tray');
this.$trigger.data( 'openLabel', this.$trigger.text() );
this.init();
}
NavTray.prototype.init = function() {
this
.setVars()
.listen();
this.setEvenHeights();
this.listen();
// Google web font loading affects this.
// I could use their loader, but don't really want their js too
@ -116,26 +123,8 @@ Modules.Nav = (function( $ ) {
setTimeout( $.proxy( this.saveHeight, this ), 100 );
};
NavTray.prototype.setVars = function() {
var self = this;
self.isOpen = false;
self.$window = $( window );
self.$trigger = self.$el.find('.js-nav-toggle');
self.$tray = self.$el.find('.js-tray');
self.$trigger.data( 'openLabel', self.$trigger.text() );
return self;
};
NavTray.prototype.saveHeight = function() {
var self = this,
height = self.$tray.children().first().outerHeight();
self.collapseHeight = height;
return height;
this.collapseHeight = this.$tray.children().first().outerHeight();
};
NavTray.prototype.listen = function() {
@ -151,6 +140,7 @@ Modules.Nav = (function( $ ) {
var self = this;
self.$tray.css( 'height', '' );
this.setEvenHeights();
self.saveHeight();
if ( self.isOpen ) {
@ -200,6 +190,14 @@ Modules.Nav = (function( $ ) {
return self;
};
NavTray.prototype.setEvenHeights = function() {
var groups = [
this.$el.find('.js-demo'),
$('#main .js-demo')
];
$.evenHeights( groups );
};
return {
init: function() {
return new NavTray( document.getElementById('nav') );

@ -2,19 +2,16 @@
## Improvements
* TESTS!
* Use Deferred objects for callbacks
* Horizontal layout
* See if I can get Zepto.js working with it.
* Find an alternative to jQuery's .data()
* Find an alternative to jQuery's .outerWidth()
* Add bootstrap 3 grid demo.
* Use an enum for events?
* More JSDoc
## Things I don't like and would like to fix
* The `transition` method and the options object that it receives.
* Move everything to Shuffle.prototype.method = function.
* Make indentation 2 spaces instead of 4.
* `_layout` and `_placeItem`s parameters.
* `_setColumns` should be simpler
* Less jQuery dependency
## Reason Zepto doesn't work
* `.data()` - although I think it can be included?
* `.filter()` and `.not()` don't work with collections.
* `.css(['style1', 'style2', 'style3'])` isn't supported.

Loading…
Cancel
Save