imagesLoaded_rails 3.0.4

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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MjhmNTllZTI0ZDE4ZDk0YzcyZDJkZmFlNzU3ZjRmMzY0ZTg0OTY2MA==
5
+ data.tar.gz: !binary |-
6
+ ZTg4N2JjZGExMTBiM2EwMzVkYzc2YTc0MmNlZmE3NDU0MGJhMzc5NQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MzQwYWNkOWY5YzczOWVmNWMwZWY5YzVmNmY0ZWU4MjA5YmVmZjQxY2I3Y2Q5
10
+ NTczZWJhYzQ5YmUyYmE1NTgxZGEwZDExM2VkZGM1ZDYzM2VhOWI5NmM1MDQy
11
+ OTEzZTYwMWQ3ZTljNjZlODMzOTBkODlmZjQwM2VkYzUzNmUwMjY=
12
+ data.tar.gz: !binary |-
13
+ MzE0ODI4NzdkMzBlMTdmNjZiZmZkZjI3YTc2YmQ0MTY5YjE1OGZhOWNkZGI4
14
+ ZWUzOTY3MmM5M2NlMjMyODMzOTRiOTA3MjdhNDI1NGQxNDU0NTMxMDQwODNj
15
+ MjI4ODVkNzllNjcyNDQzNjdlMjA0MDI4M2ZlYmRkMjBiZmRkN2U=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imagesLoaded_rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Guy Israeli
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # ImagesLoadedRails
2
+
3
+ asset pipeline wrapper for imagesLoaded.js - Detect when images have been loaded.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'imagesLoaded_rails'
11
+
12
+ and add to application.js manifest
13
+
14
+ //= require imagesloaded
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install imagesLoaded_rails
23
+
24
+ ## Usage
25
+
26
+
27
+ imagesLoaded( elem, callback )
28
+
29
+ and in jQuery
30
+
31
+ $('#container').imagesLoaded( function() {
32
+ // images have loaded
33
+ });
34
+
35
+ see https://github.com/desandro/imagesloaded for more info
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,295 @@
1
+ /*!
2
+ * imagesLoaded.js v3.0.4
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
8
+ */
9
+
10
+ ( function( window ) {
11
+
12
+ 'use strict';
13
+
14
+ var $ = window.jQuery;
15
+ var console = window.console;
16
+ var hasConsole = typeof console !== 'undefined';
17
+
18
+ // -------------------------- helpers -------------------------- //
19
+
20
+ // extend objects
21
+ function extend( a, b ) {
22
+ for ( var prop in b ) {
23
+ a[ prop ] = b[ prop ];
24
+ }
25
+ return a;
26
+ }
27
+
28
+ var objToString = Object.prototype.toString;
29
+ function isArray( obj ) {
30
+ return objToString.call( obj ) === '[object Array]';
31
+ }
32
+
33
+ // turn element or nodeList into an array
34
+ function makeArray( obj ) {
35
+ var ary = [];
36
+ if ( isArray( obj ) ) {
37
+ // use object if already an array
38
+ ary = obj;
39
+ } else if ( typeof obj.length === 'number' ) {
40
+ // convert nodeList to array
41
+ for ( var i=0, len = obj.length; i < len; i++ ) {
42
+ ary.push( obj[i] );
43
+ }
44
+ } else {
45
+ // array of single index
46
+ ary.push( obj );
47
+ }
48
+ return ary;
49
+ }
50
+
51
+ // -------------------------- -------------------------- //
52
+
53
+ function defineImagesLoaded( EventEmitter, eventie ) {
54
+
55
+ /**
56
+ * @param {Array, Element, NodeList, String} elem
57
+ * @param {Object or Function} options - if function, use as callback
58
+ * @param {Function} onAlways - callback function
59
+ */
60
+ function ImagesLoaded( elem, options, onAlways ) {
61
+ // coerce ImagesLoaded() without new, to be new ImagesLoaded()
62
+ if ( !( this instanceof ImagesLoaded ) ) {
63
+ return new ImagesLoaded( elem, options );
64
+ }
65
+ // use elem as selector string
66
+ if ( typeof elem === 'string' ) {
67
+ elem = document.querySelectorAll( elem );
68
+ }
69
+
70
+ this.elements = makeArray( elem );
71
+ this.options = extend( {}, this.options );
72
+
73
+ if ( typeof options === 'function' ) {
74
+ onAlways = options;
75
+ } else {
76
+ extend( this.options, options );
77
+ }
78
+
79
+ if ( onAlways ) {
80
+ this.on( 'always', onAlways );
81
+ }
82
+
83
+ this.getImages();
84
+
85
+ if ( $ ) {
86
+ // add jQuery Deferred object
87
+ this.jqDeferred = new $.Deferred();
88
+ }
89
+
90
+ // HACK check async to allow time to bind listeners
91
+ var _this = this;
92
+ setTimeout( function() {
93
+ _this.check();
94
+ });
95
+ }
96
+
97
+ ImagesLoaded.prototype = new EventEmitter();
98
+
99
+ ImagesLoaded.prototype.options = {};
100
+
101
+ ImagesLoaded.prototype.getImages = function() {
102
+ this.images = [];
103
+
104
+ // filter & find items if we have an item selector
105
+ for ( var i=0, len = this.elements.length; i < len; i++ ) {
106
+ var elem = this.elements[i];
107
+ // filter siblings
108
+ if ( elem.nodeName === 'IMG' ) {
109
+ this.addImage( elem );
110
+ }
111
+ // find children
112
+ var childElems = elem.querySelectorAll('img');
113
+ // concat childElems to filterFound array
114
+ for ( var j=0, jLen = childElems.length; j < jLen; j++ ) {
115
+ var img = childElems[j];
116
+ this.addImage( img );
117
+ }
118
+ }
119
+ };
120
+
121
+ /**
122
+ * @param {Image} img
123
+ */
124
+ ImagesLoaded.prototype.addImage = function( img ) {
125
+ var loadingImage = new LoadingImage( img );
126
+ this.images.push( loadingImage );
127
+ };
128
+
129
+ ImagesLoaded.prototype.check = function() {
130
+ var _this = this;
131
+ var checkedCount = 0;
132
+ var length = this.images.length;
133
+ this.hasAnyBroken = false;
134
+ // complete if no images
135
+ if ( !length ) {
136
+ this.complete();
137
+ return;
138
+ }
139
+
140
+ function onConfirm( image, message ) {
141
+ if ( _this.options.debug && hasConsole ) {
142
+ console.log( 'confirm', image, message );
143
+ }
144
+
145
+ _this.progress( image );
146
+ checkedCount++;
147
+ if ( checkedCount === length ) {
148
+ _this.complete();
149
+ }
150
+ return true; // bind once
151
+ }
152
+
153
+ for ( var i=0; i < length; i++ ) {
154
+ var loadingImage = this.images[i];
155
+ loadingImage.on( 'confirm', onConfirm );
156
+ loadingImage.check();
157
+ }
158
+ };
159
+
160
+ ImagesLoaded.prototype.progress = function( image ) {
161
+ this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
162
+ // HACK - Chrome triggers event before object properties have changed. #83
163
+ var _this = this;
164
+ setTimeout( function() {
165
+ _this.emit( 'progress', _this, image );
166
+ if ( _this.jqDeferred ) {
167
+ _this.jqDeferred.notify( _this, image );
168
+ }
169
+ });
170
+ };
171
+
172
+ ImagesLoaded.prototype.complete = function() {
173
+ var eventName = this.hasAnyBroken ? 'fail' : 'done';
174
+ this.isComplete = true;
175
+ var _this = this;
176
+ // HACK - another setTimeout so that confirm happens after progress
177
+ setTimeout( function() {
178
+ _this.emit( eventName, _this );
179
+ _this.emit( 'always', _this );
180
+ if ( _this.jqDeferred ) {
181
+ var jqMethod = _this.hasAnyBroken ? 'reject' : 'resolve';
182
+ _this.jqDeferred[ jqMethod ]( _this );
183
+ }
184
+ });
185
+ };
186
+
187
+ // -------------------------- jquery -------------------------- //
188
+
189
+ if ( $ ) {
190
+ $.fn.imagesLoaded = function( options, callback ) {
191
+ var instance = new ImagesLoaded( this, options, callback );
192
+ return instance.jqDeferred.promise( $(this) );
193
+ };
194
+ }
195
+
196
+
197
+ // -------------------------- -------------------------- //
198
+
199
+ var cache = {};
200
+
201
+ function LoadingImage( img ) {
202
+ this.img = img;
203
+ }
204
+
205
+ LoadingImage.prototype = new EventEmitter();
206
+
207
+ LoadingImage.prototype.check = function() {
208
+ // first check cached any previous images that have same src
209
+ var cached = cache[ this.img.src ];
210
+ if ( cached ) {
211
+ this.useCached( cached );
212
+ return;
213
+ }
214
+ // add this to cache
215
+ cache[ this.img.src ] = this;
216
+
217
+ // If complete is true and browser supports natural sizes,
218
+ // try to check for image status manually.
219
+ if ( this.img.complete && this.img.naturalWidth !== undefined ) {
220
+ // report based on naturalWidth
221
+ this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
222
+ return;
223
+ }
224
+
225
+ // 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
+ };
231
+
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
+ }
242
+ };
243
+
244
+ LoadingImage.prototype.confirm = function( isLoaded, message ) {
245
+ this.isConfirmed = true;
246
+ this.isLoaded = isLoaded;
247
+ this.emit( 'confirm', this, message );
248
+ };
249
+
250
+ // trigger specified handler for event type
251
+ LoadingImage.prototype.handleEvent = function( event ) {
252
+ var method = 'on' + event.type;
253
+ if ( this[ method ] ) {
254
+ this[ method ]( event );
255
+ }
256
+ };
257
+
258
+ LoadingImage.prototype.onload = function() {
259
+ this.confirm( true, 'onload' );
260
+ this.unbindProxyEvents();
261
+ };
262
+
263
+ LoadingImage.prototype.onerror = function() {
264
+ this.confirm( false, 'onerror' );
265
+ this.unbindProxyEvents();
266
+ };
267
+
268
+ LoadingImage.prototype.unbindProxyEvents = function() {
269
+ eventie.unbind( this.proxyImage, 'load', this );
270
+ eventie.unbind( this.proxyImage, 'error', this );
271
+ };
272
+
273
+ // ----- ----- //
274
+
275
+ return ImagesLoaded;
276
+ }
277
+
278
+ // -------------------------- transport -------------------------- //
279
+
280
+ if ( typeof define === 'function' && define.amd ) {
281
+ // AMD
282
+ define( [
283
+ 'eventEmitter/EventEmitter',
284
+ 'eventie/eventie'
285
+ ],
286
+ defineImagesLoaded );
287
+ } else {
288
+ // browser global
289
+ window.imagesLoaded = defineImagesLoaded(
290
+ window.EventEmitter,
291
+ window.eventie
292
+ );
293
+ }
294
+
295
+ })( window );
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imagesLoaded_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imagesLoaded_rails"
8
+ spec.version = ImagesLoadedRails::VERSION
9
+ spec.authors = ["Guy Israeli"]
10
+ spec.description = %q{imagesLoaded.js Wrapper for Rails 3.1+ Asset Pipeline }
11
+ spec.summary = %q{Asset pipeline is like "I'll take care of that js for you sir" and Rails is like "You know thats right! and what about them images?!"}
12
+ spec.homepage = "https://github.com/guyisra/imagesLoaded-rails"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_dependency "railties", ">=3.1"
23
+
24
+ end
@@ -0,0 +1,8 @@
1
+ require "imagesLoaded_rails/version"
2
+
3
+ module ImagesLoadedRails
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ImagesLoadedRails
2
+ VERSION = "3.0.4"
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imagesLoaded_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Guy Israeli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: railties
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ description: ! 'imagesLoaded.js Wrapper for Rails 3.1+ Asset Pipeline '
56
+ email:
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - LICENSE.txt
64
+ - README.md
65
+ - Rakefile
66
+ - app/assets/javascripts/imagesloaded.js
67
+ - imagesLoaded_rails.gemspec
68
+ - lib/imagesLoaded_rails.rb
69
+ - lib/imagesLoaded_rails/version.rb
70
+ homepage: https://github.com/guyisra/imagesLoaded-rails
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.1.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Asset pipeline is like "I'll take care of that js for you sir" and Rails
94
+ is like "You know thats right! and what about them images?!"
95
+ test_files: []