Commit f047851a authored by webchick's avatar webchick
Browse files

Issue #229825 by nod_, Rob Loach, sun, yched: Fixed ['has_js()'] must die.

parent b2bc3522
......@@ -104,11 +104,6 @@ function authorize_filetransfer_form($form, &$form_state) {
// Start non-JS code.
if (isset($form_state['values']['connection_settings']['authorize_filetransfer_default']) && $form_state['values']['connection_settings']['authorize_filetransfer_default'] == $name) {
// If the user switches from JS to non-JS, Drupal (and Batch API) will
// barf. This is a known bug: http://drupal.org/node/229825.
setcookie('has_js', '', time() - 3600, '/');
unset($_COOKIE['has_js']);
// Change the submit button to the submit_process one.
$form['submit_process']['#attributes'] = array();
unset($form['submit_connection']);
......
......@@ -74,7 +74,9 @@ function _batch_page() {
$output = NULL;
switch ($op) {
case 'start':
$output = _batch_start();
// Display the full progress page on startup and on each additional
// non-JavaScript iteration.
$output = _batch_progress_page();
break;
case 'do':
......@@ -84,7 +86,7 @@ function _batch_page() {
case 'do_nojs':
// Non-JavaScript-based progress page.
$output = _batch_progress_page_nojs();
$output = _batch_progress_page();
break;
case 'finished':
......@@ -95,56 +97,6 @@ function _batch_page() {
return $output;
}
/**
* Initializes the batch processing.
*
* JavaScript-enabled clients are identified by the 'has_js' cookie set in
* drupal.js. If no JavaScript-enabled page has been visited during the current
* user's browser session, the non-JavaScript version is returned.
*/
function _batch_start() {
if (isset($_COOKIE['has_js']) && $_COOKIE['has_js']) {
return _batch_progress_page_js();
}
else {
return _batch_progress_page_nojs();
}
}
/**
* Outputs a batch processing page with JavaScript support.
*
* This initializes the batch and error messages. Note that in JavaScript-based
* processing, the batch processing page is displayed only once and updated via
* AHAH requests, so only the first batch set gets to define the page title.
* Titles specified by subsequent batch sets are not displayed.
*
* @see batch_set()
* @see _batch_do()
*/
function _batch_progress_page_js() {
$batch = batch_get();
$current_set = _batch_current_set();
drupal_set_title($current_set['title'], PASS_THROUGH);
// Merge required query parameters for batch processing into those provided by
// batch_set() or hook_batch_alter().
$batch['url_options']['query']['id'] = $batch['id'];
$js_setting = array(
'batch' => array(
'errorMessage' => $current_set['error_message'] . '<br />' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => url($batch['url'], $batch['url_options']),
),
);
drupal_add_js($js_setting, 'setting');
drupal_add_library('system', 'drupal.batch');
return '<div id="progress"></div>';
}
/**
* Does one execution pass with JavaScript and returns progress to the browser.
*
......@@ -152,13 +104,6 @@ function _batch_progress_page_js() {
* @see _batch_process()
*/
function _batch_do() {
// HTTP POST required.
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
drupal_set_message(t('HTTP POST is required.'), 'error');
drupal_set_title(t('Error'));
return '';
}
// Perform actual processing.
list($percentage, $message) = _batch_process();
......@@ -166,11 +111,11 @@ function _batch_do() {
}
/**
* Outputs a batch processing page without JavaScript support.
* Outputs a batch processing page.
*
* @see _batch_process()
*/
function _batch_progress_page_nojs() {
function _batch_progress_page() {
$batch = &batch_get();
$current_set = _batch_current_set();
......@@ -218,6 +163,9 @@ function _batch_progress_page_nojs() {
$url = url($batch['url'], $batch['url_options']);
$element = array(
// Redirect through a 'Refresh' meta tag if JavaScript is disabled.
'#prefix' => '<noscript>',
'#suffix' => '</noscript>',
'#tag' => 'meta',
'#attributes' => array(
'http-equiv' => 'Refresh',
......@@ -226,6 +174,17 @@ function _batch_progress_page_nojs() {
);
drupal_add_html_head($element, 'batch_progress_meta_refresh');
// Adds JavaScript code and settings for clients where JavaScript is enabled.
$js_setting = array(
'batch' => array(
'errorMessage' => $current_set['error_message'] . '<br />' . $batch['error_message'],
'initMessage' => $current_set['init_message'],
'uri' => $url,
),
);
drupal_add_js($js_setting, 'setting');
drupal_add_library('system', 'drupal.batch');
return theme('progress_bar', array('percent' => $percentage, 'message' => $message));
}
......
......@@ -9,6 +9,9 @@ Drupal.behaviors.batch = {
attach: function (context, settings) {
$(context).find('#progress').once('batch', function () {
var holder = $(this);
// Remove HTML from no-js progress bar. The JS progress bar is created
// later on.
holder.empty();
// Success: redirect to the summary.
var updateCallback = function (progress, status, pb) {
......
......@@ -390,9 +390,6 @@ Drupal.ajaxError = function (xmlhttp, uri) {
// Class indicating that JS is enabled; used for styling purpose.
$('html').addClass('js');
// 'js enabled' cookie.
document.cookie = 'has_js=1; path=/';
//Attach all behaviors.
$(function () {
Drupal.attachBehaviors(document, Drupal.settings);
......
......@@ -147,10 +147,6 @@ function update_script_selection_form($form, &$form_state) {
else {
$form['start']['#title'] = format_plural($count, '1 pending update', '@count pending updates');
}
$form['has_js'] = array(
'#type' => 'hidden',
'#default_value' => FALSE,
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
'#type' => 'submit',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment