Index: popups.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.module,v
retrieving revision 1.11.8.11
diff -u -p -r1.11.8.11 popups.module
--- popups.module	26 Mar 2009 17:25:19 -0000	1.11.8.11
+++ popups.module	17 Jan 2010 14:34:34 -0000
@@ -3,7 +3,7 @@
 
 /**
  * @file
- * This module provides a hook_popups for links to be openned in an Ajax Popup Modal Dialog. 
+ * This module provides a hook_popups for links to be openned in an Ajax Popup Modal Dialog.
  */
 
 
@@ -16,8 +16,8 @@
  *
  * @return array of new menu items.
  */
-function popups_menu() { 
-  
+function popups_menu() {
+
   // Admin Settings.
   $items['admin/settings/popups'] = array(
     'page callback' => 'drupal_get_form',
@@ -25,17 +25,17 @@ function popups_menu() { 
     'title' => 'Popups',
     'access arguments' => array('administer site configuration'),
     'description' => 'Configure the page-in-a-dialog behavior.',
-  ); 
-  
+  );
+
   return $items;
 }
 
 /**
  * Implementation of hook_init().
- * 
+ *
  * Look at the page path and see if popup behavior has been requested for any links in this page.
  */
-function popups_init() {  
+function popups_init() {
   $popups = popups_get_popups();
 
   if (variable_get('popups_always_scan', 0)) {
@@ -49,13 +49,13 @@ function popups_init() {  
     elseif (strpos($path, '*') !== FALSE && drupal_match_path($_GET['q'], $path)) {
       popups_add_popups($popup_config);
     }
-  }  
-  
+  }
+
   $render_mode = '';
   if (isset($_SERVER['HTTP_X_DRUPAL_RENDER_MODE'])) {
     $render_mode = $_SERVER['HTTP_X_DRUPAL_RENDER_MODE'];
   }
-  
+
   // Check and see if the page_override param is in the URL.
   // Note - the magic happens here.
   // Need to cache the page_override flag in the session, so it will effect
@@ -68,38 +68,38 @@ function popups_init() {  
   if (isset($_SESSION['page_override'])) {
     // This call will not return on form submission.
     $content = menu_execute_active_handler();
-    
-    // The call did return, so it wasn't a form request, 
+
+    // The call did return, so it wasn't a form request,
     // so we are returning a result, so clear the session flag.
     $override = $_SESSION['page_override'];
     unset($_SESSION['page_override']);
-       
+
     // Menu status constants are integers; page content is a string.
     if (isset($content) && !is_int($content) && isset($override)) {
-      print popups_render_as_json($content); 
+      print popups_render_as_json($content);
       exit;  // Do not continue processing request in index.html.
-    }    
+    }
   }
-  
+
 }
 
 /**
  * Implementation of hook_form_alter().
- * 
+ *
  * Look at the form_id and see if popup behavior has been requested for any links in this form.
  *
  * @param form_array $form
  * @param array $form_state
- * @param str $form_id: 
+ * @param str $form_id:
  */
 function popups_form_alter(&$form, $form_state, $form_id) {
   // Add popup behavior to the form if requested.
   $popups = popups_get_popups();
   if (isset($popups[$form_id])) {
     popups_add_popups($popups[$form_id]);
-  } 
+  }
 
-  // Alter the theme configuration pages, to add a per-theme-content selector. 
+  // Alter the theme configuration pages, to add a per-theme-content selector.
   $theme = arg(4);
   if ($form_id == 'system_theme_settings' && $theme) {
     $form['popups'] = array(
@@ -112,11 +112,11 @@ function popups_form_alter(&$form, $form
       '#title' => t('Content Selector'),
       '#default_value' => variable_get('popups_'. $theme .'_content_selector', _popups_default_content_selector()),
       '#description' => t("jQuery selector to define the page's content area on this theme."),
-    ); 
+    );
     $form['popups']['popups_theme'] = array(
       '#type' => 'hidden',
       '#value' => $theme,
-    ); 
+    );
     $form['#submit'][] = 'popups_theme_settings_form_submit';
   }
 }
@@ -131,7 +131,7 @@ function popups_form_alter(&$form, $form
  * @param $content: themed html.
  * @return $content in a json wrapper with metadata.
  */
-function popups_render_as_json($content) { 
+function popups_render_as_json($content) {
   $path = $_GET['q']; // Get current path from params.
   return drupal_json(array(
     'title' => drupal_get_title(),
@@ -139,7 +139,7 @@ function popups_render_as_json($content)
     'path' => $path,
     'content' => $content,
     'js' => popups_get_js(),
-    'css' => popups_get_css(), 
+    'css' => popups_get_css(),
   ));
 }
 
@@ -149,7 +149,7 @@ function popups_render_as_json($content)
 function popups_get_js() {
   $js = array_merge_recursive(drupal_add_js(), drupal_add_js(NULL, NULL, 'footer'));
   $query_string = '?'. substr(variable_get('css_js_query_string', '0'), 0, 1);
-  
+
   $popup_js = array();
 
   foreach ($js as $type => $data) {
@@ -228,12 +228,12 @@ function popups_get_css() {
 /**
  * Define hook_popups().
  * Build the list of popup rules from all modules that implement hook_popups.
- * 
+ *
  * Retrieves the list of popup rules from all modules that implement hook_popups.
  *
  * @param $reset
  *   (optional) If set to TRUE, forces the popup rule cache to reset.
- * 
+ *
  */
 function popups_get_popups($reset = FALSE) {
   static $popups = NULL;
@@ -242,37 +242,37 @@ function popups_get_popups($reset = FALS
     if (!$reset && ($cache = cache_get('popups:popups')) && !empty($cache->data)) {
       $popups = $cache->data;
     }
-    else { 
+    else {
       // Call all hook_popups and cache results.
       $popups = module_invoke_all('popups');
-      
+
       // Invoke hook_popups_alter() to allow altering the default popups registry.
       drupal_alter('popups', $popups);
 
-      // Save the popup registry in the cache.      
+      // Save the popup registry in the cache.
       cache_set('popups:popups', $popups);
-    }  
+    }
   }
   return $popups;
 }
 
 /**
  * Attach the popup behavior to the page.
- * 
- * The default behavoir of a popup is to open a form that will modify the original page.  
- * The popup submits the form and reloads the original page with the resulting new content. 
+ *
+ * The default behavoir of a popup is to open a form that will modify the original page.
+ * The popup submits the form and reloads the original page with the resulting new content.
  * The popup then replaces the original page's content area with the new copy of that content area.
  *
  * @param array $rules: Array of rules to apply to the page or form, keyed by jQuery link selector.
- *   See README.txt for a listing of the options, and popups_admin.module for examples. 
+ *   See README.txt for a listing of the options, and popups_admin.module for examples.
  */
-function popups_add_popups($rules=NULL) { 
+function popups_add_popups($rules=NULL) {
   static $added = FALSE;
   $settings = array('popups' => array());
-  
+
   if (is_array($rules)) {
     $settings['popups']['links'] = array();
-    foreach ($rules as $popup_selector => $options) { 
+    foreach ($rules as $popup_selector => $options) {
       if (is_array($options)) {
         $settings['popups']['links'][$popup_selector] = $options;
       }
@@ -291,7 +291,7 @@ function popups_add_popups($rules=NULL) 
     if (!$theme) {
       $theme = variable_get('theme_default','none');
     }
-    
+
     drupal_add_js('misc/jquery.form.js');
     drupal_add_css(drupal_get_path('module', 'popups') .'/popups.css');
     drupal_add_js(drupal_get_path('module', 'popups') .'/popups.js');
@@ -301,17 +301,25 @@ function popups_add_popups($rules=NULL) 
     $skins = popups_skins();
     if (!$skins[$skin]['css']) { // $skin == 'Unskinned'
       // Look in the current theme for popups-skin.js
-      drupal_add_js(drupal_get_path('theme', $theme) . '/popups-skin.js');
+      $theme_js = drupal_get_path('theme', $theme) . '/popups-skin.js';
+      if(file_exists($theme_js)) {
+        drupal_add_js($theme_css);
+      }
+      // Look in the current theme for popups-skin.css
+      $theme_css = drupal_get_path('theme', $theme) . '/popups-skin.css';
+      if(file_exists($theme_css)) {
+        drupal_add_js($theme_css);
+      }
     }
     else { // Get css and js from selected skin.
       drupal_add_css($skins[$skin]['css']);
       if (isset($skins[$skin]['js'])) {
         drupal_add_js($skins[$skin]['js']);
-      }   
+      }
     }
-        
+
     $default_target_selector = variable_get('popups_'. $theme .'_content_selector', _popups_default_content_selector());
-    
+
     $settings['popups']['originalPath'] = $_GET['q'];
     $settings['popups']['defaultTargetSelector'] = $default_target_selector;
     $settings['popups']['modulePath'] = drupal_get_path('module', 'popups');
@@ -346,14 +354,14 @@ function popups_skins($reset = FALSE) {
 
 /**
  * Implementation of hook_popups_skins.
- * 
+ *
  * This hook allows other modules to create additional custom skins for the
  * popups module.
- * 
+ *
  * @return array
  *   An array of key => value pairs suitable for inclusion as the #options in a
- *   select or radios form element. Each key must be the location of at least a 
- *   css file for a popups skin. Optionally can have a js index as well. Each 
+ *   select or radios form element. Each key must be the location of at least a
+ *   css file for a popups skin. Optionally can have a js index as well. Each
  *   value should be the name of the skin.
  */
 function popups_popups_skins() {
@@ -375,7 +383,7 @@ function popups_popups_skins() {
 
 /**
  * Returns the default jQuery content selector as a string.
- * Currently uses the selector for Garland.  
+ * Currently uses the selector for Garland.
  * Sometime in the future I will change this to '#content' or '#content-content'.
  */
 function _popups_default_content_selector() {
@@ -409,7 +417,7 @@ function popups_admin_settings() {
   // Retrieve all available skins, forcing the registry to refresh.
   $skins['Unskinned'] = array();
   $skins += popups_skins(TRUE);
-  
+
   $skin_options = drupal_map_assoc(array_keys($skins));
   $form['popups_skins'] = array(
     '#type' => 'fieldset',
@@ -425,13 +433,13 @@ function popups_admin_settings() {
     '#options' => $skin_options,
   );
 
-  
+
   return system_settings_form($form);
 }
 
 /**
  * popups_form_alter adds this submit handler to the theme pages.
- * Set a per-theme jQuery content selector that gets passed into the js settings. 
+ * Set a per-theme jQuery content selector that gets passed into the js settings.
  *
  * @param $form
  * @param $form_state
