diff --git a/jquery_update.install b/jquery_update.install index a4e9168..2d96a2c 100644 --- a/jquery_update.install +++ b/jquery_update.install @@ -31,6 +31,7 @@ function jquery_update_requirements($phase) { function jquery_update_uninstall() { variable_del('jquery_update_compression_type'); variable_del('jquery_update_jquery_version'); + variable_del('jquery_update_jquery_admin_version'); } /** diff --git a/jquery_update.module b/jquery_update.module index 520e076..f3ab62e 100644 --- a/jquery_update.module +++ b/jquery_update.module @@ -64,7 +64,6 @@ function jquery_update_library() { * Implementation of hook_library_alter(). */ function jquery_update_library_alter(&$javascript, $module) { - // We are updating just the system module. For all other cases we return. if ($module != 'system') { return; @@ -76,8 +75,24 @@ function jquery_update_library_alter(&$javascript, $module) { $min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min'; $cdn = variable_get('jquery_update_jquery_cdn', 'none'); - // Replace jQuery with the latest version. + // 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; + } + } + + // Always add a new jquery_version array to ajaxPageState. + // This is what we used to determine which version to use + // for any ajax callback. + $javascript['drupal.ajax']['js'][] = array( + 'data' => array('ajaxPageState' => array('jquery_version' => $version)), + 'type' => 'setting' + ); + jquery_update_jquery_replace($javascript, $cdn, $path, $min, $version); // Replace jQuery UI with CDN or local files. If from a CDN include all of jQuery UI. @@ -117,17 +132,36 @@ function jquery_update_menu() { * Implementation of hook_form_FORM_ID(). */ function jquery_update_settings_form() { - $form['jquery_update_jquery_version'] = array( + $form['version_options'] = array( + '#type' => 'fieldset', + '#title' => t('Version options'), + ); + + $form['version_options']['jquery_update_jquery_version'] = array( '#type' => 'select', - '#title' => t('jQuery Version'), + '#title' => t('Default jQuery Version'), '#options' => array( '1.5' => '1.5', '1.7' => '1.7', '1.8' => '1.8', ), '#default_value' => variable_get('jquery_update_jquery_version', '1.5'), - '#description' => t('Select which jQuery version branch to use.'), + '#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.'), + ); + $form['jquery_update_compression_type'] = array( '#type' => 'radios', '#title' => t('jQuery compression level'), @@ -167,6 +201,14 @@ function jquery_update_settings_form() { * The version of jQuery to use. */ function jquery_update_jquery_replace(&$javascript, $cdn, $path, $min, $version) { + // If the ajax version is set then that one always win. + if (!empty($_POST['ajax_page_state']['jquery_version'])) { + $ajax_version = $_POST['ajax_page_state']['jquery_version']; + if (in_array($valid_version, array('1.5', '1.6', '1.7'))) { + $version = $ajax_version; + } + } + // Make sure to use the latest version in given branch. $trueversion = NULL; switch ($version) {