From b19dc21950a05a55f8a1b211365d627d55603ec7 Mon Sep 17 00:00:00 2001 From: Anthony Gubler Date: Tue, 19 Jul 2016 16:05:44 +0100 Subject: [PATCH] listen to 'keypress' event to capture 'ENTER' for Internet Explorer --- extensions/Pagination.js | 46 ++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/extensions/Pagination.js b/extensions/Pagination.js index e6e86cb29..92026410e 100644 --- a/extensions/Pagination.js +++ b/extensions/Pagination.js @@ -9,12 +9,13 @@ define([ 'dojo/query', 'dojo/string', 'dojo/has', + 'dojo/keys', 'dojo/when', '../util/misc', 'dojo/i18n!./nls/pagination', 'dojo/_base/sniff' -], function (_StoreMixin, declare, arrayUtil, lang, domConstruct, domClass, on, query, string, has, when, - miscUtil, i18n) { +], function (_StoreMixin, declare, arrayUtil, lang, domConstruct, domClass, on, query, string, has, keys, + when, miscUtil, i18n) { function cleanupContent(grid) { // Remove any currently-rendered rows, or noDataMessage if (grid.noDataNode) { @@ -189,8 +190,11 @@ define([ destroy: function () { this.inherited(arguments); - if (this._pagingTextBoxHandle) { - this._pagingTextBoxHandle.remove(); + if (this._pagingTextBoxChangeHandle) { + this._pagingTextBoxChangeHandle.remove(); + } + if (this._pagingTextBoxKeyPressHandle) { + this._pagingTextBoxKeyPressHandle.remove(); } }, @@ -283,15 +287,25 @@ define([ pagingLinks = this.pagingLinks, paginationNavigationNode = this.paginationNavigationNode, end = Math.ceil(total / this.rowsPerPage), - pagingTextBoxHandle = this._pagingTextBoxHandle, + pagingTextBoxKeyPressHandle = this._pagingTextBoxKeyPressHandle, + pagingTextBoxChangeHandle = this._pagingTextBoxChangeHandle, focused = document.activeElement, focusedPage, lastFocusablePageLink, focusableNodes; + function _gotoPage (page) { + page = +page; + if (!isNaN(page) && page > 0 && page <= end) { + grid.gotoPage(page); + } + } + function pageLink(page, addSpace) { var link; var disabled; + var requirePageChange = true; + if (grid.pagingTextBox && page === currentPage && end > 1) { // use a paging text box if enabled instead of just a number link = domConstruct.create('input', { @@ -300,10 +314,16 @@ define([ type: 'text', value: currentPage }, linksNode); - grid._pagingTextBoxHandle = on(link, 'change', function () { - var value = +this.value; - if (!isNaN(value) && value > 0 && value <= end) { - grid.gotoPage(+this.value); + grid._pagingTextBoxChangeHandle = on(link, 'change', function (evt) { + if (requirePageChange) { + _gotoPage(+this.value); + } + requirePageChange = true; + }); + grid._pagingTextBoxKeyPressHandle = on(link, 'keypress', function(evt) { + if (evt.keyCode === keys.ENTER) { + requirePageChange = false; + _gotoPage(+this.value); } }); if (focused && focused.tagName === 'INPUT') { @@ -361,9 +381,13 @@ define([ focusedPage = +focused.innerHTML; } - if (pagingTextBoxHandle) { - pagingTextBoxHandle.remove(); + if (pagingTextBoxKeyPressHandle) { + pagingTextBoxKeyPressHandle.remove(); } + if (pagingTextBoxChangeHandle) { + pagingTextBoxChangeHandle.remove(); + } + linksNode.innerHTML = ''; query('.dgrid-first, .dgrid-previous', paginationNavigationNode).forEach(function (link) { setDisabled(link, currentPage === 1);