Browse Source

Fix #3095: add event.preventDefault to href='#' link

zhixin 8 years ago
parent
commit
3fd238ce8f
2 changed files with 9 additions and 31 deletions
  1. 8 16
      src/bootstrap-table.js
  2. 1 15
      src/extensions/cookie/bootstrap-table-cookie.js

+ 8 - 16
src/bootstrap-table.js

@@ -1596,6 +1596,7 @@
     };
 
     BootstrapTable.prototype.onPageListChange = function (event) {
+        event.preventDefault();
         var $this = $(event.currentTarget);
 
         $this.parent().addClass('active').siblings().removeClass('active');
@@ -1607,14 +1608,8 @@
         return false;
     };
 
-    // TODO: remove
-    BootstrapTable.prototype.onPageFirst = function (event) {
-        this.options.pageNumber = 1;
-        this.updatePagination(event);
-        return false;
-    };
-
     BootstrapTable.prototype.onPagePre = function (event) {
+        event.preventDefault();
         if ((this.options.pageNumber - 1) === 0) {
             this.options.pageNumber = this.options.totalPages;
         } else {
@@ -1625,6 +1620,7 @@
     };
 
     BootstrapTable.prototype.onPageNext = function (event) {
+        event.preventDefault();
         if ((this.options.pageNumber + 1) > this.options.totalPages) {
             this.options.pageNumber = 1;
         } else {
@@ -1634,14 +1630,8 @@
         return false;
     };
 
-    // TODO: remove
-    BootstrapTable.prototype.onPageLast = function (event) {
-        this.options.pageNumber = this.totalPages;
-        this.updatePagination(event);
-        return false;
-    };
-
     BootstrapTable.prototype.onPageNumber = function (event) {
+        event.preventDefault();
         if (this.options.pageNumber === +$(event.currentTarget).text()) {
             return;
         }
@@ -1709,7 +1699,7 @@
             html.push('<td>');
 
             if (calculateObjectValue(null, this.options.detailFilter, [i, item])) {
-                html.push('<a class="detail-icon" href="javascript:">',
+                html.push('<a class="detail-icon" href="#">',
                 sprintf('<i class="%s %s"></i>', this.options.iconsPrefix, this.options.icons.detailOpen),
                 '</a>');
             }
@@ -1920,7 +1910,9 @@
             }
         });
 
-        this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function () {
+        this.$body.find('> tr[data-index] > td > .detail-icon').off('click').on('click', function (e) {
+            e.preventDefault();
+
             var $this = $(this),
                 $tr = $this.parent().parent(),
                 index = $tr.data('index'),

+ 1 - 15
src/extensions/cookie/bootstrap-table-cookie.js

@@ -182,7 +182,7 @@
                             if (cookie.text !== '') {
                                 $(element).val(cookie.text);
                                 cachedFilters[cookie.field] = cookie.text;
-                            }                                
+                            }
                         });
                     };
 
@@ -236,10 +236,8 @@
         _onSort = BootstrapTable.prototype.onSort,
         _onPageNumber = BootstrapTable.prototype.onPageNumber,
         _onPageListChange = BootstrapTable.prototype.onPageListChange,
-        _onPageFirst = BootstrapTable.prototype.onPageFirst,
         _onPagePre = BootstrapTable.prototype.onPagePre,
         _onPageNext = BootstrapTable.prototype.onPageNext,
-        _onPageLast = BootstrapTable.prototype.onPageLast,
         _toggleColumn = BootstrapTable.prototype.toggleColumn,
         _selectPage = BootstrapTable.prototype.selectPage,
         _onSearch = BootstrapTable.prototype.onSearch;
@@ -348,12 +346,6 @@
         return false;
     };
 
-    BootstrapTable.prototype.onPageFirst = function () {
-        _onPageFirst.apply(this, Array.prototype.slice.apply(arguments));
-        setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
-        return false;
-    };
-
     BootstrapTable.prototype.onPagePre = function () {
         _onPagePre.apply(this, Array.prototype.slice.apply(arguments));
         setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
@@ -366,12 +358,6 @@
         return false;
     };
 
-    BootstrapTable.prototype.onPageLast = function () {
-        _onPageLast.apply(this, Array.prototype.slice.apply(arguments));
-        setCookie(this, cookieIds.pageNumber, this.options.pageNumber);
-        return false;
-    };
-
     BootstrapTable.prototype.toggleColumn = function () {
         _toggleColumn.apply(this, Array.prototype.slice.apply(arguments));