You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Plugins/features/searchPane/dataTables.searchPane.min.js

26 lines
5.1 KiB
JavaScript

/*!
Copyright 2017 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
SearchPane 0.0.1
2017 SpryMedia Ltd - datatables.net/license
*/
var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(a,e,c){a instanceof String&&(a=String(a));for(var g=a.length,d=0;d<g;d++){var l=a[d];if(e.call(c,l,d,a))return{i:d,v:l}}return{i:-1,v:void 0}};$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(a,e,c){a!=Array.prototype&&a!=Object.prototype&&(a[e]=c.value)};
$jscomp.getGlobal=function(a){return"undefined"!=typeof window&&window===a?a:"undefined"!=typeof global&&null!=global?global:a};$jscomp.global=$jscomp.getGlobal(this);$jscomp.polyfill=function(a,e,c,g){if(e){c=$jscomp.global;a=a.split(".");for(g=0;g<a.length-1;g++){var d=a[g];d in c||(c[d]={});c=c[d]}a=a[a.length-1];g=c[a];e=e(g);e!=g&&null!=e&&$jscomp.defineProperty(c,a,{configurable:!0,writable:!0,value:e})}};
$jscomp.polyfill("Array.prototype.find",function(a){return a?a:function(a,c){return $jscomp.findInternal(this,a,c).v}},"es6-impl","es3");
(function(a){"function"===typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return a(e,window,document)}):"object"===typeof exports?module.exports=function(e,c){e||(e=window);c&&c.fn.dataTable||(c=require("datatables.net")(e,c).$);return a(c,e,e.document)}:a(jQuery,window,document)})(function(a,e,c,g){function d(b,h){var f=this;b=new l.Api(b);this.classes=a.extend(!0,{},d.classes);this.dom={container:a("<div/>").addClass(this.classes.container)};this.c=a.extend(!0,{},d.defaults,
h);this.s={dt:b};b.settings()[0].searchPane=this;b.columns(this.c.columns).eq(0).each(function(a){f._pane(a)});a(this.dom.container).on("click","li",function(){f._toggle(this)}).on("click","button."+this.classes.clear,function(){f._clear(a(this).closest("div."+f.classes.pane.container))});this._attach()}var l=a.fn.dataTable;a.extend(d.prototype,{rebuild:function(){var a=this;this.s.dt.columns(this.c.columns).eq(0).each(function(b){a._pane(b)})},_attach:function(){var b=this.c.container,b="function"===
typeof b?b(this.s.dt):b;"prepend"===this.c.insert?a(this.dom.container).prependTo(b):a(this.dom.container).appendTo(b)},_binData:function(a){var b={};a.each(function(a){a&&(b[a]?b[a]++:b[a]=1)});return b},_clear:function(a){var b=this.classes,f=b.item.selected;a.find("li."+f).removeClass(f);a.removeClass(b.pane.active);this.s.dt.column(a.data("column")).search("").draw()},_pane:function(b){var h=this.classes,f=h.item,h=h.pane,c=this.s.dt.column(b),e=a("<ul/>"),d=this._binData(c.data().flatten());
if(!(this._variance(d)<this.c.threshold)){for(var g=c.search(),g=g?g.substr(1,g.length-2).split("|"):[],m=c.data().unique().sort().toArray(),k=0,l=m.length;k<l;k++)if(m[k]){var n=a("<li/>").html('<span class="'+f.label+'">'+m[k]+"</span>").data("filter",m[k]).append(a("<span/>").addClass(f.count).html(d[m[k]]));if(g.length){var p=m[k].replace?a.fn.dataTable.util.escapeRegex(m[k]):m[k];-1!==a.inArray(p,g)&&n.addClass(f.selected)}e.append(n)}f=a("<div/>").data("column",b).addClass(h.container).addClass(g.length?
h.active:"").append(a('<button type="button">&times;</button>').addClass(this.classes.clear)).append(a("<div/>").addClass(h.title).html(a(c.header()).text())).append(a("<div/>").addClass(h.scroller).append(e));h=this.dom.container;c=h.children().map(function(){if(a(this).data("column")==b)return this});c.length?c.replaceWith(f):a(h).append(f)}},_toggle:function(b){var c=this.classes,f=c.item.selected,e=this.s.dt;b=a(b);var d=b.closest("div."+c.pane.container);b.toggleClass(f,!b.hasClass(f));b=d.find("li."+
f);0===b.length?(d.removeClass(c.pane.active),e.column(d.data("column")).search("").draw()):(d.addClass(c.pane.active),e.column(d.data("column")).search("^("+a.map(b,function(b){b=a(b).data("filter").toString();return a.fn.dataTable.util.escapeRegex(b)}).join("|")+")$",!0,!1).draw())},_variance:function(b){b=a.map(b,function(a,b){return a});for(var c=b.length,f=0,d=0,e=c;d<e;d++)f+=b[d];for(var f=f/c,g=0,d=0,e=c;d<e;d++)g+=Math.pow(f-b[d],2);return g/(c-1)}});d.classes={container:"dt-searchPanes",
clear:"clear",pane:{active:"filtering",container:"pane",title:"title",scroller:"scroller"},item:{selected:"selected",label:"label",count:"count"}};d.defaults={container:function(a){return a.table().container()},columns:g,insert:"prepend",threshold:.5};d.version="0.0.1";a.fn.dataTable.SearchPanes=d;a.fn.DataTable.SearchPanes=d;l.Api.register("searchPanes.rebuild()",function(){return this.iterator("table",function(a){a.searchPane&&a.searchPane.rebuild()})});a(c).on("init.dt",function(b,c,e){"dt"===
b.namespace&&(b=c.oInit.searchPane,e=l.defaults.searchPane,b||e)&&(e=a.extend({},b,e),!1!==b&&new d(c,e))})});