mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
Pager: maintain filter focus on custom controls. Fixes #1296
This commit is contained in:
parent
114b45e93b
commit
ba5ed93125
@ -1,5 +1,5 @@
|
|||||||
/*!
|
/*!
|
||||||
* custom pager controls (beta) for Tablesorter - updated 9/1/2016 (v2.27.6)
|
* custom pager controls (beta) for Tablesorter - updated 9/28/2016 (v2.27.8)
|
||||||
initialize custom pager script BEFORE initializing tablesorter/tablesorter pager
|
initialize custom pager script BEFORE initializing tablesorter/tablesorter pager
|
||||||
custom pager looks like this:
|
custom pager looks like this:
|
||||||
1 | 2 … 5 | 6 | 7 … 99 | 100
|
1 | 2 … 5 | 6 | 7 … 99 | 100
|
||||||
@ -13,7 +13,7 @@
|
|||||||
/*global jQuery: false */
|
/*global jQuery: false */
|
||||||
|
|
||||||
;(function($) {
|
;(function($) {
|
||||||
"use strict";
|
'use strict';
|
||||||
|
|
||||||
$.tablesorter = $.tablesorter || {};
|
$.tablesorter = $.tablesorter || {};
|
||||||
|
|
||||||
@ -34,9 +34,13 @@ $.tablesorter.customPagerControls = function(settings) {
|
|||||||
},
|
},
|
||||||
options = $.extend({}, defaults, settings),
|
options = $.extend({}, defaults, settings),
|
||||||
$table = $(options.table),
|
$table = $(options.table),
|
||||||
$pager = $(options.pager);
|
$pager = $(options.pager),
|
||||||
|
focusOnPager = false;
|
||||||
|
|
||||||
$table
|
$table
|
||||||
|
.on('filterStart', function() {
|
||||||
|
focusOnPager = false;
|
||||||
|
})
|
||||||
.on('pagerInitialized pagerComplete', function (e, c) {
|
.on('pagerInitialized pagerComplete', function (e, c) {
|
||||||
var indx,
|
var indx,
|
||||||
p = c.pager ? c.pager : c, // using widget
|
p = c.pager ? c.pager : c, // using widget
|
||||||
@ -83,11 +87,11 @@ $.tablesorter.customPagerControls = function(settings) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$pager
|
$pager.find('.pagecount').html(pages.html());
|
||||||
.find('.pagecount')
|
if (focusOnPager) {
|
||||||
.html(pages.html())
|
// don't focus on pager when using filter - fixes #1296
|
||||||
.find('.' + options.currentClass)
|
$pager.find('.' + options.currentClass).focus();
|
||||||
.focus();
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// set up pager controls
|
// set up pager controls
|
||||||
@ -103,6 +107,7 @@ $.tablesorter.customPagerControls = function(settings) {
|
|||||||
})
|
})
|
||||||
.end()
|
.end()
|
||||||
.on('click', options.currentPage, function() {
|
.on('click', options.currentPage, function() {
|
||||||
|
focusOnPager = true;
|
||||||
var $el = $(this);
|
var $el = $(this);
|
||||||
$el
|
$el
|
||||||
.addClass(options.currentClass)
|
.addClass(options.currentClass)
|
||||||
@ -118,11 +123,13 @@ $.tablesorter.customPagerControls = function(settings) {
|
|||||||
// ignore arrows inside form elements
|
// ignore arrows inside form elements
|
||||||
if (/input|select|textarea/i.test(events.target.nodeName) ||
|
if (/input|select|textarea/i.test(events.target.nodeName) ||
|
||||||
!(events.which > 32 && events.which < 41)) {
|
!(events.which > 32 && events.which < 41)) {
|
||||||
|
focusOnPager = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// only allow keyboard use if element inside of pager is focused
|
// only allow keyboard use if element inside of pager is focused
|
||||||
if ($(document.activeElement).closest(options.pager).is($pager)) {
|
if ($(document.activeElement).closest(options.pager).is($pager)) {
|
||||||
events.preventDefault();
|
events.preventDefault();
|
||||||
|
focusOnPager = true;
|
||||||
var key = events.which,
|
var key = events.which,
|
||||||
max = $table[0].config.totalRows,
|
max = $table[0].config.totalRows,
|
||||||
$el = $pager.find(options.currentPage).filter('.' + options.currentClass),
|
$el = $pager.find(options.currentPage).filter('.' + options.currentClass),
|
||||||
@ -140,4 +147,5 @@ $.tablesorter.customPagerControls = function(settings) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
Loading…
Reference in New Issue
Block a user