Fix WCF.Table.EmptyTableHandler when MutationObserver is used
authorMatthias Schmidt <gravatronics@live.com>
Sat, 16 May 2015 09:47:59 +0000 (11:47 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sat, 16 May 2015 09:47:59 +0000 (11:47 +0200)
wcfsetup/install/files/js/WCF.js

index b4977b77e35e693c5b589fcb972b78711d5d1ab5..ccb730481bca4984769cb284f16b903b356b5e5e 100755 (executable)
@@ -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($('<p />').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($('<p />').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();
+               }
        }
 });