Add AMD support. Add RequireJS demo. Ref #15

pull/56/head
Glen Cheney 10 years ago
parent 60e156d274
commit ea30d642bb

@ -1,12 +1,16 @@
{% if page.jquery != false %}
<!--[if lt IE 9]>
<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.1.0/jquery.min.js"></script>
<!--<![endif]-->
{% endif %}
{% if page.shuffle != false %}
<!-- Shuffle! -->
<script src="{{ site.baseurl }}/dist/jquery.shuffle.js"></script>
{% endif %}
{% if page.prism %}
<!-- Syntax highlighting via Prism -->
@ -14,8 +18,10 @@
{% endif %}
<script>var site_url = "{{ site.baseurl }}";</script>
{% if page.pagejs != false %}
<script src="{{ site.baseurl }}/js/page.js"></script>
<script src="{{ site.baseurl }}/js/evenheights.js"></script>
{% endif %}
{% if page.extraJS && page.extraJS.length %}
{% for src in page.extraJS %}

@ -0,0 +1,67 @@
---
layout: default
title: Using Shuffle with Requirejs
description: TODO
image: /demos/requirejs.jpg
extraJS: []
prism: false
shuffle: false
jquery: false
pagejs: false
---
<div class="container-fluid">
<h2>RequireJS!</h2>
<p>
Shuffle is compatible with AMD loaders like <a href="http://requirejs.org">RequireJS</a>.
You can take a peek at the <a href="/js/require-main.js">config file</a> used on this page.
Just remember, Shuffle needs Modernizr to work!
I also don't recommend using the "jquery.shuffle.modernizr.js" file with RequireJS because Modernizr doesn't have an AMD defintion block.
</p>
</div>
<style>
.shuffle-wrap {
position: relative;
}
#grid .img-item {
margin-top: 10px;
margin-left: 0;
}
#grid .img-item img {
width: 100%;
}
</style>
<div class="container-fluid shuffle-wrap">
<div id="grid" class="shuffle--container row-fluid">
{% for item in site.items %}
<figure class="js-item img-item span3 m-span3">
<div class="keep-ratio four-three">
<div class="keep-ratio-inner">
<img src="{{ site.baseurl }}/img/{{ item.img }}" alt="{{item.title}}"/>
</div>
</div>
<figcaption>{{ item.groups }}</figcaption>
</figure>
{% endfor %}
<div class="span3 m-span3" id="js-sizer"></div>
</div>
</div>
<section>
<div class="container-fluid">
<h2>Shuffle.js</h2>
<p>{{ site.longDescription }}</p>
</div>
</section>
{% include credit-jake.html %}
<script data-main="/js/require-main.js" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.11/require.min.js"></script>

@ -8,10 +8,25 @@
* @author Glen Cheney <cheney.glen@gmail.com>
* @version 2.0.6
*/
(function($, Modernizr, undefined) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery', 'modernizr'], factory);
} else {
factory(window.$, window.Modernizr);
}
})(function($, Modernizr, undefined) {
'use strict';
// Validate Modernizr exists.
// Shuffle requires `csstransitions`, `csstransforms`, `csstransforms3d`,
// and `prefixed` to exist on the Modernizr object.
if (typeof Modernizr !== 'object') {
throw new Error('Shuffle.js requires Modernizr.\n' +
'http://vestride.github.io/Shuffle/#dependencies');
}
// Used for unique instance variables
var id = 0;
@ -1196,4 +1211,6 @@ $.fn.sorted.randomize = function( array ) {
return array;
};
})(jQuery, Modernizr);
return Shuffle;
});

File diff suppressed because one or more lines are too long

@ -14,10 +14,25 @@
*/
window.Modernizr=function(a,b,c){function z(a){j.cssText=a}function A(a,b){return z(m.join(a+";")+(b||""))}function B(a,b){return typeof a===b}function C(a,b){return!!~(""+a).indexOf(b)}function D(a,b){for(var d in a){var e=a[d];if(!C(e,"-")&&j[e]!==c)return b=="pfx"?e:!0}return!1}function E(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:B(f,"function")?f.bind(d||b):f}return!1}function F(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+o.join(d+" ")+d).split(" ");return B(b,"string")||B(b,"undefined")?D(e,b):(e=(a+" "+p.join(d+" ")+d).split(" "),E(e,b,c))}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m=" -webkit- -moz- -o- -ms- ".split(" "),n="Webkit Moz O ms",o=n.split(" "),p=n.toLowerCase().split(" "),q={},r={},s={},t=[],u=t.slice,v,w=function(a,c,d,e){var f,i,j,k,l=b.createElement("div"),m=b.body,n=m||b.createElement("body");if(parseInt(d,10))while(d--)j=b.createElement("div"),j.id=e?e[d]:h+(d+1),l.appendChild(j);return f=["&#173;",'<style id="s',h,'">',a,"</style>"].join(""),l.id=h,(m?l:n).innerHTML+=f,n.appendChild(l),m||(n.style.background="",n.style.overflow="hidden",k=g.style.overflow,g.style.overflow="hidden",g.appendChild(n)),i=c(l,a),m?l.parentNode.removeChild(l):(n.parentNode.removeChild(n),g.style.overflow=k),!!i},x={}.hasOwnProperty,y;!B(x,"undefined")&&!B(x.call,"undefined")?y=function(a,b){return x.call(a,b)}:y=function(a,b){return b in a&&B(a.constructor.prototype[b],"undefined")},Function.prototype.bind||(Function.prototype.bind=function(b){var c=this;if(typeof c!="function")throw new TypeError;var d=u.call(arguments,1),e=function(){if(this instanceof e){var a=function(){};a.prototype=c.prototype;var f=new a,g=c.apply(f,d.concat(u.call(arguments)));return Object(g)===g?g:f}return c.apply(b,d.concat(u.call(arguments)))};return e}),q.csstransforms=function(){return!!F("transform")},q.csstransforms3d=function(){var a=!!F("perspective");return a&&"webkitPerspective"in g.style&&w("@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}",function(b,c){a=b.offsetLeft===9&&b.offsetHeight===3}),a},q.csstransitions=function(){return F("transition")};for(var G in q)y(q,G)&&(v=G.toLowerCase(),e[v]=q[G](),t.push((e[v]?"":"no-")+v));return e.addTest=function(a,b){if(typeof a=="object")for(var d in a)y(a,d)&&e.addTest(d,a[d]);else{a=a.toLowerCase();if(e[a]!==c)return e;b=typeof b=="function"?b():b,typeof f!="undefined"&&f&&(g.className+=" "+(b?"":"no-")+a),e[a]=b}return e},z(""),i=k=null,e._version=d,e._prefixes=m,e._domPrefixes=p,e._cssomPrefixes=o,e.testProp=function(a){return D([a])},e.testAllProps=F,e.testStyles=w,e.prefixed=function(a,b,c){return b?F(a,b,c):F(a,"pfx")},g.className=g.className.replace(/(^|\s)no-js(\s|$)/,"$1$2")+(f?" js "+t.join(" "):""),e}(this,this.document);
(function($, Modernizr, undefined) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery', 'modernizr'], factory);
} else {
factory(window.$, window.Modernizr);
}
})(function($, Modernizr, undefined) {
'use strict';
// Validate Modernizr exists.
// Shuffle requires `csstransitions`, `csstransforms`, `csstransforms3d`,
// and `prefixed` to exist on the Modernizr object.
if (typeof Modernizr !== 'object') {
throw new Error('Shuffle.js requires Modernizr.\n' +
'http://vestride.github.io/Shuffle/#dependencies');
}
// Used for unique instance variables
var id = 0;
@ -1202,4 +1217,6 @@ $.fn.sorted.randomize = function( array ) {
return array;
};
})(jQuery, Modernizr);
return Shuffle;
});

File diff suppressed because one or more lines are too long

@ -0,0 +1,51 @@
requirejs.config({
baseUrl: '/js',
paths: {
jquery: '//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min',
shuffle: '../dist/jquery.shuffle',
modernizr: '../dist/modernizr.custom.min'
},
// Shimming other page javascript.
shim: {
evenheights: {
deps: ['jquery'],
exports: 'jQuery.fn.evenHeights'
},
page: {
deps: ['jquery', 'evenheights'],
exports: 'Modules'
}
}
});
// A hack for Modernizr and AMD. This lets Modernizr be in the <head> and also
// compatible with other modules.
define('modernizr', [], window.Modernizr);
define(function(require) {
// Get jQuery.
var $ = require('jquery');
// Get Shuffle.
var Shuffle = require('shuffle');
// Page-level JavaScript used for the demo pages.
var jqEvenHeights = require('evenheights');
var Page = require('page');
// Create a new shuffle instance.
var shuffle = new Shuffle($('#grid'), {
itemSelector: '.js-item',
sizer: $('#js-sizer')
});
// DO NOT use this for determining when images load.
// See http://vestride.github.io/Shuffle/images/
// Use something like imagesLoaded.
$('#grid img').on('load', function() {
shuffle.layout();
});
});

@ -1,3 +1,9 @@
(function($, Modernizr, undefined) {
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery', 'modernizr'], factory);
} else {
factory(window.$, window.Modernizr);
}
})(function($, Modernizr, undefined) {
'use strict';

@ -1 +1 @@
})(jQuery, Modernizr);
});

@ -1,3 +1,12 @@
// Validate Modernizr exists.
// Shuffle requires `csstransitions`, `csstransforms`, `csstransforms3d`,
// and `prefixed` to exist on the Modernizr object.
if (typeof Modernizr !== 'object') {
throw new Error('Shuffle.js requires Modernizr.\n' +
'http://vestride.github.io/Shuffle/#dependencies');
}
// Used for unique instance variables
var id = 0;
@ -1181,3 +1190,5 @@ $.fn.sorted.randomize = function( array ) {
return array;
};
return Shuffle;

Loading…
Cancel
Save