diff --git a/jquery_update.module b/jquery_update.module
index 520e076..1db1aad 100644
--- a/jquery_update.module
+++ b/jquery_update.module
@@ -5,6 +5,10 @@
* Updates Drupal to use the latest version of jQuery.
*/
+define('JQUERY_UPDATE_VISIBILITY_ADMIN', 0);
+define('JQUERY_UPDATE_VISIBILITY_NOTLISTED', 1);
+define('JQUERY_UPDATE_VISIBILITY_LISTED', 2);
+
/**
* Implements hook_help().
*/
@@ -64,20 +68,57 @@ 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;
}
+ // Replace jQuery with the latest version.
+ $version = variable_get('jquery_update_jquery_version', '1.5');
+
+ // If a different version is specified for administration
+ // pages, use it instead.
+ if (variable_get('jquery_update_admin', FALSE)) {
+ $visibility = variable_get('jquery_update_visibility', JQUERY_UPDATE_VISIBILITY_ADMIN);
+ $page_match = FALSE;
+ // check admin path
+ if($visibility === JQUERY_UPDATE_VISIBILITY_ADMIN) {
+ $page_match = path_is_admin(current_path());
+ }
+ else {
+ // taken from block.module & block.admin.module
+ $pages = variable_get('jquery_update_pages', '');
+
+ // Convert path to lowercase. This allows comparison of the same path
+ // with different case. Ex: /Page, /page, /PAGE.
+ $pages = drupal_strtolower($pages);
+ // Convert the Drupal path to lowercase
+ $path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
+ // Compare the lowercase internal and lowercase path alias (if any).
+ $page_match = drupal_match_path($path, $pages);
+ if ($path != $_GET['q']) {
+ $page_match = $page_match || drupal_match_path($_GET['q'], $pages);
+ }
+
+ $page_match = !($visibility xor $page_match);
+ }
+
+ if($page_match) {
+ $admin_version = variable_get('jquery_update_jquery_admin_version', '1.5');
+ if (version_compare($version, $admin_version, '!=')) {
+ $version = $admin_version;
+ }
+ }
+
+ }
+
$path = drupal_get_path('module', 'jquery_update');
// Make sure we inject either the minified or uncompressed version as desired.
$min = variable_get('jquery_update_compression_type', 'min') == 'none' ? '' : '.min';
$cdn = variable_get('jquery_update_jquery_cdn', 'none');
- // Replace jQuery with the latest version.
- $version = variable_get('jquery_update_jquery_version', '1.5');
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,10 +158,15 @@ 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'),
'#options' => array(
+ '1.4' => '1.4',
'1.5' => '1.5',
'1.7' => '1.7',
'1.8' => '1.8',
@@ -128,6 +174,51 @@ function jquery_update_settings_form() {
'#default_value' => variable_get('jquery_update_jquery_version', '1.5'),
'#description' => t('Select which jQuery version branch to use.'),
);
+ $form['version_options']['jquery_update_admin'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use a different jQuery version on selected pages.'),
+ '#default_value' => variable_get('jquery_update_admin', FALSE),
+ );
+
+ $form['version_options']['options'] = array(
+ '#type' => 'container',
+ '#states' => array(
+ 'invisible' => array(
+ 'input[name="jquery_update_admin"]' => array('checked' => FALSE),
+ ),
+ ),
+ );
+ $form['version_options']['options']['jquery_update_jquery_admin_version'] = array(
+ '#type' => 'select',
+ '#title' => t('Alternate jQuery version on selected pages'),
+ '#options' => array(
+ '1.4' => '1.4',
+ '1.5' => '1.5',
+ '1.7' => '1.7',
+ ),
+ '#default_value' => variable_get('jquery_update_jquery_admin_version', '1.5'),
+ '#description' => t('Select which jQuery version branch to use on selected pages.'),
+ );
+
+ $visibility_options = array(
+ JQUERY_UPDATE_VISIBILITY_ADMIN => t('Administration pages only'),
+ JQUERY_UPDATE_VISIBILITY_NOTLISTED => t('All pages except those listed'),
+ JQUERY_UPDATE_VISIBILITY_LISTED => t('Only the listed pages'),
+ );
+
+ $form['version_options']['options']['jquery_update_visibility'] = array(
+ '#type' => 'radios',
+ '#title' => t('Switch JQuery on specific pages'),
+ '#options' => $visibility_options,
+ '#default_value' => variable_get('jquery_update_visibility', -1),
+ );
+ $form['version_options']['options']['jquery_update_pages'] = array(
+ '#type' => 'textarea',
+ '#title' => '' . t('Pages') . '',
+ '#default_value' => variable_get('jquery_update_pages', ''),
+ '#description' => t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. Example paths are %blog for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '')),
+ );
+
$form['jquery_update_compression_type'] = array(
'#type' => 'radios',
'#title' => t('jQuery compression level'),
@@ -170,6 +261,9 @@ function jquery_update_jquery_replace(&$javascript, $cdn, $path, $min, $version)
// Make sure to use the latest version in given branch.
$trueversion = NULL;
switch ($version) {
+ case '1.4':
+ $trueversion = '1.4.4';
+ break;
case '1.5':
$trueversion = '1.5.2';
break;