43 lines
14 KiB
JavaScript
43 lines
14 KiB
JavaScript
/*!
|
|
Copyright 2010-2018 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
|
|
AutoFill 2.3.2
|
|
©2008-2018 SpryMedia Ltd - datatables.net/license
|
|
*/
|
|
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(b,h,f){b!=Array.prototype&&b!=Object.prototype&&(b[h]=f.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.Symbol=function(){var b=0;return function(h){return $jscomp.SYMBOL_PREFIX+(h||"")+b++}}();
|
|
$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.iterator;b||(b=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[b]&&$jscomp.defineProperty(Array.prototype,b,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};
|
|
$jscomp.initSymbolAsyncIterator=function(){$jscomp.initSymbol();var b=$jscomp.global.Symbol.asyncIterator;b||(b=$jscomp.global.Symbol.asyncIterator=$jscomp.global.Symbol("asyncIterator"));$jscomp.initSymbolAsyncIterator=function(){}};$jscomp.arrayIterator=function(b){var h=0;return $jscomp.iteratorPrototype(function(){return h<b.length?{done:!1,value:b[h++]}:{done:!0}})};
|
|
$jscomp.iteratorPrototype=function(b){$jscomp.initSymbolIterator();b={next:b};b[$jscomp.global.Symbol.iterator]=function(){return this};return b};$jscomp.iteratorFromArray=function(b,h){$jscomp.initSymbolIterator();b instanceof String&&(b+="");var f=0,l={next:function(){if(f<b.length){var k=f++;return{value:h(k,b[k]),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,h,f,l){if(h){f=$jscomp.global;b=b.split(".");for(l=0;l<b.length-1;l++){var k=b[l];k in f||(f[k]={});f=f[k]}b=b[b.length-1];l=f[b];h=h(l);h!=l&&null!=h&&$jscomp.defineProperty(f,b,{configurable:!0,writable:!0,value:h})}};$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(h){return b(h,window,document)}):"object"===typeof exports?module.exports=function(h,f){h||(h=window);f&&f.fn.dataTable||(f=require("datatables.net")(h,f).$);return b(f,h,h.document)}:b(jQuery,window,document)})(function(b,h,f,l){var k=b.fn.dataTable,x=0,m=function(a,d){if(!k.versionCheck||!k.versionCheck("1.10.8"))throw"Warning: AutoFill requires DataTables 1.10.8 or greater";this.c=b.extend(!0,{},k.defaults.autoFill,
|
|
m.defaults,d);this.s={dt:new k.Api(a),namespace:".autoFill"+x++,scroll:{},scrollInterval:null,handle:{height:0,width:0},enabled:!1};this.dom={handle:b('<div class="dt-autofill-handle"/>'),select:{top:b('<div class="dt-autofill-select top"/>'),right:b('<div class="dt-autofill-select right"/>'),bottom:b('<div class="dt-autofill-select bottom"/>'),left:b('<div class="dt-autofill-select left"/>')},background:b('<div class="dt-autofill-background"/>'),list:b('<div class="dt-autofill-list">'+this.s.dt.i18n("autoFill.info",
|
|
"")+"<ul/></div>"),dtScroll:null,offsetParent:null};this._constructor()};b.extend(m.prototype,{enabled:function(){return this.s.enabled},enable:function(a){var d=this;if(!1===a)return this.disable();this.s.enabled=!0;this._focusListener();this.dom.handle.on("mousedown",function(a){d._mousedown(a);return!1});return this},disable:function(){this.s.enabled=!1;this._focusListenerRemove();return this},_constructor:function(){var a=this,d=this.s.dt,c=b("div.dataTables_scrollBody",this.s.dt.table().container());
|
|
d.settings()[0].autoFill=this;c.length&&(this.dom.dtScroll=c,"static"===c.css("position")&&c.css("position","relative"));!1!==this.c.enable&&this.enable();d.on("destroy.autoFill",function(){a._focusListenerRemove()})},_attach:function(a){var d=this.s.dt,c=d.cell(a).index(),g=this.dom.handle,e=this.s.handle;c&&-1!==d.columns(this.c.columns).indexes().indexOf(c.column)?(this.dom.offsetParent||(this.dom.offsetParent=b(d.table().node()).offsetParent()),e.height&&e.width||(g.appendTo("body"),e.height=
|
|
g.outerHeight(),e.width=g.outerWidth()),d=this._getPosition(a,this.dom.offsetParent),this.dom.attachedTo=a,g.css({top:d.top+a.offsetHeight-e.height,left:d.left+a.offsetWidth-e.width}).appendTo(this.dom.offsetParent)):this._detach()},_actionSelector:function(a){var d=this,c=this.s.dt,g=m.actions,e=[];b.each(g,function(d,b){b.available(c,a)&&e.push(d)});if(1===e.length&&!1===this.c.alwaysAsk){var n=g[e[0]].execute(c,a);this._update(n,a)}else{var f=this.dom.list.children("ul").empty();e.push("cancel");
|
|
b.each(e,function(e,n){f.append(b("<li/>").append('<div class="dt-autofill-question">'+g[n].option(c,a)+"<div>").append(b('<div class="dt-autofill-button">').append(b('<button class="'+m.classes.btn+'">'+c.i18n("autoFill.button",">")+"</button>").on("click",function(){var e=g[n].execute(c,a,b(this).closest("li"));d._update(e,a);d.dom.background.remove();d.dom.list.remove()}))))});this.dom.background.appendTo("body");this.dom.list.appendTo("body");this.dom.list.css("margin-top",this.dom.list.outerHeight()/
|
|
2*-1)}},_detach:function(){this.dom.attachedTo=null;this.dom.handle.detach()},_drawSelection:function(a,d){var c=this.s.dt;d=this.s.start;var g=b(this.dom.start),e={row:this.c.vertical?c.rows({page:"current"}).nodes().indexOf(a.parentNode):d.row,column:this.c.horizontal?b(a).index():d.column};a=c.column.index("toData",e.column);var n=c.row(":eq("+e.row+")",{page:"current"});n=b(c.cell(n.index(),a).node());if(c.cell(n).any()&&-1!==c.columns(this.c.columns).indexes().indexOf(a)){this.s.end=e;c=d.row<
|
|
e.row?g:n;var f=d.row<e.row?n:g;a=d.column<e.column?g:n;g=d.column<e.column?n:g;c=this._getPosition(c).top;a=this._getPosition(a).left;d=this._getPosition(f).top+f.outerHeight()-c;g=this._getPosition(g).left+g.outerWidth()-a;e=this.dom.select;e.top.css({top:c,left:a,width:g});e.left.css({top:c,left:a,height:d});e.bottom.css({top:c+d,left:a,width:g});e.right.css({top:c,left:a+g,height:d})}},_editor:function(a){var d=this.s.dt,c=this.c.editor;if(c){for(var b={},e=[],n=c.fields(),f=0,h=a.length;f<h;f++)for(var k=
|
|
0,m=a[f].length;k<m;k++){var q=a[f][k],r=d.settings()[0].aoColumns[q.index.column],t=r.editField;if(t===l){r=r.mData;for(var u=0,p=n.length;u<p;u++){var w=c.field(n[u]);if(w.dataSrc()===r){t=w.name();break}}}if(!t)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";b[t]||(b[t]={});r=d.row(q.index.row).id();b[t][r]=q.set;e.push(q.index)}c.bubble(e,!1).multiSet(b).submit()}},_emitEvent:function(a,d){this.s.dt.iterator("table",function(c,g){b(c.nTable).triggerHandler(a+
|
|
".dt",d)})},_focusListener:function(){var a=this,d=this.s.dt,c=this.s.namespace,g=null!==this.c.focus?this.c.focus:d.init().keys||d.settings()[0].keytable?"focus":"hover";if("focus"===g)d.on("key-focus.autoFill",function(c,d,b){a._attach(b.node())}).on("key-blur.autoFill",function(c,d,b){a._detach()});else if("click"===g)b(d.table().body()).on("click"+c,"td, th",function(c){a._attach(this)}),b(f.body).on("click"+c,function(c){b(c.target).parents().filter(d.table().body()).length||a._detach()});else b(d.table().body()).on("mouseenter"+
|
|
c,"td, th",function(c){a._attach(this)}).on("mouseleave"+c,function(c){b(c.relatedTarget).hasClass("dt-autofill-handle")||a._detach()})},_focusListenerRemove:function(){var a=this.s.dt;a.off(".autoFill");b(a.table().body()).off(this.s.namespace);b(f.body).off(this.s.namespace)},_getPosition:function(a,d){a=b(a);var c=0,g=0;d||(d=b(b(this.s.dt.table().node())[0].offsetParent));do{var e=a.position();var f=b(a[0].offsetParent);c+=e.top+f.scrollTop();g+=e.left+f.scrollLeft();c+=1*parseInt(f.css("margin-top"));
|
|
c+=1*parseInt(f.css("border-top-width"));if("body"===a.get(0).nodeName.toLowerCase())break;a=f}while(f.get(0)!==d.get(0));return{top:c,left:g}},_mousedown:function(a){var d=this,c=this.s.dt;this.dom.start=this.dom.attachedTo;this.s.start={row:c.rows({page:"current"}).nodes().indexOf(b(this.dom.start).parent()[0]),column:b(this.dom.start).index()};b(f.body).on("mousemove.autoFill",function(a){d._mousemove(a)}).on("mouseup.autoFill",function(a){d._mouseup(a)});var g=this.dom.select;c=b(c.table().node()).offsetParent();
|
|
g.top.appendTo(c);g.left.appendTo(c);g.right.appendTo(c);g.bottom.appendTo(c);this._drawSelection(this.dom.start,a);this.dom.handle.css("display","none");a=this.dom.dtScroll;this.s.scroll={windowHeight:b(h).height(),windowWidth:b(h).width(),dtTop:a?a.offset().top:null,dtLeft:a?a.offset().left:null,dtHeight:a?a.outerHeight():null,dtWidth:a?a.outerWidth():null}},_mousemove:function(a){var d=a.target.nodeName.toLowerCase();if("td"===d||"th"===d)this._drawSelection(a.target,a),this._shiftScroll(a)},_mouseup:function(a){b(f.body).off(".autoFill");
|
|
var d=this,c=this.s.dt,g=this.dom.select;g.top.remove();g.left.remove();g.right.remove();g.bottom.remove();this.dom.handle.css("display","block");g=this.s.start;var e=this.s.end;if(g.row!==e.row||g.column!==e.column){var h=c.cell(":eq("+g.row+")",g.column+":visible",{page:"current"});if(b("div.DTE",h.node()).length){var k=c.editor();k.on("submitSuccess.dtaf",function(){k.off(".dtaf");setTimeout(function(){d._mouseup(a)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf",function(){k.off(".dtaf")});
|
|
k.submit()}else{var m=this._range(g.row,e.row);g=this._range(g.column,e.column);e=[];for(var v=c.settings()[0],p=v.aoColumns,q=0;q<m.length;q++)e.push(b.map(g,function(a){var d=c.row(":eq("+m[q]+")",{page:"current"});a=c.cell(d.index(),a+":visible");d=a.data();var b=a.index(),g=p[b.column].editField;g!==l&&(d=v.oApi._fnGetObjectDataFn(g)(c.row(b.row).data()));return{cell:a,data:d,label:a.data(),index:b}}));this._actionSelector(e);clearInterval(this.s.scrollInterval);this.s.scrollInterval=null}}},
|
|
_range:function(a,d){var c=[];if(a<=d)for(;a<=d;a++)c.push(a);else for(;a>=d;a--)c.push(a);return c},_shiftScroll:function(a){var d=this,c=this.s.scroll,b=!1,e=a.pageY-f.body.scrollTop,h=a.pageX-f.body.scrollLeft,k,l,m,p;65>e?k=-5:e>c.windowHeight-65&&(k=5);65>h?l=-5:h>c.windowWidth-65&&(l=5);null!==c.dtTop&&a.pageY<c.dtTop+65?m=-5:null!==c.dtTop&&a.pageY>c.dtTop+c.dtHeight-65&&(m=5);null!==c.dtLeft&&a.pageX<c.dtLeft+65?p=-5:null!==c.dtLeft&&a.pageX>c.dtLeft+c.dtWidth-65&&(p=5);k||l||m||p?(c.windowVert=
|
|
k,c.windowHoriz=l,c.dtVert=m,c.dtHoriz=p,b=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null);!this.s.scrollInterval&&b&&(this.s.scrollInterval=setInterval(function(){c.windowVert&&(f.body.scrollTop+=c.windowVert);c.windowHoriz&&(f.body.scrollLeft+=c.windowHoriz);if(c.dtVert||c.dtHoriz){var a=d.dom.dtScroll[0];c.dtVert&&(a.scrollTop+=c.dtVert);c.dtHoriz&&(a.scrollLeft+=c.dtHoriz)}},20))},_update:function(a,d){if(!1!==a){a=this.s.dt;this._emitEvent("preAutoFill",
|
|
[a,d]);this._editor(d);if(null!==this.c.update?this.c.update:!this.c.editor){for(var c=0,b=d.length;c<b;c++)for(var e=0,f=d[c].length;e<f;e++){var h=d[c][e];h.cell.data(h.set)}a.draw(!1)}this._emitEvent("autoFill",[a,d])}}});m.actions={increment:{available:function(a,b){a=b[0][0].label;return!isNaN(a-parseFloat(a))},option:function(a,b){return a.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(a,d,c){a=1*d[0][0].data;c=1*b("input",
|
|
c).val();for(var g=0,e=d.length;g<e;g++)for(var f=0,h=d[g].length;f<h;f++)d[g][f].set=a,a+=c}},fill:{available:function(a,b){return!0},option:function(a,b){return a.i18n("autoFill.fill","Fill all cells with <i>"+b[0][0].label+"</i>")},execute:function(a,b,c){a=b[0][0].data;c=0;for(var d=b.length;c<d;c++)for(var e=0,f=b[c].length;e<f;e++)b[c][e].set=a}},fillHorizontal:{available:function(a,b){return 1<b.length&&1<b[0].length},option:function(a,b){return a.i18n("autoFill.fillHorizontal","Fill cells horizontally")},
|
|
execute:function(a,b,c){a=0;for(c=b.length;a<c;a++)for(var d=0,e=b[a].length;d<e;d++)b[a][d].set=b[a][0].data}},fillVertical:{available:function(a,b){return 1<b.length&&1<b[0].length},option:function(a,b){return a.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(a,b,c){a=0;for(c=b.length;a<c;a++)for(var d=0,e=b[a].length;d<e;d++)b[a][d].set=b[0][d].data}},cancel:{available:function(){return!1},option:function(a){return a.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}};
|
|
m.version="2.3.2";m.defaults={alwaysAsk:!1,focus:null,columns:"",enable:!0,update:null,editor:null,vertical:!0,horizontal:!0};m.classes={btn:"btn"};var p=b.fn.dataTable.Api;p.register("autoFill()",function(){return this});p.register("autoFill().enabled()",function(){var a=this.context[0];return a.autoFill?a.autoFill.enabled():!1});p.register("autoFill().enable()",function(a){return this.iterator("table",function(b){b.autoFill&&b.autoFill.enable(a)})});p.register("autoFill().disable()",function(){return this.iterator("table",
|
|
function(a){a.autoFill&&a.autoFill.disable()})});b(f).on("preInit.dt.autofill",function(a,d,c){"dt"===a.namespace&&(a=d.oInit.autoFill,c=k.defaults.autoFill,a||c)&&(c=b.extend({},a,c),!1!==a&&new m(d,c))});k.AutoFill=m;return k.AutoFill=m});
|