"use strict";function _classCallCheck(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function");}var _extends=Object.assign||function(n){for(var i,r,t=1;t<arguments.length;t++){i=arguments[t];for(r in i)Object.prototype.hasOwnProperty.call(i,r)&&(n[r]=i[r])}return n},_createClass=function(){function n(n,t){for(var i,r=0;r<t.length;r++)i=t[r],i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(n,i.key,i)}return function(t,i,r){return i&&n(t.prototype,i),r&&n(t,r),t}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n};!function(n,t,i){"function"==typeof define&&define.amd?define(["jquery"],function(r){return n(t,i,r)}):"object"===("undefined"==typeof module?"undefined":_typeof(module))&&module.exports?module.exports=n(t,i,require("jquery")):n(t,i,jQuery)}(function(n,t,i){var r=function(){function i(t){_classCallCheck(this,i);this.ctx=t;this.ie=!1;var r=n.navigator.userAgent;(r.indexOf("MSIE")>-1||r.indexOf("Trident")>-1)&&(this.ie=!0)}return _createClass(i,[{key:"log",value:function(n){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"debug",t=this.opt.log;this.opt.debug&&"object"===("undefined"==typeof t?"undefined":_typeof(t))&&"function"==typeof t[i]&&t[i]("mark.js: "+n)}},{key:"escapeStr",value:function(n){return n.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createRegExp",value:function(n){return n=this.escapeStr(n),Object.keys(this.opt.synonyms).length&&(n=this.createSynonymsRegExp(n)),this.opt.ignoreJoiners&&(n=this.setupIgnoreJoinersRegExp(n)),this.opt.diacritics&&(n=this.createDiacriticsRegExp(n)),n=this.createMergedBlanksRegExp(n),this.opt.ignoreJoiners&&(n=this.createIgnoreJoinersRegExp(n)),n=this.createAccuracyRegExp(n)}},{key:"createSynonymsRegExp",value:function(n){var i=this.opt.synonyms,f=this.opt.caseSensitive?"":"i",t;for(t in i)if(i.hasOwnProperty(t)){var e=i[t],r=this.escapeStr(t),u=this.escapeStr(e);n=n.replace(new RegExp("("+r+"|"+u+")","gm"+f),"("+r+"|"+u+")")}return n}},{key:"setupIgnoreJoinersRegExp",value:function(n){return n.replace(/[^(|)\\]/g,function(n,t,i){var r=i.charAt(t+1);return/[(|)\\]/.test(r)||""===r?n:n+"\0"})}},{key:"createIgnoreJoinersRegExp",value:function(n){return n.split("\0").join("[\\u00ad|\\u200b|\\u200c|\\u200d]?")}},{key:"createDiacriticsRegExp",value:function(n){var i=this.opt.caseSensitive?"":"i",r=this.opt.caseSensitive?["aàáâãäåāąă","AÀÁÂÃÄÅĀĄĂ","cçćč","CÇĆČ","dđď","DĐĎ","eèéêëěēę","EÈÉÊËĚĒĘ","iìíîïī","IÌÍÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóôõöøō","OÒÓÔÕÖØŌ","rř","RŘ","sšśș","SŠŚȘ","tťț","TŤȚ","uùúûüůū","UÙÚÛÜŮŪ","yÿý","YŸÝ","zžżź","ZŽŻŹ"]:["aÀÁÂÃÄÅàáâãäåĀāąĄăĂ","cÇçćĆčČ","dđĐďĎ","eÈÉÊËèéêëěĚĒēęĘ","iÌÍÎÏìíîïĪī","lłŁ","nÑñňŇńŃ","oÒÓÔÕÖØòóôõöøŌō","rřŘ","sŠšśŚșȘ","tťŤțȚ","uÙÚÛÜùúûüůŮŪū","yŸÿýÝ","zŽžżŻźŹ"],t=[];return n.split("").forEach(function(u){r.every(function(r){if(r.indexOf(u)!==-1){if(t.indexOf(r)>-1)return!1;n=n.replace(new RegExp("["+r+"]","gm"+i),"["+r+"]");t.push(r)}return!0})}),n}},{key:"createMergedBlanksRegExp",value:function(n){return n.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(n){var r=this,t=this.opt.accuracy,u="string"==typeof t?t:t.value,f="string"==typeof t?[]:t.limiters,i="";switch(f.forEach(function(n){i+="|"+r.escapeStr(n)}),u){case"partially":default:return"()("+n+")";case"complementary":return"()([^\\s"+i+"]*"+n+"[^\\s"+i+"]*)";case"exactly":return"(^|\\s"+i+")("+n+")(?=$|\\s"+i+")"}}},{key:"getSeparatedKeywords",value:function(n){var i=this,t=[];return n.forEach(function(n){i.opt.separateWordSearch?n.split(" ").forEach(function(n){n.trim()&&t.indexOf(n)===-1&&t.push(n)}):n.trim()&&t.indexOf(n)===-1&&t.push(n)}),{keywords:t.sort(function(n,t){return t.length-n.length}),length:t.length}}},{key:"getTextNodes",value:function(n){var r=this,t="",i=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,function(n){i.push({start:t.length,end:(t+=n.textContent).length,node:n})},function(n){return r.matchesExclude(n.parentNode,!0)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},function(){n({value:t,nodes:i})})}},{key:"matchesExclude",value:function(n,t){var i=this.opt.exclude.concat(["script","style","title","head","html"]);return t&&(i=i.concat(["*[data-markjs='true']"])),u.matches(n,i)}},{key:"wrapRangeInTextNode",value:function(n,i,r){var e=this.opt.element?this.opt.element:"mark",u=n.splitText(i),o=u.splitText(r-i),f=t.createElement(e);return f.setAttribute("data-markjs","true"),this.opt.className&&f.setAttribute("class",this.opt.className),f.textContent=u.textContent,u.parentNode.replaceChild(f,u),o}},{key:"wrapRangeInMappedTextNode",value:function(n,t,i,r,u){var f=this;n.nodes.every(function(e,o){var h=n.nodes[o+1],s;return("undefined"==typeof h||h.start>t)&&(s=function(){if(!r(e.node))return{v:!1};var h=t-e.start,s=(i>e.end?e.end:i)-e.start,c=n.value.substr(0,e.start),l=n.value.substr(s+e.start);return e.node=f.wrapRangeInTextNode(e.node,h,s),n.value=c+l,n.nodes.forEach(function(t,i){i>=o&&(n.nodes[i].start>0&&i!==o&&(n.nodes[i].start-=s),n.nodes[i].end-=s)}),i-=s,u(e.node.previousSibling,e.start),i>e.end?void(t=e.end):{v:!1}}(),"object"===("undefined"==typeof s?"undefined":_typeof(s)))?s.v:!0})}},{key:"wrapMatches",value:function(n,t,i,r,u){var e=this,f=0===t?0:t+1;this.getTextNodes(function(t){t.nodes.forEach(function(t){var u,o,s;for(t=t.node,u=void 0;null!==(u=n.exec(t.textContent))&&""!==u[f];)if(i(u[f],t)){if(o=u.index,0!==f)for(s=1;s<f;s++)o+=u[s].length;t=e.wrapRangeInTextNode(t,o,o+u[f].length);r(t.previousSibling);n.lastIndex=0}});u()})}},{key:"wrapMatchesAcrossElements",value:function(n,t,i,r,u){var e=this,f=0===t?0:t+1;this.getTextNodes(function(t){for(var s,h,c,o=void 0;null!==(o=n.exec(t.value))&&""!==o[f];){if(s=o.index,0!==f)for(h=1;h<f;h++)s+=o[h].length;c=s+o[f].length;e.wrapRangeInMappedTextNode(t,s,c,function(n){return i(o[f],n)},function(t,i){n.lastIndex=i;r(t)})}u()})}},{key:"unwrapMatches",value:function(n){for(var i=n.parentNode,r=t.createDocumentFragment();n.firstChild;)r.appendChild(n.removeChild(n.firstChild));i.replaceChild(r,n);this.ie?this.normalizeTextNode(i):i.normalize()}},{key:"normalizeTextNode",value:function(n){if(n){if(3===n.nodeType)for(;n.nextSibling&&3===n.nextSibling.nodeType;)n.nodeValue+=n.nextSibling.nodeValue,n.parentNode.removeChild(n.nextSibling);else this.normalizeTextNode(n.firstChild);this.normalizeTextNode(n.nextSibling)}}},{key:"markRegExp",value:function(n,t){var i=this;this.opt=t;this.log('Searching with expression "'+n+'"');var r=0,u="wrapMatches",f=function(n){r++;i.opt.each(n)};this.opt.acrossElements&&(u="wrapMatchesAcrossElements");this[u](n,this.opt.ignoreGroups,function(n,t){return i.opt.filter(t,n,r)},f,function(){0===r&&i.opt.noMatch(n);i.opt.done(r)})}},{key:"mark",value:function(n,t){var i=this;this.opt=t;var r=0,f="wrapMatches",e=this.getSeparatedKeywords("string"==typeof n?[n]:n),u=e.keywords,o=e.length,s=this.opt.caseSensitive?"":"i",h=function n(t){var h=new RegExp(i.createRegExp(t),"gm"+s),e=0;i.log('Searching with expression "'+h+'"');i[f](h,1,function(n,u){return i.opt.filter(u,t,r,e)},function(n){e++;r++;i.opt.each(n)},function(){0===e&&i.opt.noMatch(t);u[o-1]===t?i.opt.done(r):n(u[u.indexOf(t)+1])})};this.opt.acrossElements&&(f="wrapMatchesAcrossElements");0===o?this.opt.done(r):h(u[0])}},{key:"unmark",value:function(n){var i=this,t;this.opt=n;t=this.opt.element?this.opt.element:"*";t+="[data-markjs]";this.opt.className&&(t+="."+this.opt.className);this.log('Removal selector "'+t+'"');this.iterator.forEachNode(NodeFilter.SHOW_ELEMENT,function(n){i.unwrapMatches(n)},function(n){var r=u.matches(n,t),f=i.matchesExclude(n,!1);return!r||f?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},this.opt.done)}},{key:"opt",set:function(t){this._opt=_extends({},{element:"",className:"",exclude:[],iframes:!1,separateWordSearch:!0,diacritics:!0,synonyms:{},accuracy:"partially",acrossElements:!1,caseSensitive:!1,ignoreJoiners:!1,ignoreGroups:0,each:function(){},noMatch:function(){},filter:function(){return!0},done:function(){},debug:!1,log:n.console},t)},get:function(){return this._opt}},{key:"iterator",get:function(){return this._iterator||(this._iterator=new u(this.ctx,this.opt.iframes,this.opt.exclude)),this._iterator}}]),i}(),u=function(){function n(t){var i=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];_classCallCheck(this,n);this.ctx=t;this.iframes=i;this.exclude=r}return _createClass(n,[{key:"getContexts",value:function(){var i=void 0,n=[];return i="undefined"!=typeof this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(t.querySelectorAll(this.ctx)):[this.ctx]:[],i.forEach(function(t){var i=n.filter(function(n){return n.contains(t)}).length>0;n.indexOf(t)!==-1||i||n.push(t)}),n}},{key:"getIframeContents",value:function(n,t){var u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},i=void 0,r;try{if(r=n.contentWindow,i=r.document,!r||!i)throw new Error("iframe inaccessible");}catch(n){u()}i&&t(i)}},{key:"onIframeReady",value:function(n,t,i){var r=this;try{!function(){var u=n.contentWindow,f="about:blank",e=function(){var t=n.getAttribute("src").trim(),i=u.location.href;return i===f&&t!==f&&t},o=function(){var u=function u(){try{e()||(n.removeEventListener("load",u),r.getIframeContents(n,t,i))}catch(n){i()}};n.addEventListener("load",u)};u.document.readyState==="complete"?e()?o():r.getIframeContents(n,t,i):o()}()}catch(n){i()}}},{key:"waitForIframes",value:function(n,t){var r=this,i=0;this.forEachIframe(n,function(){return!0},function(n){i++;r.waitForIframes(n.querySelector("html"),function(){--i||t()})},function(n){n||t()})}},{key:"forEachIframe",value:function(t,i,r){var e=this,h=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},f=t.querySelectorAll("iframe"),o=f.length,s=0,u;f=Array.prototype.slice.call(f);u=function(){--o<=0&&h(s)};o||u();f.forEach(function(t){n.matches(t,e.exclude)?u():e.onIframeReady(t,function(n){i(t)&&(s++,r(n));u()},u)})}},{key:"createIterator",value:function(n,i,r){return t.createNodeIterator(n,i,r,!1)}},{key:"createInstanceOnIframe",value:function(t){return new n(t.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(n,t,i){var f=n.compareDocumentPosition(i),e=Node.DOCUMENT_POSITION_PRECEDING,r,u;return f&e&&(null===t||(r=t.compareDocumentPosition(i),u=Node.DOCUMENT_POSITION_FOLLOWING,r&u))?!0:!1}},{key:"getIteratorNode",value:function(n){var t=n.previousNode(),i=void 0;return i=null===t?n.nextNode():n.nextNode()&&n.nextNode(),{prevNode:t,node:i}}},{key:"checkIframeFilter",value:function(n,t,i,r){var u=!1,f=!1;return r.forEach(function(n,t){n.val===i&&(u=t,f=n.handled)}),this.compareNodeIframe(n,t,i)?(u!==!1||f?u===!1||f||(r[u].handled=!0):r.push({val:i,handled:!0}),!0):(u===!1&&r.push({val:i,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(n,t,i,r){var u=this;n.forEach(function(n){n.handled||u.getIframeContents(n.val,function(n){u.createInstanceOnIframe(n).forEachNode(t,i,r)})})}},{key:"iterateThroughNodes",value:function(n,t,i,r,u){for(var f=this,c=this.createIterator(t,n,r),o=[],s=[],e=void 0,h=void 0,l=function(){var n=f.getIteratorNode(c);return h=n.prevNode,e=n.node};l();)this.iframes&&this.forEachIframe(t,function(n){return f.checkIframeFilter(e,h,n,o)},function(t){f.createInstanceOnIframe(t).forEachNode(n,i,r)}),s.push(e);s.forEach(function(n){i(n)});this.iframes&&this.handleOpenIframes(o,n,i,r);u()}},{key:"forEachNode",value:function(n,t,i){var r=this,u=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},f=this.getContexts(),e=f.length;e||u();f.forEach(function(f){var o=function(){r.iterateThroughNodes(n,f,t,i,function(){--e<=0&&u()})};r.iframes?r.waitForIframes(f,o):o()})}}],[{key:"matches",value:function(n,t){var u="string"==typeof t?[t]:t,r=n.matches||n.matchesSelector||n.msMatchesSelector||n.mozMatchesSelector||n.oMatchesSelector||n.webkitMatchesSelector,i;return r?(i=!1,u.every(function(t){return!r.call(n,t)||(i=!0,!1)}),i):!1}}]),n}();return i.fn.mark=function(n,t){return new r(this.get()).mark(n,t),this},i.fn.markRegExp=function(n,t){return new r(this.get()).markRegExp(n,t),this},i.fn.unmark=function(n){return new r(this.get()).unmark(n),this},i},window,document)