datatables.net-keytable
Advanced tools
Comparing version 2.5.0 to 2.5.1
@@ -1,3 +0,3 @@ | ||
/*! KeyTable 2.5.0 | ||
* ©2009-2018 SpryMedia Ltd - datatables.net/license | ||
/*! KeyTable 2.5.1 | ||
* ©2009-2019 SpryMedia Ltd - datatables.net/license | ||
*/ | ||
@@ -8,7 +8,7 @@ | ||
* @description Spreadsheet like keyboard navigation for DataTables | ||
* @version 2.5.0 | ||
* @version 2.5.1 | ||
* @file dataTables.keyTable.js | ||
* @author SpryMedia Ltd (www.sprymedia.co.uk) | ||
* @contact www.sprymedia.co.uk/contact | ||
* @copyright Copyright 2009-2018 SpryMedia Ltd. | ||
* @copyright Copyright 2009-2019 SpryMedia Ltd. | ||
* | ||
@@ -53,2 +53,3 @@ * This source file is free software, available under the following license: | ||
var DataTable = $.fn.dataTable; | ||
var namespaceCounter = 0; | ||
@@ -85,3 +86,6 @@ | ||
/** @type {object} Information about the last cell that was focused */ | ||
lastFocus: null | ||
lastFocus: null, | ||
/** @type {string} Unique namespace per instance */ | ||
namespace: '.keyTable-'+(namespaceCounter++) | ||
}; | ||
@@ -173,2 +177,4 @@ | ||
var table = $( dt.table().node() ); | ||
var namespace = this.s.namespace; | ||
var editorBlock = false; | ||
@@ -181,3 +187,3 @@ // Need to be able to calculate the cell positions relative to the table | ||
// Click to focus | ||
$( dt.table().body() ).on( 'click.keyTable', 'th, td', function (e) { | ||
$( dt.table().body() ).on( 'click'+namespace, 'th, td', function (e) { | ||
if ( that.s.enable === false ) { | ||
@@ -197,4 +203,6 @@ return; | ||
// Key events | ||
$( document ).on( 'keydown.keyTable', function (e) { | ||
that._key( e ); | ||
$( document ).on( 'keydown'+namespace, function (e) { | ||
if ( ! editorBlock ) { | ||
that._key( e ); | ||
} | ||
} ); | ||
@@ -204,3 +212,3 @@ | ||
if ( this.c.blurable ) { | ||
$( document ).on( 'mousedown.keyTable', function ( e ) { | ||
$( document ).on( 'mousedown'+namespace, function ( e ) { | ||
// Click on the search input will blur focus | ||
@@ -243,3 +251,3 @@ if ( $(e.target).parents( '.dataTables_filter' ).length ) { | ||
editor.one( 'close.keyTable', function () { | ||
editor.one( 'close'+namespace, function () { | ||
that.enable( true ); | ||
@@ -251,3 +259,3 @@ } ); | ||
if ( this.c.editOnFocus ) { | ||
dt.on( 'key-focus.keyTable key-refocus.keyTable', function ( e, dt, cell, orig ) { | ||
dt.on( 'key-focus'+namespace+' key-refocus'+namespace, function ( e, dt, cell, orig ) { | ||
that._editor( null, orig, true ); | ||
@@ -259,3 +267,3 @@ } ); | ||
// already active). | ||
dt.on( 'key.keyTable', function ( e, dt, key, cell, orig ) { | ||
dt.on( 'key'+namespace, function ( e, dt, key, cell, orig ) { | ||
that._editor( key, orig, false ); | ||
@@ -266,3 +274,3 @@ } ); | ||
// the click event handler above | ||
$( dt.table().body() ).on( 'dblclick.keyTable', 'th, td', function (e) { | ||
$( dt.table().body() ).on( 'dblclick'+namespace, 'th, td', function (e) { | ||
if ( that.s.enable === false ) { | ||
@@ -280,2 +288,14 @@ return; | ||
} ); | ||
// While Editor is busy processing, we don't want to process any key events | ||
editor | ||
.on('preSubmit', function () { | ||
editorBlock = true; | ||
} ) | ||
.on('preSubmitCancelled', function () { | ||
editorBlock = false; | ||
} ) | ||
.on('submitComplete', function () { | ||
editorBlock = false; | ||
} ); | ||
} | ||
@@ -285,3 +305,3 @@ | ||
if ( dt.settings()[0].oFeatures.bStateSave ) { | ||
dt.on( 'stateSaveParams.keyTable', function (e, s, d) { | ||
dt.on( 'stateSaveParams'+namespace, function (e, s, d) { | ||
d.keyTable = that.s.lastFocus ? | ||
@@ -294,3 +314,3 @@ that.s.lastFocus.cell.index() : | ||
// Redraw - retain focus on the current cell | ||
dt.on( 'draw.keyTable', function (e) { | ||
dt.on( 'draw'+namespace, function (e) { | ||
if ( that.s.focusDraw ) { | ||
@@ -325,10 +345,17 @@ return; | ||
dt.on( 'destroy.keyTable', function () { | ||
dt.off( '.keyTable' ); | ||
$( dt.table().body() ).off( 'click.keyTable', 'th, td' ); | ||
dt.on( 'destroy'+namespace, function () { | ||
that._blur( true ); | ||
// Event tidy up | ||
dt.off( namespace ); | ||
$( dt.table().body() ) | ||
.off( 'click'+namespace, 'th, td' ) | ||
.off( 'dblclick'+namespace, 'th, td' ); | ||
$( document ) | ||
.off( 'keydown.keyTable' ) | ||
.off( 'click.keyTable' ) | ||
.off( 'copy.keyTable' ) | ||
.off( 'paste.keyTable' ); | ||
.off( 'mousedown'+namespace ) | ||
.off( 'keydown'+namespace ) | ||
.off( 'copy'+namespace ) | ||
.off( 'paste'+namespace ); | ||
} ); | ||
@@ -363,5 +390,6 @@ | ||
* | ||
* @param {boolean} [noEvents=false] Don't trigger updates / events (for destroying) | ||
* @private | ||
*/ | ||
_blur: function () | ||
_blur: function (noEvents) | ||
{ | ||
@@ -377,5 +405,7 @@ if ( ! this.s.enable || ! this.s.lastFocus ) { | ||
this._updateFixedColumns(cell.index().column); | ||
if ( ! noEvents ) { | ||
this._updateFixedColumns(cell.index().column); | ||
this._emitEvent( 'key-blur', [ this.s.dt, cell ] ); | ||
this._emitEvent( 'key-blur', [ this.s.dt, cell ] ); | ||
} | ||
}, | ||
@@ -392,2 +422,3 @@ | ||
var that = this; | ||
var namespace = this.s.namespace; | ||
@@ -399,3 +430,3 @@ // IE8 doesn't support getting selected text | ||
$(document).on( 'copy.keyTable', function (ejq) { | ||
$(document).on( 'copy'+namespace, function (ejq) { | ||
var e = ejq.originalEvent; | ||
@@ -416,3 +447,3 @@ var selection = window.getSelection().toString(); | ||
$(document).on( 'paste.keyTable', function (ejq) { | ||
$(document).on( 'paste'+namespace, function (ejq) { | ||
var e = ejq.originalEvent; | ||
@@ -490,2 +521,3 @@ var focused = that.s.lastFocus; | ||
var editCell = this.s.lastFocus.cell; | ||
var namespace = this.s.namespace; | ||
@@ -519,5 +551,5 @@ // Do nothing if there is already an inline edit in this cell | ||
editor | ||
.one( 'open.keyTable', function () { | ||
.one( 'open'+namespace, function () { | ||
// Remove cancel open | ||
editor.off( 'cancelOpen.keyTable' ); | ||
editor.off( 'cancelOpen'+namespace ); | ||
@@ -533,4 +565,4 @@ // Excel style - select all text | ||
// On blur of the navigation submit | ||
dt.on( 'key-blur.editor', function () { | ||
if ( editor.displayed() ) { | ||
dt.on( 'key-blur.editor', function (e, dt, cell) { | ||
if ( editor.displayed() && cell.node() === editCell.node() ) { | ||
editor.submit(); | ||
@@ -545,3 +577,10 @@ } | ||
editor.on( 'submitUnsuccessful.keyTable', function () { | ||
// If the dev cancels the submit, we need to return focus | ||
editor.on( 'preSubmitCancelled'+namespace, function () { | ||
setTimeout( function () { | ||
that._focus( editCell, null, false ); | ||
}, 50 ); | ||
} ); | ||
editor.on( 'submitUnsuccessful'+namespace, function () { | ||
that._focus( editCell, null, false ); | ||
@@ -554,10 +593,10 @@ } ); | ||
dt.off( 'key-blur.editor' ); | ||
editor.off( '.keyTable' ); | ||
editor.off( namespace ); | ||
$( dt.table().container() ).removeClass('dtk-focus-alt'); | ||
} ); | ||
} ) | ||
.one( 'cancelOpen.keyTable', function () { | ||
.one( 'cancelOpen'+namespace, function () { | ||
// `preOpen` can cancel the display of the form, so it | ||
// might be that the open event handler isn't needed | ||
editor.off( '.keyTable' ); | ||
editor.off( namespace ); | ||
} ) | ||
@@ -697,2 +736,5 @@ .inline( editCell.index() ); | ||
// Clear focus from other tables | ||
this._removeOtherFocus(); | ||
var node = $( cell.node() ); | ||
@@ -761,2 +803,8 @@ node.addClass( this.c.className ); | ||
// And the last focus still exists! | ||
if ( ! this.s.dt.cell(lastFocus.node).any() ) { | ||
this.s.lastFocus = null; | ||
return; | ||
} | ||
var that = this; | ||
@@ -831,2 +879,9 @@ var dt = this.s.dt; | ||
case 113: // F2 - Excel like hard edit | ||
if ( this.c.editor ) { | ||
this._editor(null, e, true); | ||
break; | ||
} | ||
// else fallthrough | ||
default: | ||
@@ -841,3 +896,16 @@ // Everything else - pass through only when fully enabled | ||
/** | ||
* Remove focus from all tables other than this one | ||
*/ | ||
_removeOtherFocus: function () | ||
{ | ||
var thisTable = this.s.dt.table().node(); | ||
$.fn.dataTable.tables({api:true}).iterator('table', function (settings) { | ||
if (this.table().node() !== thisTable) { | ||
this.cell.blur(); | ||
} | ||
}); | ||
}, | ||
/** | ||
@@ -963,5 +1031,6 @@ * Scroll a container to make a cell visible in it. This can be used for | ||
if ( row >= 0 && row < rows && $.inArray( column, columns ) !== -1 | ||
) { | ||
e.preventDefault(); | ||
if ( row >= 0 && row < rows && $.inArray( column, columns ) !== -1 ) { | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
@@ -973,3 +1042,5 @@ this._focus( row, column, true, e ); | ||
// focus | ||
e.preventDefault(); | ||
if (e) { | ||
e.preventDefault(); | ||
} | ||
} | ||
@@ -1010,4 +1081,6 @@ else { | ||
div.children().on( 'focus', function (e) { | ||
if ( dt.cell(':eq(0)', {page: 'current'}).any() ) { | ||
that._focus( dt.cell(':eq(0)', '0:visible', {page: 'current'}), null, true, e ); | ||
var cell = dt.cell(':eq(0)', that._columns(), {page: 'current'}); | ||
if ( cell.any() ) { | ||
that._focus( cell, null, true, e ); | ||
} | ||
@@ -1113,3 +1186,3 @@ } ); | ||
KeyTable.version = "2.5.0"; | ||
KeyTable.version = "2.5.1"; | ||
@@ -1153,2 +1226,10 @@ | ||
DataTable.Api.register( 'keys.move()', function ( dir ) { | ||
return this.iterator( 'table', function (ctx) { | ||
if ( ctx.keytable ) { | ||
ctx.keytable._shift( null, dir, false ); | ||
} | ||
} ); | ||
} ); | ||
// Cell selector | ||
@@ -1155,0 +1236,0 @@ DataTable.ext.selector.cell.push( function ( settings, opts, cells ) { |
/*! | ||
KeyTable 2.5.0 | ||
©2009-2018 SpryMedia Ltd - datatables.net/license | ||
KeyTable 2.5.1 | ||
©2009-2019 SpryMedia Ltd - datatables.net/license | ||
*/ | ||
(function(f){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(k){return f(k,window,document)}):"object"===typeof exports?module.exports=function(k,h){k||(k=window);if(!h||!h.fn.dataTable)h=require("datatables.net")(k,h).$;return f(h,k,k.document)}:f(jQuery,window,document)})(function(f,k,h,o){var l=f.fn.dataTable,n=function(a,b){if(!l.versionCheck||!l.versionCheck("1.10.8"))throw"KeyTable requires DataTables 1.10.8 or newer";this.c=f.extend(!0,{},l.defaults.keyTable, | ||
n.defaults,b);this.s={dt:new l.Api(a),enable:!0,focusDraw:!1,waitingForDraw:!1,lastFocus:null};this.dom={};var c=this.s.dt.settings()[0],d=c.keytable;if(d)return d;c.keytable=this;this._constructor()};f.extend(n.prototype,{blur:function(){this._blur()},enable:function(a){this.s.enable=a},focus:function(a,b){this._focus(this.s.dt.cell(a,b))},focused:function(a){if(!this.s.lastFocus)return!1;var b=this.s.lastFocus.cell.index();return a.row===b.row&&a.column===b.column},_constructor:function(){this._tabInput(); | ||
var a=this,b=this.s.dt,c=f(b.table().node());"static"===c.css("position")&&c.css("position","relative");f(b.table().body()).on("click.keyTable","th, td",function(c){if(!1!==a.s.enable){var d=b.cell(this);d.any()&&a._focus(d,null,!1,c)}});f(h).on("keydown.keyTable",function(b){a._key(b)});if(this.c.blurable)f(h).on("mousedown.keyTable",function(c){f(c.target).parents(".dataTables_filter").length&&a._blur();f(c.target).parents().filter(b.table().container()).length||f(c.target).parents("div.DTE").length|| | ||
f(c.target).parents("div.editor-datetime").length||f(c.target).parents().filter(".DTFC_Cloned").length||a._blur()});if(this.c.editor){var d=this.c.editor;d.on("open.keyTableMain",function(b,c){"inline"!==c&&a.s.enable&&(a.enable(!1),d.one("close.keyTable",function(){a.enable(!0)}))});if(this.c.editOnFocus)b.on("key-focus.keyTable key-refocus.keyTable",function(b,c,d,e){a._editor(null,e,!0)});b.on("key.keyTable",function(b,c,d,e,f){a._editor(d,f,!1)});f(b.table().body()).on("dblclick.keyTable","th, td", | ||
function(c){!1!==a.s.enable&&b.cell(this).any()&&a._editor(null,c,!0)})}if(b.settings()[0].oFeatures.bStateSave)b.on("stateSaveParams.keyTable",function(b,c,d){d.keyTable=a.s.lastFocus?a.s.lastFocus.cell.index():null});b.on("draw.keyTable",function(c){if(!a.s.focusDraw){var d=a.s.lastFocus;if(d&&d.node&&f(d.node).closest("body")===h.body){var d=a.s.lastFocus.relative,e=b.page.info(),m=d.row+e.start;0!==e.recordsDisplay&&(m>=e.recordsDisplay&&(m=e.recordsDisplay-1),a._focus(m,d.column,!0,c))}}});this.c.clipboard&& | ||
this._clipboard();b.on("destroy.keyTable",function(){b.off(".keyTable");f(b.table().body()).off("click.keyTable","th, td");f(h).off("keydown.keyTable").off("click.keyTable").off("copy.keyTable").off("paste.keyTable")});var e=b.state.loaded();if(e&&e.keyTable)b.one("init",function(){var a=b.cell(e.keyTable);a.any()&&a.focus()});else this.c.focus&&b.cell(this.c.focus).focus()},_blur:function(){if(this.s.enable&&this.s.lastFocus){var a=this.s.lastFocus.cell;f(a.node()).removeClass(this.c.className); | ||
this.s.lastFocus=null;this._updateFixedColumns(a.index().column);this._emitEvent("key-blur",[this.s.dt,a])}},_clipboard:function(){var a=this.s.dt,b=this;k.getSelection&&(f(h).on("copy.keyTable",function(a){var a=a.originalEvent,d=k.getSelection().toString(),e=b.s.lastFocus;!d&&e&&(a.clipboardData.setData("text/plain",e.cell.render(b.c.clipboardOrthogonal)),a.preventDefault())}),f(h).on("paste.keyTable",function(c){var c=c.originalEvent,d=b.s.lastFocus,e=h.activeElement,f=b.c.editor,g;if(d&&(!e|| | ||
"body"===e.nodeName.toLowerCase()))c.preventDefault(),k.clipboardData&&k.clipboardData.getData?g=k.clipboardData.getData("Text"):c.clipboardData&&c.clipboardData.getData&&(g=c.clipboardData.getData("text/plain")),f?f.inline(d.cell.index()).set(f.displayed()[0],g).submit():(d.cell.data(g),a.draw(!1))}))},_columns:function(){var a=this.s.dt,b=a.columns(this.c.columns).indexes(),c=[];a.columns(":visible").every(function(a){-1!==b.indexOf(a)&&c.push(a)});return c},_editor:function(a,b,c){var d=this,e= | ||
this.s.dt,j=this.c.editor,g=this.s.lastFocus.cell;if(!f("div.DTE",g.node()).length&&!(null!==a&&(0<=a&&9>=a||11===a||12===a||14<=a&&31>=a||112<=a&&123>=a||127<=a&&159>=a))){b.stopPropagation();13===a&&b.preventDefault();var i=function(){j.one("open.keyTable",function(){j.off("cancelOpen.keyTable");c||f("div.DTE_Field_InputControl input, div.DTE_Field_InputControl textarea").select();e.keys.enable(c?"tab-only":"navigation-only");e.on("key-blur.editor",function(){j.displayed()&&j.submit()});c&&f(e.table().container()).addClass("dtk-focus-alt"); | ||
j.on("submitUnsuccessful.keyTable",function(){d._focus(g,null,!1)});j.one("close",function(){e.keys.enable(!0);e.off("key-blur.editor");j.off(".keyTable");f(e.table().container()).removeClass("dtk-focus-alt")})}).one("cancelOpen.keyTable",function(){j.off(".keyTable")}).inline(g.index())};13===a?(c=!0,f(h).one("keyup",function(){i()})):i()}},_emitEvent:function(a,b){this.s.dt.iterator("table",function(c){f(c.nTable).triggerHandler(a,b)})},_focus:function(a,b,c,d){var e=this,j=this.s.dt,g=j.page.info(), | ||
i=this.s.lastFocus;d||(d=null);if(this.s.enable){if("number"!==typeof a){if(!a.any())return;var m=a.index(),b=m.column,a=j.rows({filter:"applied",order:"applied"}).indexes().indexOf(m.row);if(0>a)return;g.serverSide&&(a+=g.start)}if(-1!==g.length&&(a<g.start||a>=g.start+g.length))this.s.focusDraw=!0,this.s.waitingForDraw=!0,j.one("draw",function(){e.s.focusDraw=!1;e.s.waitingForDraw=!1;e._focus(a,b,o,d)}).page(Math.floor(a/g.length)).draw(!1);else if(-1!==f.inArray(b,this._columns())){g.serverSide&& | ||
(a-=g.start);g=j.cells(null,b,{search:"applied",order:"applied"}).flatten();g=j.cell(g[a]);if(i){if(i.node===g.node()){this._emitEvent("key-refocus",[this.s.dt,g,d||null]);return}this._blur()}i=f(g.node());i.addClass(this.c.className);this._updateFixedColumns(b);if(c===o||!0===c)this._scroll(f(k),f(h.body),i,"offset"),c=j.table().body().parentNode,c!==j.table().header().parentNode&&(c=f(c.parentNode),this._scroll(c,c,i,"position"));this.s.lastFocus={cell:g,node:g.node(),relative:{row:j.rows({page:"current"}).indexes().indexOf(g.index().row), | ||
column:g.index().column}};this._emitEvent("key-focus",[this.s.dt,g,d||null]);j.state.save()}}},_key:function(a){if(this.s.waitingForDraw)a.preventDefault();else{var b=this.s.enable,c=!0===b||"navigation-only"===b;if(b&&(!(0===a.keyCode||a.ctrlKey||a.metaKey||a.altKey)||a.ctrlKey&&a.altKey)&&this.s.lastFocus){var d=this.s.dt,e=this.s.dt.settings()[0].oScroll.sY?!0:!1;if(!(this.c.keys&&-1===f.inArray(a.keyCode,this.c.keys)))switch(a.keyCode){case 9:this._shift(a,a.shiftKey?"left":"right",!0);break; | ||
case 27:this.s.blurable&&!0===b&&this._blur();break;case 33:case 34:c&&!e&&(a.preventDefault(),d.page(33===a.keyCode?"previous":"next").draw(!1));break;case 35:case 36:c&&(a.preventDefault(),b=d.cells({page:"current"}).indexes(),c=this._columns(),this._focus(d.cell(b[35===a.keyCode?b.length-1:c[0]]),null,!0,a));break;case 37:c&&this._shift(a,"left");break;case 38:c&&this._shift(a,"up");break;case 39:c&&this._shift(a,"right");break;case 40:c&&this._shift(a,"down");break;default:!0===b&&this._emitEvent("key", | ||
[d,a.keyCode,this.s.lastFocus.cell,a])}}}},_scroll:function(a,b,c,d){var e=c[d](),f=c.outerHeight(),g=c.outerWidth(),i=b.scrollTop(),m=b.scrollLeft(),h=a.height(),a=a.width();"position"===d&&(e.top+=parseInt(c.closest("table").css("top"),10));e.top<i&&b.scrollTop(e.top);e.left<m&&b.scrollLeft(e.left);e.top+f>i+h&&f<h&&b.scrollTop(e.top+f-h);e.left+g>m+a&&g<a&&b.scrollLeft(e.left+g-a)},_shift:function(a,b,c){var d=this.s.dt,e=d.page.info(),j=e.recordsDisplay,g=this.s.lastFocus.cell,i=this._columns(); | ||
if(g){var h=d.rows({filter:"applied",order:"applied"}).indexes().indexOf(g.index().row);e.serverSide&&(h+=e.start);d=d.columns(i).indexes().indexOf(g.index().column);e=i[d];"right"===b?d>=i.length-1?(h++,e=i[0]):e=i[d+1]:"left"===b?0===d?(h--,e=i[i.length-1]):e=i[d-1]:"up"===b?h--:"down"===b&&h++;0<=h&&h<j&&-1!==f.inArray(e,i)?(a.preventDefault(),this._focus(h,e,!0,a)):!c||!this.c.blurable?a.preventDefault():this._blur()}},_tabInput:function(){var a=this,b=this.s.dt,c=null!==this.c.tabIndex?this.c.tabIndex: | ||
b.settings()[0].iTabIndex;if(-1!=c)f('<div><input type="text" tabindex="'+c+'"/></div>').css({position:"absolute",height:1,width:0,overflow:"hidden"}).insertBefore(b.table().node()).children().on("focus",function(c){b.cell(":eq(0)",{page:"current"}).any()&&a._focus(b.cell(":eq(0)","0:visible",{page:"current"}),null,!0,c)})},_updateFixedColumns:function(a){var b=this.s.dt,c=b.settings()[0];if(c._oFixedColumns){var d=c.aoColumns.length-c._oFixedColumns.s.iRightColumns;(a<c._oFixedColumns.s.iLeftColumns|| | ||
a>=d)&&b.fixedColumns().update()}}});n.defaults={blurable:!0,className:"focus",clipboard:!0,clipboardOrthogonal:"display",columns:"",editor:null,editOnFocus:!1,focus:null,keys:null,tabIndex:null};n.version="2.5.0";f.fn.dataTable.KeyTable=n;f.fn.DataTable.KeyTable=n;l.Api.register("cell.blur()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.blur()})});l.Api.register("cell().focus()",function(){return this.iterator("cell",function(a,b,c){a.keytable&&a.keytable.focus(b,c)})}); | ||
l.Api.register("keys.disable()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.enable(!1)})});l.Api.register("keys.enable()",function(a){return this.iterator("table",function(b){b.keytable&&b.keytable.enable(a===o?!0:a)})});l.ext.selector.cell.push(function(a,b,c){var b=b.focused,a=a.keytable,d=[];if(!a||b===o)return c;for(var e=0,f=c.length;e<f;e++)(!0===b&&a.focused(c[e])||!1===b&&!a.focused(c[e]))&&d.push(c[e]);return d});f(h).on("preInit.dt.dtk",function(a,b){if("dt"=== | ||
a.namespace){var c=b.oInit.keys,d=l.defaults.keys;if(c||d)d=f.extend({},d,c),!1!==c&&new n(b,d)}});return n}); | ||
(function(e){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(k){return e(k,window,document)}):"object"===typeof exports?module.exports=function(k,i){k||(k=window);if(!i||!i.fn.dataTable)i=require("datatables.net")(k,i).$;return e(i,k,k.document)}:e(jQuery,window,document)})(function(e,k,i,o){var l=e.fn.dataTable,p=0,m=function(a,b){if(!l.versionCheck||!l.versionCheck("1.10.8"))throw"KeyTable requires DataTables 1.10.8 or newer";this.c=e.extend(!0,{},l.defaults.keyTable, | ||
m.defaults,b);this.s={dt:new l.Api(a),enable:!0,focusDraw:!1,waitingForDraw:!1,lastFocus:null,namespace:".keyTable-"+p++};this.dom={};var c=this.s.dt.settings()[0],d=c.keytable;if(d)return d;c.keytable=this;this._constructor()};e.extend(m.prototype,{blur:function(){this._blur()},enable:function(a){this.s.enable=a},focus:function(a,b){this._focus(this.s.dt.cell(a,b))},focused:function(a){if(!this.s.lastFocus)return!1;var b=this.s.lastFocus.cell.index();return a.row===b.row&&a.column===b.column},_constructor:function(){this._tabInput(); | ||
var a=this,b=this.s.dt,c=e(b.table().node()),d=this.s.namespace,f=!1;"static"===c.css("position")&&c.css("position","relative");e(b.table().body()).on("click"+d,"th, td",function(d){if(!1!==a.s.enable){var c=b.cell(this);c.any()&&a._focus(c,null,!1,d)}});e(i).on("keydown"+d,function(b){f||a._key(b)});if(this.c.blurable)e(i).on("mousedown"+d,function(d){e(d.target).parents(".dataTables_filter").length&&a._blur();e(d.target).parents().filter(b.table().container()).length||e(d.target).parents("div.DTE").length|| | ||
e(d.target).parents("div.editor-datetime").length||e(d.target).parents().filter(".DTFC_Cloned").length||a._blur()});if(this.c.editor){var j=this.c.editor;j.on("open.keyTableMain",function(b,c){"inline"!==c&&a.s.enable&&(a.enable(!1),j.one("close"+d,function(){a.enable(!0)}))});if(this.c.editOnFocus)b.on("key-focus"+d+" key-refocus"+d,function(b,d,c,f){a._editor(null,f,!0)});b.on("key"+d,function(b,d,c,f,e){a._editor(c,e,!1)});e(b.table().body()).on("dblclick"+d,"th, td",function(d){!1!==a.s.enable&& | ||
b.cell(this).any()&&a._editor(null,d,!0)});j.on("preSubmit",function(){f=!0}).on("preSubmitCancelled",function(){f=!1}).on("submitComplete",function(){f=!1})}if(b.settings()[0].oFeatures.bStateSave)b.on("stateSaveParams"+d,function(b,d,c){c.keyTable=a.s.lastFocus?a.s.lastFocus.cell.index():null});b.on("draw"+d,function(d){if(!a.s.focusDraw){var c=a.s.lastFocus;if(c&&c.node&&e(c.node).closest("body")===i.body){var c=a.s.lastFocus.relative,f=b.page.info(),g=c.row+f.start;0!==f.recordsDisplay&&(g>=f.recordsDisplay&& | ||
(g=f.recordsDisplay-1),a._focus(g,c.column,!0,d))}}});this.c.clipboard&&this._clipboard();b.on("destroy"+d,function(){a._blur(!0);b.off(d);e(b.table().body()).off("click"+d,"th, td").off("dblclick"+d,"th, td");e(i).off("mousedown"+d).off("keydown"+d).off("copy"+d).off("paste"+d)});var g=b.state.loaded();if(g&&g.keyTable)b.one("init",function(){var a=b.cell(g.keyTable);a.any()&&a.focus()});else this.c.focus&&b.cell(this.c.focus).focus()},_blur:function(a){if(this.s.enable&&this.s.lastFocus){var b= | ||
this.s.lastFocus.cell;e(b.node()).removeClass(this.c.className);this.s.lastFocus=null;a||(this._updateFixedColumns(b.index().column),this._emitEvent("key-blur",[this.s.dt,b]))}},_clipboard:function(){var a=this.s.dt,b=this,c=this.s.namespace;k.getSelection&&(e(i).on("copy"+c,function(a){var a=a.originalEvent,c=k.getSelection().toString(),e=b.s.lastFocus;!c&&e&&(a.clipboardData.setData("text/plain",e.cell.render(b.c.clipboardOrthogonal)),a.preventDefault())}),e(i).on("paste"+c,function(d){var d=d.originalEvent, | ||
c=b.s.lastFocus,e=i.activeElement,g=b.c.editor,h;if(c&&(!e||"body"===e.nodeName.toLowerCase()))d.preventDefault(),k.clipboardData&&k.clipboardData.getData?h=k.clipboardData.getData("Text"):d.clipboardData&&d.clipboardData.getData&&(h=d.clipboardData.getData("text/plain")),g?g.inline(c.cell.index()).set(g.displayed()[0],h).submit():(c.cell.data(h),a.draw(!1))}))},_columns:function(){var a=this.s.dt,b=a.columns(this.c.columns).indexes(),c=[];a.columns(":visible").every(function(a){-1!==b.indexOf(a)&& | ||
c.push(a)});return c},_editor:function(a,b,c){var d=this,f=this.s.dt,j=this.c.editor,g=this.s.lastFocus.cell,h=this.s.namespace;if(!e("div.DTE",g.node()).length&&!(null!==a&&(0<=a&&9>=a||11===a||12===a||14<=a&&31>=a||112<=a&&123>=a||127<=a&&159>=a))){b.stopPropagation();13===a&&b.preventDefault();var n=function(){j.one("open"+h,function(){j.off("cancelOpen"+h);c||e("div.DTE_Field_InputControl input, div.DTE_Field_InputControl textarea").select();f.keys.enable(c?"tab-only":"navigation-only");f.on("key-blur.editor", | ||
function(a,b,c){j.displayed()&&c.node()===g.node()&&j.submit()});c&&e(f.table().container()).addClass("dtk-focus-alt");j.on("preSubmitCancelled"+h,function(){setTimeout(function(){d._focus(g,null,!1)},50)});j.on("submitUnsuccessful"+h,function(){d._focus(g,null,!1)});j.one("close",function(){f.keys.enable(!0);f.off("key-blur.editor");j.off(h);e(f.table().container()).removeClass("dtk-focus-alt")})}).one("cancelOpen"+h,function(){j.off(h)}).inline(g.index())};13===a?(c=!0,e(i).one("keyup",function(){n()})): | ||
n()}},_emitEvent:function(a,b){this.s.dt.iterator("table",function(c){e(c.nTable).triggerHandler(a,b)})},_focus:function(a,b,c,d){var f=this,j=this.s.dt,g=j.page.info(),h=this.s.lastFocus;d||(d=null);if(this.s.enable){if("number"!==typeof a){if(!a.any())return;var n=a.index(),b=n.column,a=j.rows({filter:"applied",order:"applied"}).indexes().indexOf(n.row);if(0>a)return;g.serverSide&&(a+=g.start)}if(-1!==g.length&&(a<g.start||a>=g.start+g.length))this.s.focusDraw=!0,this.s.waitingForDraw=!0,j.one("draw", | ||
function(){f.s.focusDraw=!1;f.s.waitingForDraw=!1;f._focus(a,b,o,d)}).page(Math.floor(a/g.length)).draw(!1);else if(-1!==e.inArray(b,this._columns())){g.serverSide&&(a-=g.start);g=j.cells(null,b,{search:"applied",order:"applied"}).flatten();g=j.cell(g[a]);if(h){if(h.node===g.node()){this._emitEvent("key-refocus",[this.s.dt,g,d||null]);return}this._blur()}this._removeOtherFocus();h=e(g.node());h.addClass(this.c.className);this._updateFixedColumns(b);if(c===o||!0===c)this._scroll(e(k),e(i.body),h,"offset"), | ||
c=j.table().body().parentNode,c!==j.table().header().parentNode&&(c=e(c.parentNode),this._scroll(c,c,h,"position"));this.s.lastFocus={cell:g,node:g.node(),relative:{row:j.rows({page:"current"}).indexes().indexOf(g.index().row),column:g.index().column}};this._emitEvent("key-focus",[this.s.dt,g,d||null]);j.state.save()}}},_key:function(a){if(this.s.waitingForDraw)a.preventDefault();else{var b=this.s.enable,c=!0===b||"navigation-only"===b;if(b&&(!(0===a.keyCode||a.ctrlKey||a.metaKey||a.altKey)||a.ctrlKey&& | ||
a.altKey)){var d=this.s.lastFocus;if(d)if(this.s.dt.cell(d.node).any()){var d=this.s.dt,f=this.s.dt.settings()[0].oScroll.sY?!0:!1;if(!(this.c.keys&&-1===e.inArray(a.keyCode,this.c.keys)))switch(a.keyCode){case 9:this._shift(a,a.shiftKey?"left":"right",!0);break;case 27:this.s.blurable&&!0===b&&this._blur();break;case 33:case 34:c&&!f&&(a.preventDefault(),d.page(33===a.keyCode?"previous":"next").draw(!1));break;case 35:case 36:c&&(a.preventDefault(),b=d.cells({page:"current"}).indexes(),c=this._columns(), | ||
this._focus(d.cell(b[35===a.keyCode?b.length-1:c[0]]),null,!0,a));break;case 37:c&&this._shift(a,"left");break;case 38:c&&this._shift(a,"up");break;case 39:c&&this._shift(a,"right");break;case 40:c&&this._shift(a,"down");break;case 113:if(this.c.editor){this._editor(null,a,!0);break}default:!0===b&&this._emitEvent("key",[d,a.keyCode,this.s.lastFocus.cell,a])}}else this.s.lastFocus=null}}},_removeOtherFocus:function(){var a=this.s.dt.table().node();e.fn.dataTable.tables({api:!0}).iterator("table", | ||
function(){this.table().node()!==a&&this.cell.blur()})},_scroll:function(a,b,c,d){var f=c[d](),e=c.outerHeight(),g=c.outerWidth(),h=b.scrollTop(),n=b.scrollLeft(),i=a.height(),a=a.width();"position"===d&&(f.top+=parseInt(c.closest("table").css("top"),10));f.top<h&&b.scrollTop(f.top);f.left<n&&b.scrollLeft(f.left);f.top+e>h+i&&e<i&&b.scrollTop(f.top+e-i);f.left+g>n+a&&g<a&&b.scrollLeft(f.left+g-a)},_shift:function(a,b,c){var d=this.s.dt,f=d.page.info(),j=f.recordsDisplay,g=this.s.lastFocus.cell,h= | ||
this._columns();if(g){var i=d.rows({filter:"applied",order:"applied"}).indexes().indexOf(g.index().row);f.serverSide&&(i+=f.start);d=d.columns(h).indexes().indexOf(g.index().column);f=h[d];"right"===b?d>=h.length-1?(i++,f=h[0]):f=h[d+1]:"left"===b?0===d?(i--,f=h[h.length-1]):f=h[d-1]:"up"===b?i--:"down"===b&&i++;0<=i&&i<j&&-1!==e.inArray(f,h)?(a&&a.preventDefault(),this._focus(i,f,!0,a)):!c||!this.c.blurable?a&&a.preventDefault():this._blur()}},_tabInput:function(){var a=this,b=this.s.dt,c=null!== | ||
this.c.tabIndex?this.c.tabIndex:b.settings()[0].iTabIndex;if(-1!=c)e('<div><input type="text" tabindex="'+c+'"/></div>').css({position:"absolute",height:1,width:0,overflow:"hidden"}).insertBefore(b.table().node()).children().on("focus",function(c){var f=b.cell(":eq(0)",a._columns(),{page:"current"});f.any()&&a._focus(f,null,!0,c)})},_updateFixedColumns:function(a){var b=this.s.dt,c=b.settings()[0];if(c._oFixedColumns){var d=c.aoColumns.length-c._oFixedColumns.s.iRightColumns;(a<c._oFixedColumns.s.iLeftColumns|| | ||
a>=d)&&b.fixedColumns().update()}}});m.defaults={blurable:!0,className:"focus",clipboard:!0,clipboardOrthogonal:"display",columns:"",editor:null,editOnFocus:!1,focus:null,keys:null,tabIndex:null};m.version="2.5.1";e.fn.dataTable.KeyTable=m;e.fn.DataTable.KeyTable=m;l.Api.register("cell.blur()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.blur()})});l.Api.register("cell().focus()",function(){return this.iterator("cell",function(a,b,c){a.keytable&&a.keytable.focus(b,c)})}); | ||
l.Api.register("keys.disable()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.enable(!1)})});l.Api.register("keys.enable()",function(a){return this.iterator("table",function(b){b.keytable&&b.keytable.enable(a===o?!0:a)})});l.Api.register("keys.move()",function(a){return this.iterator("table",function(b){b.keytable&&b.keytable._shift(null,a,!1)})});l.ext.selector.cell.push(function(a,b,c){var b=b.focused,a=a.keytable,d=[];if(!a||b===o)return c;for(var f=0,e=c.length;f< | ||
e;f++)(!0===b&&a.focused(c[f])||!1===b&&!a.focused(c[f]))&&d.push(c[f]);return d});e(i).on("preInit.dt.dtk",function(a,b){if("dt"===a.namespace){var c=b.oInit.keys,d=l.defaults.keys;if(c||d)d=e.extend({},d,c),!1!==c&&new m(b,d)}});return m}); |
{ | ||
"name": "datatables.net-keytable", | ||
"version": "2.5.0", | ||
"version": "2.5.1", | ||
"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
44337
1083