Skip to content

Commit

Permalink
↔️ switch out EventEmitter for ev-emitter
Browse files Browse the repository at this point in the history
⬆️ build v4.1.0

use npmcdn for CDN
  • Loading branch information
desandro committed Jan 15, 2016
1 parent b6b1ec8 commit eb483b9
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 522 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

Detect when images have been loaded.

<!-- demo -->

## Install

### Download
Expand All @@ -18,14 +16,14 @@ Detect when images have been loaded.
### CDN

``` html
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.0.0/imagesloaded.pkgd.min.js"></script>
<script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.min.js"></script>
<!-- or -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.0.0/imagesloaded.pkgd.js"></script>
<script src="https://npmcdn.com/imagesloaded@4.1/imagesloaded.pkgd.js"></script>
```

### 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`

Expand Down Expand Up @@ -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`.
Expand All @@ -282,7 +279,7 @@ module.exports = {
module: {
loaders: [
{
test: /imagesloaded|wolfy87-eventemitter/,
test: /imagesloaded|ev\-emitter/,
loader: 'imports?define=>false&this=>window'
}
]
Expand Down
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
9 changes: 5 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.') );
});

Expand Down
28 changes: 14 additions & 14 deletions imagesloaded.js
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -12,29 +12,29 @@
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
);
}

})( window,

// -------------------------- factory -------------------------- //

function factory( window, EventEmitter ) {
function factory( window, EvEmitter ) {

'use strict';

Expand Down Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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 );
}
Expand All @@ -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 );
Expand All @@ -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,
Expand Down Expand Up @@ -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 ----- //
Expand Down Expand Up @@ -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 -------------------------- //
Expand Down
Loading

0 comments on commit eb483b9

Please sign in to comment.