diff --git a/includes/ajax.inc b/includes/ajax.inc index 50e8e28..6f16ef4 100644 --- a/includes/ajax.inc +++ b/includes/ajax.inc @@ -796,6 +796,7 @@ function ajax_pre_render_element($element) { 'type' => 'setting', 'data' => array( 'ajax' => array($element['#id'] => $settings), + 'ajaxErrorDisplay' => variable_get('ajax_error_level', AJAX_ERROR_REPORTING_ALERT), 'urlIsAjaxTrusted' => array( $settings['url'] => TRUE, ), diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index b66ae17..59c2b45 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -41,6 +41,16 @@ define('ERROR_REPORTING_DISPLAY_SOME', 1); define('ERROR_REPORTING_DISPLAY_ALL', 2); /** + * Ajax error reporting level: display errors is alert window. + */ +define('AJAX_ERROR_REPORTING_ALERT', 0); + +/** + * Ajax error reporting level: display errors in console. + */ +define('AJAX_ERROR_REPORTING_CONSOLE', 1); + +/** * Indicates that the item should never be removed unless explicitly selected. * * The item may be removed using cache_clear_all() with a cache ID. diff --git a/misc/ajax.js b/misc/ajax.js index bb4a6e1..fbe3383 100644 --- a/misc/ajax.js +++ b/misc/ajax.js @@ -230,16 +230,16 @@ Drupal.ajax = function (base, element, element_settings) { * will test to see if the key press is valid to trigger this event and * if it is, trigger it for us and prevent other keypresses from triggering. * In this case we're handling RETURN and SPACEBAR keypresses (event codes 13 - * and 32. RETURN is often used to submit a form when in a textfield, and - * SPACE is often used to activate an element without submitting. + * and 32. RETURN is often used to submit a form when in a textfield, and + * SPACE is often used to activate an element without submitting. */ Drupal.ajax.prototype.keypressResponse = function (element, event) { // Create a synonym for this to reduce code confusion. var ajax = this; // Detect enter key and space bar and allow the standard response for them, - // except for form elements of type 'text' and 'textarea', where the - // spacebar activation causes inappropriate activation if #ajax['keypress'] is + // except for form elements of type 'text' and 'textarea', where the + // spacebar activation causes inappropriate activation if #ajax['keypress'] is // TRUE. On a text-type widget a space should always be a space. if (event.which == 13 || (event.which == 32 && element.type != 'text' && element.type != 'textarea')) { $(ajax.element_settings.element).trigger(ajax.element_settings.event); @@ -476,7 +476,15 @@ Drupal.ajax.prototype.getEffect = function (response) { * Handler for the form redirection error. */ Drupal.ajax.prototype.error = function (xmlhttprequest, uri, customMessage) { - alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); + if (Drupal.settings.ajaxErrorDisplay === '1') { + if (typeof(window.console) !== 'undefined') { + window.console.log(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); + } + } + else { + alert(Drupal.ajaxError(xmlhttprequest, uri, customMessage)); + } + // Remove the progress element. if (this.progress.element) { $(this.progress.element).remove(); diff --git a/misc/autocomplete.js b/misc/autocomplete.js index d71441b..eb27df3 100644 --- a/misc/autocomplete.js +++ b/misc/autocomplete.js @@ -310,7 +310,14 @@ Drupal.ACDB.prototype.search = function (searchString) { } }, error: function (xmlhttp) { - alert(Drupal.ajaxError(xmlhttp, db.uri)); + if (Drupal.settings.ajaxErrorDisplay === '1') { + if (typeof(window.console) !== 'undefined') { + window.console.log(Drupal.ajaxError(xmlhttp, db.uri)); + } + } + else { + alert(Drupal.ajaxError(xmlhttp, db.uri)); + } } }); }, this.delay); diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc index 8ef7d7c..cfd87c7 100644 --- a/modules/system/system.admin.inc +++ b/modules/system/system.admin.inc @@ -1676,6 +1676,16 @@ function system_logging_settings() { '#description' => t('It is recommended that sites running on production environments do not display any errors.'), ); + $form['ajax_error_level'] = array( + '#type' => 'radios', + '#title' => t('Ajax errors to display'), + '#default_value' => variable_get('ajax_error_level', AJAX_ERROR_REPORTING_ALERT), + '#options' => array( + AJAX_ERROR_REPORTING_ALERT => t('Show in alert window'), + AJAX_ERROR_REPORTING_CONSOLE => t('Show in console'), + ), + ); + return system_settings_form($form); }