From d40c2a197c02192cbdd6d1698b280dc34dc3157d Mon Sep 17 00:00:00 2001
From: Cristina Hanes <clhanes@hotmail.com>
Date: Wed, 12 Sep 2012 16:46:06 -0700
Subject: [PATCH] Issue #1228266 by cristinawithout, idflood: Add responsive
 support

---
 field_slideshow.css     |  7 +++++++
 field_slideshow.install | 18 ++++++++++++++++++
 field_slideshow.js      | 34 ++++++++++++++++++++++++++++++++++
 field_slideshow.module  |  5 +++++
 4 files changed, 64 insertions(+)

diff --git a/field_slideshow.css b/field_slideshow.css
index c4595ae..160fdb4 100644
--- a/field_slideshow.css
+++ b/field_slideshow.css
@@ -1,5 +1,12 @@
 .field-slideshow {
   overflow: hidden;
+  max-width: 100%;
+}
+
+.field-slideshow-slide, .field-slideshow-slide a, .field-slideshow-slide img {
+  max-width: 100%;
+  height: auto !important;
+  width: auto !important;
 }

 .region-content ul.field-slideshow-pager {
diff --git a/field_slideshow.install b/field_slideshow.install
index 32253b2..8417970 100644
--- a/field_slideshow.install
+++ b/field_slideshow.install
@@ -65,6 +65,24 @@ function field_slideshow_requirements($phase) {
         );
       }
     }
+
+    $path = libraries_get_path('jquery.imagesloaded');
+    if ($path == '') $path = '/sites/all/libraries/jquery.imagesloaded';
+    if (file_exists($path . '/jquery.imagesloaded.min.js') || file_exists($path . '/jquery.imagesloaded.js')) {
+      $requirements['field_slideshow_imagesloaded_plugin'] = array(
+        'title'     => $t('JQuery ImagesLoaded plugin'),
+        'severity'  => REQUIREMENT_OK,
+        'value'     => $t('Installed'),
+      );
+    }
+    else {
+      $requirements['field_slideshow_imagesloaded_plugin'] = array(
+        'title'       => $t('JQuery ImagesLoaded plugin'),
+        'value'       => $t('Not found'),
+        'severity'    => REQUIREMENT_WARNING,
+        'description' => $t('For best results, you should download the !name and move the downloaded js file(s) into the %path folder of your server.', array('!name' => l($t('JQuery ImagesLoaded plugin'), 'https://github.com/desandro/imagesloaded/downloads'), '%path' => $path)),
+      );
+    }
   }

   return $requirements;
diff --git a/field_slideshow.js b/field_slideshow.js
index 48fbac3..59cba47 100644
--- a/field_slideshow.js
+++ b/field_slideshow.js
@@ -137,6 +137,40 @@
         }

       }
+
+      // Recalculate height for responsive layouts
+      var rebuild_max_height = function(context) {
+        var max_height = 0;
+        var heights = $('.field-slideshow-slide',context).map(function ()
+        {
+          return $(this).height();
+        }).get(),
+        max_height = Math.max.apply(Math, heights);
+        if (max_height > 0) {
+          context.css("height", max_height);
+        }
+      };
+
+      if (jQuery.isFunction($.fn.imagesLoaded)) {
+        $('.field-slideshow').each(function() {
+          $('img',this).imagesLoaded(function($images) {
+            rebuild_max_height($images.parents('.field-slideshow'));
+          });
+        });
+      }
+      else {
+        $(window).load(function(){
+          $('.field-slideshow').each(function(){
+            rebuild_max_height($(this))
+          })
+        });
+
+      }
+      $(window).resize(function(){
+        $('.field-slideshow').each(function(){
+          rebuild_max_height($(this))
+        })
+      });

     }
   }
diff --git a/field_slideshow.module b/field_slideshow.module
index 36575bd..cf78c5f 100644
--- a/field_slideshow.module
+++ b/field_slideshow.module
@@ -793,6 +793,11 @@ function template_preprocess_field_slideshow(&$variables) {
       if (file_exists($path . '/lib/jquery.jcarousel.min.js')) drupal_add_js($path . '/lib/jquery.jcarousel.min.js');
       elseif (file_exists($path . '/lib/jquery.jcarousel.js')) drupal_add_js($path . '/lib/jquery.jcarousel.js');
     }
+
+    $path = libraries_get_path('jquery.imagesloaded');
+    if (file_exists($path . '/jquery.imagesloaded.min.js')) drupal_add_js($path . '/jquery.imagesloaded.min.js');
+    elseif (file_exists($path . '/jquery.imagesloaded.js')) drupal_add_js($path . '/jquery.imagesloaded.js');
+
     drupal_add_js(drupal_get_path('module', 'field_slideshow') . '/field_slideshow.js');
   }

--
1.7.11.3

