From dc6755d0a285c857aa42419d85c10e6cbecf8160 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 16 May 2015 11:47:59 +0200 Subject: [PATCH] Fix WCF.Table.EmptyTableHandler when MutationObserver is used --- wcfsetup/install/files/js/WCF.js | 91 ++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 35 deletions(-) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index b4977b77e3..ccb730481b 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -6338,7 +6338,7 @@ WCF.PageVisibilityHandler = { /** * Namespace for table related classes. */ -WCF.Table = {}; +WCF.Table = { }; /** * Handles empty tables which can be used in combination with WCF.Action.Proxy. @@ -6378,48 +6378,69 @@ WCF.Table.EmptyTableHandler = Class.extend({ }, /** - * Handles the removal of a DOM node. + * Returns the current number of table rows. + * + * @return integer */ - _remove: function(event) { - var element = $(event.target); - - // check if DOM element is relevant - if (element.hasClass(this._rowClassName)) { - var tbody = element.parents('tbody:eq(0)'); - - // check if table will be empty if DOM node is removed - if (tbody.children('tr').length == 1) { - if (this._options.emptyMessage) { - // insert message - this._tableContainer.replaceWith($('

').addClass(this._options.messageType).text(this._options.emptyMessage)); - } - else if (this._options.refreshPage) { - // refresh page - if (this._options.updatePageNumber) { - // calculate the new page number - var pageNumberURLComponents = window.location.href.match(/(\?|&)pageNo=(\d+)/g); - if (pageNumberURLComponents) { - var currentPageNumber = pageNumberURLComponents[pageNumberURLComponents.length - 1].match(/\d+/g); - if (this._options.updatePageNumber > 0) { - currentPageNumber++; - } - else { - currentPageNumber--; - } - - window.location = window.location.href.replace(pageNumberURLComponents[pageNumberURLComponents.length - 1], pageNumberURLComponents[pageNumberURLComponents.length - 1][0] + 'pageNo=' + currentPageNumber); - } + _getRowCount: function() { + return this._tableContainer.find('table tr.' + this._rowClassName).length; + }, + + /** + * Handles an empty table. + */ + _handleEmptyTable: function() { + if (this._options.emptyMessage) { + // insert message + this._tableContainer.replaceWith($('

').addClass(this._options.messageType).text(this._options.emptyMessage)); + } + else if (this._options.refreshPage) { + // refresh page + if (this._options.updatePageNumber) { + // calculate the new page number + var pageNumberURLComponents = window.location.href.match(/(\?|&)pageNo=(\d+)/g); + if (pageNumberURLComponents) { + var currentPageNumber = pageNumberURLComponents[pageNumberURLComponents.length - 1].match(/\d+/g); + if (this._options.updatePageNumber > 0) { + currentPageNumber++; } else { - window.location.reload(); + currentPageNumber--; } + + window.location = window.location.href.replace(pageNumberURLComponents[pageNumberURLComponents.length - 1], pageNumberURLComponents[pageNumberURLComponents.length - 1][0] + 'pageNo=' + currentPageNumber); } - else { - // simply remove the table container - this._tableContainer.remove(); + } + else { + window.location.reload(); + } + } + else { + // simply remove the table container + this._tableContainer.remove(); + } + }, + + /** + * Handles the removal of a DOM node. + */ + _remove: function(event) { + if ($.getLength(event)) { + var element = $(event.target); + + // check if DOM element is relevant + if (element.hasClass(this._rowClassName)) { + var tbody = element.parents('tbody:eq(0)'); + + // check if table will be empty if DOM node is removed + if (tbody.children('tr').length == 1) { + this._handleEmptyTable(); } } } + else if (!this._getRowCount()) { + this._handleEmptyTable(); + } } }); -- 2.20.1