Skip to content

Commit 801130f

Browse files
committed
#19: Added text highighter for search terms. Added datatables.mark.js and jquery.mark.js libraries and .ABOUT files.
1 parent d9ac5ef commit 801130f

14 files changed

+747
-0
lines changed

assets/css/datatables.mark.ABOUT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
about_resource: datatables.mark.css
2+
download_url: https://github.com/julmot/datatables.mark.js/releases/tag/v2.0.0
3+
4+
version: 2.0.0
5+
name: datatables.mark.js
6+
home_url: https://github.com/julmot/datatables.mark.js
7+
owner: Julian Motz
8+
copyright: Copyright (c) 2016, Julian Motz
9+
10+
license_url: https://raw.githubusercontent.com/julmot/datatables.mark.js/v2.0.0/LICENSE
11+
dje_license: mit
12+
license_text_file: datatables.mark.LICENSE

assets/css/datatables.mark.LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Julian Motz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

assets/css/datatables.mark.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
mark {
2+
background: #EEFF41;
3+
color: black;
4+
}

assets/css/datatables.mark.min.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mark{background:orange;color:black;}

assets/js/datatables.mark.ABOUT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
about_resource: datatables.mark.js
2+
download_url: https://github.com/julmot/datatables.mark.js/releases/tag/v2.0.0
3+
4+
version: 2.0.0
5+
name: datatables.mark.js
6+
home_url: https://github.com/julmot/datatables.mark.js
7+
owner: Julian Motz
8+
copyright: Copyright (c) 2016, Julian Motz
9+
10+
license_url: https://raw.githubusercontent.com/julmot/datatables.mark.js/v2.0.0/LICENSE
11+
dje_license: mit
12+
license_text_file: datatables.mark.LICENSE

assets/js/datatables.mark.LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Julian Motz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

assets/js/datatables.mark.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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);

assets/js/datatables.mark.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/jquery.mark.ABOUT

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
about_resource: jquery.mark.js
2+
download_url: https://github.com/julmot/datatables.mark.js/releases/tag/v7.0.0
3+
4+
version: 7.0.0
5+
name: mark.js
6+
home_url: https://github.com/julmot/mark.js/tree/7.0.0
7+
owner: Julian Motz
8+
copyright: Copyright (c) 2014–2016 Julian Motz
9+
10+
license_url: https://raw.githubusercontent.com/julmot/mark.js/7.0.0/LICENSE
11+
dje_license: mit
12+
license_text_file: jquery.mark.LICENSE

assets/js/jquery.mark.LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2014–2016 Julian Motz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)