Moved example code to their own includes

Unindented shuffle once.
pull/56/head
Glen Cheney 11 years ago
parent e0902b49f4
commit 4c8ff13cce

@ -0,0 +1,26 @@
<h2>Advanced Filtering</h2>
<p>By passing a function to shuffle, you can customize the filtering to your hearts content. Shuffle will iterate over each item and give your function the element wrapped in jQuery and the shuffle instance. Return <code>true</code> to keep the element or <code>false</code> to hide it.</p>
<h3>Example</h3>
<pre rel="JavaScript"><code class="language-javascript">// Filters elements with a data-title attribute with less than 10 characters
$('#grid').shuffle(function($el, shuffle) {
return $el.data('title').length &lt; 10;
});</code></pre>
<h3>Searching</h3>
<pre rel="JavaScript"><code class="language-javascript">// Advanced filtering
$('.js-shuffle-search').on('keyup change', function() {
var val = this.value.toLowerCase();
$grid.shuffle(function($el, shuffle) {
// Only search elements in the current group
if (shuffle.group !== 'all' &amp;&amp; $.inArray(shuffle.group, $el.data('groups')) === -1) {
return false;
}
var text = $.trim( $el.find('.picture-item__title').text() ).toLowerCase();
return text.indexOf(val) != -1;
});</code></pre>
<p>For another example of advanced filters, check out the <a href="responsive.html">compounded filters demo</a>.</p>

@ -0,0 +1,2 @@
<h2>Events</h2>
<p>These events will be triggered at their respective times: <code>'shrink.shuffle'</code>, <code>'shrunk.shuffle'</code>, <code>'filter.shuffle'</code>, <code>'filtered.shuffle'</code>, and <code>'sorted.shuffle'</code>.</p>

@ -0,0 +1,10 @@
<h2>Features</h2>
<ul>
<li>Uses CSS Transitions!</li>
<li>Responsive (try resizing the window!)</li>
<li>Filter items by groups</li>
<li>Items can have multiple groups and be different sizes</li>
<li>Sort items</li>
<li>Advanced filtering method (like searching)</li>
</ul>

@ -0,0 +1,14 @@
<h2>Options</h2>
<p>Settings you can change (these are the defaults)</p>
<pre rel="JavaScript"><code class="language-javascript">// Overrideable options
$.fn.shuffle.options = {
group : 'all', // Which category to show
speed : 600, // Speed of the transition (in milliseconds). 600 = .6 seconds
easing : 'ease-out', // css easing function to use
gutterWidth : 0, // space between columns. Can be a function or number
columnWidth : 0 // can be a function or number or calculated by plugin
};
</code></pre>
<p>The easing function is one of <code>'default'</code>, <code>'linear'</code>, <code>'ease-in'</code>, <code>'ease-out'</code>, <code>'ease-in-out'</code>, or <code>'cubic-bezier'</code>.</p>

@ -0,0 +1,39 @@
<h2>Sorting</h2>
<p>You can order the elements based off a function you supply. In the example above, each item has a <code>data-date-created</code> and <code>data-title</code> attribute. The filter buttons have a <code>data-sort</code> attribute with the value of the item&rsquo;s attribute. Then, with some JavaScript, we can get the correct attribute and provide a function to sort by.</p>
<pre rel="HTML"><code class="language-markup">&lt;li data-sort="title"&gt;Title&lt;/li&gt;</code></pre>
<pre rel="HTML"><code class="language-markup">&lt;div class="item" data-title="Baseball"&gt;&hellip;&lt;/div&gt;</code></pre>
<pre rel="JavaScript"><code class="language-javascript">// Sorting options
$('.sort-options button').on('click', function() {
var $this = $(this),
sort = $this.data('sort'),
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 = {
by: function($el) {
return $el.data('date-created');
}
}
} else if (sort === 'title') {
opts = {
by: function($el) {
return $el.data('title').toLowerCase();
}
};
}
// Filter elements
$grid.shuffle('sort', opts);
});</code></pre>
<p>The <code class="language-javascript">opts</code> parameter can contain two properties. <code class="language-javascript">reverse</code>, a boolean which will reverse the array. <code class="language-javascript">by</code> is a function that is passed the element wrapped in jQuery. In the case above, we&rsquo;re returning the value of the data-date-created or data-title attributes.</p>
<p>Calling sort with an empty object will reset the elements to DOM order.</p>

@ -0,0 +1,58 @@
<h2>Usage</h2>
<h3>The HTML Structure</h3>
<p>The only real important thing here is the <code class="language-markup token attr-name">data-groups</code> attribute. It has to be a <a href="http://jsonlint.com/">valid JSON</a> array of strings.</p>
<pre rel="HTML"><code class="language-markup">
&lt;div id="grid"&gt;
&lt;div class="item" data-groups='["photography"]' data-date-created="2010-09-14" data-title="Baseball"&gt;
&lt;img src="img/baseball.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;Photography&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["wallpaper", "3d"]' data-date-created="2011-08-14" data-title="Tennis"&gt;
&lt;img src="img/tennis-ball.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;3D Render, Wallpaper&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["3d", "wallpaper"]' data-date-created="2009-05-27" data-title="iMac"&gt;
&lt;img src="img/imac.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;3D Render, Wallpaper&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["graphics"]' data-date-created="2012-05-14" data-title="Master Chief"&gt;
&lt;img src="img/master-chief.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;Graphic Design&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h3>How column widths work</h3>
<p>The <code>columnWidth</code> option is used to calculate the column width. This option <strong>can be a function</strong> for responsive layouts. If it's not a function, it uses jQuery's <code class="language-javascript">outerWidth(true)</code> to calculate the column width (this includes margins). If the <code>columnWidth</code> option isn't specified, the width will be the width of the first item.</p>
<h3>A basic setup example</h3>
<p>Sets up the button clicks and runs shuffle</p>
<pre rel="jQuery"><code class="language-javascript">
$(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();
});
</code></pre>

@ -1,5 +1,5 @@
{% include head.html %}
<main role="main" id="main">
<main role="main" id="main" class="language-markup">
{{ content }}
</main>
{% include scripts.html %}

@ -300,8 +300,6 @@
clear: both;
}
.container-fluid {
padding-right: 20px;
padding-left: 20px;
*zoom: 1;
}
.container-fluid:before,

@ -1,10 +1,11 @@
body {
font-family: 'Ubuntu', sans-serif;
pre {
max-height: 30em;
}
/* lets have some constraints shall we */
.container-fluid {
max-width: 93%;
width: 93%;
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
@ -13,50 +14,6 @@ body {
margin-left: 0;
}
// Links
a {
&,
&:visited {
color: $river;
}
&:hover {
text-decoration: none;
}
&:active {
color: $emerald;
}
}
h1 {
margin: 20px 0;
font-weight: 300;
font-size: 4em;
line-height: 1;
color: $emerald;
}
h2 {
position: relative;
color: $wetAsphalt;
font-size: 2.5em;
// border-bottom: 2px solid $emerald;
margin-bottom: 18px;
&:after {
content: '';
position: absolute;
bottom: 4px;
left: 0;
z-index: -1;
width: 100%;
height: 2px;
background-color: $emerald;
}
}
nav > a {

@ -100,15 +100,15 @@ a:hover {
Typography
========================================================================== */
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0;
}
// /**
// * Address variable `h1` font-size and margin within `section` and `article`
// * contexts in Firefox 4+, Safari 5, and Chrome.
// */
// h1 {
// font-size: 2em;
// margin: 0.67em 0;
// }
/**
* Address styling not present in IE 8/9, Safari 5, and Chrome.

@ -0,0 +1,68 @@
body {
font-family: 'Ubuntu', sans-serif;
color: $gray30;
}
// Links
a {
&,
&:visited {
color: $river;
}
&:hover {
text-decoration: none;
}
&:active {
color: $emerald;
}
}
h2,
h3,
h4,
h5,
h6 {
color: $wetAsphalt;
}
// Headers
h1 {
margin: 20px 0;
font-weight: 300;
font-size: 4em;
line-height: 1;
color: $emerald;
}
h2 {
position: relative;
font-size: 2.5em;
margin-bottom: 18px;
// Bottom border BEHIND the descenders!
&::after {
content: '';
position: absolute;
bottom: 4px;
left: 0;
z-index: -1;
width: 100%;
height: 2px;
background-color: $emerald;
}
}
h3 {
margin: .6667em 0 0.5em;
font-size: 1.5em;
}
h4 {
font-size: 1.25em;
}

@ -1,17 +1,4 @@
/*
Some colors from Flat UI
Firm/Turquiose: #1ABC9C;
Success/Emerald: #2ECC71;
Info/River: #3498DB;
Amethyst: #9B59B6;
Night/Wet Asphalt: #34495E;
Bright/Sunflower: #F1C40F;
Bright/Organge: #F39C12;
Carrot: #E67E22;
Alizarin: #E74C3C;
Clouds: #ECF0F1;
Concrete: #95A5A6;
*/
// Some colors from Flat UI
$turqoise: #1ABC9C;
$greenSea: #16A085;
@ -44,6 +31,17 @@ $concrete: #95A5A6;
$asbestos: #7F8C8D;
//
$black: #000;
$gray10: $midnightBlue;
$gray30: #5D6D77;
$gray20: $wetAsphalt;
$gray40: $concrete;
$gray50: $asbestos;
$white: #FFF;
@mixin clearfix() {
&:before,

@ -2,6 +2,7 @@
@import "normalize.scss";
// @import "csswizardry-grids";
@import "bootstrap.scss";
@import "type.scss";
@import "main.scss";
@import "buttons.scss";
@import "helpers.scss";

@ -1,17 +1,3 @@
/*
Some colors from Flat UI
Firm/Turquiose: #1ABC9C;
Success/Emerald: #2ECC71;
Info/River: #3498DB;
Amethyst: #9B59B6;
Night/Wet Asphalt: #34495E;
Bright/Sunflower: #F1C40F;
Bright/Organge: #F39C12;
Carrot: #E67E22;
Alizarin: #E74C3C;
Clouds: #ECF0F1;
Concrete: #95A5A6;
*/
/* normalize.css v2.1.2 | MIT License | git.io/normalize */
/* ==========================================================================
HTML5 display definitions
@ -96,14 +82,6 @@ a:hover {
/* ==========================================================================
Typography
========================================================================== */
/**
* Address variable `h1` font-size and margin within `section` and `article`
* contexts in Firefox 4+, Safari 5, and Chrome.
*/
h1 {
font-size: 2em;
margin: 0.67em 0; }
/**
* Address styling not present in IE 8/9, Safari 5, and Chrome.
*/
@ -646,8 +624,6 @@ table {
clear: both; }
.container-fluid {
padding-right: 20px;
padding-left: 20px;
*zoom: 1; }
.container-fluid:before,
@ -1489,16 +1465,8 @@ table {
.row-fluid .thumbnails {
margin-left: 0; } }
body {
font-family: 'Ubuntu', sans-serif; }
/* lets have some constraints shall we */
.container-fluid {
max-width: 93%;
margin-left: auto;
margin-right: auto; }
.row.row--full {
margin-left: 0; }
font-family: 'Ubuntu', sans-serif;
color: #5d6d77; }
a, a:visited {
color: #3498db; }
@ -1507,6 +1475,13 @@ a:hover {
a:active {
color: #2ecc71; }
h2,
h3,
h4,
h5,
h6 {
color: #34495e; }
h1 {
margin: 20px 0;
font-weight: 300;
@ -1516,10 +1491,9 @@ h1 {
h2 {
position: relative;
color: #34495e;
font-size: 2.5em;
margin-bottom: 18px; }
h2:after {
h2::after {
content: '';
position: absolute;
bottom: 4px;
@ -1529,6 +1503,26 @@ h2 {
height: 2px;
background-color: #2ecc71; }
h3 {
margin: .6667em 0 0.5em;
font-size: 1.5em; }
h4 {
font-size: 1.25em; }
pre {
max-height: 30em; }
/* lets have some constraints shall we */
.container-fluid {
width: 93%;
max-width: 1200px;
margin-left: auto;
margin-right: auto; }
.row.row--full {
margin-left: 0; }
nav > a {
display: block;
margin: 5px 0; }

@ -173,210 +173,37 @@ extraJS: [ "homepage.js" ]
<section>
<div class="container-fluid">
<h2>Features</h2>
<ul>
<li>Uses CSS Transitions!</li>
<li>Responsive (try resizing the window!)</li>
<li>Filter items by groups</li>
<li>Items can have multiple groups and be different sizes</li>
<li>Sort items</li>
<li>Advanced filtering method (like searching)</li>
</ul>
{% include features.html %}
</div>
</section>
<section>
<div class="container-fluid">
<h2>Options</h2>
<div>
<p>Settings you can change (these are the defaults)</p>
<pre rel="JavaScript">
<code class="language-javascript">
// Overrideable options
$.fn.shuffle.options = {
group : 'all', // Which category to show
speed : 600, // Speed of the transition (in milliseconds). 600 = .6 seconds
easing : 'ease-out', // css easing function to use
gutterWidth : 0, // space between columns. Can be a function or number
columnWidth : 0 // can be a function or number or calculated by plugin
};
</code>
</pre>
<p>The easing function is one of <code>'default'</code>, <code>'linear'</code>, <code>'ease-in'</code>, <code>'ease-out'</code>, <code>'ease-in-out'</code>, or <code>'cubic-bezier'</code>.</p>
</div>
{% include options.html %}
</div>
</section>
<section>
<div class="container-fluid">
<h2>Usage</h2>
<div>
<h3>The HTML Structure</h3>
<p>The only real important thing here is the <code class="language-markup token attr-name">data-groups</code> attribute. It has to be a <a href="http://jsonlint.com/">valid JSON</a> array of strings.</p>
<pre rel="HTML">
<code class="language-markup">
&lt;div id="grid"&gt;
&lt;div class="item" data-groups='["photography"]' data-date-created="2010-09-14" data-title="Baseball"&gt;
&lt;img src="img/baseball.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;Photography&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["wallpaper", "3d"]' data-date-created="2011-08-14" data-title="Tennis"&gt;
&lt;img src="img/tennis-ball.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;3D Render, Wallpaper&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["3d", "wallpaper"]' data-date-created="2009-05-27" data-title="iMac"&gt;
&lt;img src="img/imac.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;3D Render, Wallpaper&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="item" data-groups='["graphics"]' data-date-created="2012-05-14" data-title="Master Chief"&gt;
&lt;img src="img/master-chief.png" /&gt;
&lt;div class="item-details"&gt;
&lt;a href="#"&gt;Graphic Design&lt;/a&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</code>
</pre>
<h3>How column widths work</h3>
<p>The <code>columnWidth</code> option is used to calculate the column width. This option <strong>can be a function</strong> for responsive layouts. If it's not a function, it uses jQuery's <code class="language-javascript">outerWidth(true)</code> to calculate the column width (this includes margins). If the <code>columnWidth</code> option isn't specified, the width will be the width of the first item.</p>
<h3>A basic setup example</h3>
<p>Sets up the button clicks and runs shuffle</p>
<pre rel="jQuery">
<code class="language-javascript">
$(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();
});
</code>
</pre>
<h3>Events</h3>
<p>These events will be triggered at their respective times: <code>'shrink.shuffle'</code>, <code>'shrunk.shuffle'</code>, <code>'filter.shuffle'</code>, <code>'filtered.shuffle'</code>, and <code>'sorted.shuffle'</code>.</p>
</div>
{% include usage.html %}
</div>
</section>
<section>
<div class="container-fluid">
<h2>Sorting</h2>
<p>You can order the elements based off a function you supply. In the example above, each item has a <code>data-date-created</code> and <code>data-title</code> attribute. The filter buttons have a <code>data-sort</code> attribute with the value of the item&rsquo;s attribute. Then, with some JavaScript, we can get the correct attribute and provide a function to sort by.</p>
<pre rel="HTML">
<code class="language-markup">
&lt;li data-sort="title"&gt;Title&lt;/li&gt;
</code>
</pre>
<pre rel="HTML">
<code class="language-markup">
&lt;div class="item" data-title="Baseball"&gt;&hellip;&lt;/div&gt;
</code>
</pre>
<pre rel="JavaScript">
<code class="language-javascript">
// Sorting options
$('.sort-options li').on('click', function() {
var $this = $(this),
$grid = $('#grid'),
sort = $this.data('sort'),
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 = {
by: function($el) {
return $el.data('date-created');
}
}
} else if (sort === 'title') {
opts = {
by: function($el) {
return $el.data('title').toLowerCase();
}
}
}
// Filter elements
$grid.shuffle('sort', opts);
});
</code>
</pre>
<p>The <code>opts</code> parameter can contain two properties. <code>reverse</code>, a boolean which will reverse the array. <code>by</code> is a function that is passed the element wrapped in jQuery. In the case above, we&rsquo;re returning the value of the data-date-created or data-title attributes.</p>
<p>Calling sort with an empty object will reset the elements to DOM order.</p>
{% include events.html %}
</div>
</section>
<section>
<div class="container-fluid">
<h2>Advanced Filtering</h2>
<p>By passing a function to shuffle, you can customize the filtering to your hearts content. Shuffle will iterate over each item in the container and give your function the element wrapped in jQuery and the shuffle instance. Return <code>true</code> to keep the element or <code>false</code> to hide it.</p>
<h3>Example</h3>
<pre rel="JavaScript">
<code class="language-javascript">
// Filters elements with a data-title attribute with less than 10 characters
$('#grid').shuffle(function($el, shuffle) {
return $el.data('title').length &lt; 10;
});
</code>
</pre>
<h3>Searching</h3>
<pre rel="JavaScript">
<code class="language-javascript">
// Advanced filtering
$('.filter .search').on('keyup change', function() {
var val = this.value.toLowerCase();
$('#grid').shuffle(function($el, shuffle) {
// Only search elements in the current group
if (shuffle.group !== 'all' &amp;&amp; $.inArray(shuffle.group, $el.data('groups')) === -1) {
return false;
}
// Get the text inside our element and search for the value in the input
var text = $.trim($el.text()).toLowerCase();
return text.indexOf(val) != -1;
});
});
</code>
</pre>
{% include sorting.html %}
</div>
</section>
<p>For another example of advanced filters, check out the <a href="responsive.html">compounded filters demo</a>.</p>
<section>
<div class="container-fluid">
{% include advanced-filters.html %}
</div>
</section>

@ -18,7 +18,8 @@ var DEMO = (function($, window) {
// Destroy it! o_O
// $grid.shuffle('destroy');
// You can subscribe to custom events: shrink, shrunk, filter, filtered, and sorted
// You can subscribe to custom events:
// shrink, shrunk, filter, filtered, sorted, load, done
// $grid.on('shrink.shuffle shrunk.shuffle filter.shuffle filtered.shuffle sorted.shuffle layout.shuffle', function(evt, shuffle) {
// if ( window.console ) {
// console.log(evt.type, shuffle, this);
@ -86,12 +87,11 @@ var DEMO = (function($, window) {
$grid.shuffle(function($el, shuffle) {
// Only search elements in the current group
// if (shuffle.group !== 'all' && $.inArray(shuffle.group, $el.data('groups')) === -1) {
// return false;
// }
if (shuffle.group !== 'all' && $.inArray(shuffle.group, $el.data('groups')) === -1) {
return false;
}
var text = $.trim($el.text()).toLowerCase();
console.log(text);
var text = $.trim( $el.find('.picture-item__title').text() ).toLowerCase();
return text.indexOf(val) != -1;
});
});

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save