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/fuzzySearch/dataTables.fuzzySearch.min.js

10 lines
5.8 KiB
JavaScript

/*!
* Fuzzy Search for DataTables
* 2021 SpryMedia Ltd - datatables.net/license MIT license
*
* Damerau-Levenshtein function courtesy of https://github.com/tad-lispy/node-damerau-levenshtein
* BSD 2-Clause License
* Copyright (c) 2018, Tadeusz Łazurski
* All rights reserved.
*/
!function(r){var o,n;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(e){return r(e,window,document)}):"object"==typeof exports?(o=require("jquery"),n=function(e,t){t.fn.dataTable||require("datatables.net")(e,t)},"undefined"==typeof window?module.exports=function(e,t){return e=e||window,t=t||o(e),n(e,t),r(t,0,e.document)}:(n(window,o),module.exports=r(o,window,window.document))):r(jQuery,window,document)}(function(z,e,t){"use strict";var y=z.fn.dataTable;function k(e,t,r){if(void 0===e||0===e.length)return{pass:!0,score:""};for(var o=void 0!==r.threshold?r.threshold:.5,n=e.split(/ /g),a=[],i=0;i<n.length;i++)0===n[i].length||" "===n[i]?(n.splice(i,1),i--):a.length<n.length&&a.push({pass:!1,score:0});for(var s=0;s<t.length;s++){t[s]=t[s].toLowerCase();for(var c=t[s].split(/ /g),u=0;u<c.length;u++)0!==c[u].length&&" "!==c[u]||(c.splice(u,1),i--);for(i=0;i<n.length;i++){for(var l={pass:void 0,score:0},u=0;u<c.length;u++){0===c[u].indexOf(n[i])&&(d=n[i].length/c[u].length,l={pass:!0,score:l.score<d?d:l.score});var d=function(e,t,r){var o=e.length,n=t.length,a=[];r=(r||(o<n?n:o))+1;for(var i,s,c,u,l,d,h=0;h<r;h++)a[h]=[h],a[h].length=r;for(h=0;h<r;h++)a[0][h]=h;if(Math.abs(o-n)>(r||100))return f(r||100);if(0===o)return f(n);if(0===n)return f(o);for(h=1;h<=o;++h)for(s=e[h-1],i=1;i<=n;++i){if(h===i&&4<a[h][i])return f(o);c=t[i-1],l=a[h-1][i]+1,(d=a[h][i-1]+1)<l&&(l=d),(d=a[h-1][i-1]+(u=s===c?0:1))<l&&(l=d),a[h][i]=1<h&&1<i&&s===t[i-2]&&e[h-2]===c&&(d=a[h-2][i-2]+u)<l?d:l}return f(a[o][n]);function f(e){var t=Math.max(o,n),t=0===t?0:e/t;return{steps:e,relative:t,similarity:1-t}}}(n[i],c[u]).similarity;d>l.score&&(l.score=d)}(a[i].score<l.score||l.pass)&&(a[i]={pass:!(!l.pass&&!a[i].pass)||l.score>o,score:l.score})}}for(s=0;s<a.length;s++)if(!a[s].pass)return{pass:!1,score:Math.round(a.reduce((e,t)=>e+t.score,0)/a.length*100)+"%"};return{pass:!0,score:Math.round(a.reduce((e,t)=>e+t.score,0)/a.length*100)+"%"}}return y.ext.search.push(function(e,t,r){var o,n=e.oInit.fuzzySearch;if(n&&e.aoData[r]){if(void 0!==e.aoData[r]._fuzzySearch)return o=e.aoData[r]._fuzzySearch.score,void 0!==n.rankColumn&&(e.aoData[r].anCells[n.rankColumn].innerHTML=o,e.aoData[r]._aSortData[n.rankColumn]=+o.substring(0,o.length-1)),e.aoData[r]._fuzzySearch.pass;void 0!==n.rankColumn&&(e.aoData[r].anCells[n.rankColumn].innerHTML="",e.aoData[r]._aSortData[n.rankColumn]="")}return!0}),z(t).on("init.dt",function(e,t){var r,o,n,a,i,s,c,u,l,d,h,f,p=new y.Api(t),g=p.init(),v=g.fuzzySearch;function b(e){(i.attr("blurred")?(i.css({filter:"blur(0px)"}).removeAttr("blurred"),u.removeAttr("highlighted").css(a),c):(i.css({filter:"blur(1px)"}).attr("blurred",!0),c.removeAttr("highlighted").css(a),u)).attr("highlighted",!0).css(n),h(e)}function m(e,t){e.attr("highlighted")||b(t)}function w(){s.remove()}v&&(r=!1,o=z("div.dt-search input",p.table().container()),n={"font-weight":"600","background-color":"rgba(255,255,255,0.1)"},a={"font-weight":"500","background-color":"transparent"},f={border:"none",background:"none","font-size":"100%",width:"50%",display:"inline-block",color:"white",cursor:"pointer",padding:"0.5em"},!0!==v&&!v.toggleSmart||(i=z('<button class="toggleSearch">Abc</button>').insertAfter(o).css({border:"none",background:"none",position:"relative",right:"33px",top:"0px",cursor:"pointer",color:"#3b5e99","margin-top":"1px"}),c=z('<button class="toggleSearch">Exact</button>').insertAfter(o).css(f).css(n).attr("highlighted","true"),u=z('<button class="toggleSearch">Fuzzy</button>').insertAfter(o).css(f),o.css({"padding-right":"30px"}),z(o.parent()).css("right","-33px").css("position","relative"),f=z("<div>Search Type<div>").css({"padding-bottom":"0.5em","font-size":"0.8em"}),s=z('<div class="fuzzyToolTip"></div>').css({position:"absolute",top:"2em",background:"white","border-radius":"4px","text-align":"center",padding:"0.5em","background-color":"#16232a","box-shadow":"4px 4px 4px rgba(0, 0, 0, 0.5)",color:"white",transition:"opacity 0.25s","z-index":"30001",width:o.outerWidth()-3}).append(f).append(c).append(u)),z(t.nTable).off("sea