datatables.net-keytable
Advanced tools
Comparing version 2.1.3 to 2.2.0
@@ -1,2 +0,2 @@ | ||
/*! KeyTable 2.1.3 | ||
/*! KeyTable 2.2.0 | ||
* ©2009-2016 SpryMedia Ltd - datatables.net/license | ||
@@ -8,3 +8,3 @@ */ | ||
* @description Spreadsheet like keyboard navigation for DataTables | ||
* @version 2.1.3 | ||
* @version 2.2.0 | ||
* @file dataTables.keyTable.js | ||
@@ -76,3 +76,11 @@ * @author SpryMedia Ltd (www.sprymedia.co.uk) | ||
/** @type {bool} Flag for if a draw is triggered by focus */ | ||
focusDraw: false | ||
focusDraw: false, | ||
/** @type {bool} Flag to indicate when waiting for a draw to happen. | ||
* Will ignore key presses at this point | ||
*/ | ||
waitingForDraw: false, | ||
/** @type {object} Information about the last cell that was focused */ | ||
lastFocus: null | ||
}; | ||
@@ -143,3 +151,3 @@ | ||
var lastIdx = this.s.lastFocus.index(); | ||
var lastIdx = this.s.lastFocus.cell.index(); | ||
return cell.row === lastIdx.row && cell.column === lastIdx.column; | ||
@@ -193,3 +201,3 @@ }, | ||
if ( this.c.blurable ) { | ||
$( document ).on( 'click.keyTable', function ( e ) { | ||
$( document ).on( 'mousedown.keyTable', function ( e ) { | ||
// Click on the search input will blur focus | ||
@@ -229,3 +237,3 @@ if ( $(e.target).parents( '.dataTables_filter' ).length ) { | ||
d.keyTable = that.s.lastFocus ? | ||
that.s.lastFocus.index() : | ||
that.s.lastFocus.cell.index() : | ||
null; | ||
@@ -235,9 +243,5 @@ } ); | ||
// Reload - re-focus on the currently selected item. In SSP mode this | ||
// has the effect of keeping the focus in position when changing page as | ||
// well (which is different from how client-side processing works). | ||
dt.on( 'xhr.keyTable', function ( e ) { | ||
// Redraw - retain focus on the current cell | ||
dt.on( 'draw.keyTable', function (e) { | ||
if ( that.s.focusDraw ) { | ||
// Triggered by server-side processing, and thus `_focus` will | ||
// do the refocus on the next draw event | ||
return; | ||
@@ -249,7 +253,12 @@ } | ||
if ( lastFocus ) { | ||
that.s.lastFocus = null; | ||
var relative = that.s.lastFocus.relative; | ||
var info = dt.page.info(); | ||
var row = relative.row + info.start; | ||
dt.one( 'draw', function () { | ||
that._focus( lastFocus ); | ||
} ); | ||
// Reverse if needed | ||
if ( row >= info.recordsDisplay ) { | ||
row = info.recordsDisplay - 1; | ||
} | ||
that._focus( row, relative.column, true, e ); | ||
} | ||
@@ -303,3 +312,3 @@ } ); | ||
var cell = this.s.lastFocus; | ||
var cell = this.s.lastFocus.cell; | ||
@@ -350,2 +359,7 @@ $( cell.node() ).removeClass( this.c.className ); | ||
// Don't activate inline editing when the shift key is pressed | ||
if ( key === 16 ) { | ||
return; | ||
} | ||
orig.stopPropagation(); | ||
@@ -359,3 +373,3 @@ | ||
editor.inline( this.s.lastFocus.index() ); | ||
editor.inline( this.s.lastFocus.cell.index() ); | ||
@@ -403,3 +417,3 @@ // Excel style - select all text | ||
* contains the cell to focus or as an integer. As the latter it is the | ||
* visible row index - NOT the data index | ||
* visible row index (from the whole data set) - NOT the data index | ||
* @param {integer} [column] Not required if a cell is given as the first | ||
@@ -445,2 +459,3 @@ * parameter. Otherwise this is the column data index for the cell to | ||
this.s.focusDraw = true; | ||
this.s.waitingForDraw = true; | ||
@@ -450,2 +465,3 @@ dt | ||
that.s.focusDraw = false; | ||
that.s.waitingForDraw = false; | ||
that._focus( row, column ); | ||
@@ -474,3 +490,3 @@ } ) | ||
// Don't trigger a refocus on the same cell | ||
if ( lastFocus.node() === cell.node() ) { | ||
if ( lastFocus.node === cell.node() ) { | ||
return; | ||
@@ -501,3 +517,10 @@ } | ||
// Event and finish | ||
this.s.lastFocus = cell; | ||
this.s.lastFocus = { | ||
cell: cell, | ||
node: cell.node(), | ||
relative: { | ||
row: dt.rows( { page: 'current' } ).indexes().indexOf( cell.index().row ), | ||
column: cell.index().column | ||
} | ||
}; | ||
@@ -517,2 +540,9 @@ this._emitEvent( 'key-focus', [ this.s.dt, cell, originalEvent || null ] ); | ||
{ | ||
// If we are waiting for a draw to happen from another key event, then | ||
// do nothing for this new key press. | ||
if ( this.s.waitingForDraw ) { | ||
e.preventDefault(); | ||
return; | ||
} | ||
var enable = this.s.enable; | ||
@@ -529,4 +559,4 @@ var navEnable = enable === true || enable === 'navigation-only'; | ||
// If not focused, then there is no key action to take | ||
var cell = this.s.lastFocus; | ||
if ( ! cell ) { | ||
var lastFocus = this.s.lastFocus; | ||
if ( ! lastFocus ) { | ||
return; | ||
@@ -559,13 +589,4 @@ } | ||
e.preventDefault(); | ||
var index = dt.cells( {page: 'current'} ).nodes().indexOf( cell.node() ); | ||
dt | ||
.one( 'draw', function () { | ||
var nodes = dt.cells( {page: 'current'} ).nodes(); | ||
that._focus( dt.cell( index < nodes.length ? | ||
nodes[ index ] : | ||
nodes[ nodes.length-1 ] | ||
) , null, true, e); | ||
} ) | ||
.page( e.keyCode === 33 ? 'previous' : 'next' ) | ||
@@ -581,5 +602,6 @@ .draw( false ); | ||
var indexes = dt.cells( {page: 'current'} ).indexes(); | ||
var colIndexes = this._columns(); | ||
this._focus( dt.cell( | ||
indexes[ e.keyCode === 35 ? indexes.length-1 : 0 ] | ||
indexes[ e.keyCode === 35 ? indexes.length-1 : colIndexes[0] ] | ||
), null, true, e ); | ||
@@ -616,3 +638,3 @@ } | ||
if ( enable === true ) { | ||
this._emitEvent( 'key', [ dt, e.keyCode, this.s.lastFocus, e ] ); | ||
this._emitEvent( 'key', [ dt, e.keyCode, this.s.lastFocus.cell, e ] ); | ||
} | ||
@@ -685,3 +707,3 @@ break; | ||
var rows = pageInfo.recordsDisplay; | ||
var currentCell = this.s.lastFocus; | ||
var currentCell = this.s.lastFocus.cell; | ||
var columns = this._columns(); | ||
@@ -869,3 +891,3 @@ | ||
KeyTable.version = "2.1.3"; | ||
KeyTable.version = "2.2.0"; | ||
@@ -872,0 +894,0 @@ |
{ | ||
"name": "datatables.net-keytable", | ||
"version": "2.1.3", | ||
"version": "2.2.0", | ||
"description": "KeyTable for DataTables ", | ||
@@ -5,0 +5,0 @@ "files": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25119
786