datatables.net-autofill 3.0.0-beta.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! AutoFill 3.0.0
|
|
1
|
+
/*! AutoFill 3.0.0 for DataTables
|
|
2
2
|
* Copyright (c) SpryMedia Ltd - datatables.net/license
|
|
3
3
|
*/
|
|
4
4
|
|
|
@@ -59,6 +59,7 @@ class AutoFill {
|
|
|
59
59
|
}
|
|
60
60
|
enable(flag = true) {
|
|
61
61
|
let that = this;
|
|
62
|
+
let namespace = this.s.namespace;
|
|
62
63
|
if (flag === false) {
|
|
63
64
|
return this.disable();
|
|
64
65
|
}
|
|
@@ -81,13 +82,13 @@ class AutoFill {
|
|
|
81
82
|
that._attach(that.dom.attachedTo);
|
|
82
83
|
}
|
|
83
84
|
};
|
|
84
|
-
|
|
85
|
+
Dom.w.on('resize' + namespace, function () {
|
|
85
86
|
let handle = Dom.s('div.dtaf-handle');
|
|
86
87
|
if (handle.count() > 0 && that.dom.attachedTo) {
|
|
87
88
|
that._attach(that.dom.attachedTo);
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
|
-
|
|
91
|
+
Dom.w.on('orientationchange' + namespace, function () {
|
|
91
92
|
setTimeout(function () {
|
|
92
93
|
orientationReset();
|
|
93
94
|
setTimeout(orientationReset, 150);
|
|
@@ -128,14 +129,12 @@ class AutoFill {
|
|
|
128
129
|
this.dom = {
|
|
129
130
|
attachedTo: null,
|
|
130
131
|
container: Dom.c('div').classAdd('dtaf-container'),
|
|
131
|
-
closeButton: Dom
|
|
132
|
-
.c('button')
|
|
132
|
+
closeButton: Dom.c('button')
|
|
133
133
|
.classAdd(AutoFill.classes.close)
|
|
134
134
|
.html('×'),
|
|
135
135
|
dtScroll: null,
|
|
136
136
|
handle: Dom.c('div').classAdd('dtaf-handle'),
|
|
137
|
-
list: Dom
|
|
138
|
-
.c('div')
|
|
137
|
+
list: Dom.c('div')
|
|
139
138
|
.classAdd('dtaf-list')
|
|
140
139
|
.html(this.s.dt.i18n('autoFill.info', ''))
|
|
141
140
|
.attr('aria-modal', true)
|
|
@@ -161,12 +160,9 @@ class AutoFill {
|
|
|
161
160
|
* Initialise the RowReorder instance
|
|
162
161
|
*/
|
|
163
162
|
_init() {
|
|
164
|
-
let that = this;
|
|
165
163
|
let dt = this.s.dt;
|
|
166
164
|
// Need to account for scrolling as it has a different DOM structure
|
|
167
|
-
let dtScroll = Dom
|
|
168
|
-
.s(this.s.dt.table().container())
|
|
169
|
-
.find('div.dt-scroll-body');
|
|
165
|
+
let dtScroll = Dom.s(this.s.dt.table().container()).find('div.dt-scroll-body');
|
|
170
166
|
// Make the instance accessible to the API
|
|
171
167
|
dt.settings()[0].autoFill = this;
|
|
172
168
|
if (dtScroll.count()) {
|
|
@@ -179,8 +175,9 @@ class AutoFill {
|
|
|
179
175
|
if (this.c.enable !== false) {
|
|
180
176
|
this.enable();
|
|
181
177
|
}
|
|
182
|
-
dt.on('destroy.autoFill',
|
|
183
|
-
|
|
178
|
+
dt.on('destroy.autoFill', () => {
|
|
179
|
+
this._focusListenerRemove();
|
|
180
|
+
this.dom.handle.off();
|
|
184
181
|
});
|
|
185
182
|
}
|
|
186
183
|
/**
|
|
@@ -252,12 +249,10 @@ class AutoFill {
|
|
|
252
249
|
available.push('cancel');
|
|
253
250
|
for (let i = 0; i < available.length; i++) {
|
|
254
251
|
let name = available[i];
|
|
255
|
-
list.append(Dom
|
|
256
|
-
.c('button')
|
|
252
|
+
list.append(Dom.c('button')
|
|
257
253
|
.classAdd(AutoFill.classes.btn)
|
|
258
254
|
.html(actions[name].option(dt, cells))
|
|
259
|
-
.append(Dom
|
|
260
|
-
.c('span')
|
|
255
|
+
.append(Dom.c('span')
|
|
261
256
|
.classAdd('dtaf-button')
|
|
262
257
|
.html(dt.i18n('autoFill.button', '')))
|
|
263
258
|
.on('click', function (e) {
|
|
@@ -480,11 +475,16 @@ class AutoFill {
|
|
|
480
475
|
});
|
|
481
476
|
}
|
|
482
477
|
}
|
|
478
|
+
/**
|
|
479
|
+
* Clean up the event listeners
|
|
480
|
+
*/
|
|
483
481
|
_focusListenerRemove() {
|
|
484
|
-
|
|
482
|
+
let namespace = this.s.namespace;
|
|
483
|
+
let dt = this.s.dt;
|
|
485
484
|
dt.off('.autoFill');
|
|
486
|
-
Dom.s(dt.table().body()).off(
|
|
487
|
-
Dom.s(document.body).off(
|
|
485
|
+
Dom.s(dt.table().body()).off(namespace);
|
|
486
|
+
Dom.s(document.body).off(namespace);
|
|
487
|
+
Dom.w.off(namespace);
|
|
488
488
|
}
|
|
489
489
|
/**
|
|
490
490
|
* Get the position of a node, relative to another, including any scrolling
|
|
@@ -939,7 +939,7 @@ AutoFill.defaults = {
|
|
|
939
939
|
horizontal: true
|
|
940
940
|
};
|
|
941
941
|
/** AutoFill version */
|
|
942
|
-
AutoFill.version = '3.0.0
|
|
942
|
+
AutoFill.version = '3.0.0';
|
|
943
943
|
|
|
944
944
|
// Doesn't do anything - Not documented
|
|
945
945
|
Api.register('autoFill()', function () {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! AutoFill 3.0.0
|
|
1
|
+
/*! AutoFill 3.0.0 for DataTables
|
|
2
2
|
* Copyright (c) SpryMedia Ltd - datatables.net/license
|
|
3
3
|
*/
|
|
4
|
-
(e=>{var o;"function"==typeof define&&define.amd?define(["datatables.net"],function(t){return e(window,document,t)}):"object"==typeof exports?(o=function(t){t.DataTable||require("datatables.net")(t)},"undefined"==typeof window?module.exports=function(t){return t=t||window,o(t),e(t,t.document,t.DataTable)}:(o(window),module.exports=e(window,window.document,window.DataTable))):e(window,document,window.DataTable)})(function(c,n,u){var h=u.Dom,t=u.Api,d=u.util;if(!u||!u.versionCheck||!u.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var o=0;class r{enabled(){return this.s.enabled}enable(t=!0){let e=this;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function o(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return c.addEventListener("resize",function(){0<h.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),c.addEventListener("orientationchange",function(){setTimeout(function(){o(),setTimeout(o,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=d.object.assignDeep({},r.defaults,e),this.s={dt:new u.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+o++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:h.c("div").classAdd("dtaf-container"),closeButton:h.c("button").classAdd(r.classes.close).html("×"),dtScroll:null,handle:h.c("div").classAdd("dtaf-handle"),list:h.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(h.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:h.c("div").classAdd("dtaf-select top"),right:h.c("div").classAdd("dtaf-select right"),bottom:h.c("div").classAdd("dtaf-select bottom"),left:h.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){let t=this;var e=this.s.dt,o=h.s(this.s.dt.table().container()).find("div.dt-scroll-body");e.settings()[0].autoFill=this,o.count()&&"static"===(this.dom.dtScroll=o).css("position")&&o.css("position","relative"),!1!==this.c.enable&&this.enable(),e.on("destroy.autoFill",function(){t._focusListenerRemove()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=r.actions,s=[];if(d.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(h.c("button").classAdd(r.classes.btn).html(n[e].option(l,o)).append(h.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,h.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(r.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=h.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?h.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=h.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(h.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),h.s(n.body).on("click"+t,function(t){h.s(t.target).closest(e.table().body()).count()||i._detach()})):h.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){h.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.dt;t.off(".autoFill"),h.s(t.table().body()).off(this.s.namespace),h.s(n.body).off(this.s.namespace)}_getPosition(t,e){let o=h.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=h.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=h.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(h.s(this.dom.start).parent().get(0)),column:h.s(this.dom.start).index()},h.s(n.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&h.s(n.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:c.innerHeight,windowWidth:c.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?n.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){h.s(n.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(h.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=u.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-c.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-c.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;c.scrollTo(c.scrollX+(s.windowHoriz||0),c.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}return r.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},r.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},r.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},r.version="3.0.0-beta.1",t.register("autoFill()",function(){return this.inst(this.context)}),t.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),t.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),t.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),h.s(n).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=u.defaults.autoFill,t||o)&&(i={},d.is.plainObject(o)&&d.object.assign(i,o),d.is.plainObject(t)&&d.object.assign(i,t),!1!==t)&&new r(e,i)}),u.AutoFill=r,u});
|
|
4
|
+
(e=>{var o;"function"==typeof define&&define.amd?define(["datatables.net"],function(t){return e(window,document,t)}):"object"==typeof exports?(o=function(t){t.DataTable||require("datatables.net")(t)},"undefined"==typeof window?module.exports=function(t){return t=t||window,o(t),e(t,t.document,t.DataTable)}:(o(window),module.exports=e(window,window.document,window.DataTable))):e(window,document,window.DataTable)})(function(c,n,u){var h=u.Dom,t=u.Api,d=u.util;if(!u||!u.versionCheck||!u.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var o=0;class r{enabled(){return this.s.enabled}enable(t=!0){let e=this;var o=this.s.namespace;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function i(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return h.w.on("resize"+o,function(){0<h.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),h.w.on("orientationchange"+o,function(){setTimeout(function(){i(),setTimeout(i,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=d.object.assignDeep({},r.defaults,e),this.s={dt:new u.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+o++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:h.c("div").classAdd("dtaf-container"),closeButton:h.c("button").classAdd(r.classes.close).html("×"),dtScroll:null,handle:h.c("div").classAdd("dtaf-handle"),list:h.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(h.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:h.c("div").classAdd("dtaf-select top"),right:h.c("div").classAdd("dtaf-select right"),bottom:h.c("div").classAdd("dtaf-select bottom"),left:h.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){var t=this.s.dt,e=h.s(this.s.dt.table().container()).find("div.dt-scroll-body");t.settings()[0].autoFill=this,e.count()&&"static"===(this.dom.dtScroll=e).css("position")&&e.css("position","relative"),!1!==this.c.enable&&this.enable(),t.on("destroy.autoFill",()=>{this._focusListenerRemove(),this.dom.handle.off()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=r.actions,s=[];if(d.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(h.c("button").classAdd(r.classes.btn).html(n[e].option(l,o)).append(h.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,h.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(r.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=h.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?h.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=h.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(h.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),h.s(n.body).on("click"+t,function(t){h.s(t.target).closest(e.table().body()).count()||i._detach()})):h.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){h.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.namespace,e=this.s.dt;e.off(".autoFill"),h.s(e.table().body()).off(t),h.s(n.body).off(t),h.w.off(t)}_getPosition(t,e){let o=h.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=h.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=h.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(h.s(this.dom.start).parent().get(0)),column:h.s(this.dom.start).index()},h.s(n.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&h.s(n.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:c.innerHeight,windowWidth:c.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?n.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){h.s(n.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(h.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=u.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-c.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-c.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;c.scrollTo(c.scrollX+(s.windowHoriz||0),c.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}return r.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},r.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},r.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},r.version="3.0.0",t.register("autoFill()",function(){return this.inst(this.context)}),t.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),t.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),t.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),h.s(n).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=u.defaults.autoFill,t||o)&&(i={},d.is.plainObject(o)&&d.object.assign(i,o),d.is.plainObject(t)&&d.object.assign(i,t),!1!==t)&&new r(e,i)}),u.AutoFill=r,u});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! AutoFill 3.0.0
|
|
1
|
+
/*! AutoFill 3.0.0 for DataTables
|
|
2
2
|
* Copyright (c) SpryMedia Ltd - datatables.net/license
|
|
3
3
|
*/
|
|
4
|
-
import DataTable,{Dom,util,Api}from"datatables.net";if(!DataTable||!DataTable.versionCheck||!DataTable.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var _instance=0;class AutoFill{enabled(){return this.s.enabled}enable(t=!0){let e=this;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function o(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return window.addEventListener("resize",function(){0<Dom.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),window.addEventListener("orientationchange",function(){setTimeout(function(){o(),setTimeout(o,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=util.object.assignDeep({},AutoFill.defaults,e),this.s={dt:new DataTable.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+_instance++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:Dom.c("div").classAdd("dtaf-container"),closeButton:Dom.c("button").classAdd(AutoFill.classes.close).html("×"),dtScroll:null,handle:Dom.c("div").classAdd("dtaf-handle"),list:Dom.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(Dom.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:Dom.c("div").classAdd("dtaf-select top"),right:Dom.c("div").classAdd("dtaf-select right"),bottom:Dom.c("div").classAdd("dtaf-select bottom"),left:Dom.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){let t=this;var e=this.s.dt,o=Dom.s(this.s.dt.table().container()).find("div.dt-scroll-body");e.settings()[0].autoFill=this,o.count()&&"static"===(this.dom.dtScroll=o).css("position")&&o.css("position","relative"),!1!==this.c.enable&&this.enable(),e.on("destroy.autoFill",function(){t._focusListenerRemove()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=AutoFill.actions,s=[];if(util.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(Dom.c("button").classAdd(AutoFill.classes.btn).html(n[e].option(l,o)).append(Dom.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,Dom.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(AutoFill.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=Dom.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?Dom.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=Dom.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(Dom.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),Dom.s(document.body).on("click"+t,function(t){Dom.s(t.target).closest(e.table().body()).count()||i._detach()})):Dom.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){Dom.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.dt;t.off(".autoFill"),Dom.s(t.table().body()).off(this.s.namespace),Dom.s(document.body).off(this.s.namespace)}_getPosition(t,e){let o=Dom.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=Dom.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=Dom.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(Dom.s(this.dom.start).parent().get(0)),column:Dom.s(this.dom.start).index()},Dom.s(document.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&Dom.s(document.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:window.innerHeight,windowWidth:window.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?document.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){Dom.s(document.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(Dom.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=DataTable.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-window.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-window.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;window.scrollTo(window.scrollX+(s.windowHoriz||0),window.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}AutoFill.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},AutoFill.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},AutoFill.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},AutoFill.version="3.0.0-beta.1",Api.register("autoFill()",function(){return this.inst(this.context)}),Api.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),Api.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),Api.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),Dom.s(document).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=DataTable.defaults.autoFill,t||o)&&(i={},util.is.plainObject(o)&&util.object.assign(i,o),util.is.plainObject(t)&&util.object.assign(i,t),!1!==t)&&new AutoFill(e,i)}),DataTable.AutoFill=AutoFill;export default DataTable;
|
|
4
|
+
import DataTable,{Dom,util,Api}from"datatables.net";if(!DataTable||!DataTable.versionCheck||!DataTable.versionCheck("3"))throw"Warning: AutoFill requires DataTables 3 or greater";var _instance=0;class AutoFill{enabled(){return this.s.enabled}enable(t=!0){let e=this;var o=this.s.namespace;if(!1===t)return this.disable();this.s.enabled=!0,this._focusListener(),this.dom.handle.on("mousedown touchstart",function(t){return e._mousedown(t),!1});function i(){e.s.handle={height:0,width:0},e.dom.handle.css({height:"",width:""}),e.dom.attachedTo&&e._attach(e.dom.attachedTo)}return Dom.w.on("resize"+o,function(){0<Dom.s("div.dtaf-handle").count()&&e.dom.attachedTo&&e._attach(e.dom.attachedTo)}),Dom.w.on("orientationchange"+o,function(){setTimeout(function(){i(),setTimeout(i,150)},50)}),this}disable(){return this.s.enabled=!1,this._focusListenerRemove(),this}constructor(t,e){this.c=util.object.assignDeep({},AutoFill.defaults,e),this.s={dt:new DataTable.Api(t),enabled:!1,end:{column:0,row:0},handle:{height:0,width:0},namespace:".autoFill"+_instance++,scroll:{windowHeight:0,windowWidth:0,dtTop:0,dtLeft:0,dtHeight:0,dtWidth:0},scrollInterval:null,start:{column:0,row:0}},this.dom={attachedTo:null,container:Dom.c("div").classAdd("dtaf-container"),closeButton:Dom.c("button").classAdd(AutoFill.classes.close).html("×"),dtScroll:null,handle:Dom.c("div").classAdd("dtaf-handle"),list:Dom.c("div").classAdd("dtaf-list").html(this.s.dt.i18n("autoFill.info","")).attr("aria-modal",!0).attr("role","dialog").append(Dom.c("div").classAdd("dtaf-list-items")),offsetParent:null,start:null,select:{top:Dom.c("div").classAdd("dtaf-select top"),right:Dom.c("div").classAdd("dtaf-select right"),bottom:Dom.c("div").classAdd("dtaf-select bottom"),left:Dom.c("div").classAdd("dtaf-select left")}},this.dom.list.appendTo(this.dom.container),this._init()}_init(){var t=this.s.dt,e=Dom.s(this.s.dt.table().container()).find("div.dt-scroll-body");t.settings()[0].autoFill=this,e.count()&&"static"===(this.dom.dtScroll=e).css("position")&&e.css("position","relative"),!1!==this.c.enable&&this.enable(),t.on("destroy.autoFill",()=>{this._focusListenerRemove(),this.dom.handle.off()})}_attach(t){var e=this.s.dt,o=e.cell(t).index(),i=this.dom.handle,l=this.s.handle;o&&-1!==e.columns(this.c.columns).indexes().indexOf(o.column)?(this.dom.offsetParent||(this.dom.offsetParent=e.table().node().offsetParent),l.height&&l.width||(i.appendTo("body"),l.height=i.height("outer"),l.width=i.width("outer")),o=this._getPosition(t,this.dom.offsetParent),this.dom.attachedTo=t,i.css({top:o.top+t.offsetHeight-l.height+"px",left:o.left+t.offsetWidth-l.width+"px"}).appendTo(this.dom.offsetParent)):this._detach()}_actionSelector(o){let i=this,l=this.s.dt,n=AutoFill.actions,s=[];if(util.object.each(n,function(t,e){e.available(l,o)&&s.push(t)}),1===s.length&&!1===this.c.alwaysAsk){var t=n[s[0]].execute(l,o,null);this._update(t,o)}else if(1<s.length||this.c.alwaysAsk){var a=this.dom.list.children("div.dtaf-list-items").empty();s.push("cancel");for(let t=0;t<s.length;t++){let e=s[t];a.append(Dom.c("button").classAdd(AutoFill.classes.btn).html(n[e].option(l,o)).append(Dom.c("span").classAdd("dtaf-button").html(l.i18n("autoFill.button",""))).on("click",function(t){"button"===t.target.nodeName.toLowerCase()&&(t=n[e].execute(l,o,Dom.s(this).closest("button")),i._update(t,o),i.dom.container.remove())}))}this.dom.container.appendTo("body"),this.dom.container.on("click",function(t){t.target===i.dom.container.get(0)&&i.dom.container.remove()}),this.c.closeButton&&(this.dom.list.prepend(this.dom.closeButton).classAdd(AutoFill.classes.closeable),this.dom.closeButton.on("click",function(){return i.dom.container.trigger("click")}))}}_detach(){this.dom.attachedTo=null,this.dom.handle.detach()}_drawSelection(t,e){var o,i=this.s.dt,l=this.s.start,n=Dom.s(this.dom.start),t={row:this.c.vertical?i.rows({page:"current"}).nodes().indexOf(t.parentNode):l.row,column:this.c.horizontal?Dom.s(t).index():l.column},s=i.column.index("toData",t.column),a=i.row(":eq("+t.row+")",{page:"current"}),a=Dom.s(i.cell(a.index(),s).node());i.cell(a.get(0)).any()&&-1!==i.columns(this.c.columns).indexes().indexOf(s)&&-1!==t.row&&(this.s.end=t,i=l.row<t.row?n:a,s=l.row<t.row?a:n,o=l.column<t.column?n:a,l=l.column<t.column?a:n,i=this._getPosition(i.get(0)).top,o=this._getPosition(o.get(0)).left,t=this._getPosition(s.get(0)).top+s.height("outer")-i,a=this._getPosition(l.get(0)).left+l.width("outer")-o,(n=this.dom.select).top.css({top:i+"px",left:o+"px",width:a+"px"}),n.left.css({top:i+"px",left:o+"px",height:t+"px"}),n.bottom.css({top:i+t+"px",left:o+"px",width:a+"px"}),n.right.css({top:i+"px",left:o+a+"px",height:t+"px"}))}_editor(l){var n=this.s.dt;let s=this.c.editor;if(s){var a={},d=[],c=s.fields();for(let i=0,t=l.length;i<t;i++)for(let t=0,e=l[i].length;t<e;t++){var r=l[i][t],u=n.settings()[0].columns[r.index.column];let o=u.editField;if(void 0===o){var h=u.data;for(let t=0,e=c.length;t<e;t++){var f=s.field(c[t]);if(f.dataSrc()===h){o=f.name();break}}}if(!o)throw"Could not automatically determine field data. Please see https://datatables.net/tn/11";if("string"!=typeof o)throw"AutoFill with multiple edit fields is not supported";a[o]||(a[o]={});u=n.row(r.index.row).id();a[o][u]=r.set,d.push(r.index)}s.bubble(d,!1).multiSet(a).submit(null,function(){s.close()})}}_emitEvent(t,e){this.s.dt.trigger(t,e)}_focusListener(){var i=this,e=this.s.dt,t=this.s.namespace,o=null!==this.c.focus?this.c.focus:e.init().keys||e.settings()[0].keytable?"focus":"hover";"focus"===o?e.on("key-focus.autoFill",function(t,e,o){i._attach(o.node())}).on("key-blur.autoFill",function(t,e,o){i._detach()}):"click"===o?(Dom.s(e.table().body()).on("click"+t,"td, th",function(t){i._attach(this)}),Dom.s(document.body).on("click"+t,function(t){Dom.s(t.target).closest(e.table().body()).count()||i._detach()})):Dom.s(e.table().body()).on("mouseenter"+t+" touchstart"+t,"td, th",function(t){i._attach(this)}).on("mouseleave"+t+"touchend"+t,function(t){Dom.s(t.relatedTarget).classHas("dtaf-handle")||i._detach()})}_focusListenerRemove(){var t=this.s.namespace,e=this.s.dt;e.off(".autoFill"),Dom.s(e.table().body()).off(t),Dom.s(document.body).off(t),Dom.w.off(t)}_getPosition(t,e){let o=Dom.s(this.s.dt.table().node().offsetParent),i=t,l,n=0,s=0;e&&(o=Dom.s(e));do{var a=i.offsetTop,d=i.offsetLeft;if(l=Dom.s(i.offsetParent),n+=a+ +parseInt(l.css("border-top-width")||"0"),s+=d+ +parseInt(l.css("border-left-width")||"0"),"body"===i.nodeName.toLowerCase())break}while(i=l.get(0),l.get(0)!==o.get(0));return{top:n,left:s}}_mousedown(t){let e=this;var o=this.s.dt,i=(this.dom.start=this.dom.attachedTo,this.s.start={row:o.rows({page:"current"}).nodes().indexOf(Dom.s(this.dom.start).parent().get(0)),column:Dom.s(this.dom.start).index()},Dom.s(document.body).on("mousemove.autoFill touchmove.autoFill",function(t){e._mousemove(t),"touchmove"===t.type&&Dom.s(document.body).one("touchend.autoFill",function(){e._detach()})}).on("mouseup.autoFill touchend.autoFill",function(t){e._mouseup(t)}),this.dom.select),o=o.table().node().offsetParent,i=(i.top.appendTo(o),i.left.appendTo(o),i.right.appendTo(o),i.bottom.appendTo(o),this._drawSelection(this.dom.start,t),this.dom.handle.css("display","none"),this.dom.dtScroll);this.s.scroll={windowHeight:window.innerHeight,windowWidth:window.innerWidth,dtTop:i?i.offset().top:0,dtLeft:i?i.offset().left:0,dtHeight:i?i.height("outer"):0,dtWidth:i?i.width("outer"):0}}_mousemove(t){var e=t.touches&&t.touches.length?document.elementFromPoint(t.touches[0].clientX,t.touches[0].clientY):t.target,o=e.nodeName.toLowerCase();"td"!==o&&"th"!==o||(this._drawSelection(e,t),this._shiftScroll(t))}_mouseup(e){Dom.s(document.body).off(".autoFill");let o=this,d=this.s.dt;var t=this.dom.select,t=(t.top.remove(),t.left.remove(),t.right.remove(),t.bottom.remove(),this.dom.handle.css("display","block"),this.s.start),i=this.s.end;if(t.row!==i.row||t.column!==i.column){var l=d.cell(":eq("+t.row+")",t.column+":visible",{page:"current"});if(Dom.s(l.node()).find("div.DTE").count()){let t=d.editor();t.on("submitSuccess.dtaf close.dtaf",function(){t.off(".dtaf"),setTimeout(function(){o._mouseup(e)},100)}).on("submitComplete.dtaf preSubmitCancelled.dtaf close.dtaf",function(){t.off(".dtaf")}),void t.submit()}else{let n=this._range(t.row,i.row);var c=this._range(t.column,i.column),r=[];let s=d.settings()[0].columns,a=d.columns(this.c.columns).indexes();for(let l=0;l<n.length;l++)r.push(c.map(function(t){var e=d.row(":eq("+n[l]+")",{page:"current"}),e=d.cell(e.index(),t+":visible");let o=e.data();var t=e.index(),i=s[t.column].editField;if(void 0!==i&&(o=DataTable.util.get(i)(d.row(t.row).data())),-1!==a.indexOf(t.column))return{cell:e,data:o,label:e.data(),index:t}}).filter(t=>!!t));this._actionSelector(r),this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null)}}}_range(t,e){var o,i=[];if(t<=e)for(o=t;o<=e;o++)i.push(o);else for(o=t;e<=o;o--)i.push(o);return i}_shiftScroll(t){var e,o,i,l,n=this,s=this.s.scroll,a=!1,d=t.type.includes("touch")?t.touches[0].clientX:t.pageX-window.scrollX,t=t.type.includes("touch")?t.touches[0].clientY:t.pageY-window.scrollY;t<65?e=-5:t>s.windowHeight-65&&(e=5),d<65?o=-5:d>s.windowWidth-65&&(o=5),null!==s.dtTop&&t<s.dtTop+65?i=-5:null!==s.dtTop&&t>s.dtTop+s.dtHeight-65&&(i=5),null!==s.dtLeft&&d<s.dtLeft+65?l=-5:null!==s.dtLeft&&d>s.dtLeft+s.dtWidth-65&&(l=5),e||o||i||l?(s.windowVert=e,s.windowHoriz=o,s.dtVert=i,s.dtHoriz=l,a=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&a&&(this.s.scrollInterval=setInterval(function(){var t;window.scrollTo(window.scrollX+(s.windowHoriz||0),window.scrollY+(s.windowVert||0)),(s.dtVert||s.dtHoriz)&&((t=null==(t=n.dom.dtScroll)?void 0:t.get(0))&&s.dtVert&&(t.scrollTop+=s.dtVert),t)&&s.dtHoriz&&(t.scrollLeft+=s.dtHoriz)},20))}_update(t,i){if(!1!==t){var l,t=this.s.dt,n=t.columns(this.c.columns).indexes(),e=(this._emitEvent("preAutoFill",[t,i]),this._editor(i),null!==this.c.update?this.c.update:!this.c.editor);if(e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)l=i[o][t],-1!==n.indexOf(l.index.column)&&l.cell.data(l.set);t.draw(!1)}this._emitEvent("autoFill",[t,i])}}}AutoFill.actions={increment:{available:function(t,e){e=e[0][0].label;return!isNaN(e-parseFloat(e))},option:function(t,e){return t.i18n("autoFill.increment",'Increment / decrement each cell by: <input type="number" value="1">')},execute:function(t,i,e){let l=+i[0][0].data;var n=e?parseFloat(e.find("input").val()):1;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l,l+=n}},fill:{available:function(t,e){return!0},option:function(t,e){return t.i18n("autoFill.fill","Fill all cells with <i>%d</i>",e[0][0].label)},execute:function(t,i,e){var l=i[0][0].data;for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=l}},fillHorizontal:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillHorizontal","Fill cells horizontally")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[o][0].data}},fillVertical:{available:function(t,e){return 1<e.length&&1<e[0].length},option:function(t,e){return t.i18n("autoFill.fillVertical","Fill cells vertically")},execute:function(t,i,e){for(let o=0,t=i.length;o<t;o++)for(let t=0,e=i[o].length;t<e;t++)i[o][t].set=i[0][t].data}},cancel:{available:function(){return!1},option:function(t){return t.i18n("autoFill.cancel","Cancel")},execute:function(){return!1}}},AutoFill.classes={btn:"btn",close:"dtaf-list-close",closeable:"dtaf-list-closeable"},AutoFill.defaults={alwaysAsk:!1,closeButton:!0,focus:null,columns:"",enable:!0,update:!0,editor:null,vertical:!0,horizontal:!0},AutoFill.version="3.0.0",Api.register("autoFill()",function(){return this.inst(this.context)}),Api.register("autoFill().enabled()",function(){var t=this.context[0];return!!t.autoFill&&t.autoFill.enabled()}),Api.register("autoFill().enable()",function(e){return this.iterator("table",function(t){t.autoFill&&t.autoFill.enable(e)})}),Api.register("autoFill().disable()",function(){return this.iterator("table",function(t){t.autoFill&&t.autoFill.disable()})}),Dom.s(document).on("preInit.dt.autofill",function(t,e){var o,i;"dt"===t.namespace&&(t=e.init.autoFill,o=DataTable.defaults.autoFill,t||o)&&(i={},util.is.plainObject(o)&&util.object.assign(i,o),util.is.plainObject(t)&&util.object.assign(i,t),!1!==t)&&new AutoFill(e,i)}),DataTable.AutoFill=AutoFill;export default DataTable;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! AutoFill 3.0.0
|
|
1
|
+
/*! AutoFill 3.0.0 for DataTables
|
|
2
2
|
* Copyright (c) SpryMedia Ltd - datatables.net/license
|
|
3
3
|
*/
|
|
4
4
|
|
|
@@ -18,6 +18,7 @@ class AutoFill {
|
|
|
18
18
|
}
|
|
19
19
|
enable(flag = true) {
|
|
20
20
|
let that = this;
|
|
21
|
+
let namespace = this.s.namespace;
|
|
21
22
|
if (flag === false) {
|
|
22
23
|
return this.disable();
|
|
23
24
|
}
|
|
@@ -40,13 +41,13 @@ class AutoFill {
|
|
|
40
41
|
that._attach(that.dom.attachedTo);
|
|
41
42
|
}
|
|
42
43
|
};
|
|
43
|
-
|
|
44
|
+
Dom.w.on('resize' + namespace, function () {
|
|
44
45
|
let handle = Dom.s('div.dtaf-handle');
|
|
45
46
|
if (handle.count() > 0 && that.dom.attachedTo) {
|
|
46
47
|
that._attach(that.dom.attachedTo);
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
|
-
|
|
50
|
+
Dom.w.on('orientationchange' + namespace, function () {
|
|
50
51
|
setTimeout(function () {
|
|
51
52
|
orientationReset();
|
|
52
53
|
setTimeout(orientationReset, 150);
|
|
@@ -87,14 +88,12 @@ class AutoFill {
|
|
|
87
88
|
this.dom = {
|
|
88
89
|
attachedTo: null,
|
|
89
90
|
container: Dom.c('div').classAdd('dtaf-container'),
|
|
90
|
-
closeButton: Dom
|
|
91
|
-
.c('button')
|
|
91
|
+
closeButton: Dom.c('button')
|
|
92
92
|
.classAdd(AutoFill.classes.close)
|
|
93
93
|
.html('×'),
|
|
94
94
|
dtScroll: null,
|
|
95
95
|
handle: Dom.c('div').classAdd('dtaf-handle'),
|
|
96
|
-
list: Dom
|
|
97
|
-
.c('div')
|
|
96
|
+
list: Dom.c('div')
|
|
98
97
|
.classAdd('dtaf-list')
|
|
99
98
|
.html(this.s.dt.i18n('autoFill.info', ''))
|
|
100
99
|
.attr('aria-modal', true)
|
|
@@ -120,12 +119,9 @@ class AutoFill {
|
|
|
120
119
|
* Initialise the RowReorder instance
|
|
121
120
|
*/
|
|
122
121
|
_init() {
|
|
123
|
-
let that = this;
|
|
124
122
|
let dt = this.s.dt;
|
|
125
123
|
// Need to account for scrolling as it has a different DOM structure
|
|
126
|
-
let dtScroll = Dom
|
|
127
|
-
.s(this.s.dt.table().container())
|
|
128
|
-
.find('div.dt-scroll-body');
|
|
124
|
+
let dtScroll = Dom.s(this.s.dt.table().container()).find('div.dt-scroll-body');
|
|
129
125
|
// Make the instance accessible to the API
|
|
130
126
|
dt.settings()[0].autoFill = this;
|
|
131
127
|
if (dtScroll.count()) {
|
|
@@ -138,8 +134,9 @@ class AutoFill {
|
|
|
138
134
|
if (this.c.enable !== false) {
|
|
139
135
|
this.enable();
|
|
140
136
|
}
|
|
141
|
-
dt.on('destroy.autoFill',
|
|
142
|
-
|
|
137
|
+
dt.on('destroy.autoFill', () => {
|
|
138
|
+
this._focusListenerRemove();
|
|
139
|
+
this.dom.handle.off();
|
|
143
140
|
});
|
|
144
141
|
}
|
|
145
142
|
/**
|
|
@@ -211,12 +208,10 @@ class AutoFill {
|
|
|
211
208
|
available.push('cancel');
|
|
212
209
|
for (let i = 0; i < available.length; i++) {
|
|
213
210
|
let name = available[i];
|
|
214
|
-
list.append(Dom
|
|
215
|
-
.c('button')
|
|
211
|
+
list.append(Dom.c('button')
|
|
216
212
|
.classAdd(AutoFill.classes.btn)
|
|
217
213
|
.html(actions[name].option(dt, cells))
|
|
218
|
-
.append(Dom
|
|
219
|
-
.c('span')
|
|
214
|
+
.append(Dom.c('span')
|
|
220
215
|
.classAdd('dtaf-button')
|
|
221
216
|
.html(dt.i18n('autoFill.button', '')))
|
|
222
217
|
.on('click', function (e) {
|
|
@@ -439,11 +434,16 @@ class AutoFill {
|
|
|
439
434
|
});
|
|
440
435
|
}
|
|
441
436
|
}
|
|
437
|
+
/**
|
|
438
|
+
* Clean up the event listeners
|
|
439
|
+
*/
|
|
442
440
|
_focusListenerRemove() {
|
|
443
|
-
|
|
441
|
+
let namespace = this.s.namespace;
|
|
442
|
+
let dt = this.s.dt;
|
|
444
443
|
dt.off('.autoFill');
|
|
445
|
-
Dom.s(dt.table().body()).off(
|
|
446
|
-
Dom.s(document.body).off(
|
|
444
|
+
Dom.s(dt.table().body()).off(namespace);
|
|
445
|
+
Dom.s(document.body).off(namespace);
|
|
446
|
+
Dom.w.off(namespace);
|
|
447
447
|
}
|
|
448
448
|
/**
|
|
449
449
|
* Get the position of a node, relative to another, including any scrolling
|
|
@@ -898,7 +898,7 @@ AutoFill.defaults = {
|
|
|
898
898
|
horizontal: true
|
|
899
899
|
};
|
|
900
900
|
/** AutoFill version */
|
|
901
|
-
AutoFill.version = '3.0.0
|
|
901
|
+
AutoFill.version = '3.0.0';
|
|
902
902
|
|
|
903
903
|
// Doesn't do anything - Not documented
|
|
904
904
|
Api.register('autoFill()', function () {
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"main": "js/dataTables.autoFill.js",
|
|
5
5
|
"module": "js/dataTables.autoFill.mjs",
|
|
6
6
|
"types": "./types/types.d.ts",
|
|
7
|
-
"version": "3.0.0
|
|
7
|
+
"version": "3.0.0",
|
|
8
8
|
"files": [
|
|
9
9
|
"js/**/*.js",
|
|
10
10
|
"js/**/*.mjs",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"sort"
|
|
20
20
|
],
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"datatables.net": "3
|
|
22
|
+
"datatables.net": "^3"
|
|
23
23
|
},
|
|
24
24
|
"author": {
|
|
25
25
|
"name": "SpryMedia Ltd",
|
|
@@ -30,6 +30,6 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "https://github.com/DataTables/
|
|
33
|
+
"url": "git+https://github.com/DataTables/AutoFill.git"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/types/types.d.ts
CHANGED
|
@@ -117,6 +117,9 @@ declare class AutoFill {
|
|
|
117
117
|
* and detach the AutoFill handle in the document.
|
|
118
118
|
*/
|
|
119
119
|
private _focusListener;
|
|
120
|
+
/**
|
|
121
|
+
* Clean up the event listeners
|
|
122
|
+
*/
|
|
120
123
|
private _focusListenerRemove;
|
|
121
124
|
/**
|
|
122
125
|
* Get the position of a node, relative to another, including any scrolling
|