From ca6b283e20dea3c73fec0fd513c78f9d0aad748e Mon Sep 17 00:00:00 2001 From: Nick Stakenburg Date: Thu, 20 Aug 2015 22:43:40 +0200 Subject: [PATCH] Changed wrapper to work with Node/CommonJS --- Gruntfile.js | 4 ++-- LICENSE.txt | 2 +- bower.json | 2 +- package.json | 4 ++-- src/intro.js | 17 ----------------- src/umd-head.js | 22 ++++++++++++++++++++++ src/{outro.js => umd-tail.js} | 0 voila.pkgd.js | 17 +++++++++++------ voila.pkgd.min.js | 4 ++-- 9 files changed, 41 insertions(+), 31 deletions(-) delete mode 100644 src/intro.js create mode 100644 src/umd-head.js rename src/{outro.js => umd-tail.js} (100%) diff --git a/Gruntfile.js b/Gruntfile.js index 2834c5b..44dbbec 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -15,13 +15,13 @@ module.exports = function(grunt) { process: true }, src: [ - 'src/intro.js', + 'src/umd-head.js', // core 'src/voila.js', 'src/imageready.js', - 'src/outro.js' + 'src/umd-tail.js' ], dest: 'voila.pkgd.js' } diff --git a/LICENSE.txt b/LICENSE.txt index 76734d2..21aee25 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2014 Nick Stakenburg +Copyright (c) 2015 Nick Stakenburg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/bower.json b/bower.json index 9520f20..5712e4b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "voila", - "version": "1.3.1", + "version": "1.4.0", "description": "A jQuery plugin that provides callbacks for images, letting you know when they've loaded.", "keywords": [ "image", diff --git a/package.json b/package.json index bdae2d7..80d6665 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "voila", - "title": "Voilà", - "version": "1.3.1", + "title": "Voilà", + "version": "1.4.0", "description": "A jQuery plugin that provides callbacks for images, letting you know when they've loaded.", "keywords": [ "image", diff --git a/src/intro.js b/src/intro.js deleted file mode 100644 index 90316bc..0000000 --- a/src/intro.js +++ /dev/null @@ -1,17 +0,0 @@ -/*! - * Voilà - v<%= pkg.version %> - * (c) <%= grunt.template.today("yyyy") %> Nick Stakenburg - * - * http://voila.nickstakenburg.com - * - * MIT License - */ - -// Use AMD or window -;(function(factory) { - if (typeof define === 'function' && define.amd) { - define(['jquery'], factory); - } else if (jQuery && !window.Voila) { - window.Voila = factory(jQuery); - } -}(function($) { diff --git a/src/umd-head.js b/src/umd-head.js new file mode 100644 index 0000000..0eb6d01 --- /dev/null +++ b/src/umd-head.js @@ -0,0 +1,22 @@ +/*! + * Voilà - v<%= pkg.version %> + * (c) <%= grunt.template.today("yyyy") %> Nick Stakenburg + * + * http://voila.nickstakenburg.com + * + * MIT License + */ + +// UMD wrapper +(function(root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD + define(['jquery'], factory); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = factory(require('jquery')); + } else { + // Browser global + root.Voila = factory(jQuery); + } +}(this, function($) { diff --git a/src/outro.js b/src/umd-tail.js similarity index 100% rename from src/outro.js rename to src/umd-tail.js diff --git a/voila.pkgd.js b/voila.pkgd.js index 132a85f..16a0fcc 100644 --- a/voila.pkgd.js +++ b/voila.pkgd.js @@ -1,5 +1,5 @@ /*! - * Voilà - v1.3.1 + * Voilà - v1.4.0 * (c) 2015 Nick Stakenburg * * http://voila.nickstakenburg.com @@ -7,14 +7,19 @@ * MIT License */ -// Use AMD or window -;(function(factory) { +// UMD wrapper +(function(root, factory) { if (typeof define === 'function' && define.amd) { + // AMD define(['jquery'], factory); - } else if (jQuery && !window.Voila) { - window.Voila = factory(jQuery); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = factory(require('jquery')); + } else { + // Browser global + root.Voila = factory(jQuery); } -}(function($) { +}(this, function($) { function Voila(elements, opts, cb) { if (!(this instanceof Voila)) { diff --git a/voila.pkgd.min.js b/voila.pkgd.min.js index 614005c..fe98b1c 100644 --- a/voila.pkgd.min.js +++ b/voila.pkgd.min.js @@ -1,9 +1,9 @@ /*! - * Voilà - v1.3.1 + * Voilà - v1.4.0 * (c) 2015 Nick Stakenburg * * http://voila.nickstakenburg.com * * MIT License */ -!function(a){"function"==typeof define&&define.amd?define(["jquery"],a):jQuery&&!window.Voila&&(window.Voila=a(jQuery))}(function(a){function b(c,d,e){if(!(this instanceof b))return new b(c,d,e);var f=a.type(arguments[1]),g="object"===f?arguments[1]:{},h="function"===f?arguments[1]:"function"===a.type(arguments[2])?arguments[2]:!1;return this.options=a.extend({method:"onload"},g),this.deferred=new jQuery.Deferred,h&&this.always(h),this._processed=0,this.images=[],this._add(c),this}a.extend(b.prototype,{_add:function(b){var d="string"==a.type(b)?a(b):b instanceof jQuery||b.length>0?b:[b];a.each(d,a.proxy(function(b,d){var e=a(),f=a(d);e=e.add(f.is("img")?f:f.find("img")),e.each(a.proxy(function(b,d){this.images.push(new c(d,a.proxy(function(a){this._progress(a)},this),a.proxy(function(a){this._progress(a)},this),this.options))},this))},this)),this.images.length<1&&setTimeout(a.proxy(function(){this._resolve()},this))},abort:function(){this._progress=this._notify=this._reject=this._resolve=function(){},a.each(this.images,function(a,b){b.abort()}),this.images=[]},_progress:function(a){this._processed++,a.isLoaded||(this._broken=!0),this._notify(a),this._processed==this.images.length&&this[this._broken?"_reject":"_resolve"]()},_notify:function(a){this.deferred.notify(this,a)},_reject:function(){this.deferred.reject(this)},_resolve:function(){this.deferred.resolve(this)},always:function(a){return this.deferred.always(a),this},done:function(a){return this.deferred.done(a),this},fail:function(a){return this.deferred.fail(a),this},progress:function(a){return this.deferred.progress(a),this}}),a.fn.voila=function(){return b.apply(b,[this].concat(Array.prototype.slice.call(arguments)))};var c=function(a){var b=function(){return this.initialize.apply(this,Array.prototype.slice.call(arguments))};a.extend(b.prototype,{initialize:function(){this.options=a.extend({test:function(){},success:function(){},timeout:function(){},callAt:!1,intervals:[[0,0],[1e3,10],[2e3,50],[4e3,100],[2e4,500]]},arguments[0]||{}),this._test=this.options.test,this._success=this.options.success,this._timeout=this.options.timeout,this._ipos=0,this._time=0,this._delay=this.options.intervals[this._ipos][1],this._callTimeouts=[],this.poll(),this._createCallsAt()},poll:function(){this._polling=setTimeout(a.proxy(function(){if(this._test())return void this.success();if(this._time+=this._delay,this._time>=this.options.intervals[this._ipos][0]){if(!this.options.intervals[this._ipos+1])return void("function"==a.type(this._timeout)&&this._timeout());this._ipos++,this._delay=this.options.intervals[this._ipos][1]}this.poll()},this),this._delay)},success:function(){this.abort(),this._success()},_createCallsAt:function(){this.options.callAt&&a.each(this.options.callAt,a.proxy(function(b,c){var d=c[0],e=c[1],f=setTimeout(a.proxy(function(){e()},this),d);this._callTimeouts.push(f)},this))},_stopCallTimeouts:function(){a.each(this._callTimeouts,function(a,b){clearTimeout(b)}),this._callTimeouts=[]},abort:function(){this._stopCallTimeouts(),this._polling&&(clearTimeout(this._polling),this._polling=null)}});var c=function(){return this.initialize.apply(this,Array.prototype.slice.call(arguments))};return a.extend(c.prototype,{supports:{naturalWidth:function(){return"naturalWidth"in new Image}()},initialize:function(b,c,d){return this.img=a(b)[0],this.successCallback=c,this.errorCallback=d,this.isLoaded=!1,this.options=a.extend({method:"onload",pollFallbackAfter:1e3},arguments[3]||{}),"onload"!=this.options.method&&this.supports.naturalWidth?void this.poll():void this.load()},poll:function(){this._poll=new b({test:a.proxy(function(){return this.img.naturalWidth>0},this),success:a.proxy(function(){this.success()},this),timeout:a.proxy(function(){this.error()},this),callAt:[[this.options.pollFallbackAfter,a.proxy(function(){this.load()},this)]]})},load:function(){this._loading=setTimeout(a.proxy(function(){var b=new Image;this._onloadImage=b,b.onload=a.proxy(function(){b.onload=function(){},this.supports.naturalWidth||(this.img.naturalWidth=b.width,this.img.naturalHeight=b.height,b.naturalWidth=b.width,b.naturalHeight=b.height),this.success()},this),b.onerror=a.proxy(this.error,this),b.src=this.img.src},this))},success:function(){this._calledSuccess||(this._calledSuccess=!0,this.abort(),this.waitForRender(a.proxy(function(){this.isLoaded=!0,this.successCallback(this)},this)))},error:function(){this._calledError||(this._calledError=!0,this.abort(),this._errorRenderTimeout=setTimeout(a.proxy(function(){this.errorCallback&&this.errorCallback(this)},this)))},abort:function(){this.stopLoading(),this.stopPolling(),this.stopWaitingForRender()},stopPolling:function(){this._poll&&(this._poll.abort(),this._poll=null)},stopLoading:function(){this._loading&&(clearTimeout(this._loading),this._loading=null),this._onloadImage&&(this._onloadImage.onload=function(){},this._onloadImage.onerror=function(){})},waitForRender:function(a){this._renderTimeout=setTimeout(a)},stopWaitingForRender:function(){this._renderTimeout&&(clearTimeout(this._renderTimeout),this._renderTimeout=null),this._errorRenderTimeout&&(clearTimeout(this._errorRenderTimeout),this._errorRenderTimeout=null)}}),c}(jQuery);return b}); \ No newline at end of file +!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof module&&module.exports?module.exports=b(require("jquery")):a.Voila=b(jQuery)}(this,function(a){function b(c,d,e){if(!(this instanceof b))return new b(c,d,e);var f=a.type(arguments[1]),g="object"===f?arguments[1]:{},h="function"===f?arguments[1]:"function"===a.type(arguments[2])?arguments[2]:!1;return this.options=a.extend({method:"onload"},g),this.deferred=new jQuery.Deferred,h&&this.always(h),this._processed=0,this.images=[],this._add(c),this}a.extend(b.prototype,{_add:function(b){var d="string"==a.type(b)?a(b):b instanceof jQuery||b.length>0?b:[b];a.each(d,a.proxy(function(b,d){var e=a(),f=a(d);e=e.add(f.is("img")?f:f.find("img")),e.each(a.proxy(function(b,d){this.images.push(new c(d,a.proxy(function(a){this._progress(a)},this),a.proxy(function(a){this._progress(a)},this),this.options))},this))},this)),this.images.length<1&&setTimeout(a.proxy(function(){this._resolve()},this))},abort:function(){this._progress=this._notify=this._reject=this._resolve=function(){},a.each(this.images,function(a,b){b.abort()}),this.images=[]},_progress:function(a){this._processed++,a.isLoaded||(this._broken=!0),this._notify(a),this._processed==this.images.length&&this[this._broken?"_reject":"_resolve"]()},_notify:function(a){this.deferred.notify(this,a)},_reject:function(){this.deferred.reject(this)},_resolve:function(){this.deferred.resolve(this)},always:function(a){return this.deferred.always(a),this},done:function(a){return this.deferred.done(a),this},fail:function(a){return this.deferred.fail(a),this},progress:function(a){return this.deferred.progress(a),this}}),a.fn.voila=function(){return b.apply(b,[this].concat(Array.prototype.slice.call(arguments)))};var c=function(a){var b=function(){return this.initialize.apply(this,Array.prototype.slice.call(arguments))};a.extend(b.prototype,{initialize:function(){this.options=a.extend({test:function(){},success:function(){},timeout:function(){},callAt:!1,intervals:[[0,0],[1e3,10],[2e3,50],[4e3,100],[2e4,500]]},arguments[0]||{}),this._test=this.options.test,this._success=this.options.success,this._timeout=this.options.timeout,this._ipos=0,this._time=0,this._delay=this.options.intervals[this._ipos][1],this._callTimeouts=[],this.poll(),this._createCallsAt()},poll:function(){this._polling=setTimeout(a.proxy(function(){if(this._test())return void this.success();if(this._time+=this._delay,this._time>=this.options.intervals[this._ipos][0]){if(!this.options.intervals[this._ipos+1])return void("function"==a.type(this._timeout)&&this._timeout());this._ipos++,this._delay=this.options.intervals[this._ipos][1]}this.poll()},this),this._delay)},success:function(){this.abort(),this._success()},_createCallsAt:function(){this.options.callAt&&a.each(this.options.callAt,a.proxy(function(b,c){var d=c[0],e=c[1],f=setTimeout(a.proxy(function(){e()},this),d);this._callTimeouts.push(f)},this))},_stopCallTimeouts:function(){a.each(this._callTimeouts,function(a,b){clearTimeout(b)}),this._callTimeouts=[]},abort:function(){this._stopCallTimeouts(),this._polling&&(clearTimeout(this._polling),this._polling=null)}});var c=function(){return this.initialize.apply(this,Array.prototype.slice.call(arguments))};return a.extend(c.prototype,{supports:{naturalWidth:function(){return"naturalWidth"in new Image}()},initialize:function(b,c,d){return this.img=a(b)[0],this.successCallback=c,this.errorCallback=d,this.isLoaded=!1,this.options=a.extend({method:"onload",pollFallbackAfter:1e3},arguments[3]||{}),"onload"!=this.options.method&&this.supports.naturalWidth?void this.poll():void this.load()},poll:function(){this._poll=new b({test:a.proxy(function(){return this.img.naturalWidth>0},this),success:a.proxy(function(){this.success()},this),timeout:a.proxy(function(){this.error()},this),callAt:[[this.options.pollFallbackAfter,a.proxy(function(){this.load()},this)]]})},load:function(){this._loading=setTimeout(a.proxy(function(){var b=new Image;this._onloadImage=b,b.onload=a.proxy(function(){b.onload=function(){},this.supports.naturalWidth||(this.img.naturalWidth=b.width,this.img.naturalHeight=b.height,b.naturalWidth=b.width,b.naturalHeight=b.height),this.success()},this),b.onerror=a.proxy(this.error,this),b.src=this.img.src},this))},success:function(){this._calledSuccess||(this._calledSuccess=!0,this.abort(),this.waitForRender(a.proxy(function(){this.isLoaded=!0,this.successCallback(this)},this)))},error:function(){this._calledError||(this._calledError=!0,this.abort(),this._errorRenderTimeout=setTimeout(a.proxy(function(){this.errorCallback&&this.errorCallback(this)},this)))},abort:function(){this.stopLoading(),this.stopPolling(),this.stopWaitingForRender()},stopPolling:function(){this._poll&&(this._poll.abort(),this._poll=null)},stopLoading:function(){this._loading&&(clearTimeout(this._loading),this._loading=null),this._onloadImage&&(this._onloadImage.onload=function(){},this._onloadImage.onerror=function(){})},waitForRender:function(a){this._renderTimeout=setTimeout(a)},stopWaitingForRender:function(){this._renderTimeout&&(clearTimeout(this._renderTimeout),this._renderTimeout=null),this._errorRenderTimeout&&(clearTimeout(this._errorRenderTimeout),this._errorRenderTimeout=null)}}),c}(jQuery);return b}); \ No newline at end of file