responsive_image_tag 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -17,7 +17,7 @@ You can run it like this:
17
17
 
18
18
  === Rails 3
19
19
 
20
- rails generate responsive_image_tag
20
+ rails g responsive_image_tag:javascript
21
21
 
22
22
  === Rails 2
23
23
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -1,10 +1,10 @@
1
- class ResponsiveImageTagGenerator < Rails::Generator::Base
1
+ class JqueryResponsiveImageTagGenerator < Rails::Generator::Base
2
2
 
3
- SOURCE = File.join("..", "..", "..", "lib", "rails", "generators", "responsive_image_tag", "javascript", "templates", "responsive-image-tag.js")
3
+ SOURCE = File.join("..", "..", "..", "lib", "rails", "generators", "responsive_image_tag", "javascript", "templates", "responsive-image-tag-jquery.js")
4
4
 
5
5
  def manifest
6
6
  record do |m|
7
- m.file SOURCE, "public/javascripts/responsive-image-tag.js"
7
+ m.file SOURCE, "public/javascripts/responsive-image-tag-jquery.js"
8
8
  end
9
9
  end
10
10
 
@@ -0,0 +1,11 @@
1
+ class PrototypeResponsiveImageTagGenerator < Rails::Generator::Base
2
+
3
+ SOURCE = File.join("..", "..", "..", "lib", "rails", "generators", "responsive_image_tag", "javascript", "templates", "responsive-image-tag-prototype.js")
4
+
5
+ def manifest
6
+ record do |m|
7
+ m.file SOURCE, "public/javascripts/responsive-image-tag-prototype.js"
8
+ end
9
+ end
10
+
11
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module ResponsiveImageTag
4
4
  module Generators
5
- class JavascriptGenerator < Rails::Generators::Base
5
+ class JqueryJavascriptGenerator < Rails::Generators::Base
6
6
  desc 'Creates a javascript file which takes care of responsive images for you'
7
7
 
8
8
  def self.source_root
@@ -10,8 +10,9 @@ module ResponsiveImageTag
10
10
  end
11
11
 
12
12
  def create_javascript_file
13
- template 'responsive-image-tag.js',
14
- File.join('public', 'javascripts', 'responsive-image-tag.js')
13
+ template 'responsive-image-tag-jquery.js',
14
+ File.join(
15
+ 'public', 'javascripts', 'responsive-image-tag-prototype.js')
15
16
  end
16
17
 
17
18
  end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ module ResponsiveImageTag
4
+ module Generators
5
+ class PrototypeJavascriptGenerator < Rails::Generators::Base
6
+ desc 'Creates a javascript file which takes care of responsive images for you'
7
+
8
+ def self.source_root
9
+ File.expand_path("../templates", __FILE__)
10
+ end
11
+
12
+ def create_javascript_file
13
+ template 'responsive-image-tag-prototype.js',
14
+ File.join(
15
+ 'public', 'javascripts', 'responsive-image-tag-prototype.js')
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -23,25 +23,25 @@ var responsiveImageTag = {
23
23
 
24
24
  //set initial source element on image
25
25
  for(i = 0; i < noOfresponsiveImages; i = i + 1 ){
26
- var noScriptElem = responsiveImages[i];
26
+ var noScriptElem = $(responsiveImages[i]);
27
27
  var img = window.document.createElement("img");
28
28
 
29
- img.alt = noScriptElem.getAttribute("data-alttext");
29
+ img.alt = noScriptElem.attr("data-alttext");
30
30
 
31
31
  if(platform === "mobile"){
32
- img.src = noScriptElem.getAttribute("data-mobilesrc");
32
+ img.src = noScriptElem.attr("data-mobilesrc");
33
33
  }else{
34
- img.src = noScriptElem.getAttribute("data-fullsrc");
34
+ img.src = noScriptElem.attr("data-fullsrc");
35
35
  }
36
36
 
37
37
  img.className = "responsive";
38
- noScriptElem.previous().appendChild(img);
39
- noScriptElem.style.display = "none";
38
+ noScriptElem.prev().append(img);
39
+ noScriptElem.hide();
40
40
  }
41
41
  }
42
42
  };
43
43
 
44
- document.observe("dom:loaded", function() {
44
+ $(function() {
45
45
  responsiveImageTag.replaceInitialImages();
46
46
  });
47
-
47
+
@@ -0,0 +1,50 @@
1
+ /*jslint browser:true */
2
+ /*global $, $$*/
3
+
4
+ // responsiveImageTag detects all noscript elements on the page with a class
5
+ // of 'responsivize'.
6
+
7
+ // It retrieves both HTML5 data attributes and then creates an image tag with
8
+ // the correct source destination depending on the available screen width of
9
+ // the user'ss device. This way smaller images are sent to mobile devices or
10
+ // any device smaller than 768px.
11
+
12
+ // The <noscript> tags are then removed from the page.
13
+ var responsiveImageTag = {
14
+
15
+ replaceInitialImages:function() {
16
+ var platform = "desktop";
17
+ var responsiveImages = $$(".responsivize");
18
+ var i,
19
+ noOfresponsiveImages = responsiveImages.length;
20
+
21
+ // Test for available width in current browser window
22
+ // 767px, anything smaller than an ipad is considered mobile
23
+ if(screen.width <= 767){
24
+ platform = "mobile";
25
+ }
26
+
27
+ // Set initial source element on image
28
+ for(i = 0; i < noOfresponsiveImages; i = i + 1 ){
29
+ var noScriptElem = responsiveImages[i];
30
+ var img = window.document.createElement("img");
31
+
32
+ img.alt = noScriptElem.getAttribute("data-alttext");
33
+
34
+ if(platform === "mobile"){
35
+ img.src = noScriptElem.getAttribute("data-mobilesrc");
36
+ }else{
37
+ img.src = noScriptElem.getAttribute("data-fullsrc");
38
+ }
39
+
40
+ img.className = "responsive";
41
+ noScriptElem.previous().appendChild(img);
42
+ noScriptElem.style.display = "none";
43
+ }
44
+ }
45
+ };
46
+
47
+ document.observe("dom:loaded", function() {
48
+ responsiveImageTag.replaceInitialImages();
49
+ });
50
+
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{responsive_image_tag}
8
- s.version = "0.1.3"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dave Hrycyszyn"]
@@ -24,10 +24,13 @@ Gem::Specification.new do |s|
24
24
  "README.rdoc",
25
25
  "Rakefile",
26
26
  "VERSION",
27
- "generators/responsive_image_tag/responsive_image_tag_generator.rb",
27
+ "generators/responsive_image_tag/jquery_responsive_image_tag_generator.rb",
28
+ "generators/responsive_image_tag/prototype_responsive_image_tag_generator.rb",
28
29
  "generators/responsive_image_tag/templates/README",
29
- "lib/rails/generators/responsive_image_tag/javascript/javascript_generator.rb",
30
- "lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag.js",
30
+ "lib/rails/generators/responsive_image_tag/javascript/jquery_javascript_generator.rb",
31
+ "lib/rails/generators/responsive_image_tag/javascript/prototype_javascript_generator.rb",
32
+ "lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag-jquery.js",
33
+ "lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag-prototype.js",
31
34
  "lib/responsive_image_tag.rb",
32
35
  "responsive_image_tag.gemspec",
33
36
  "test/helper.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: responsive_image_tag
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 3
10
- version: 0.1.3
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dave Hrycyszyn
@@ -123,10 +123,13 @@ files:
123
123
  - README.rdoc
124
124
  - Rakefile
125
125
  - VERSION
126
- - generators/responsive_image_tag/responsive_image_tag_generator.rb
126
+ - generators/responsive_image_tag/jquery_responsive_image_tag_generator.rb
127
+ - generators/responsive_image_tag/prototype_responsive_image_tag_generator.rb
127
128
  - generators/responsive_image_tag/templates/README
128
- - lib/rails/generators/responsive_image_tag/javascript/javascript_generator.rb
129
- - lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag.js
129
+ - lib/rails/generators/responsive_image_tag/javascript/jquery_javascript_generator.rb
130
+ - lib/rails/generators/responsive_image_tag/javascript/prototype_javascript_generator.rb
131
+ - lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag-jquery.js
132
+ - lib/rails/generators/responsive_image_tag/javascript/templates/responsive-image-tag-prototype.js
130
133
  - lib/responsive_image_tag.rb
131
134
  - responsive_image_tag.gemspec
132
135
  - test/helper.rb