From 2f326e85e7d9166c4e7fe099778ac273fa75f379 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 5 Jun 2012 23:02:40 +0200 Subject: [PATCH] Suppressing a few issues on page unload Popovers and WCF.Action.Proxy no longer cause strange errors if you're unloading the page (e.g. clicked a link). --- wcfsetup/install/files/js/WCF.js | 65 +++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index dc5a3749d3..22f33af8f9 100644 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -1196,6 +1196,12 @@ WCF.Action.Proxy.prototype = { * @var integer */ _loadingOverlayVisibleTimer: 0, + + /** + * suppresses errors + * @var boolean + */ + _suppressErrors: false, /** * Initializes AJAXProxy. @@ -1218,11 +1224,15 @@ WCF.Action.Proxy.prototype = { this.confirmationDialog = null; this.loading = null; + this._suppressErrors = false; // send request immediately after initialization if (this.options.autoSend) { this.sendRequest(); } + + var self = this; + $(window).on('beforeunload', function() { self._suppressErrors = true; }); }, /** @@ -1302,17 +1312,26 @@ WCF.Action.Proxy.prototype = { var data = $.parseJSON(jqXHR.responseText); // call child method if applicable + var $showError = true; if ($.isFunction(this.options.failure)) { - this.options.failure(jqXHR, textStatus, errorThrown, data); + $showError = this.options.failure(jqXHR, textStatus, errorThrown, jqXHR.responseText); } - var $randomID = WCF.getRandomID(); - $('

' + data.message + '

Stacktrace:

' + data.stacktrace + '

').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); + if (!this._suppressErrors && $showError !== false) { + $('

' + data.message + '

Stacktrace:

' + data.stacktrace + '

').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); + } } // failed to parse JSON catch (e) { - var $randomID = WCF.getRandomID(); - $('

' + jqXHR.responseText + '.

').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); + // call child method if applicable + var $showError = true; + if ($.isFunction(this.options.failure)) { + $showError = this.options.failure(jqXHR, textStatus, errorThrown, jqXHR.responseText); + } + + if (!this._suppressErrors && $showError !== false) { + $('

' + jqXHR.responseText + '

').wcfDialog({ title: WCF.Language.get('wcf.global.error.title') }); + } } this._after(); @@ -4980,6 +4999,12 @@ WCF.Popover = Class.extend({ */ _activeElementID: '', + /** + * cancels popover + * @var boolean + */ + _cancelPopover: false, + /** * element data * @var object @@ -5082,6 +5107,7 @@ WCF.Popover = Class.extend({ init: function(selector) { // assign default values this._activeElementID = ''; + this._cancelPopover = false; this._data = { }; this._defaultDimensions = { height: 150, @@ -5131,16 +5157,32 @@ WCF.Popover = Class.extend({ }; $element.hover($.proxy(this._overElement, this), $.proxy(this._out, this)); + + if ($element.getTagName() === 'a') { + $element.click($.proxy(this._cancel, this)); + } } }, this)); }, + /** + * Cancels popovers if link is being clicked + */ + _cancel: function(event) { + this._cancelPopover = true; + this._hide(true); + }, + /** * Triggered once an element is being hovered. * * @param object event */ _overElement: function(event) { + if (this._cancelPopover) { + return; + } + if (this._peOverElement !== null) { this._peOverElement.stop(); } @@ -5165,6 +5207,10 @@ WCF.Popover = Class.extend({ * Prepares popover to be displayed. */ _prepare: function() { + if (this._cancelPopover) { + return; + } + if (this._peOut !== null) { this._peOut.stop(); } @@ -5209,6 +5255,10 @@ WCF.Popover = Class.extend({ * Displays the popover. */ _show: function() { + if (this._cancelPopover) { + return; + } + this._popover.stop().wcfFadeIn(); if (this._data[this._activeElementID].loading) { @@ -5277,6 +5327,7 @@ WCF.Popover = Class.extend({ this._popover.stop(); if (disableAnimation) { + sekf._popover.css({ opacity: 0 }); self._popoverContent.empty().css({ height: 'auto', opacity: 0, width: 'auto' }); } else { @@ -5302,6 +5353,10 @@ WCF.Popover = Class.extend({ * Triggered once element *or* popover is now longer hovered. */ _out: function(event) { + if (this._cancelPopover) { + return; + } + this._hoverElementID = ''; this._hoverElement = false; this._hoverPopover = false; -- 2.20.1