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 035da0c21cb..2efb4206e2f 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); + }); + } }; /** 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=/'; +} +