responsive_image_tag 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,38 @@
1
1
  = responsive_image_tag
2
2
 
3
- Description goes here.
3
+ == Installation
4
+
5
+ Put it in your Gemfile:
6
+
7
+ gem 'responsive_image_tag'
8
+
9
+ Then install it:
10
+
11
+ bundle install
12
+
13
+ There's a generator which copies a JavaScript file into place in @public/javascripts@.
14
+
15
+ You can run it like this:
16
+
17
+
18
+ === Rails 3
19
+
20
+ rails generate responsive_image_tag
21
+
22
+ === Rails 2
23
+
24
+ script/generate responsive_image_tag
25
+
26
+
27
+ == Usage
28
+
29
+ You need to do two things. First, make sure that you include a reference to the JavaScript file in your layout:
30
+
31
+ <%= javascript_include_tag "responsive-image-tag" %>
32
+
33
+ After that, you can use the new tag like so, in a view:
34
+
35
+ <%= responsive_image_tag("small.jpg", "big.jpg") %>
4
36
 
5
37
  == Contributing to responsive_image_tag
6
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -11,7 +11,7 @@ module ResponsiveImageTag
11
11
 
12
12
  def create_javascript_file
13
13
  template 'responsive-image-tag.js',
14
- File.join('javascript', 'responsive-image-tag.js')
14
+ File.join('public', 'javascripts', 'responsive-image-tag.js')
15
15
  end
16
16
 
17
17
  end
@@ -1,18 +1,40 @@
1
- function replaceImages(){
2
-
1
+ //responsiveImageTag detects all noscript elements on the page with a class of responsivize.
2
+
3
+ //It retrieves both HTML5 data attributes and then creates an image tag with the correct source
4
+ //destination depending on the available screen width of the users device. This way smaller
5
+ //images are sent to mobile devices or any device smaller than 768px.
6
+
7
+ //The noscript tags are then removed from the page.
8
+ var responsiveImageTag = new function() {
9
+ this.replaceInitialImages = function() {
10
+ var platform = "desktop";
3
11
  var responsiveImages = $$(".responsivize");
4
12
  var i,
5
13
  noOfresponsiveImages = responsiveImages.length;
6
-
7
- for(i = 0; i < noOfresponsiveImages; i = i + 1 ){
8
- var newImg = window.document.createElement("img");
9
- newImg.src = responsiveImages[i].getAttribute("data-fullsrc");
10
- responsiveImages[i].previous().appendChild(newImg);
11
- responsiveImages[i].style.display = "none";
14
+
15
+ //test for available width in current browser window
16
+ if(screen.width <= 767){ //767px, anything smaller than an ipad is considered mobile
17
+ platform = "mobile";
12
18
  }
13
-
14
- }
15
19
 
20
+ //set initial source element on image
21
+ for(i = 0; i < noOfresponsiveImages; i = i + 1 ){
22
+ var noScriptElem = responsiveImages[i];
23
+ var img = window.document.createElement("img");
24
+
25
+ if(platform === "mobile"){
26
+ img.src = noScriptElem.getAttribute("data-mobilesrc");
27
+ }else{
28
+ img.src = noScriptElem.getAttribute("data-fullsrc");
29
+ }
30
+
31
+ img.className = "responsive";
32
+ noScriptElem.previous().appendChild(img);
33
+ noScriptElem.style.display = "none";
34
+ }
35
+ };
36
+ }
16
37
  document.observe("dom:loaded", function() {
17
- replaceImages()
38
+ responsiveImageTag.replaceInitialImages();
18
39
  })
40
+
@@ -8,8 +8,11 @@ module ResponsiveImageTag
8
8
  #
9
9
  def responsive_image_tag(small, big, options = {})
10
10
  output = tag "span", {:class => "img-placeholder"}
11
- output += tag "/span"
12
- output += tag "noscript", {"data-fullsrc" => image_path(big), :class => "responsivize"}, true
11
+ output += tag "/span", nil, true
12
+ output += tag "noscript", {
13
+ "data-fullsrc" => image_path(big),
14
+ "data-mobilesrc" => image_path(small),
15
+ :class => "responsivize"}, true
13
16
  output += image_tag(small, options)
14
17
  output += tag "/noscript", nil, true
15
18
  output
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{responsive_image_tag}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
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"]
12
- s.date = %q{2011-08-16}
12
+ s.date = %q{2011-08-17}
13
13
  s.description = %q{Allows you to specify two images in a responsive_image_tag, and includes a javascript generator which will rewrite the DOM, requesting the correct image based on the screen size of the current client device.}
14
14
  s.email = %q{dave.hrycyszyn@headlondon.com}
15
15
  s.extra_rdoc_files = [
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: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Dave Hrycyszyn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-16 00:00:00 +01:00
18
+ date: 2011-08-17 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency