Index: popups.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.module,v retrieving revision 1.11.8.2 diff -u -p -r1.11.8.2 popups.module --- popups.module 21 Nov 2008 08:51:14 -0000 1.11.8.2 +++ popups.module 10 Feb 2009 21:20:08 -0000 @@ -109,6 +109,21 @@ function popups_theme($existing, $type) } /** + * Implementation of hook_theme_registry_alter(). + * + * Hijack the popups theming to use a custom tpl. + */ +function popups_theme_registry_alter(&$theme_registry) { + $skin = variable_get('popups_skin', 'Basic'); + $skins = module_invoke_all('popups_skins'); + $skin_path = dirname($skins[$skin]['css']); + $theme_registry['popups_popup']['template'] = $skin_path .'/popups-popup'; + $theme_registry['popups_popup']['theme path'] = $skin_path; + // Note that we overwrite 'theme paths' instead of adding to it. + $theme_registry['popups_popup']['theme paths'][0] = $skin_path; +} + +/** * Implementation of hook_form_alter(). * * Look at the form_id and see if popup behavior has been requested for any links in this form. @@ -326,7 +341,14 @@ function popups_add_popups($rules=NULL) } if (!$added) { drupal_add_css(drupal_get_path('module', 'popups') .'/popups.css'); - drupal_add_css(drupal_get_path('module', 'popups') .'/popups-skin.css'); + // allow skin override here + $skin = variable_get('popups_skin', 'Basic'); + $skins = module_invoke_all('popups_skins'); + $skin_path = dirname($skins[$skin]['css']); + drupal_add_css($skins[$skin]['css']); + if (isset($skins[$skin]['js'])) { + drupal_add_js($skins[$skin]['js']); + } drupal_add_js(drupal_get_path('module', 'popups') .'/popups.js'); drupal_add_js('misc/jquery.form.js'); @@ -366,6 +388,7 @@ function _popups_default_content_selecto * */ function popups_admin_settings() { + popups_add_popups(); drupal_set_title("Popups Settings"); $form = array(); @@ -380,6 +403,24 @@ function popups_admin_settings() { '#default_value' => variable_get('popups_popup_final_message', 1), ); + // traverse the skins directory looking for subdirectories to come up with + // our $skin_options + $skins = module_invoke_all('popups_skins'); + $skin_options = drupal_map_assoc(array_keys($skins)); + $form['popups_skins'] = array( + '#type' => 'fieldset', + '#title' => t('Skins'), + '#description' => t('Choose a skin from the list. Click !here to test it out.', array('!here' => l('here', 'user', array('attributes' => array('class' => 'popups'))))), + '#collapsible' => TRUE, + '#collapsed' => FALSE, + ); + $form['popups_skins']['popups_skin'] = array( + '#type' => 'radios', + '#title' => t('Available skins'), + '#default_value' => variable_get('popups_skin', 'Basic'), + '#options' => $skin_options, + ); + return system_settings_form($form); } @@ -396,3 +437,32 @@ function popups_theme_settings_form_subm variable_set('popups_'. $theme .'_content_selector', $content_selector); } + +/** + * 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 + * value should be the name of the widget. + */ +function popups_popups_skins() { + $skins_directory = drupal_get_path('module', 'popups') .'/skins'; + $files = file_scan_directory($skins_directory, '\.css$'); + + $skins = array(); + foreach ($files as $file) { + $name = drupal_ucfirst($file->name); + $skins[$name]['css'] = $file->filename; + } + $files = file_scan_directory($skins_directory, '\.js$'); + foreach ($files as $file) { + $name = drupal_ucfirst($file->name); + $skins[$name]['js'] = $file->filename; + } + return $skins; +} \ No newline at end of file