From fe2e9643ecc1dbf2862b69d04d85c09dd4bfb7b4 Mon Sep 17 00:00:00 2001
From: James Nettik <james.nettik@gmail.com>
Date: Mon, 21 Oct 2013 10:03:03 -0600
Subject: [PATCH 1/4] updated readme text

---
 README.txt | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/README.txt b/README.txt
index 69c5065..264be93 100644
--- a/README.txt
+++ b/README.txt
@@ -109,6 +109,17 @@ You may use the Client-side adaptive image formatter within other
 types of entities as well, but the path to the formatter's settings
 will vary.
 
+-- RETINA SUPPORT --
+
+If you wish an image style to be served with it's retina display variant just
+create a new style with the name '--retina' in the end.
+This module will automatically detect if a retina variant is available and will
+use that image-style.
+
+Exmaple:
+If the name of your image style is: "news-thumbnail"
+The name of the retina image style has to be: "news-thumbnail--retina"
+
 
 -- SIMILAR PROJECTS --
 
-- 
1.7.12.4 (Apple Git-37)


From 2f635d5f8f9f1b1fb8ef6ed5ad39cc8da29ff7d3 Mon Sep 17 00:00:00 2001
From: James Nettik <james.nettik@gmail.com>
Date: Mon, 21 Oct 2013 10:03:43 -0600
Subject: [PATCH 2/4] added support for retina media queries in the javascript

---
 cs_adaptive_image.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/cs_adaptive_image.js b/cs_adaptive_image.js
index 77abd00..33829e3 100644
--- a/cs_adaptive_image.js
+++ b/cs_adaptive_image.js
@@ -18,6 +18,11 @@
           $.each(breakpoints.split(' '), function(key, breakpoint) {
             if (document.documentElement.clientWidth <= Number(breakpoint) && (selected_breakpoint == 'max' || Number(breakpoint) < Number(selected_breakpoint))) {
               selected_breakpoint = breakpoint;
+
+              // check for retina availability
+              if (typeof(window.devicePixelRatio) != 'undefined' && window.devicePixelRatio > 1 && $(element).attr('data-adaptive-image-' + selected_breakpoint + '-retina-img')) {
+                selected_breakpoint = selected_breakpoint + '-retina';
+              }
             }
           });
         }
@@ -50,4 +55,4 @@
       });
     }
   };
-})(jQuery);
\ No newline at end of file
+})(jQuery);
-- 
1.7.12.4 (Apple Git-37)


From 8fff9f32803780369571fc9bfde99c3bd4c2fb00 Mon Sep 17 00:00:00 2001
From: James Nettik <james.nettik@gmail.com>
Date: Mon, 21 Oct 2013 10:06:12 -0600
Subject: [PATCH 3/4] created image style detection for --retina styles

---
 cs_adaptive_image.module | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/cs_adaptive_image.module b/cs_adaptive_image.module
index 38f43d3..86f7ef9 100644
--- a/cs_adaptive_image.module
+++ b/cs_adaptive_image.module
@@ -231,6 +231,8 @@ function theme_cs_adaptive_image_formatter($variables) {
   // Output fallback image that will work without JavaScript.
   $image_output = _cs_adaptive_image_view_image($image, $variables['fallback_style']);
 
+  $styles = image_styles();
+
   // Prepare attributes that will be picked up by our JavaScript code
   // to serve an adapted image. Some browsers cannot access the
   // children of a <noscript> element, thus all the data needs to be
@@ -242,6 +244,11 @@ function theme_cs_adaptive_image_formatter($variables) {
       $image['attributes']['data-adaptive-image-breakpoint'] = $breakpoint;
       $attributes['data-adaptive-image-breakpoints'][] = $breakpoint; // Append to list of breakpoints.
       $attributes['data-adaptive-image-' . $breakpoint . '-img'] = _cs_adaptive_image_view_image($image, $style_name);
+
+      // check if this image has a retina equivalent
+      if(in_array($style_name . '--retina',array_keys($styles))) {
+        $attributes['data-adaptive-image-' . $breakpoint . '-retina-img'] = _cs_adaptive_image_view_image($image, $style_name . '--retina');
+      }
     }
   }
   $image['attributes']['data-adaptive-image-breakpoint'] = 'max';
-- 
1.7.12.4 (Apple Git-37)


From 3a857414f1eb8f1503db41836354d396fe428999 Mon Sep 17 00:00:00 2001
From: James Nettik <james.nettik@gmail.com>
Date: Mon, 21 Oct 2013 10:06:40 -0600
Subject: [PATCH 4/4] added preprocess to put correct image dimensions in
 retina styles

---
 cs_adaptive_image.module | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/cs_adaptive_image.module b/cs_adaptive_image.module
index 86f7ef9..1b1ffbe 100644
--- a/cs_adaptive_image.module
+++ b/cs_adaptive_image.module
@@ -198,6 +198,22 @@ function cs_adaptive_image_preprocess_cs_adaptive_image_formatter(&$variables) {
 }
 
 /**
+ * Preprocess function for theme_image()
+ */
+function cs_adaptive_image_preprocess_image(&$variables) {
+  $namespace = '--retina';
+  $namespace_length = strlen($namespace);
+
+  // If this is a retina named image style we change the dimensions
+  if (
+    isset($variables['style_name']) &&
+    substr($variables['style_name'], -$namespace_length) == $namespace) {
+    $variables['height'] = $variables['height'] / 2;
+    $variables['width'] = $variables['width'] / 2;
+  }
+}
+
+/**
  * Returns HTML for an adaptive image formatter.
  *
  * @param $variables
-- 
1.7.12.4 (Apple Git-37)

