retina_tag 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -37,9 +37,8 @@ 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.
40
+ ## Lazy Loading Images
41
+ if you set `:lazy => true` on an image_tag, the src attribute is moved to a lodpi_src attribute. You will need to manually instruct the image to load. To do this use `RetinaTag.refreshImage(img)` where img is the image element.
43
42
 
44
43
 
45
44
  ## Contributing
@@ -1,7 +1,6 @@
1
1
  var RetinaTag = RetinaTag || {};
2
2
 
3
3
  RetinaTag.init = function() {
4
- RetinaTag.updateImages();
5
4
  window.matchMedia('(-webkit-device-pixel-ratio:1)').addListener(RetinaTag.updateImages);
6
5
  document.addEventListener("page:load", RetinaTag.updateImages);
7
6
  document.addEventListener("retina_tag:refresh", RetinaTag.updateImages);
@@ -10,7 +9,9 @@ RetinaTag.init = function() {
10
9
  RetinaTag.updateImages = function() {
11
10
  var images = document.getElementsByTagName('img');
12
11
  for(var counter=0; counter < images.length; counter++) {
13
- RetinaTag.refreshImage(images[counter]);
12
+ if(!images[counter].getAttribute('data-lazy-load')) {
13
+ RetinaTag.refreshImage(images[counter]);
14
+ }
14
15
  }
15
16
  };
16
17
 
@@ -22,27 +23,20 @@ RetinaTag.refreshImage = function(image) {
22
23
  if(!hiDpiSrc) {
23
24
  return;
24
25
  }
25
-
26
+ if(lazyLoad)
27
+ {
28
+ image.removeAttribute('data-lazy-load');
29
+ }
26
30
  if(window.devicePixelRatio > 1 && imageSrc != hiDpiSrc) {
27
31
  if(!lowDpiSrc) {
28
32
  image.setAttribute('lowdpi_src',imageSrc);
29
33
  }
30
- if(lazyLoad) {
31
- image.setAttribute('data-lazy-load','2x');
32
- }
33
- else {
34
- image.src = hiDpiSrc;
35
- }
36
-
34
+ image.src = hiDpiSrc;
37
35
  }
38
36
  else if(window.devicePixelRatio <= 1 && (imageSrc == hiDpiSrc || (lowDpiSrc && imageSrc != lowDpiSrc))) {
39
- if(lazyLoad) {
40
- image.setAttribute('data-lazy-load','1x');
41
- }
42
- else {
43
- image.src = lowDpiSrc;
44
- }
37
+ image.src = lowDpiSrc;
45
38
  }
46
39
  };
47
40
 
48
- $(document).ready(RetinaTag.init);
41
+ RetinaTag.init();
42
+ $(document).ready(RetinaTag.updateImages);
@@ -19,13 +19,21 @@ module ActionView
19
19
  def image_tag_with_retina(source,options={})
20
20
  options_default = { :hidpi_src => hidpi_asset_path(source) }
21
21
 
22
- if options[:lazy]
23
- options.delete(:lazy)
24
- options["data-lazy-load"] = "1x"
25
- options[:lowdpi_src] = source
26
- source = ''
22
+ if lazy = options.delete(:lazy)
23
+ options["data-lazy-load"] = lazy
27
24
  end
28
- image_tag_without_retina(source,options_default.merge(options))
25
+
26
+ options_default.merge!(options)
27
+
28
+ image_tag_without_retina(source,options_default)
29
+
30
+ if options_default[:"data-lazy-load"]
31
+ puts "Lazy load detected"
32
+ options_default[:lowdpi_src] = options_default.delete(:src)
33
+ end
34
+ puts "Using custom image Tag!"
35
+ puts options_default
36
+ tag("img", options_default)
29
37
  end
30
38
 
31
39
  alias_method_chain :image_tag, :retina
@@ -1,3 +1,3 @@
1
1
  module RetinaTag
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
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.1.1
4
+ version: 1.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -76,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
76
  version: '0'
77
77
  segments:
78
78
  - 0
79
- hash: -803285465304008810
79
+ hash: -755295882179579949
80
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  segments:
87
87
  - 0
88
- hash: -803285465304008810
88
+ hash: -755295882179579949
89
89
  requirements: []
90
90
  rubyforge_project:
91
91
  rubygems_version: 1.8.24