Skip to content

Commit

Permalink
listen to 'keypress' event to capture 'ENTER' for Internet Explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
agubler committed Jul 19, 2016
1 parent 9496a55 commit b19dc21
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions extensions/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
},

Expand Down Expand Up @@ -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', {
Expand All @@ -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') {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit b19dc21

Please sign in to comment.