mirror of
https://github.com/Mottie/tablesorter.git
synced 2024-11-15 23:54:22 +00:00
2 lines
2.3 KiB
JavaScript
2 lines
2.3 KiB
JavaScript
/*! Widget: mark.js - updated 9/23/2016 (v2.27.7) */
|
||
!function(e){"use strict";var t=e.tablesorter;t.mark={init:function(r){if("function"==typeof e.fn.mark){var n,a=r.widgetOptions.mark_tsUpdate;r.$table.on("filterEnd.tsmark pagerComplete.tsmark"+(a?" "+a:""),function(e,n){t.mark.update(r,e.type===a?n:"")}),n="(?:<|=|>|\\||\"|\\'|\\s+(?:&&|-|"+(t.language.and||"and")+"|"+(t.language.or||"or")+"|"+(t.language.to||"to")+")\\s+)",t.mark.regex.filter=new RegExp(n,"gim")}else console.warn('Widget-mark not initialized: missing "jquery.mark.js"')},regex:{mark:/^mark_(.+)$/,pure:/^\/((?:\\\/|[^\/])+)\/([mig]{0,3})?$/},checkRegex:function(e){if(e instanceof RegExp){var t="".match(e);return null===t||t.length<5}return!1},cleanMatches:function(e){for(var t=[],r=e&&e.length||0;r--;)""!==e[r]&&(t[t.length]=e[r]);return t},ignoreColumns:function(t){for(var r=t.widgetOptions,n=t.columns,a=[];n--;)(r.mark_tsIgnore[n]||e(t.$headerIndexed[n]).hasClass("mark-ignore"))&&(a[a.length]=":nth-child("+(n+1)+")");return a.length?":not("+a.join(",")+")":""},update:function(r,n){var a={},i=r.widgetOptions,o=t.mark.regex,l=r.$table.find("tbody tr").unmark().not("."+(r.widgetOptions.filter_filteredRow||"filtered"));n=n||e.tablesorter.getFilters(r.$table),e.each(r.widgetOptions,function(e,t){var r=e.match(o.mark);r&&void 0!==r[1]&&(a[r[1]]=t)}),e.each(n,function(n,g){if(g&&!e(r.$headerIndexed[n]).hasClass("mark-ignore")&&!i.mark_tsIgnore[n]){var m=null,s=g,c=!1,d=n===r.columns?t.mark.ignoreColumns(r):":nth-child("+(n+1)+")";if(o.pure.test(g)){".*"===(s=o.pure.exec(g))[1]&&(s[1]="");try{m=new RegExp(s[1],"gim"),s=new RegExp(s[1],s[2])}catch(e){s=null}return void(t.mark.checkRegex(m)&&l.children(d).markRegExp(s,a))}0===g.indexOf("~")?(c=!0,s=g.replace(/~/g,"").split("")):(g.indexOf("?")>-1&&(c=!0,g=g.replace(/\?/g,"\\S{1}")),g.indexOf("*")>-1&&(c=!0,g=g.replace(/\*/g,"\\S*")),s=g.split(o.filter)),c&&s&&s.length?(s=new RegExp(t.mark.cleanMatches(s).join(".*"),"gm"),t.mark.checkRegex(s)&&l.children(d).markRegExp(s,a)):l.children(d).mark(t.mark.cleanMatches(s),a)}})}},t.addWidget({id:"mark",options:{mark_tsUpdate:"markUpdate",mark_tsIgnore:{}},init:function(e,r,n,a){t.mark.init(n,a)},remove:function(e,t){var r=t.widgetOptions.mark_tsUpdate;t.$table.off("filterEnd.tsmark pagerComplete.tsmark"+(r?" "+r:""))}})}(jQuery); |