retina_tag 1.0.2 → 1.1.0
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.
- data/README.md +5 -0
- data/app/assets/javascripts/retina_tag.js +42 -13
- data/lib/retina_tag/image_tag_helper.rb +7 -0
- data/lib/retina_tag/version.rb +1 -1
- data/retina_tag.gemspec +0 -1
- metadata +8 -18
data/README.md
CHANGED
@@ -37,6 +37,11 @@ Be sure to also specify the base dimensions in your `image_tag` calls:
|
|
37
37
|
|
38
38
|
Awesome right?
|
39
39
|
|
40
|
+
## Lazy Loading Images (EXPIREMENTAL)
|
41
|
+
if you set `:lazy => true` on an image_tag, the src attribute is moved to a lodpi_src attribute. A seperate attribuet `data-lazy-load` is live updated with the devicePixelRatio state, and the src attribute is not automatically updated.
|
42
|
+
When you are ready to load the image, you can simply remove the image elements `data-lazy-load` attribute, and retina_tag will automatically insert the src attribute properly.
|
43
|
+
|
44
|
+
|
40
45
|
## Contributing
|
41
46
|
|
42
47
|
1. Fork it
|
@@ -1,17 +1,46 @@
|
|
1
|
-
|
2
|
-
if(window.devicePixelRatio > 1)
|
3
|
-
{
|
4
|
-
var els = jQuery("img").get();
|
5
|
-
for(var i = 0; i < els.length; i++) {
|
6
|
-
var hiDpiSrc = $(els[i]).attr('hidpi_src');
|
1
|
+
var RetinaTag = RetinaTag || {};
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
RetinaTag.init = function() {
|
4
|
+
RetinaTag.updateImages();
|
5
|
+
RetinaTag.interval = setInterval(RetinaTag.updateImages,50);
|
6
|
+
};
|
7
|
+
|
8
|
+
RetinaTag.updateImages = function() {
|
9
|
+
var images = document.getElementsByTagName('img');
|
10
|
+
for(var counter=0; counter < images.length; counter++) {
|
11
|
+
RetinaTag.refreshImage(images[counter]);
|
12
|
+
}
|
13
|
+
};
|
14
|
+
|
15
|
+
RetinaTag.refreshImage = function(image) {
|
16
|
+
var lazyLoad = image.getAttribute('data-lazy-load');
|
17
|
+
var imageSrc = image.src;
|
18
|
+
var hiDpiSrc = image.getAttribute('hidpi_src');
|
19
|
+
var lowDpiSrc = image.getAttribute('lowdpi_src');
|
20
|
+
if(!hiDpiSrc) {
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
if(window.devicePixelRatio > 1 && imageSrc != hiDpiSrc) {
|
25
|
+
if(!lowDpiSrc) {
|
26
|
+
image.setAttribute('lowdpi_src',imageSrc);
|
27
|
+
}
|
28
|
+
if(lazyLoad) {
|
29
|
+
lazyLoad.setAttribute('data-lazy-load','2x');
|
30
|
+
}
|
31
|
+
else {
|
32
|
+
image.src = hiDpiSrc;
|
33
|
+
}
|
34
|
+
|
35
|
+
}
|
36
|
+
else if(window.devicePixelRatio <= 1 && (imageSrc == hiDpiSrc || (lowDpiSrc && imageSrc != lowDpiSrc))) {
|
37
|
+
if(lazyLoad) {
|
38
|
+
lazyLoad.setAttribute('data-lazy-load','1x');
|
39
|
+
}
|
40
|
+
else {
|
41
|
+
image.src = lowDpiSrc;
|
11
42
|
}
|
12
43
|
}
|
13
|
-
}
|
44
|
+
};
|
14
45
|
|
15
|
-
|
16
|
-
highdpi_init();
|
17
|
-
});
|
46
|
+
RetinaTag.init();
|
@@ -18,6 +18,13 @@ module ActionView
|
|
18
18
|
|
19
19
|
def image_tag_with_retina(source,options={})
|
20
20
|
options_default = { :hidpi_src => hidpi_asset_path(source) }
|
21
|
+
|
22
|
+
if options[:lazy]
|
23
|
+
options.delete(:lazy)
|
24
|
+
options["data-lazy-load"] = "1x"
|
25
|
+
options[:lowdpi_src] = source
|
26
|
+
source = ''
|
27
|
+
end
|
21
28
|
image_tag_without_retina(source,options_default.merge(options))
|
22
29
|
end
|
23
30
|
|
data/lib/retina_tag/version.rb
CHANGED
data/retina_tag.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retina_tag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,24 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: jquery-rails
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
14
|
- !ruby/object:Gem::Dependency
|
31
15
|
name: rails
|
32
16
|
requirement: !ruby/object:Gem::Requirement
|
@@ -74,12 +58,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
58
|
- - ! '>='
|
75
59
|
- !ruby/object:Gem::Version
|
76
60
|
version: '0'
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
hash: -2961901041095853751
|
77
64
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
65
|
none: false
|
79
66
|
requirements:
|
80
67
|
- - ! '>='
|
81
68
|
- !ruby/object:Gem::Version
|
82
69
|
version: '0'
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
hash: -2961901041095853751
|
83
73
|
requirements: []
|
84
74
|
rubyforge_project:
|
85
75
|
rubygems_version: 1.8.24
|