summaryrefslogtreecommitdiffstats
path: root/misc/drupal.js
diff options
context:
space:
mode:
Diffstat (limited to 'misc/drupal.js')
-rw-r--r--misc/drupal.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/misc/drupal.js b/misc/drupal.js
index 427c4a1..03eef50 100644
--- a/misc/drupal.js
+++ b/misc/drupal.js
@@ -414,6 +414,29 @@ Drupal.getSelection = function (element) {
};
/**
+ * Add a global variable which determines if the window is being unloaded.
+ *
+ * This is primarily used by Drupal.displayAjaxError().
+ */
+Drupal.beforeUnloadCalled = false;
+$(window).bind('beforeunload pagehide', function () {
+ Drupal.beforeUnloadCalled = true;
+});
+
+/**
+ * Displays a JavaScript error from an Ajax response when appropriate to do so.
+ */
+Drupal.displayAjaxError = function (message) {
+ // Skip displaying the message if the user deliberately aborted (for example,
+ // by reloading the page or navigating to a different page) while the Ajax
+ // request was still ongoing. See, for example, the discussion at
+ // http://stackoverflow.com/questions/699941/handle-ajax-error-when-a-user-clicks-refresh.
+ if (!Drupal.beforeUnloadCalled) {
+ alert(message);
+ }
+};
+
+/**
* Build an error message from an Ajax response.
*/
Drupal.ajaxError = function (xmlhttp, uri, customMessage) {