diff --git a/jquery_update.module b/jquery_update.module index 76644f8..48d3c2c 100644 --- a/jquery_update.module +++ b/jquery_update.module @@ -75,6 +75,7 @@ function jquery_update_library() { * Implementation of hook_library_alter(). */ function jquery_update_library_alter(&$javascript, $module) { + global $theme; // We are updating just the system module. For all other cases we return. if ($module != 'system') { return; @@ -88,11 +89,13 @@ function jquery_update_library_alter(&$javascript, $module) { // Replace jQuery with the alternative version. $version = variable_get('jquery_update_jquery_version', '1.5'); - $admin_version = variable_get('jquery_update_jquery_admin_version', ''); - if (!empty($admin_version) && path_is_admin(current_path())) { - if (version_compare($version, $admin_version, '!=')) { - $version = $admin_version; + $theme_settings = variable_get('theme_' . $theme . '_settings', array()) + array('jquery_update_version' => NULL); + $theme_version = $theme_settings['jquery_update_version'] ? $theme_settings['jquery_update_version'] : ''; + + if ($theme_version) { + if (version_compare($version, $theme_version, '!=')) { + $version = $theme_version; } } @@ -150,32 +153,51 @@ function jquery_update_settings_form() { $form['version_options'] = array( '#type' => 'fieldset', '#title' => t('Version options'), + '#description' => t('You can override the jQuery version on a per-theme basis on each themes settings page.'), ); + $default_version = variable_get('jquery_update_jquery_version', '1.5'); $form['version_options']['jquery_update_jquery_version'] = array( '#type' => 'select', '#title' => t('Default jQuery Version'), - '#options' => array( - '1.5' => '1.5', - '1.7' => '1.7', - '1.8' => '1.8', - ), + '#options' => array('' => t('Use the default')) + jquery_update_get_versions(), '#default_value' => variable_get('jquery_update_jquery_version', '1.5'), '#description' => t('Select which jQuery version to use by default.'), ); - $form['version_options']['jquery_update_jquery_admin_version'] = array( - '#type' => 'select', - '#title' => t('Alternate jQuery version for administrative pages'), - '#options' => array( - '' => t('Use the default'), - '1.5' => '1.5', - '1.7' => '1.7', - '1.8' => '1.8', - ), - '#default_value' => variable_get('jquery_update_jquery_admin_version', ''), - '#description' => t('Optionally select a different version of jQuery to use on administrative pages.'), - ); + $themes = list_themes(); + $header = array(t('Theme'), t('Status'), t('jQuery version'), t('')); + $rows = array(); + $themes_collapsed = TRUE; + foreach ($themes as $theme_name => $theme) { + if (!$theme->status) { + continue; + } + $settings = variable_get('theme_' . $theme_name . '_settings', array()) + array('jquery_update_version' => NULL); + $theme_version = $settings['jquery_update_version'] ? $settings['jquery_update_version'] : $default_version; + if ($theme_version != $default_version) { + $themes_collapsed = FALSE; + } + $rows[] = array( + $theme->info['name'], + $theme_version != $default_version ? t('Overridden') : t('Default'), + $theme_version, + l(t('Change'), 'admin/appearance/settings/' . $theme_name, array('fragment' => 'edit-jquery-update-version', 'query' => drupal_get_destination())), + ); + } + + if (count($rows) > 1 || !$themes_collapsed) { + $form['version_options']['themes'] = array( + '#type' => 'fieldset', + '#title' => t('Theme specific versions'), + '#collapsible' => TRUE, + '#collapsed' => $themes_collapsed, + ); + $form['version_options']['themes']['overrides'] = array( + '#type' => 'markup', + '#markup' => theme('table', array('header' => $header, 'rows' => $rows)), + ); + } $form['jquery_update_compression_type'] = array( '#type' => 'radios', @@ -203,6 +225,49 @@ function jquery_update_settings_form() { } /** + * Implements hook_form_FORM_ID_alter(). + */ +function jquery_update_form_system_theme_settings_alter(&$form, $form_state) { + if ($form['var']['#value'] == 'theme_settings') { + // global theme settings page + return; + } + $theme_name = preg_replace('[^theme_|_settings$]', '', $form['var']['#value']); + $themes = list_themes(); + $settings = variable_get('theme_' . $theme_name . '_settings', array()) + array('jquery_update_version' => NULL); + $form['options_settings'][$theme_name . '_jquery_update'] = array( + '#type' => 'fieldset', + '#title' => t('jQuery Update'), + ); + $form['options_settings'][$theme_name . '_jquery_update']['jquery_update_version'] = array( + '#type' => 'select', + '#title' => t('jQuery version for theme %theme_name', array( + '%theme_name' => $themes[$theme_name]->info['name'], + )), + '#options' => array( + '' => t('Use the default'), + ) + jquery_update_get_versions(), + '#default_value' => $settings['jquery_update_version'], + '#description' => t('Optionally select a different version of jQuery to use for pages that are rendered using the %theme_name theme.', array( + '%theme_name' => $themes[$theme_name]->info['name'], + )), + ); +} + +/** + * Retrieve the jQuery versions availabile by this module. + * + * @return array The available jQuery versions + */ +function jquery_update_get_versions() { + return array( + '1.5' => '1.5', + '1.7' => '1.7', + '1.8' => '1.8', + ); +} + +/** * Update jQuery to the CDN or local path. * * @param array $javascript