datatables.net-keytable
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -1,2 +0,2 @@ | ||
/*! KeyTable 2.0.0 | ||
/*! KeyTable 2.1.0 | ||
* ©2009-2015 SpryMedia Ltd - datatables.net/license | ||
@@ -8,3 +8,3 @@ */ | ||
* @description Spreadsheet like keyboard navigation for DataTables | ||
* @version 2.0.0 | ||
* @version 2.1.0 | ||
* @file dataTables.keyTable.js | ||
@@ -25,11 +25,32 @@ * @author SpryMedia Ltd (www.sprymedia.co.uk) | ||
(function( factory ){ | ||
if ( typeof define === 'function' && define.amd ) { | ||
// AMD | ||
define( ['jquery', 'datatables.net'], function ( $ ) { | ||
return factory( $, window, document ); | ||
} ); | ||
} | ||
else if ( typeof exports === 'object' ) { | ||
// CommonJS | ||
module.exports = function (root, $) { | ||
if ( ! root ) { | ||
root = window; | ||
} | ||
(function(window, document, undefined) { | ||
if ( ! $ || ! $.fn.dataTable ) { | ||
$ = require('datatables.net')(root, $).$; | ||
} | ||
return factory( $, root, root.document ); | ||
}; | ||
} | ||
else { | ||
// Browser | ||
factory( jQuery, window, document ); | ||
} | ||
}(function( $, window, document, undefined ) { | ||
'use strict'; | ||
var DataTable = $.fn.dataTable; | ||
var factory = function( $, DataTable ) { | ||
"use strict"; | ||
var KeyTable = function ( dt, opts ) { | ||
@@ -73,3 +94,3 @@ // Sanity check that we are using DataTables 1.10 or newer | ||
KeyTable.prototype = { | ||
$.extend( KeyTable.prototype, { | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
@@ -107,3 +128,20 @@ * API methods for DataTables API interface | ||
/** | ||
* Is the cell focused | ||
* @param {object} cell Cell index to check | ||
* @returns {boolean} true if focused, false otherwise | ||
*/ | ||
focused: function ( cell ) | ||
{ | ||
var lastFocus = this.s.lastFocus; | ||
if ( ! lastFocus ) { | ||
return false; | ||
} | ||
var lastIdx = this.s.lastFocus.index(); | ||
return cell.row === lastIdx.row && cell.column === lastIdx.column; | ||
}, | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
@@ -353,3 +391,3 @@ * Constructor | ||
// page | ||
if ( row < pageInfo.start || row >= pageInfo.start+pageInfo.length ) { | ||
if ( pageInfo.length !== -1 && (row < pageInfo.start || row >= pageInfo.start+pageInfo.length) ) { | ||
dt | ||
@@ -376,3 +414,3 @@ .one( 'draw', function () { | ||
var cell = dt.cell( ':eq('+row+')', column ); | ||
var cell = dt.cell( ':eq('+row+')', column, {search: 'applied'} ); | ||
@@ -619,4 +657,3 @@ if ( lastFocus ) { | ||
if ( row >= 0 && row < rows && | ||
column >= 0 && column <= columns.length | ||
if ( row >= 0 && row < rows && $.inArray( column, columns ) !== -1 | ||
) { | ||
@@ -669,3 +706,3 @@ e.preventDefault(); | ||
} | ||
}; | ||
} ); | ||
@@ -728,3 +765,3 @@ | ||
KeyTable.version = "2.0.0"; | ||
KeyTable.version = "2.1.0"; | ||
@@ -768,3 +805,24 @@ | ||
// Cell selector | ||
DataTable.ext.selector.cell.push( function ( settings, opts, cells ) { | ||
var focused = opts.focused; | ||
var kt = settings.keytable; | ||
var out = []; | ||
if ( ! kt || focused === undefined ) { | ||
return cells; | ||
} | ||
for ( var i=0, ien=cells.length ; i<ien ; i++ ) { | ||
if ( (focused === true && kt.focused( cells[i] ) ) || | ||
(focused === false && ! kt.focused( cells[i] ) ) | ||
) { | ||
out.push( cells[i] ); | ||
} | ||
} | ||
return out; | ||
} ); | ||
// Attach a listener to the document which listens for DataTables initialisation | ||
@@ -791,19 +849,2 @@ // events so we can automatically initialise | ||
return KeyTable; | ||
}; // /factory | ||
// Define as an AMD module if possible | ||
if ( typeof define === 'function' && define.amd ) { | ||
define( ['jquery', 'datatables'], factory ); | ||
} | ||
else if ( typeof exports === 'object' ) { | ||
// Node/CommonJS | ||
factory( require('jquery'), require('datatables') ); | ||
} | ||
else if ( jQuery && !jQuery.fn.dataTable.KeyTable ) { | ||
// Otherwise simply initialise as normal, stopping multiple evaluation | ||
factory( jQuery, jQuery.fn.dataTable ); | ||
} | ||
})(window, document); | ||
})); |
{ | ||
"name": "datatables.net-keytable", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "KeyTable for DataTables ", | ||
@@ -5,0 +5,0 @@ "files": [ |
@@ -22,3 +22,3 @@ # KeyTable for DataTables | ||
var $ = require( 'jquery' ); | ||
require( 'datatables.net-keytable' )( $ ); | ||
require( 'datatables.net-keytable' )( window, $ ); | ||
``` | ||
@@ -25,0 +25,0 @@ |
21832
690