From 8ed10a62f567f58b27a0794e0e16c38f8ae540fc Mon Sep 17 00:00:00 2001
From: Stephen Duff <sduff@slv.vic.gov.au>
Date: Wed, 25 Jul 2012 11:39:30 +1000
Subject: [PATCH] Issue #0 by sduff_07: Modified JS to appear as a single
 inline option and added a settings file too allow for
 drupal aggregate js options.

---
 deepzoom.module      |   35 +++++++++++++++++++++++++----------
 deepzoom_settings.js |   24 ++++++++++++++++++++++++
 2 files changed, 49 insertions(+), 10 deletions(-)
 create mode 100644 deepzoom_settings.js

diff --git a/deepzoom.module b/deepzoom.module
index 77dffef..1543b00 100755
--- a/deepzoom.module
+++ b/deepzoom.module
@@ -65,7 +65,7 @@ function deepzoom_menu() {
 
   $items['admin/config/media/deepzom'] = array(
     'title' => 'Deepzoom',
-    'description' => t('Configure defaults for Deep Zoom images.'),
+    'description' => 'Configure defaults for Deep Zoom images.',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('deepzoom_configuration_form'),
     'access arguments' => array('administer deepzoom'),
@@ -85,19 +85,25 @@ function deepzoom_page_alter($variables) {
   drupal_add_js(array('deepzoom' => file_create_url('public://deepzoom')), 'setting');
 
   $config = deepzoom_load_defaults();
-  foreach (deepzoom_load_defaults() as $key => $value) {
-    switch (TRUE) {
-      case is_bool($value):
-        $value = $value == TRUE ? 'true' : 'false';
+  if (variable_get('dz_loadJS', 'FALSE')) {
+    drupal_add_js(drupal_get_path('module', 'deepzoom') . '/deepzoom_settings.js');
+  }
+  else{
+    $deepzoom_js = "";
+    foreach (deepzoom_load_defaults() as $key => $value) {
+      switch (TRUE) {
+        case is_bool($value):
+          $value = $value == TRUE ? 'true' : 'false';
         break;
 
-      case is_string($value):
-        $value = "'{$value}'";
+        case is_string($value):
+          $value = "'{$value}'";
         break;
+      }
+     $deepzoom_js .= "Seadragon.Config.{$key} = {$value};";
     }
-
-    drupal_add_js("Seadragon.Config.{$key} = {$value};", 'inline');
-  }
+  drupal_add_js($deepzoom_js, 'inline');
+ }
 }
 
 /**
@@ -191,6 +197,14 @@ function deepzoom_configuration_form($form, &$form_alter) {
       '<strong>' . t('NOTE: this is an experimental API and is not guaranteed to work. The API is also very likely to change in the future. Use at your own risk!') . '</strong>',
   );
 
+  $form['deepzoom_config']['dz_loadJS'] = array(
+    '#title' => t('Load settings from JS file'),
+    '#type' => 'checkbox',
+    '#default_value' => $config['dz_loadJS'],
+    '#description' =>
+      t('Use a javascript file on the server to load settings'),
+  );
+
   $form['deepzoom_config']['minZoomImageRatio'] = array(
     '#title' => t('Minimum zoom image ratio'),
     '#type' => 'textfield',
@@ -317,6 +331,7 @@ function deepzoom_load_defaults() {
     'wrapVertical' => FALSE,
     'wrapOverlays' => FALSE,
     'transformOverlays' => FALSE,
+    'dz_loadJS' => FALSE,
     'minZoomImageRatio' => 0.8,
     'maxZoomPixelRatio' => 2,
     'visibilityRatio' => 0.5,
diff --git a/deepzoom_settings.js b/deepzoom_settings.js
new file mode 100644
index 0000000..9cfdc3d
--- /dev/null
+++ b/deepzoom_settings.js
@@ -0,0 +1,24 @@
+Seadragon.Config.debugMode = 0;
+Seadragon.Config.animationTime = '1.5';
+Seadragon.Config.blendTime = '0.5';
+Seadragon.Config.alwaysBlend = 0;
+Seadragon.Config.autoHideControls = 1;
+Seadragon.Config.immediateRender = 0;
+Seadragon.Config.wrapHorizontal = 0;
+Seadragon.Config.wrapVertical = 0;
+Seadragon.Config.wrapOverlays = 0;
+Seadragon.Config.transformOverlays = 0;
+Seadragon.Config.minZoomImageRatio = '0.8';
+Seadragon.Config.maxZoomPixelRatio = '1';
+Seadragon.Config.visibilityRatio = '0.5';
+Seadragon.Config.springStiffness = '5';
+Seadragon.Config.imageLoaderLimit = '2';
+Seadragon.Config.clickTimeThreshold = '200';
+Seadragon.Config.clickDistThreshold = '5';
+Seadragon.Config.zoomPerClick = '2';
+Seadragon.Config.zoomPerScroll = '1.2';
+Seadragon.Config.zoomPerSecond = '2';
+Seadragon.Config.proxyUrl = '';
+Seadragon.Config.imagePath = '/sites/all/libraries/seadragon/img/';
+Seadragon.Config.tile_size = '254';
+Seadragon.Config.tile_overlap = '1';
\ No newline at end of file
-- 
1.7.6.4

