lazyloadjs 0.0.1 → 0.0.3
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 +4 -4
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +17 -8
- data/Rakefile +1 -0
- data/lazyloadjs.gemspec +22 -0
- data/lib/lazyloadjs/railtie.rb +1 -1
- data/lib/lazyloadjs/version.rb +1 -1
- data/lib/lazyloadjs/view_helpers.rb +13 -4
- data/vendor/assets/javascripts/lazyload.js +15 -9
- metadata +11 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f89ab1223476132d7a8059ffd2ad24b32f623af
|
4
|
+
data.tar.gz: 06d22d6f01300ebba48d0e46fa8b6239094d64bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71f717362e11c7b79d5b750cc0fb8257656d67d569be119dc461010b109ca256bd03aacbeed9b65287e7a51304c10b57f2d827ab2af0a1f5623c149e3b27b4b2
|
7
|
+
data.tar.gz: fa7032c33a6d1eb08a15981de051ceb4a52ac8a7c52c13cda55c6361ed6bd27d6be306856da9c374b05b7bd6086c0d165d4fcd65593e7a22ad0d3c4b41680826
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Angelo Delefortrie
|
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
CHANGED
@@ -18,18 +18,27 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
|
21
|
+
In your `application.js` :
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
```javascript
|
24
|
+
...
|
25
|
+
//= require lazyload
|
26
|
+
...
|
27
|
+
```
|
25
28
|
|
26
|
-
Restart your application.
|
29
|
+
Restart your application. Lazy load is now availlable.
|
27
30
|
|
28
|
-
This gem
|
31
|
+
This gem provide simple helper generate requiered attributes in the img tag :
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
```ruby
|
34
|
+
image_lazy 'https://upload.wikimedi....png'
|
35
|
+
# => <img data-frz-src="https://upload.wikimedi....png" src="data:ima..." onload="lzld(this)" onerror="lzld(this)" />
|
36
|
+
|
37
|
+
image_lazy 'https://upload.wikimedi....png', alt: "Google logo"
|
38
|
+
# => <img data-frz-src="https://upload.wikimedi....png" src="data:ima..." onload="lzld(this)" onerror="lzld(this)" alt="Google logo" />
|
39
|
+
|
40
|
+
# etc.
|
41
|
+
```
|
33
42
|
|
34
43
|
## Contributing
|
35
44
|
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lazyloadjs.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'lazyloadjs/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "lazyloadjs"
|
8
|
+
spec.version = Lazyloadjs::VERSION
|
9
|
+
spec.authors = ["Angelo Delefortrie"]
|
10
|
+
spec.email = ["angelo.delefortrie@gmail.com"]
|
11
|
+
spec.summary = "Implementing LazyLoad ( http://github.com/fasterize/lazyload ) for Ruby on Rails"
|
12
|
+
spec.description = "Implementing LazyLoad ( http://github.com/fasterize/lazyload ) for Ruby on Rails"
|
13
|
+
spec.homepage = "http://github.com/angelodlfrtr/lazyloadjs/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency 'railties', ">= 3.2.6"
|
22
|
+
end
|
data/lib/lazyloadjs/railtie.rb
CHANGED
data/lib/lazyloadjs/version.rb
CHANGED
@@ -1,10 +1,19 @@
|
|
1
1
|
module Lazyloadjs
|
2
2
|
module ViewHelpers
|
3
|
+
|
3
4
|
def image_lazy image_path, args = {}
|
4
|
-
options = ''
|
5
|
-
args.each{|arg| options += "#{arg[0]}='#{arg[1]}'"}
|
6
5
|
|
7
|
-
|
6
|
+
args.merge!({
|
7
|
+
'data-frz-src' => image_path,
|
8
|
+
'src' => 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
|
9
|
+
'onload' => 'lzld(this)',
|
10
|
+
'onerror' => 'lzld(this)'
|
11
|
+
})
|
12
|
+
|
13
|
+
opts = args.map{ |n, v| "#{n}=\"#{v}\"" }
|
14
|
+
|
15
|
+
raw "<img #{opts.join(' ')} />"
|
8
16
|
end
|
17
|
+
|
9
18
|
end
|
10
|
-
end
|
19
|
+
end
|
@@ -21,6 +21,7 @@
|
|
21
21
|
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
22
|
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
23
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
|
24
25
|
*/
|
25
26
|
|
26
27
|
// Prevent double lazyload script on same page
|
@@ -40,8 +41,9 @@ if (!window['lzld']) {
|
|
40
41
|
unsubscribed = false,
|
41
42
|
|
42
43
|
// throttled functions, so that we do not call them too much
|
43
|
-
saveViewportT = throttle(
|
44
|
-
showImagesT = throttle(showImages, 20)
|
44
|
+
saveViewportT = throttle(saveViewport, 20),
|
45
|
+
showImagesT = throttle(showImages, 20),
|
46
|
+
isiOSDevice = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
|
45
47
|
|
46
48
|
// Override image element .getAttribute globally so that we give the real src
|
47
49
|
// does not works for ie < 8: http://perfectionkills.com/whats-wrong-with-extending-the-dom/
|
@@ -174,11 +176,13 @@ if (!window['lzld']) {
|
|
174
176
|
// img = dom element
|
175
177
|
// index = imgs array index
|
176
178
|
function showIfVisible(img, index) {
|
179
|
+
// Note that iOS devices freeze DOM manipulation during scroll, queuing them to apply when the scroll finishes.
|
180
|
+
// So it's better to disable the lazyloading on iOS device.
|
177
181
|
// We have to check that the current node is in the DOM
|
178
182
|
// It could be a detached() dom node
|
179
183
|
// http://bugs.jquery.com/ticket/4996
|
180
|
-
if (contains(document.documentElement, img)
|
181
|
-
&& img.getBoundingClientRect().top < winH + offset) {
|
184
|
+
if (isiOSDevice || (contains(document.documentElement, img)
|
185
|
+
&& img.getBoundingClientRect().top < winH + offset)) {
|
182
186
|
// To avoid onload loop calls
|
183
187
|
// removeAttribute on IE is not enough to prevent the event to fire
|
184
188
|
img.onload = null;
|
@@ -199,14 +203,14 @@ if (!window['lzld']) {
|
|
199
203
|
|
200
204
|
// cross browser viewport calculation
|
201
205
|
function viewport() {
|
202
|
-
if (document.documentElement.clientHeight
|
206
|
+
if (document.documentElement.clientHeight > 0) {
|
203
207
|
return document.documentElement.clientHeight;
|
204
|
-
} else if (document.body && document.body.clientHeight
|
208
|
+
} else if (document.body && document.body.clientHeight > 0) {
|
205
209
|
return document.body.clientHeight
|
206
|
-
} else if (window.innerHeight
|
210
|
+
} else if (window.innerHeight > 0) {
|
207
211
|
return window.innerHeight;
|
208
212
|
} else {
|
209
|
-
return
|
213
|
+
return 200;
|
210
214
|
}
|
211
215
|
}
|
212
216
|
|
@@ -239,6 +243,7 @@ if (!window['lzld']) {
|
|
239
243
|
unsubscribed = true;
|
240
244
|
removeEvent(window, 'resize', saveViewportT);
|
241
245
|
removeEvent(window, 'scroll', showImagesT);
|
246
|
+
removeEvent(window, 'touchmove', showImagesT);
|
242
247
|
removeEvent(window, 'load', onLoad);
|
243
248
|
}
|
244
249
|
|
@@ -246,6 +251,7 @@ if (!window['lzld']) {
|
|
246
251
|
unsubscribed = false;
|
247
252
|
addEvent(window, 'resize', saveViewportT);
|
248
253
|
addEvent(window, 'scroll', showImagesT);
|
254
|
+
addEvent(window, 'touchmove', showImagesT);
|
249
255
|
}
|
250
256
|
|
251
257
|
function overrideGetattribute() {
|
@@ -305,4 +311,4 @@ if (!window['lzld']) {
|
|
305
311
|
}
|
306
312
|
|
307
313
|
}(this, document))
|
308
|
-
}
|
314
|
+
}
|
metadata
CHANGED
@@ -1,57 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lazyloadjs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angelo Delefortrie
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-01 00:00:00.000000000 Z
|
12
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.5'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.5'
|
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
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: railties
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
44
16
|
requirements:
|
45
17
|
- - ">="
|
46
18
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
19
|
+
version: 3.2.6
|
48
20
|
type: :runtime
|
49
21
|
prerelease: false
|
50
22
|
version_requirements: !ruby/object:Gem::Requirement
|
51
23
|
requirements:
|
52
24
|
- - ">="
|
53
25
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
26
|
+
version: 3.2.6
|
55
27
|
description: Implementing LazyLoad ( http://github.com/fasterize/lazyload ) for Ruby
|
56
28
|
on Rails
|
57
29
|
email:
|
@@ -60,7 +32,12 @@ executables: []
|
|
60
32
|
extensions: []
|
61
33
|
extra_rdoc_files: []
|
62
34
|
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- Gemfile
|
37
|
+
- LICENSE.txt
|
63
38
|
- README.md
|
39
|
+
- Rakefile
|
40
|
+
- lazyloadjs.gemspec
|
64
41
|
- lib/lazyloadjs.rb
|
65
42
|
- lib/lazyloadjs/railtie.rb
|
66
43
|
- lib/lazyloadjs/version.rb
|
@@ -86,9 +63,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
63
|
version: '0'
|
87
64
|
requirements: []
|
88
65
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.
|
66
|
+
rubygems_version: 2.4.3
|
90
67
|
signing_key:
|
91
68
|
specification_version: 4
|
92
69
|
summary: Implementing LazyLoad ( http://github.com/fasterize/lazyload ) for Ruby on
|
93
70
|
Rails
|
94
71
|
test_files: []
|
72
|
+
has_rdoc:
|