|
| 1 | +/*!*************************************************** |
| 2 | + * datatables.mark.js v2.0.0 |
| 3 | + * https://github.com/julmot/datatables.mark.js |
| 4 | + * Copyright (c) 2016, Julian Motz |
| 5 | + * Released under the MIT license https://git.io/voRZ7 |
| 6 | + *****************************************************/ |
| 7 | + |
| 8 | +"use strict"; |
| 9 | + |
| 10 | +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
| 11 | + |
| 12 | +var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; |
| 13 | + |
| 14 | +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } |
| 15 | + |
| 16 | +(function (factory, window, document) { |
| 17 | + if (typeof define === "function" && define.amd) { |
| 18 | + define(["jquery", "datatables.net", "markjs"], function (jQuery) { |
| 19 | + return factory(window, document, jQuery); |
| 20 | + }); |
| 21 | + } else if ((typeof exports === "undefined" ? "undefined" : _typeof(exports)) === "object") { |
| 22 | + require("datatables.net"); |
| 23 | + require("markjs"); |
| 24 | + factory(window, document, require("jquery")); |
| 25 | + } else { |
| 26 | + factory(window, document, jQuery); |
| 27 | + } |
| 28 | +})(function (window, document, $) { |
| 29 | + var Mark_DataTables = function () { |
| 30 | + function Mark_DataTables(dtInstance, options) { |
| 31 | + _classCallCheck(this, Mark_DataTables); |
| 32 | + |
| 33 | + if (typeof $.fn.mark !== "function" || typeof $.fn.unmark !== "function") { |
| 34 | + throw new Error("jquery.mark.js is necessary for datatables.mark.js"); |
| 35 | + } |
| 36 | + this.instance = dtInstance; |
| 37 | + this.options = (typeof options === "undefined" ? "undefined" : _typeof(options)) === "object" ? options : {}; |
| 38 | + this.intervalThreshold = 49; |
| 39 | + this.intervalMs = 300; |
| 40 | + this.initMarkListener(); |
| 41 | + } |
| 42 | + |
| 43 | + _createClass(Mark_DataTables, [{ |
| 44 | + key: "initMarkListener", |
| 45 | + value: function initMarkListener() { |
| 46 | + var _this = this; |
| 47 | + |
| 48 | + var ev = "draw.dt.dth column-visibility.dt.dth column-reorder.dt.dth"; |
| 49 | + var intvl = null; |
| 50 | + this.instance.on(ev, function () { |
| 51 | + var rows = _this.instance.rows({ |
| 52 | + filter: "applied", |
| 53 | + page: "current" |
| 54 | + }).nodes().length; |
| 55 | + if (rows > _this.intervalThreshold) { |
| 56 | + clearTimeout(intvl); |
| 57 | + intvl = setTimeout(function () { |
| 58 | + _this.mark(); |
| 59 | + }, _this.intervalMs); |
| 60 | + } else { |
| 61 | + _this.mark(); |
| 62 | + } |
| 63 | + }); |
| 64 | + this.instance.on("destroy", function () { |
| 65 | + _this.instance.off(ev); |
| 66 | + }); |
| 67 | + this.mark(); |
| 68 | + } |
| 69 | + }, { |
| 70 | + key: "mark", |
| 71 | + value: function mark() { |
| 72 | + var _this2 = this; |
| 73 | + |
| 74 | + var globalSearch = this.instance.search(); |
| 75 | + $(this.instance.table().body()).unmark(this.options); |
| 76 | + this.instance.columns({ |
| 77 | + search: "applied", |
| 78 | + page: "current" |
| 79 | + }).nodes().each(function (nodes, colIndex) { |
| 80 | + var columnSearch = _this2.instance.column(colIndex).search(), |
| 81 | + searchVal = columnSearch || globalSearch; |
| 82 | + if (searchVal) { |
| 83 | + nodes.forEach(function (node) { |
| 84 | + $(node).mark(searchVal, _this2.options); |
| 85 | + }); |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | + }]); |
| 90 | + |
| 91 | + return Mark_DataTables; |
| 92 | + }(); |
| 93 | + |
| 94 | + $(document).on("init.dt.dth", function (event, settings) { |
| 95 | + if (event.namespace !== "dt") { |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + var dtInstance = $.fn.dataTable.Api(settings); |
| 100 | + |
| 101 | + var options = null; |
| 102 | + if (dtInstance.init().mark) { |
| 103 | + options = dtInstance.init().mark; |
| 104 | + } else if ($.fn.dataTable.defaults.mark) { |
| 105 | + options = $.fn.dataTable.defaults.mark; |
| 106 | + } |
| 107 | + if (options === null) { |
| 108 | + return; |
| 109 | + } |
| 110 | + |
| 111 | + new Mark_DataTables(dtInstance, options); |
| 112 | + }); |
| 113 | +}, window, document); |
0 commit comments