From eb483b9b5e1edcc06daa6bb980810b4accd406f0 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Fri, 15 Jan 2016 09:56:20 -0500 Subject: [PATCH] =?UTF-8?q?=E2=86=94=EF=B8=8F=20switch=20out=20EventEmitte?= =?UTF-8?q?r=20for=20ev-emitter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⬆️ build v4.1.0 use npmcdn for CDN --- README.md | 13 +- bower.json | 5 +- gulpfile.js | 9 +- imagesloaded.js | 28 +- imagesloaded.pkgd.js | 607 +++++++--------------------------- imagesloaded.pkgd.min.js | 4 +- package.json | 4 +- sandbox/background/index.html | 2 +- sandbox/progress/index.html | 2 +- test/index.html | 2 +- 10 files changed, 154 insertions(+), 522 deletions(-) diff --git a/README.md b/README.md index 9e2992a..b4bf90e 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,6 @@ Detect when images have been loaded. - - ## Install ### Download @@ -18,14 +16,14 @@ Detect when images have been loaded. ### CDN ``` html - + - + ``` ### Package managers -Install via npm: `npm install imagesloaded` +Install via [npm](https://www.npmjs.com/package/imagesloaded): `npm install imagesloaded` Install via [Bower](http://bower.io): `bower install imagesloaded --save` @@ -271,8 +269,7 @@ $('#container').imagesLoaded( function() {...}); Install imagesLoaded and [imports-loader](https://github.com/webpack/imports-loader) with npm. ``` bash -npm install imagesLoaded -npm install imports-loader +npm install imagesloaded imports-loader ``` In your config file, `webpack.config.js`, use the imports loader to disable `define` and set window for `imagesloaded`. @@ -282,7 +279,7 @@ module.exports = { module: { loaders: [ { - test: /imagesloaded|wolfy87-eventemitter/, + test: /imagesloaded|ev\-emitter/, loader: 'imports?define=>false&this=>window' } ] diff --git a/bower.json b/bower.json index 0b8bcec..3b78c4c 100644 --- a/bower.json +++ b/bower.json @@ -1,13 +1,12 @@ { "name": "imagesloaded", - "version": "4.0.0", "description": "JavaScript is all like _You images done yet or what?_", "main": "imagesloaded.js", "dependencies": { - "eventEmitter": ">=4.2 <5.0" + "ev-emitter": "~1.0.0" }, "devDependencies": { - "jquery": ">=1.9 <2.0", + "jquery": ">=1.9 <4.0", "qunit": "~1.20.0" }, "ignore": [ diff --git a/gulpfile.js b/gulpfile.js index c926aea..f3f8152 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -144,22 +144,23 @@ var minimist = require('minimist'); gulp.task( 'version', function() { var args = minimist( process.argv.slice(3) ); var version = args.t; - if ( !version || !/\d\.\d\.\d/.test( version ) ) { + if ( !version || !/\d+\.\d+\.\d+/.test( version ) ) { gutil.log( 'invalid version: ' + chalk.red( version ) ); return; } gutil.log( 'ticking version to ' + chalk.green( version ) ); gulp.src('imagesloaded.js') - .pipe( replace( /imagesLoaded v\d\.\d\.\d/, 'imagesLoaded v' + version ) ) + .pipe( replace( /imagesLoaded v\d+\.\d+\.\d+/, 'imagesLoaded v' + version ) ) .pipe( gulp.dest('.') ); gulp.src( [ 'bower.json', 'package.json' ] ) - .pipe( replace( /"version": "\d\.\d\.\d"/, '"version": "' + version + '"' ) ) + .pipe( replace( /"version": "\d+\.\d+\.\d+"/, '"version": "' + version + '"' ) ) .pipe( gulp.dest('.') ); // replace CDN links in README + var minorVersion = version.match( /^\d+\.\d+/ )[0]; gulp.src('README.md') - .pipe( replace( /ajax\/libs\/jquery.imagesloaded\/\d\.\d\.\d/g, 'ajax/libs/jquery.imagesloaded/' + version )) + .pipe( replace( /imagesloaded@\d+\.\d+/g, 'imagesloaded@' + minorVersion )) .pipe( gulp.dest('.') ); }); diff --git a/imagesloaded.js b/imagesloaded.js index c2e4413..c507d24 100644 --- a/imagesloaded.js +++ b/imagesloaded.js @@ -1,5 +1,5 @@ /*! - * imagesLoaded v4.0.0 + * imagesLoaded v4.1.0 * JavaScript is all like "You images are done yet or what?" * MIT License */ @@ -12,21 +12,21 @@ if ( typeof define == 'function' && define.amd ) { // AMD define( [ - 'eventEmitter/EventEmitter' - ], function( EventEmitter ) { - return factory( window, EventEmitter ); + 'ev-emitter/ev-emitter' + ], function( EvEmitter ) { + return factory( window, EvEmitter ); }); } else if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory( window, - require('wolfy87-eventemitter') + require('ev-emitter') ); } else { // browser global window.imagesLoaded = factory( window, - window.EventEmitter + window.EvEmitter ); } @@ -34,7 +34,7 @@ // -------------------------- factory -------------------------- // -function factory( window, EventEmitter ) { +function factory( window, EvEmitter ) { 'use strict'; @@ -112,7 +112,7 @@ function ImagesLoaded( elem, options, onAlways ) { }.bind( this )); } -ImagesLoaded.prototype = Object.create( EventEmitter.prototype ); +ImagesLoaded.prototype = Object.create( EvEmitter.prototype ); ImagesLoaded.prototype.options = {}; @@ -223,7 +223,7 @@ ImagesLoaded.prototype.progress = function( image, elem, message ) { this.progressedCount++; this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded; // progress event - this.emit( 'progress', this, image, elem ); + this.emitEvent( 'progress', [ this, image, elem ] ); if ( this.jqDeferred && this.jqDeferred.notify ) { this.jqDeferred.notify( this, image ); } @@ -240,8 +240,8 @@ ImagesLoaded.prototype.progress = function( image, elem, message ) { ImagesLoaded.prototype.complete = function() { var eventName = this.hasAnyBroken ? 'fail' : 'done'; this.isComplete = true; - this.emit( eventName, this ); - this.emit( 'always', this ); + this.emitEvent( eventName, [ this ] ); + this.emitEvent( 'always', [ this ] ); if ( this.jqDeferred ) { var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve'; this.jqDeferred[ jqMethod ]( this ); @@ -254,7 +254,7 @@ function LoadingImage( img ) { this.img = img; } -LoadingImage.prototype = Object.create( EventEmitter.prototype ); +LoadingImage.prototype = Object.create( EvEmitter.prototype ); LoadingImage.prototype.check = function() { // If complete is true and browser supports natural sizes, @@ -282,7 +282,7 @@ LoadingImage.prototype.getIsImageComplete = function() { LoadingImage.prototype.confirm = function( isLoaded, message ) { this.isLoaded = isLoaded; - this.emit( 'progress', this, this.img, message ); + this.emitEvent( 'progress', [ this, this.img, message ] ); }; // ----- events ----- // @@ -342,7 +342,7 @@ Background.prototype.unbindEvents = function() { Background.prototype.confirm = function( isLoaded, message ) { this.isLoaded = isLoaded; - this.emit( 'progress', this, this.element, message ); + this.emitEvent( 'progress', [ this, this.element, message ] ); }; // -------------------------- jQuery -------------------------- // diff --git a/imagesloaded.pkgd.js b/imagesloaded.pkgd.js index ddfbef4..ef23971 100644 --- a/imagesloaded.pkgd.js +++ b/imagesloaded.pkgd.js @@ -1,486 +1,121 @@ /*! - * imagesLoaded PACKAGED v4.0.0 + * imagesLoaded PACKAGED v4.1.0 * JavaScript is all like "You images are done yet or what?" * MIT License */ -/*! - * EventEmitter v4.2.11 - git.io/ee - * Unlicense - http://unlicense.org/ - * Oliver Caldwell - http://oli.me.uk/ - * @preserve +/** + * EvEmitter v1.0.1 + * Lil' event emitter + * MIT License */ -;(function () { - 'use strict'; - - /** - * Class for managing events. - * Can be extended to provide event functionality in other classes. - * - * @class EventEmitter Manages event registering and emitting. - */ - function EventEmitter() {} - - // Shortcuts to improve speed and size - var proto = EventEmitter.prototype; - var exports = this; - var originalGlobalValue = exports.EventEmitter; - - /** - * Finds the index of the listener for the event in its storage array. - * - * @param {Function[]} listeners Array of listeners to search through. - * @param {Function} listener Method to look for. - * @return {Number} Index of the specified listener, -1 if not found - * @api private - */ - function indexOfListener(listeners, listener) { - var i = listeners.length; - while (i--) { - if (listeners[i].listener === listener) { - return i; - } - } - - return -1; - } +/* jshint unused: true, undef: true, strict: true */ - /** - * Alias a method while keeping the context correct, to allow for overwriting of target method. - * - * @param {String} name The name of the target method. - * @return {Function} The aliased method - * @api private - */ - function alias(name) { - return function aliasClosure() { - return this[name].apply(this, arguments); - }; - } +( function( global, factory ) { + // universal module definition + /* jshint strict: false */ /* globals define, module */ + if ( typeof define == 'function' && define.amd ) { + // AMD - RequireJS + define( 'ev-emitter/ev-emitter',factory ); + } else if ( typeof module == 'object' && module.exports ) { + // CommonJS - Browserify, Webpack + module.exports = factory(); + } else { + // Browser globals + global.EvEmitter = factory(); + } - /** - * Returns the listener array for the specified event. - * Will initialise the event object and listener arrays if required. - * Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them. - * Each property in the object response is an array of listener functions. - * - * @param {String|RegExp} evt Name of the event to return the listeners from. - * @return {Function[]|Object} All listener functions for the event. - */ - proto.getListeners = function getListeners(evt) { - var events = this._getEvents(); - var response; - var key; - - // Return a concatenated array of all matching events if - // the selector is a regular expression. - if (evt instanceof RegExp) { - response = {}; - for (key in events) { - if (events.hasOwnProperty(key) && evt.test(key)) { - response[key] = events[key]; - } - } - } - else { - response = events[evt] || (events[evt] = []); - } - - return response; - }; - - /** - * Takes a list of listener objects and flattens it into a list of listener functions. - * - * @param {Object[]} listeners Raw listener objects. - * @return {Function[]} Just the listener functions. - */ - proto.flattenListeners = function flattenListeners(listeners) { - var flatListeners = []; - var i; - - for (i = 0; i < listeners.length; i += 1) { - flatListeners.push(listeners[i].listener); - } - - return flatListeners; - }; - - /** - * Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful. - * - * @param {String|RegExp} evt Name of the event to return the listeners from. - * @return {Object} All listener functions for an event in an object. - */ - proto.getListenersAsObject = function getListenersAsObject(evt) { - var listeners = this.getListeners(evt); - var response; - - if (listeners instanceof Array) { - response = {}; - response[evt] = listeners; - } - - return response || listeners; - }; - - /** - * Adds a listener function to the specified event. - * The listener will not be added if it is a duplicate. - * If the listener returns true then it will be removed after it is called. - * If you pass a regular expression as the event name then the listener will be added to all events that match it. - * - * @param {String|RegExp} evt Name of the event to attach the listener to. - * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.addListener = function addListener(evt, listener) { - var listeners = this.getListenersAsObject(evt); - var listenerIsWrapped = typeof listener === 'object'; - var key; - - for (key in listeners) { - if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) { - listeners[key].push(listenerIsWrapped ? listener : { - listener: listener, - once: false - }); - } - } - - return this; - }; - - /** - * Alias of addListener - */ - proto.on = alias('addListener'); - - /** - * Semi-alias of addListener. It will add a listener that will be - * automatically removed after its first execution. - * - * @param {String|RegExp} evt Name of the event to attach the listener to. - * @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.addOnceListener = function addOnceListener(evt, listener) { - return this.addListener(evt, { - listener: listener, - once: true - }); - }; - - /** - * Alias of addOnceListener. - */ - proto.once = alias('addOnceListener'); - - /** - * Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad. - * You need to tell it what event names should be matched by a regex. - * - * @param {String} evt Name of the event to create. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.defineEvent = function defineEvent(evt) { - this.getListeners(evt); - return this; - }; - - /** - * Uses defineEvent to define multiple events. - * - * @param {String[]} evts An array of event names to define. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.defineEvents = function defineEvents(evts) { - for (var i = 0; i < evts.length; i += 1) { - this.defineEvent(evts[i]); - } - return this; - }; - - /** - * Removes a listener function from the specified event. - * When passed a regular expression as the event name, it will remove the listener from all events that match it. - * - * @param {String|RegExp} evt Name of the event to remove the listener from. - * @param {Function} listener Method to remove from the event. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.removeListener = function removeListener(evt, listener) { - var listeners = this.getListenersAsObject(evt); - var index; - var key; - - for (key in listeners) { - if (listeners.hasOwnProperty(key)) { - index = indexOfListener(listeners[key], listener); - - if (index !== -1) { - listeners[key].splice(index, 1); - } - } - } - - return this; - }; - - /** - * Alias of removeListener - */ - proto.off = alias('removeListener'); - - /** - * Adds listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added. - * You can also pass it a regular expression to add the array of listeners to all events that match it. - * Yeah, this function does quite a bit. That's probably a bad thing. - * - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once. - * @param {Function[]} [listeners] An optional array of listener functions to add. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.addListeners = function addListeners(evt, listeners) { - // Pass through to manipulateListeners - return this.manipulateListeners(false, evt, listeners); - }; - - /** - * Removes listeners in bulk using the manipulateListeners method. - * If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. - * You can also pass it an event name and an array of listeners to be removed. - * You can also pass it a regular expression to remove the listeners from all events that match it. - * - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once. - * @param {Function[]} [listeners] An optional array of listener functions to remove. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.removeListeners = function removeListeners(evt, listeners) { - // Pass through to manipulateListeners - return this.manipulateListeners(true, evt, listeners); - }; - - /** - * Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level. - * The first argument will determine if the listeners are removed (true) or added (false). - * If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. - * You can also pass it an event name and an array of listeners to be added/removed. - * You can also pass it a regular expression to manipulate the listeners of all events that match it. - * - * @param {Boolean} remove True if you want to remove listeners, false if you want to add. - * @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once. - * @param {Function[]} [listeners] An optional array of listener functions to add/remove. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) { - var i; - var value; - var single = remove ? this.removeListener : this.addListener; - var multiple = remove ? this.removeListeners : this.addListeners; - - // If evt is an object then pass each of its properties to this method - if (typeof evt === 'object' && !(evt instanceof RegExp)) { - for (i in evt) { - if (evt.hasOwnProperty(i) && (value = evt[i])) { - // Pass the single listener straight through to the singular method - if (typeof value === 'function') { - single.call(this, i, value); - } - else { - // Otherwise pass back to the multiple function - multiple.call(this, i, value); - } - } - } - } - else { - // So evt must be a string - // And listeners must be an array of listeners - // Loop over it and pass each one to the multiple method - i = listeners.length; - while (i--) { - single.call(this, evt, listeners[i]); - } - } - - return this; - }; - - /** - * Removes all listeners from a specified event. - * If you do not specify an event then all listeners will be removed. - * That means every event will be emptied. - * You can also pass a regex to remove all events that match it. - * - * @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.removeEvent = function removeEvent(evt) { - var type = typeof evt; - var events = this._getEvents(); - var key; - - // Remove different things depending on the state of evt - if (type === 'string') { - // Remove all listeners for the specified event - delete events[evt]; - } - else if (evt instanceof RegExp) { - // Remove all events matching the regex. - for (key in events) { - if (events.hasOwnProperty(key) && evt.test(key)) { - delete events[key]; - } - } - } - else { - // Remove all listeners in all events - delete this._events; - } - - return this; - }; - - /** - * Alias of removeEvent. - * - * Added to mirror the node API. - */ - proto.removeAllListeners = alias('removeEvent'); - - /** - * Emits an event of your choice. - * When emitted, every listener attached to that event will be executed. - * If you pass the optional argument array then those arguments will be passed to every listener upon execution. - * Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately. - * So they will not arrive within the array on the other side, they will be separate. - * You can also pass a regular expression to emit to all events that match it. - * - * @param {String|RegExp} evt Name of the event to emit and execute listeners for. - * @param {Array} [args] Optional array of arguments to be passed to each listener. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.emitEvent = function emitEvent(evt, args) { - var listenersMap = this.getListenersAsObject(evt); - var listeners; - var listener; - var i; - var key; - var response; - - for (key in listenersMap) { - if (listenersMap.hasOwnProperty(key)) { - listeners = listenersMap[key].slice(0); - i = listeners.length; - - while (i--) { - // If the listener returns true then it shall be removed from the event - // The function is executed either with a basic call or an apply if there is an args array - listener = listeners[i]; - - if (listener.once === true) { - this.removeListener(evt, listener.listener); - } - - response = listener.listener.apply(this, args || []); - - if (response === this._getOnceReturnValue()) { - this.removeListener(evt, listener.listener); - } - } - } - } - - return this; - }; - - /** - * Alias of emitEvent - */ - proto.trigger = alias('emitEvent'); - - /** - * Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on. - * As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it. - * - * @param {String|RegExp} evt Name of the event to emit and execute listeners for. - * @param {...*} Optional additional arguments to be passed to each listener. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.emit = function emit(evt) { - var args = Array.prototype.slice.call(arguments, 1); - return this.emitEvent(evt, args); - }; - - /** - * Sets the current value to check against when executing listeners. If a - * listeners return value matches the one set here then it will be removed - * after execution. This value defaults to true. - * - * @param {*} value The new value to check for when executing listeners. - * @return {Object} Current instance of EventEmitter for chaining. - */ - proto.setOnceReturnValue = function setOnceReturnValue(value) { - this._onceReturnValue = value; - return this; - }; - - /** - * Fetches the current value to check against when executing listeners. If - * the listeners return value matches this one then it should be removed - * automatically. It will return true by default. - * - * @return {*|Boolean} The current value to check for or the default, true. - * @api private - */ - proto._getOnceReturnValue = function _getOnceReturnValue() { - if (this.hasOwnProperty('_onceReturnValue')) { - return this._onceReturnValue; - } - else { - return true; - } - }; - - /** - * Fetches the events object and creates one if required. - * - * @return {Object} The events storage object. - * @api private - */ - proto._getEvents = function _getEvents() { - return this._events || (this._events = {}); - }; - - /** - * Reverts the global {@link EventEmitter} to its previous value and returns a reference to this version. - * - * @return {Function} Non conflicting EventEmitter class. - */ - EventEmitter.noConflict = function noConflict() { - exports.EventEmitter = originalGlobalValue; - return EventEmitter; - }; - - // Expose the class either via AMD, CommonJS or the global object - if (typeof define === 'function' && define.amd) { - define('eventEmitter/EventEmitter',[],function () { - return EventEmitter; - }); - } - else if (typeof module === 'object' && module.exports){ - module.exports = EventEmitter; - } - else { - exports.EventEmitter = EventEmitter; +}( this, function() { + + + +function EvEmitter() {} + +var proto = EvEmitter.prototype; + +proto.on = function( eventName, listener ) { + if ( !eventName || !listener ) { + return; + } + // set events hash + var events = this._events = this._events || {}; + // set listeners array + var listeners = events[ eventName ] = events[ eventName ] || []; + // only add once + if ( listeners.indexOf( listener ) == -1 ) { + listeners.push( listener ); + } + + return this; +}; + +proto.once = function( eventName, listener ) { + if ( !eventName || !listener ) { + return; + } + // add event + this.on( eventName, listener ); + // set once flag + // set onceEvents hash + var onceEvents = this._onceEvents = this._onceEvents || {}; + // set onceListeners array + var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || []; + // set flag + onceListeners[ listener ] = true; + + return this; +}; + +proto.off = function( eventName, listener ) { + var listeners = this._events && this._events[ eventName ]; + if ( !listeners || !listeners.length ) { + return; + } + var index = listeners.indexOf( listener ); + if ( index != -1 ) { + listeners.splice( index, 1 ); + } + + return this; +}; + +proto.emitEvent = function( eventName, args ) { + var listeners = this._events && this._events[ eventName ]; + if ( !listeners || !listeners.length ) { + return; + } + var i = 0; + var listener = listeners[i]; + args = args || []; + // once stuff + var onceListeners = this._onceEvents && this._onceEvents[ eventName ]; + + while ( listener ) { + var isOnce = onceListeners && onceListeners[ listener ]; + if ( isOnce ) { + // remove listener + // remove before trigger to prevent recursion + this.off( eventName, listener ); + // unset once flag + delete onceListeners[ listener ]; } -}.call(this)); + // trigger listener + listener.apply( this, args ); + // get next listener + i += isOnce ? 0 : 1; + listener = listeners[i]; + } + + return this; +}; + +return EvEmitter; + +})); /*! - * imagesLoaded v4.0.0 + * imagesLoaded v4.1.0 * JavaScript is all like "You images are done yet or what?" * MIT License */ @@ -493,21 +128,21 @@ if ( typeof define == 'function' && define.amd ) { // AMD define( [ - 'eventEmitter/EventEmitter' - ], function( EventEmitter ) { - return factory( window, EventEmitter ); + 'ev-emitter/ev-emitter' + ], function( EvEmitter ) { + return factory( window, EvEmitter ); }); } else if ( typeof module == 'object' && module.exports ) { // CommonJS module.exports = factory( window, - require('wolfy87-eventemitter') + require('ev-emitter') ); } else { // browser global window.imagesLoaded = factory( window, - window.EventEmitter + window.EvEmitter ); } @@ -515,7 +150,7 @@ // -------------------------- factory -------------------------- // -function factory( window, EventEmitter ) { +function factory( window, EvEmitter ) { @@ -593,7 +228,7 @@ function ImagesLoaded( elem, options, onAlways ) { }.bind( this )); } -ImagesLoaded.prototype = Object.create( EventEmitter.prototype ); +ImagesLoaded.prototype = Object.create( EvEmitter.prototype ); ImagesLoaded.prototype.options = {}; @@ -704,7 +339,7 @@ ImagesLoaded.prototype.progress = function( image, elem, message ) { this.progressedCount++; this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded; // progress event - this.emit( 'progress', this, image, elem ); + this.emitEvent( 'progress', [ this, image, elem ] ); if ( this.jqDeferred && this.jqDeferred.notify ) { this.jqDeferred.notify( this, image ); } @@ -721,8 +356,8 @@ ImagesLoaded.prototype.progress = function( image, elem, message ) { ImagesLoaded.prototype.complete = function() { var eventName = this.hasAnyBroken ? 'fail' : 'done'; this.isComplete = true; - this.emit( eventName, this ); - this.emit( 'always', this ); + this.emitEvent( eventName, [ this ] ); + this.emitEvent( 'always', [ this ] ); if ( this.jqDeferred ) { var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve'; this.jqDeferred[ jqMethod ]( this ); @@ -735,7 +370,7 @@ function LoadingImage( img ) { this.img = img; } -LoadingImage.prototype = Object.create( EventEmitter.prototype ); +LoadingImage.prototype = Object.create( EvEmitter.prototype ); LoadingImage.prototype.check = function() { // If complete is true and browser supports natural sizes, @@ -763,7 +398,7 @@ LoadingImage.prototype.getIsImageComplete = function() { LoadingImage.prototype.confirm = function( isLoaded, message ) { this.isLoaded = isLoaded; - this.emit( 'progress', this, this.img, message ); + this.emitEvent( 'progress', [ this, this.img, message ] ); }; // ----- events ----- // @@ -817,13 +452,13 @@ Background.prototype.check = function() { }; Background.prototype.unbindEvents = function() { - this.img.addEventListener( 'load', this ); - this.img.addEventListener( 'error', this ); + this.img.removeEventListener( 'load', this ); + this.img.removeEventListener( 'error', this ); }; Background.prototype.confirm = function( isLoaded, message ) { this.isLoaded = isLoaded; - this.emit( 'progress', this, this.element, message ); + this.emitEvent( 'progress', [ this, this.element, message ] ); }; // -------------------------- jQuery -------------------------- // diff --git a/imagesloaded.pkgd.min.js b/imagesloaded.pkgd.min.js index c484256..c3e71fa 100644 --- a/imagesloaded.pkgd.min.js +++ b/imagesloaded.pkgd.min.js @@ -1,7 +1,7 @@ /*! - * imagesLoaded PACKAGED v4.0.0 + * imagesLoaded PACKAGED v4.1.0 * JavaScript is all like "You images are done yet or what?" * MIT License */ -(function(){"use strict";function e(){}function t(e,t){for(var n=e.length;n--;)if(e[n].listener===t)return n;return-1}function n(e){return function(){return this[e].apply(this,arguments)}}var i=e.prototype,r=this,s=r.EventEmitter;i.getListeners=function(e){var t,n,i=this._getEvents();if(e instanceof RegExp){t={};for(n in i)i.hasOwnProperty(n)&&e.test(n)&&(t[n]=i[n])}else t=i[e]||(i[e]=[]);return t},i.flattenListeners=function(e){var t,n=[];for(t=0;t=4.2 <5.0" + "ev-emitter": "~1.0.0" }, "devDependencies": { "chalk": "^1.1.1", diff --git a/sandbox/background/index.html b/sandbox/background/index.html index b07398f..853f8ff 100644 --- a/sandbox/background/index.html +++ b/sandbox/background/index.html @@ -22,7 +22,7 @@

background

- + + diff --git a/test/index.html b/test/index.html index 3f19f11..4c5c603 100644 --- a/test/index.html +++ b/test/index.html @@ -8,7 +8,7 @@ - +