From 438423c537765c854f0109d7f3d2342bd0c52aed Mon Sep 17 00:00:00 2001 From: Julian Motz Date: Thu, 7 Jul 2016 11:14:08 +0200 Subject: [PATCH] Added datatables.mark.js v1.0.1 --- features/mark.js/datatables.mark.es6.js | 24 +++++++++++++++++---- features/mark.js/datatables.mark.es6.min.js | 4 ++-- features/mark.js/datatables.mark.js | 24 +++++++++++++++++---- features/mark.js/datatables.mark.min.js | 4 ++-- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/features/mark.js/datatables.mark.es6.js b/features/mark.js/datatables.mark.es6.js index c4cdeb1..e6de541 100644 --- a/features/mark.js/datatables.mark.es6.js +++ b/features/mark.js/datatables.mark.es6.js @@ -1,5 +1,5 @@ /*!*************************************************** - * datatables.mark.js v1.0.0 + * datatables.mark.js v1.0.1 * https://github.com/julmot/datatables.mark.js * Copyright (c) 2016, Julian Motz * Released under the MIT license https://git.io/voRZ7 @@ -27,20 +27,36 @@ } this.instance = dtInstance; this.options = typeof options === "object" ? options : {}; + this.intervalThreshold = 49; + this.intervalMs = 300; this.initMarkListener(); } initMarkListener() { - this.instance.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth", this.mark.bind(this)); + const ev = "draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth"; + let intvl = null; + this.instance.on(ev, () => { + const rows = this.instance.rows({ + filter: "applied", + page: "current" + }).nodes().length; + if (rows > this.intervalThreshold) { + clearTimeout(intvl); + intvl = setTimeout(() => { + this.mark(); + }, this.intervalMs); + } else { + this.mark(); + } + }); this.instance.on("destroy", () => { - this.instance.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth"); + this.instance.off(ev); }); this.mark(); } mark() { const globalSearch = this.instance.search(); - $(this.instance.table().body()).unmark(this.options); this.instance.columns({ search: "applied", diff --git a/features/mark.js/datatables.mark.es6.min.js b/features/mark.js/datatables.mark.es6.min.js index ed137bb..2fef0d1 100644 --- a/features/mark.js/datatables.mark.es6.min.js +++ b/features/mark.js/datatables.mark.es6.min.js @@ -1,7 +1,7 @@ /*!*************************************************** - * datatables.mark.js v1.0.0 + * datatables.mark.js v1.0.1 * https://github.com/julmot/datatables.mark.js * Copyright (c) 2016, Julian Motz * Released under the MIT license https://git.io/voRZ7 *****************************************************/ -"use strict";((factory,window,document) => {if(typeof define==="function"&&define.amd){define(["jquery","datatables","markjs"],jQuery => {return factory(window,document,jQuery);});}else if(typeof exports==="object"){require("datatables");require("markjs");factory(window,document,require("jquery"));}else {factory(window,document,jQuery);}})((window,document,$) => {class Mark_DataTables{constructor(dtInstance,options){if(typeof $.fn.mark!=="function"||typeof $.fn.unmark!=="function"){throw new Error("jquery.mark.js is necessary for datatables.mark.js");}this.instance=dtInstance;this.options=typeof options==="object"?options:{};this.initMarkListener();}initMarkListener(){this.instance.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth",this.mark.bind(this));this.instance.on("destroy",() => {this.instance.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth");});this.mark();}mark(){const globalSearch=this.instance.search();$(this.instance.table().body()).unmark(this.options);this.instance.columns({search:"applied",page:"current"}).nodes().each((nodes,colIndex) => {const columnSearch=this.instance.column(colIndex).search(),searchVal=columnSearch||globalSearch;if(searchVal){nodes.forEach(node => {$(node).mark(searchVal,this.options);});}});}}$(document).on("init.dt.dth",(event,settings) => {if(event.namespace!=="dt"){return;}const dtInstance=$.fn.dataTable.Api(settings);let options=null;if(dtInstance.init().mark){options=dtInstance.init().mark;}else if($.fn.dataTable.defaults.mark){options=$.fn.dataTable.defaults.mark;}if(options===null){return;}new Mark_DataTables(dtInstance,options);});},window,document); +"use strict";((factory,window,document)=>{if(typeof define==="function"&&define.amd){define(["jquery","datatables","markjs"],jQuery=>{return factory(window,document,jQuery);});}else if(typeof exports==="object"){require("datatables");require("markjs");factory(window,document,require("jquery"));}else{factory(window,document,jQuery);}})((window,document,$)=>{class Mark_DataTables{constructor(dtInstance,options){if(typeof $.fn.mark!=="function"||typeof $.fn.unmark!=="function"){throw new Error("jquery.mark.js is necessary for datatables.mark.js");}this.instance=dtInstance;this.options=typeof options==="object"?options:{};this.intervalThreshold=49;this.intervalMs=300;this.initMarkListener();}initMarkListener(){const ev="draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth";let intvl=null;this.instance.on(ev,()=>{const rows=this.instance.rows({filter:"applied",page:"current"}).nodes().length;if(rows>this.intervalThreshold){clearTimeout(intvl);intvl=setTimeout(()=>{this.mark();},this.intervalMs);}else{this.mark();}});this.instance.on("destroy",()=>{this.instance.off(ev);});this.mark();}mark(){const globalSearch=this.instance.search();$(this.instance.table().body()).unmark(this.options);this.instance.columns({search:"applied",page:"current"}).nodes().each((nodes,colIndex)=>{const columnSearch=this.instance.column(colIndex).search(),searchVal=columnSearch||globalSearch;if(searchVal){nodes.forEach(node=>{$(node).mark(searchVal,this.options);});}});}}$(document).on("init.dt.dth",(event,settings)=>{if(event.namespace!=="dt"){return;}const dtInstance=$.fn.dataTable.Api(settings);let options=null;if(dtInstance.init().mark){options=dtInstance.init().mark;}else if($.fn.dataTable.defaults.mark){options=$.fn.dataTable.defaults.mark;}if(options===null){return;}new Mark_DataTables(dtInstance,options);});},window,document); diff --git a/features/mark.js/datatables.mark.js b/features/mark.js/datatables.mark.js index cab3a29..925bf15 100644 --- a/features/mark.js/datatables.mark.js +++ b/features/mark.js/datatables.mark.js @@ -1,5 +1,5 @@ /*!*************************************************** - * datatables.mark.js v1.0.0 + * datatables.mark.js v1.0.1 * https://github.com/julmot/datatables.mark.js * Copyright (c) 2016, Julian Motz * Released under the MIT license https://git.io/voRZ7 @@ -35,6 +35,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons } this.instance = dtInstance; this.options = (typeof options === "undefined" ? "undefined" : _typeof(options)) === "object" ? options : {}; + this.intervalThreshold = 49; + this.intervalMs = 300; this.initMarkListener(); } @@ -43,9 +45,24 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons value: function initMarkListener() { var _this = this; - this.instance.on("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth", this.mark.bind(this)); + var ev = "draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth"; + var intvl = null; + this.instance.on(ev, function () { + var rows = _this.instance.rows({ + filter: "applied", + page: "current" + }).nodes().length; + if (rows > _this.intervalThreshold) { + clearTimeout(intvl); + intvl = setTimeout(function () { + _this.mark(); + }, _this.intervalMs); + } else { + _this.mark(); + } + }); this.instance.on("destroy", function () { - _this.instance.off("draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth"); + _this.instance.off(ev); }); this.mark(); } @@ -55,7 +72,6 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons var _this2 = this; var globalSearch = this.instance.search(); - $(this.instance.table().body()).unmark(this.options); this.instance.columns({ search: "applied", diff --git a/features/mark.js/datatables.mark.min.js b/features/mark.js/datatables.mark.min.js index f108cbd..d51918e 100644 --- a/features/mark.js/datatables.mark.min.js +++ b/features/mark.js/datatables.mark.min.js @@ -1,7 +1,7 @@ /*!*************************************************** - * datatables.mark.js v1.0.0 + * datatables.mark.js v1.0.1 * https://github.com/julmot/datatables.mark.js * Copyright (c) 2016, Julian Motz * Released under the MIT license https://git.io/voRZ7 *****************************************************/ -"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;ca.intervalThreshold?(clearTimeout(c),c=setTimeout(function(){a.mark()},a.intervalMs)):a.mark()}),this.instance.on("destroy",function(){a.instance.off(b)}),this.mark()}},{key:"mark",value:function(){var a=this,b=this.instance.search();c(this.instance.table().body()).unmark(this.options),this.instance.columns({search:"applied",page:"current"}).nodes().each(function(d,e){var f=a.instance.column(e).search(),g=f||b;g&&d.forEach(function(b){c(b).mark(g,a.options)})})}}]),a}();c(b).on("init.dt.dth",function(a,b){if("dt"===a.namespace){var e=c.fn.dataTable.Api(b),f=null;e.init().mark?f=e.init().mark:c.fn.dataTable.defaults.mark&&(f=c.fn.dataTable.defaults.mark),null!==f&&new d(e,f)}})},window,document); \ No newline at end of file