43 lines
13 KiB
JavaScript
43 lines
13 KiB
JavaScript
/*!
|
|
Copyright 2009-2019 SpryMedia Ltd.
|
|
|
|
This source file is free software, available under the following license:
|
|
MIT license - http://datatables.net/license/mit
|
|
|
|
This source file is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
|
|
|
|
For details please refer to: http://www.datatables.net
|
|
KeyTable 2.5.1
|
|
©2009-2019 SpryMedia Ltd - datatables.net/license
|
|
*/
|
|
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.arrayIteratorImpl=function(b){var f=0;return function(){return f<b.length?{done:!1,value:b[f++]}:{done:!0}}};$jscomp.arrayIterator=function(b){return{next:$jscomp.arrayIteratorImpl(b)}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;
|
|
$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,f,k){b!=Array.prototype&&b!=Object.prototype&&(b[f]=k.value)};$jscomp.getGlobal=function(b){return"undefined"!=typeof window&&window===b?b:"undefined"!=typeof global&&null!=global?global:b};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_";$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};
|
|
$jscomp.SymbolClass=function(b,f){this.$jscomp$symbol$id_=b;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:f})};$jscomp.SymbolClass.prototype.toString=function(){return this.$jscomp$symbol$id_};$jscomp.Symbol=function(){function b(k){if(this instanceof b)throw new TypeError("Symbol is not a constructor");return new $jscomp.SymbolClass($jscomp.SYMBOL_PREFIX+(k||"")+"_"+f++,k)}var f=0;return b}();
|
|
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.iterator;b||(b=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("Symbol.iterator"));"function"!=typeof Array.prototype[b]&&$jscomp.defineProperty(Array.prototype,b,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}});$jscomp.initSymbolIterator=function(){}};
|
|
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.asyncIterator;b||(b=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("Symbol.asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.iteratorPrototype=function(b){$jscomp.initSymbolIterator();b={next:b};b[$jscomp.global.Symbol.iterator]=function(){return this};return b};
|
|
$jscomp.iteratorFromArray=function(b,f){$jscomp.initSymbolIterator();b instanceof String&&(b+="");var k=0,l={next:function(){if(k<b.length){var g=k++;return{value:f(g,b[g]),done:!1}}l.next=function(){return{done:!0,value:void 0}};return l.next()}};l[Symbol.iterator]=function(){return l};return l};
|
|
$jscomp.polyfill=function(b,f,k,l){if(f){k=$jscomp.global;b=b.split(".");for(l=0;l<b.length-1;l++){var g=b[l];g in k||(k[g]={});k=k[g]}b=b[b.length-1];l=k[b];f=f(l);f!=l&&null!=f&&$jscomp.defineProperty(k,b,{configurable:!0,writable:!0,value:f})}};$jscomp.polyfill("Array.prototype.keys",function(b){return b?b:function(){return $jscomp.iteratorFromArray(this,function(b){return b})}},"es6","es3");
|
|
(function(b){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(f){return b(f,window,document)}):"object"===typeof exports?module.exports=function(f,k){f||(f=window);k&&k.fn.dataTable||(k=require("datatables.net")(f,k).$);return b(k,f,f.document)}:b(jQuery,window,document)})(function(b,f,k,l){var g=b.fn.dataTable,t=0,p=function(a,c){if(!g.versionCheck||!g.versionCheck("1.10.8"))throw"KeyTable requires DataTables 1.10.8 or newer";this.c=b.extend(!0,{},g.defaults.keyTable,
|
|
p.defaults,c);this.s={dt:new g.Api(a),enable:!0,focusDraw:!1,waitingForDraw:!1,lastFocus:null,namespace:".keyTable-"+t++};this.dom={};a=this.s.dt.settings()[0];if(c=a.keytable)return c;a.keytable=this;this._constructor()};b.extend(p.prototype,{blur:function(){this._blur()},enable:function(a){this.s.enable=a},focus:function(a,c){this._focus(this.s.dt.cell(a,c))},focused:function(a){if(!this.s.lastFocus)return!1;var c=this.s.lastFocus.cell.index();return a.row===c.row&&a.column===c.column},_constructor:function(){this._tabInput();
|
|
var a=this,c=this.s.dt,e=b(c.table().node()),d=this.s.namespace,m=!1;"static"===e.css("position")&&e.css("position","relative");b(c.table().body()).on("click"+d,"th, td",function(b){if(!1!==a.s.enable){var d=c.cell(this);d.any()&&a._focus(d,null,!1,b)}});b(k).on("keydown"+d,function(c){m||a._key(c)});if(this.c.blurable)b(k).on("mousedown"+d,function(d){b(d.target).parents(".dataTables_filter").length&&a._blur();b(d.target).parents().filter(c.table().container()).length||b(d.target).parents("div.DTE").length||
|
|
b(d.target).parents("div.editor-datetime").length||b(d.target).parents().filter(".DTFC_Cloned").length||a._blur()});if(this.c.editor){var q=this.c.editor;q.on("open.keyTableMain",function(c,b,e){"inline"!==b&&a.s.enable&&(a.enable(!1),q.one("close"+d,function(){a.enable(!0)}))});if(this.c.editOnFocus)c.on("key-focus"+d+" key-refocus"+d,function(c,b,d,e){a._editor(null,e,!0)});c.on("key"+d,function(c,b,d,e,m){a._editor(d,m,!1)});b(c.table().body()).on("dblclick"+d,"th, td",function(b){!1!==a.s.enable&&
|
|
c.cell(this).any()&&a._editor(null,b,!0)});q.on("preSubmit",function(){m=!0}).on("preSubmitCancelled",function(){m=!1}).on("submitComplete",function(){m=!1})}if(c.settings()[0].oFeatures.bStateSave)c.on("stateSaveParams"+d,function(b,c,d){d.keyTable=a.s.lastFocus?a.s.lastFocus.cell.index():null});c.on("draw"+d,function(d){if(!a.s.focusDraw){var e=a.s.lastFocus;if(e&&e.node&&b(e.node).closest("body")===k.body){e=a.s.lastFocus.relative;var m=c.page.info(),h=e.row+m.start;0!==m.recordsDisplay&&(h>=m.recordsDisplay&&
|
|
(h=m.recordsDisplay-1),a._focus(h,e.column,!0,d))}}});this.c.clipboard&&this._clipboard();c.on("destroy"+d,function(){a._blur(!0);c.off(d);b(c.table().body()).off("click"+d,"th, td").off("dblclick"+d,"th, td");b(k).off("mousedown"+d).off("keydown"+d).off("copy"+d).off("paste"+d)});var h=c.state.loaded();if(h&&h.keyTable)c.one("init",function(){var a=c.cell(h.keyTable);a.any()&&a.focus()});else this.c.focus&&c.cell(this.c.focus).focus()},_blur:function(a){if(this.s.enable&&this.s.lastFocus){var c=
|
|
this.s.lastFocus.cell;b(c.node()).removeClass(this.c.className);this.s.lastFocus=null;a||(this._updateFixedColumns(c.index().column),this._emitEvent("key-blur",[this.s.dt,c]))}},_clipboard:function(){var a=this.s.dt,c=this,e=this.s.namespace;f.getSelection&&(b(k).on("copy"+e,function(a){a=a.originalEvent;var b=f.getSelection().toString(),d=c.s.lastFocus;!b&&d&&(a.clipboardData.setData("text/plain",d.cell.render(c.c.clipboardOrthogonal)),a.preventDefault())}),b(k).on("paste"+e,function(b){b=b.originalEvent;
|
|
var d=c.s.lastFocus,e=k.activeElement,h=c.c.editor,n;!d||e&&"body"!==e.nodeName.toLowerCase()||(b.preventDefault(),f.clipboardData&&f.clipboardData.getData?n=f.clipboardData.getData("Text"):b.clipboardData&&b.clipboardData.getData&&(n=b.clipboardData.getData("text/plain")),h?h.inline(d.cell.index()).set(h.displayed()[0],n).submit():(d.cell.data(n),a.draw(!1)))}))},_columns:function(){var a=this.s.dt,b=a.columns(this.c.columns).indexes(),e=[];a.columns(":visible").every(function(a){-1!==b.indexOf(a)&&
|
|
e.push(a)});return e},_editor:function(a,c,e){var d=this,m=this.s.dt,f=this.c.editor,h=this.s.lastFocus.cell,n=this.s.namespace;if(!(b("div.DTE",h.node()).length||null!==a&&(0<=a&&9>=a||11===a||12===a||14<=a&&31>=a||112<=a&&123>=a||127<=a&&159>=a))){c.stopPropagation();13===a&&c.preventDefault();var g=function(){f.one("open"+n,function(){f.off("cancelOpen"+n);e||b("div.DTE_Field_InputControl input, div.DTE_Field_InputControl textarea").select();m.keys.enable(e?"tab-only":"navigation-only");m.on("key-blur.editor",
|
|
function(a,b,c){f.displayed()&&c.node()===h.node()&&f.submit()});e&&b(m.table().container()).addClass("dtk-focus-alt");f.on("preSubmitCancelled"+n,function(){setTimeout(function(){d._focus(h,null,!1)},50)});f.on("submitUnsuccessful"+n,function(){d._focus(h,null,!1)});f.one("close",function(){m.keys.enable(!0);m.off("key-blur.editor");f.off(n);b(m.table().container()).removeClass("dtk-focus-alt")})}).one("cancelOpen"+n,function(){f.off(n)}).inline(h.index())};13===a?(e=!0,b(k).one("keyup",function(){g()})):
|
|
g()}},_emitEvent:function(a,c){this.s.dt.iterator("table",function(e,d){b(e.nTable).triggerHandler(a,c)})},_focus:function(a,c,e,d){var m=this,g=this.s.dt,h=g.page.info(),n=this.s.lastFocus;d||(d=null);if(this.s.enable){if("number"!==typeof a){if(!a.any())return;var r=a.index();c=r.column;a=g.rows({filter:"applied",order:"applied"}).indexes().indexOf(r.row);if(0>a)return;h.serverSide&&(a+=h.start)}if(-1!==h.length&&(a<h.start||a>=h.start+h.length))this.s.focusDraw=!0,this.s.waitingForDraw=!0,g.one("draw",
|
|
function(){m.s.focusDraw=!1;m.s.waitingForDraw=!1;m._focus(a,c,l,d)}).page(Math.floor(a/h.length)).draw(!1);else if(-1!==b.inArray(c,this._columns())){h.serverSide&&(a-=h.start);h=g.cells(null,c,{search:"applied",order:"applied"}).flatten();h=g.cell(h[a]);if(n){if(n.node===h.node()){this._emitEvent("key-refocus",[this.s.dt,h,d||null]);return}this._blur()}this._removeOtherFocus();n=b(h.node());n.addClass(this.c.className);this._updateFixedColumns(c);if(e===l||!0===e)this._scroll(b(f),b(k.body),n,"offset"),
|
|
e=g.table().body().parentNode,e!==g.table().header().parentNode&&(e=b(e.parentNode),this._scroll(e,e,n,"position"));this.s.lastFocus={cell:h,node:h.node(),relative:{row:g.rows({page:"current"}).indexes().indexOf(h.index().row),column:h.index().column}};this._emitEvent("key-focus",[this.s.dt,h,d||null]);g.state.save()}}},_key:function(a){if(this.s.waitingForDraw)a.preventDefault();else{var c=this.s.enable,e=!0===c||"navigation-only"===c;if(c&&(!(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()){d=this.s.dt;var m=this.s.dt.settings()[0].oScroll.sY?!0:!1;if(!this.c.keys||-1!==b.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===c&&this._blur();break;case 33:case 34:e&&!m&&(a.preventDefault(),d.page(33===a.keyCode?"previous":"next").draw(!1));break;case 35:case 36:e&&(a.preventDefault(),c=d.cells({page:"current"}).indexes(),e=this._columns(),
|
|
this._focus(d.cell(c[35===a.keyCode?c.length-1:e[0]]),null,!0,a));break;case 37:e&&this._shift(a,"left");break;case 38:e&&this._shift(a,"up");break;case 39:e&&this._shift(a,"right");break;case 40:e&&this._shift(a,"down");break;case 113:if(this.c.editor){this._editor(null,a,!0);break}default:!0===c&&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();b.fn.dataTable.tables({api:!0}).iterator("table",
|
|
function(b){this.table().node()!==a&&this.cell.blur()})},_scroll:function(a,b,e,d){var c=e[d](),f=e.outerHeight(),h=e.outerWidth(),k=b.scrollTop(),g=b.scrollLeft(),l=a.height();a=a.width();"position"===d&&(c.top+=parseInt(e.closest("table").css("top"),10));c.top<k&&b.scrollTop(c.top);c.left<g&&b.scrollLeft(c.left);c.top+f>k+l&&f<l&&b.scrollTop(c.top+f-l);c.left+h>g+a&&h<a&&b.scrollLeft(c.left+h-a)},_shift:function(a,c,e){var d=this.s.dt,f=d.page.info(),k=f.recordsDisplay,h=this.s.lastFocus.cell,g=
|
|
this._columns();if(h){var l=d.rows({filter:"applied",order:"applied"}).indexes().indexOf(h.index().row);f.serverSide&&(l+=f.start);d=d.columns(g).indexes().indexOf(h.index().column);f=g[d];"right"===c?d>=g.length-1?(l++,f=g[0]):f=g[d+1]:"left"===c?0===d?(l--,f=g[g.length-1]):f=g[d-1]:"up"===c?l--:"down"===c&&l++;0<=l&&l<k&&-1!==b.inArray(f,g)?(a&&a.preventDefault(),this._focus(l,f,!0,a)):e&&this.c.blurable?this._blur():a&&a.preventDefault()}},_tabInput:function(){var a=this,c=this.s.dt,e=null!==this.c.tabIndex?
|
|
this.c.tabIndex:c.settings()[0].iTabIndex;if(-1!=e)b('<div><input type="text" tabindex="'+e+'"/></div>').css({position:"absolute",height:1,width:0,overflow:"hidden"}).insertBefore(c.table().node()).children().on("focus",function(b){var d=c.cell(":eq(0)",a._columns(),{page:"current"});d.any()&&a._focus(d,null,!0,b)})},_updateFixedColumns:function(a){var b=this.s.dt,e=b.settings()[0];if(e._oFixedColumns){var d=e.aoColumns.length-e._oFixedColumns.s.iRightColumns;(a<e._oFixedColumns.s.iLeftColumns||a>=
|
|
d)&&b.fixedColumns().update()}}});p.defaults={blurable:!0,className:"focus",clipboard:!0,clipboardOrthogonal:"display",columns:"",editor:null,editOnFocus:!1,focus:null,keys:null,tabIndex:null};p.version="2.5.1";b.fn.dataTable.KeyTable=p;b.fn.DataTable.KeyTable=p;g.Api.register("cell.blur()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.blur()})});g.Api.register("cell().focus()",function(){return this.iterator("cell",function(a,b,e){a.keytable&&a.keytable.focus(b,e)})});
|
|
g.Api.register("keys.disable()",function(){return this.iterator("table",function(a){a.keytable&&a.keytable.enable(!1)})});g.Api.register("keys.enable()",function(a){return this.iterator("table",function(b){b.keytable&&b.keytable.enable(a===l?!0:a)})});g.Api.register("keys.move()",function(a){return this.iterator("table",function(b){b.keytable&&b.keytable._shift(null,a,!1)})});g.ext.selector.cell.push(function(a,b,e){b=b.focused;a=a.keytable;var c=[];if(!a||b===l)return e;for(var f=0,g=e.length;f<
|
|
g;f++)(!0===b&&a.focused(e[f])||!1===b&&!a.focused(e[f]))&&c.push(e[f]);return c});b(k).on("preInit.dt.dtk",function(a,c,e){"dt"===a.namespace&&(a=c.oInit.keys,e=g.defaults.keys,a||e)&&(e=b.extend({},e,a),!1!==a&&new p(c,e))});return p});
|