imagesLoaded_rails 3.0.4 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjhmNTllZTI0ZDE4ZDk0YzcyZDJkZmFlNzU3ZjRmMzY0ZTg0OTY2MA==
4
+ YTZmM2JhYWU2MjkxOTY5NzI1YzAwM2VhNjE3ZGYwODc5NGIwZTMyNw==
5
5
  data.tar.gz: !binary |-
6
- ZTg4N2JjZGExMTBiM2EwMzVkYzc2YTc0MmNlZmE3NDU0MGJhMzc5NQ==
6
+ YTc2YmQ5MDNlOTQ3MjcxOGM4M2ZlM2ZkOTFmMmE3NDhhMDJkOGQ0OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzQwYWNkOWY5YzczOWVmNWMwZWY5YzVmNmY0ZWU4MjA5YmVmZjQxY2I3Y2Q5
10
- NTczZWJhYzQ5YmUyYmE1NTgxZGEwZDExM2VkZGM1ZDYzM2VhOWI5NmM1MDQy
11
- OTEzZTYwMWQ3ZTljNjZlODMzOTBkODlmZjQwM2VkYzUzNmUwMjY=
9
+ NDQ3YWI5ZTU3OGVmOTMzNzIyNjA5ODAzMDgwOTRlNDc0MWIyNTFmNmZiMjNh
10
+ YjY2N2JmY2RjMTc4MTUyMzA4NjcwYWU5MDJmZTA2NWQwMzJlMjkxZGQzODFj
11
+ NjcyOTYxOGI1MWY0MjZhNzVmM2ZmMWMwMDA0ZWY0Y2JkMTgyNjg=
12
12
  data.tar.gz: !binary |-
13
- MzE0ODI4NzdkMzBlMTdmNjZiZmZkZjI3YTc2YmQ0MTY5YjE1OGZhOWNkZGI4
14
- ZWUzOTY3MmM5M2NlMjMyODMzOTRiOTA3MjdhNDI1NGQxNDU0NTMxMDQwODNj
15
- MjI4ODVkNzllNjcyNDQzNjdlMjA0MDI4M2ZlYmRkMjBiZmRkN2U=
13
+ NDBkODViMDE4ODVkMzZkMTViM2ZmODkxZTQ1NWY1ZjliMTdhNWJhNDljN2Zm
14
+ NDVhZThkZjQyMWM0YWNiZTQ1NjBlMGRhZDk3Y2I4ZGYwZmFiNzQwODAwM2E4
15
+ ZTkxYWRkM2ZlOGE0NThmM2M1YTk3ZjNkZTU1MTE4YTZhNTg5NGE=
@@ -1,10 +1,7 @@
1
1
  /*!
2
- * imagesLoaded.js v3.0.4
2
+ * imagesLoaded v3.1.1
3
3
  * JavaScript is all like "You images are done yet or what?"
4
- * Tomas Sardyha @Darsain and David DeSandro @desandro.
5
- * MIT license - http://desandro.mit-license.org/
6
- * http://desandro.github.io/imagesloaded/
7
- * source - https://github.com/desandro/imagesloaded
4
+ * MIT License
8
5
  */
9
6
 
10
7
  ( function( window ) {
@@ -196,8 +193,6 @@ function defineImagesLoaded( EventEmitter, eventie ) {
196
193
 
197
194
  // -------------------------- -------------------------- //
198
195
 
199
- var cache = {};
200
-
201
196
  function LoadingImage( img ) {
202
197
  this.img = img;
203
198
  }
@@ -206,13 +201,11 @@ function defineImagesLoaded( EventEmitter, eventie ) {
206
201
 
207
202
  LoadingImage.prototype.check = function() {
208
203
  // first check cached any previous images that have same src
209
- var cached = cache[ this.img.src ];
210
- if ( cached ) {
211
- this.useCached( cached );
204
+ var resource = cache[ this.img.src ] || new Resource( this.img.src );
205
+ if ( resource.isConfirmed ) {
206
+ this.confirm( resource.isLoaded, 'cached was confirmed' );
212
207
  return;
213
208
  }
214
- // add this to cache
215
- cache[ this.img.src ] = this;
216
209
 
217
210
  // If complete is true and browser supports natural sizes,
218
211
  // try to check for image status manually.
@@ -223,51 +216,80 @@ function defineImagesLoaded( EventEmitter, eventie ) {
223
216
  }
224
217
 
225
218
  // If none of the checks above matched, simulate loading on detached element.
226
- var proxyImage = this.proxyImage = new Image();
227
- eventie.bind( proxyImage, 'load', this );
228
- eventie.bind( proxyImage, 'error', this );
229
- proxyImage.src = this.img.src;
230
- };
219
+ var _this = this;
220
+ resource.on( 'confirm', function( resrc, message ) {
221
+ _this.confirm( resrc.isLoaded, message );
222
+ return true;
223
+ });
231
224
 
232
- LoadingImage.prototype.useCached = function( cached ) {
233
- if ( cached.isConfirmed ) {
234
- this.confirm( cached.isLoaded, 'cached was confirmed' );
235
- } else {
236
- var _this = this;
237
- cached.on( 'confirm', function( image ) {
238
- _this.confirm( image.isLoaded, 'cache emitted confirmed' );
239
- return true; // bind once
240
- });
241
- }
225
+ resource.check();
242
226
  };
243
227
 
244
228
  LoadingImage.prototype.confirm = function( isLoaded, message ) {
245
- this.isConfirmed = true;
246
229
  this.isLoaded = isLoaded;
247
230
  this.emit( 'confirm', this, message );
248
231
  };
249
232
 
233
+ // -------------------------- Resource -------------------------- //
234
+
235
+ // Resource checks each src, only once
236
+ // separate class from LoadingImage to prevent memory leaks. See #115
237
+
238
+ var cache = {};
239
+
240
+ function Resource( src ) {
241
+ this.src = src;
242
+ // add to cache
243
+ cache[ src ] = this;
244
+ }
245
+
246
+ Resource.prototype = new EventEmitter();
247
+
248
+ Resource.prototype.check = function() {
249
+ // only trigger checking once
250
+ if ( this.isChecked ) {
251
+ return;
252
+ }
253
+ // simulate loading on detached element
254
+ var proxyImage = new Image();
255
+ eventie.bind( proxyImage, 'load', this );
256
+ eventie.bind( proxyImage, 'error', this );
257
+ proxyImage.src = this.src;
258
+ // set flag
259
+ this.isChecked = true;
260
+ };
261
+
262
+ // ----- events ----- //
263
+
250
264
  // trigger specified handler for event type
251
- LoadingImage.prototype.handleEvent = function( event ) {
265
+ Resource.prototype.handleEvent = function( event ) {
252
266
  var method = 'on' + event.type;
253
267
  if ( this[ method ] ) {
254
268
  this[ method ]( event );
255
269
  }
256
270
  };
257
271
 
258
- LoadingImage.prototype.onload = function() {
272
+ Resource.prototype.onload = function( event ) {
259
273
  this.confirm( true, 'onload' );
260
- this.unbindProxyEvents();
274
+ this.unbindProxyEvents( event );
261
275
  };
262
276
 
263
- LoadingImage.prototype.onerror = function() {
277
+ Resource.prototype.onerror = function( event ) {
264
278
  this.confirm( false, 'onerror' );
265
- this.unbindProxyEvents();
279
+ this.unbindProxyEvents( event );
280
+ };
281
+
282
+ // ----- confirm ----- //
283
+
284
+ Resource.prototype.confirm = function( isLoaded, message ) {
285
+ this.isConfirmed = true;
286
+ this.isLoaded = isLoaded;
287
+ this.emit( 'confirm', this, message );
266
288
  };
267
289
 
268
- LoadingImage.prototype.unbindProxyEvents = function() {
269
- eventie.unbind( this.proxyImage, 'load', this );
270
- eventie.unbind( this.proxyImage, 'error', this );
290
+ Resource.prototype.unbindProxyEvents = function( event ) {
291
+ eventie.unbind( event.target, 'load', this );
292
+ eventie.unbind( event.target, 'error', this );
271
293
  };
272
294
 
273
295
  // ----- ----- //
@@ -1,3 +1,3 @@
1
1
  module ImagesLoadedRails
2
- VERSION = "3.0.4"
2
+ VERSION = "3.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imagesLoaded_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guy Israeli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-15 00:00:00.000000000 Z
11
+ date: 2014-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler