--- F:/Documents and Settings/justin/Desktop/Main/Software/_Staging_Area/D6.x/javascript_aggregator-6.x-1.x-dev.tar/javascript_aggregator/javascript_aggregator.module	Wed Apr 14 10:31:42 2010
+++ F:/EngNet - Justin/Backups/civilwatch.eng.co.za/2010-08-12/public_html/sites/all/modules/javascript_aggregator/javascript_aggregator.module	Thu Aug 12 13:01:00 2010
@@ -1,6 +1,10 @@
 <?php
 // $Id: javascript_aggregator.module,v 1.17.2.21 2010/04/14 08:31:42 derjochenmeyer Exp $
 
+define('JAVASCRIPT_AGGREGATOR_MIN', 1);
+define('JAVASCRIPT_AGGREGATOR_GZIP', 2);
+define('JAVASCRIPT_AGGREGATOR_MIN_GZIP', 3);
+
 /**
  * Implementation of hook_help().
  */
@@ -21,11 +25,12 @@
     $form['bandwidth_optimizations']['preprocess_js']['#description'] .= t(' Once the JavaScript files have been aggregated, they will be minified.');
     $form['bandwidth_optimizations']['preprocess_js']['#weight'] = 2;
 
-    $form['bandwidth_optimizations']['javascript_aggregator_gzip'] = array(
-      '#type' => 'checkbox',
-      '#title' => t('GZip JavaScript'),
-      '#description' => t('Once minified, optionally <a href="@gzip">GZip</a> the aggregated JavaScript file to dramatically decrease its size.', array('@gzip' => 'http://en.wikipedia.org/wiki/Gzip')),
-      '#default_value' => variable_get('javascript_aggregator_gzip', FALSE),
+    $form['bandwidth_optimizations']['javascript_aggregator_type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Type of JavaScript compression'),
+      '#description' => t('Optionally Minify and/or GZip the aggregated CSS file to dramatically decrease its size.'),
+      '#default_value' => variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN),
+      '#options' => array(JAVASCRIPT_AGGREGATOR_MIN => t('Minify'), JAVASCRIPT_AGGREGATOR_GZIP => t('GZip') , JAVASCRIPT_AGGREGATOR_MIN_GZIP => t('Minify and GZip')),
       '#weight' => 3,
     );
     $form['bandwidth_optimizations']['javascript_aggregator_no_htaccess'] = array(
@@ -58,7 +63,7 @@
     }
     // Now tack it on at the end so it runs after everything else.
     $theme_registry['page']['preprocess functions'][] = 'javascript_aggregator_preprocess_page';
-  } 
+  }
 }
 
 /**
@@ -78,7 +83,7 @@
  */
 function phptemplate_closure($main = 0) {
   $footer = module_invoke_all('footer', $main);
-  
+
   $js_footer = drupal_get_js('footer');
   // Only do this for pages that have JavaScript on them.
   if (!empty($js_footer)) {
@@ -100,42 +105,42 @@
     $pattern = "!(<script type=\"text\/javascript\" src=\"(.*?)$path_to_files_directory)(.*?)(\"(.*?)><\/script>)!";
     if (preg_match_all($pattern, $scripts, $matches) > 0) {
       $aggregated_file_name = $matches[3][0];
-      $jsmin_file_name = $aggregated_file_name .'min.js';
+
+      $jsmin_file_name = $aggregated_file_name;
+      if (variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN) != JAVASCRIPT_AGGREGATOR_GZIP) {
+        $jsmin_file_name .= 'min.js';
+      }
 
       // Construct the final JSMin file path.
       $jsmin_file_path = file_directory_path() . $jsmin_file_name;
 
+      if (variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN) != JAVASCRIPT_AGGREGATOR_MIN) {
+        $jsmin_file_path .= '.gz';
+      }
+
       // Create the JSMinified file if it doesn't exist yet.
       if (!file_exists($jsmin_file_path)) {
 
-        if (variable_get('javascript_aggregator_jsminplus', FALSE)) {
-          // JSMin+ the contents of the aggregated file.
-          require_once(drupal_get_path('module', 'javascript_aggregator') .'/jsminplus.php');
-          // Strip Byte Order Marks (BOM's) from the file, JSMin+ cannot parse these.
-          $file = str_replace(pack("CCC",0xef,0xbb,0xbf), "", file_get_contents(file_directory_path() . $aggregated_file_name));
-          $contents = JSMinPlus::minify($file);
-        }
-        else {
-          // JSMin the contents of the aggregated file.
-          require_once(drupal_get_path('module', 'javascript_aggregator') .'/jsmin.php');
-          $contents = JSMin::minify(file_get_contents(file_directory_path() . $aggregated_file_name));
+        // Select the type of aggregator to run.
+        switch (variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN)) {
+          case JAVASCRIPT_AGGREGATOR_MIN:
+            $contents = _javascript_aggregator_jsmin($aggregated_file_name, $path_to_files_directory);
+            break;
+
+          case JAVASCRIPT_AGGREGATOR_GZIP:
+            $contents = file_get_contents(file_directory_path() . $aggregated_file_name);
+            _javascript_aggregator_gzip($jsmin_file_name, $contents);
+            break;
+
+          case JAVASCRIPT_AGGREGATOR_MIN_GZIP:
+            $contents = _javascript_aggregator_jsmin($aggregated_file_name, $path_to_files_directory);
+            _javascript_aggregator_gzip($jsmin_file_name, $contents);
+            break;
         }
 
-        // Code comments containing copyright notices and licensing information
-        // are stripped when the file is minified. GPL and most other open
-        // source licenses require the license text to be included whenever the
-        // file is distributed, so include a reference to the un-minified file.
-        $contents = '// Minified using Javascript Aggregator - see '. $path_to_files_directory . $aggregated_file_name ." for original source including licensing information.\n". $contents;
-
         // GZip the JavaScript if required.
         $htaccess = file_directory_path() . '/js/.htaccess';
-        if (variable_get('javascript_aggregator_gzip', FALSE)) {
-
-          // Create the GZip file if it doesn't already exist.
-          if (!file_exists($jsmin_file_name .'.gz')) {
-            file_save_data(gzencode($contents, 9), $jsmin_file_name .'.gz', FILE_EXISTS_REPLACE);
-          }
-
+        if (variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN) != JAVASCRIPT_AGGREGATOR_MIN) {
           // Make sure the .htaccess file is active to handle GZipped JavaScript files.
           if (!variable_get('javascript_aggregator_no_htaccess', FALSE) && !file_exists($htaccess)) {
             $htaccess_contents = <<<EOT
@@ -161,14 +166,50 @@
           }
         }
 
-        // Save the contents to the JavaScript file.
-        file_save_data($contents, $jsmin_file_path, FILE_EXISTS_REPLACE);
+        // Only save JSMin file if Minify is on.
+        // This saves duplicating identical JS files.
+        if (variable_get('javascript_aggregator_type', JAVASCRIPT_AGGREGATOR_MIN) != JAVASCRIPT_AGGREGATOR_GZIP) {
+          // Make sure the file path is the correct name
+          $jsmin_file_path = file_directory_path() . $jsmin_file_name;
+          // Save the contents to the JavaScript file.
+          file_save_data($contents, $jsmin_file_path, FILE_EXISTS_REPLACE);
+        }
       }
 
       // Replace the aggregated file with the minified JavaScript file.
       $scripts = str_replace($aggregated_file_name, $jsmin_file_name, $scripts);
     }
   }
-  
+
   return $scripts;
+}
+
+function _javascript_aggregator_jsmin($js_file, $path_to_files_directory) {
+  if (variable_get('javascript_aggregator_jsminplus', FALSE)) {
+    // JSMin+ the contents of the aggregated file.
+    require_once(drupal_get_path('module', 'javascript_aggregator') .'/jsminplus.php');
+    // Strip Byte Order Marks (BOM's) from the file, JSMin+ cannot parse these.
+    $file = str_replace(pack("CCC",0xef,0xbb,0xbf), "", file_get_contents(file_directory_path() . $js_file));
+    $contents = JSMinPlus::minify($file);
+  }
+  else {
+    // JSMin the contents of the aggregated file.
+    require_once(drupal_get_path('module', 'javascript_aggregator') .'/jsmin.php');
+    $contents = JSMin::minify(file_get_contents(file_directory_path() . $js_file));
+  }
+
+  // Code comments containing copyright notices and licensing information
+  // are stripped when the file is minified. GPL and most other open
+  // source licenses require the license text to be included whenever the
+  // file is distributed, so include a reference to the un-minified file.
+  $contents = '// Minified using Javascript Aggregator - see '. $path_to_files_directory . $js_file ." for original source including licensing information.\n". $contents;
+
+  return $contents;
+}
+
+function _javascript_aggregator_gzip($file_name, $contents) {
+  // Create the GZip file if it doesn't already exist.
+  if (!file_exists($file_name .'.gz')) {
+    file_save_data(gzencode($contents, 9), $file_name .'.gz', FILE_EXISTS_REPLACE);
+  }
 }
\ No newline at end of file
