From 580d402ec7a5ae255811a3568e6be3beb47c5eaa Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Wed, 23 Nov 2011 10:13:45 -0500 Subject: [PATCH 1/2] Restore the Drupal.jsEnabled variable. --- misc/drupal.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/misc/drupal.js b/misc/drupal.js index 035da0c21cb..0c71c313b3d 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -4,7 +4,7 @@ var Drupal = Drupal || { 'settings': {}, 'behaviors': {}, 'themes': {}, 'locale' /** * Set the variable that indicates if JavaScript behaviors should be applied */ -Drupal.jsEnabled = true; +Drupal.jsEnabled = document.getElementsByTagName && document.createElement && document.createTextNode && document.documentElement && document.getElementById; /** * Attach all registered behaviors to a page element. @@ -35,10 +35,12 @@ Drupal.jsEnabled = true; */ Drupal.attachBehaviors = function(context) { context = context || document; - // Execute all of them. - jQuery.each(Drupal.behaviors, function() { - this(context); - }); + if (Drupal.jsEnabled) { + // Execute all of them. + jQuery.each(Drupal.behaviors, function() { + this(context); + }); + } }; /** @@ -264,11 +266,16 @@ Drupal.ahahError = function(xmlhttp, uri) { } // Global Killswitch on the element -$(document.documentElement).addClass('js'); -// Attach all behaviors. -$(document).ready(function() { - Drupal.attachBehaviors(this); -}); +if (Drupal.jsEnabled) { + // Global Killswitch on the element + $(document.documentElement).addClass('js'); + // 'js enabled' cookie + document.cookie = 'has_js=1; path=/'; + // Attach all behaviors. + $(document).ready(function() { + Drupal.attachBehaviors(this); + }); +} /** * The default themes. From f678c7b621f61f0bb499d4a7c25bb4ce90e06e8a Mon Sep 17 00:00:00 2001 From: Andrew Berry Date: Wed, 23 Nov 2011 10:14:56 -0500 Subject: [PATCH 2/2] Allow setting of the has_js cookie for authenticated users. --- includes/common.inc | 7 +++++++ misc/drupal.js | 15 +++++---------- misc/jsenabled.js | 5 +++++ 3 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 misc/jsenabled.js diff --git a/includes/common.inc b/includes/common.inc index 43f05d4c6df..e1331ad886f 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -2180,6 +2180,13 @@ function drupal_add_js($data = NULL, $type = 'module', $scope = 'header', $defer ), 'inline' => array(), ); + + // We never cache authenticated user pages, so if they are logged in we + // allow setting of the has_js cookie so batch API functions use the JS + // version. + if (!user_is_anonymous()) { + $javascript['header']['core']['misc/jsenabled.js'] = array('cache' => TRUE, 'defer' => FALSE, 'preprocess' => TRUE); + } } if (isset($scope) && !isset($javascript[$scope])) { diff --git a/misc/drupal.js b/misc/drupal.js index 0c71c313b3d..2efb4206e2f 100644 --- a/misc/drupal.js +++ b/misc/drupal.js @@ -266,16 +266,11 @@ Drupal.ahahError = function(xmlhttp, uri) { } // Global Killswitch on the element -if (Drupal.jsEnabled) { - // Global Killswitch on the element - $(document.documentElement).addClass('js'); - // 'js enabled' cookie - document.cookie = 'has_js=1; path=/'; - // Attach all behaviors. - $(document).ready(function() { - Drupal.attachBehaviors(this); - }); -} +$(document.documentElement).addClass('js'); +// Attach all behaviors. +$(document).ready(function() { + Drupal.attachBehaviors(this); +}); /** * The default themes. diff --git a/misc/jsenabled.js b/misc/jsenabled.js new file mode 100644 index 00000000000..39c212c3ec7 --- /dev/null +++ b/misc/jsenabled.js @@ -0,0 +1,5 @@ +if (Drupal.jsEnabled) { + // 'js enabled' cookie + document.cookie = 'has_js=1; path=/'; +} +