retina_tag 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
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
- function highdpi_init() {
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
- if(hiDpiSrc) {
9
- els[i].src = hiDpiSrc;
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
- $(document).ready(function() {
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
 
@@ -1,3 +1,3 @@
1
1
  module RetinaTag
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
data/retina_tag.gemspec CHANGED
@@ -15,6 +15,5 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = RetinaTag::VERSION
17
17
 
18
- gem.add_dependency 'jquery-rails'
19
18
  gem.add_dependency "rails", "~> 3.1"
20
19
  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.0.2
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-10-17 00:00:00.000000000 Z
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