From f0e78e0700afc7f83dd2d147daabdb640af0ea8d Mon Sep 17 00:00:00 2001
From: Dariusz Paliwoda <malcolm@1424180.no-reply.drupal.org>
Date: Thu, 14 Feb 2013 18:54:45 +0000
Subject: [PATCH] Moved foreach loop from theme to preprocess function

---
 views-slideshow-j360-main-frame.tpl.php |   25 ++++---------------------
 views_slideshow_j360.module             |   16 ++++++++++++++++
 2 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/views-slideshow-j360-main-frame.tpl.php b/views-slideshow-j360-main-frame.tpl.php
index 6f26e59..fd8c54c 100755
--- a/views-slideshow-j360-main-frame.tpl.php
+++ b/views-slideshow-j360-main-frame.tpl.php
@@ -20,28 +20,11 @@
 
   <div id="views-slideshow-j360-images-<?php echo $id; ?>" class="views-slideshow-j360-images <?php echo $classes; ?>">
 
-    <?php
-      // Echoes only the image tag.
-      foreach ($view->style_plugin->rendered_fields as $index => $field) :
-        foreach ($field as $key => $value) :
-          if ($value) :
-            echo $field[$key];
+    <?php foreach ($images as $image) : ?>
+      <?php echo $image; ?>
+    <? endforeach; ?>
 
-            /* Store original image dimensions and use it into
-             * views_slideshow_j360.js
-             * This can be found inspecting the $view with something like
-             * kpr($view); */
-            if ($index == 0) :
-              $width = $view->result[$index]->{'field_' . $key}[0]['raw']['width'];
-              $height = $view->result[$index]->{'field_' . $key}[0]['raw']['height'];
-            endif;
-          endif;
-        endforeach;
-      endforeach;
-
-    // Add original image width/height to an hidden element.
-    if (isset($width)) :
-    ?>
+    <?php if (isset($width)) : ?>
       <span class="j360-img-info" id="j360-img-width" style="display:none"><?php echo $width; ?></span>
       <span class="j360-img-info" id="j360-img-height" style="display:none"><?php echo $height; ?></span>
     <?php endif; ?>
diff --git a/views_slideshow_j360.module b/views_slideshow_j360.module
index 5f375b9..a9fdda1 100755
--- a/views_slideshow_j360.module
+++ b/views_slideshow_j360.module
@@ -67,6 +67,22 @@ function template_preprocess_views_slideshow_j360_main_frame(&$vars) {
     'maxwidth' => (int) check_plain($maxwidth),
   );
 
+  $view = $vars['view'];
+  $vars['images'] = array();
+  foreach ($view->style_plugin->rendered_fields as $index => $field) {
+    foreach ($field as $key => $value) {
+      if ($value) {
+        $vars['images'][] = $field[$key];
+      }
+      // Store original image dimensions and use it into
+      // views_slideshow_j360.js.
+      // This can be found inspecting the $view with something like kpr($view).
+      if ($index == 0) {
+        $vars['width'] = $view->result[$index]->{'field_' . $key}[0]['raw']['width'];
+        $vars['height'] = $view->result[$index]->{'field_' . $key}[0]['raw']['height'];
+      }
+    }
+  }
   // Load spritespin.
   drupal_add_js(views_slideshow_j360_spritespin_path(), array('group' => JS_LIBRARY));
 
-- 
1.7.9.5

