Skip to content

Instantly share code, notes, and snippets.

@slashdotdash
Created March 10, 2013 10:06
Show Gist options
  • Save slashdotdash/f6be39fcd1ae2615a2b5 to your computer and use it in GitHub Desktop.
Save slashdotdash/f6be39fcd1ae2615a2b5 to your computer and use it in GitHub Desktop.
jekyll-lunr-js-search JavaScript without jQuery (and minified)
(function(d,f){"object"===typeof exports&&exports?module.exports=f:"function"===typeof define&&define.amd?define(f):d.Mustache=f})(this,function(){function d(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function f(a){this.tail=this.string=a;this.pos=0}function b(a,g){this.view=a;this.parent=g;this._cache={}}function c(){this.clearCache()}function e(a,g,c,d){for(var b="",f,k,l=0,m=a.length;l<m;++l)switch(f=a[l],k=f[1],f[0]){case "#":k=c.lookup(k);if("object"===typeof k)if(t(k))for(var n=
0,p=k.length;n<p;++n)b+=e(f[4],g,c.push(k[n]),d);else k&&(b+=e(f[4],g,c.push(k),d));else"function"===typeof k?(f=null==d?null:d.slice(f[3],f[5]),k=k.call(c.view,f,function(a){return g.render(a,c)}),null!=k&&(b+=k)):k&&(b+=e(f[4],g,c,d));break;case "^":k=c.lookup(k);if(!k||t(k)&&0===k.length)b+=e(f[4],g,c,d);break;case ">":k=g.getPartial(k);"function"===typeof k&&(b+=k(c));break;case "&":k=c.lookup(k);null!=k&&(b+=k);break;case "name":k=c.lookup(k);null!=k&&(b+=h.escape(k));break;case "text":b+=k}return b}
function k(a){return[RegExp(d(a[0])+"\\s*"),RegExp("\\s*"+d(a[1]))]}var h={name:"mustache.js",version:"0.7.2",tags:["{{","}}"]};h.Scanner=f;h.Context=b;h.Writer=c;var l=/\s*/,n=/\s+/,m=/\S/,p=/\s*=/,s=/\s*\}/,B=/#|\^|\/|>|\{|&|=|!/,u=RegExp.prototype.test,v=Object.prototype.toString,t=Array.isArray||function(a){return"[object Array]"===v.call(a)},a={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};h.escape=function(g){return String(g).replace(/[&<>"'\/]/g,function(g){return a[g]})};
f.prototype.eos=function(){return""===this.tail};f.prototype.scan=function(a){return(a=this.tail.match(a))&&0===a.index?(this.tail=this.tail.substring(a[0].length),this.pos+=a[0].length,a[0]):""};f.prototype.scanUntil=function(a){var g=this.tail.search(a);switch(g){case -1:a=this.tail;this.pos+=this.tail.length;this.tail="";break;case 0:a="";break;default:a=this.tail.substring(0,g),this.tail=this.tail.substring(g),this.pos+=g}return a};b.make=function(a){return a instanceof b?a:new b(a)};b.prototype.push=
function(a){return new b(a,this)};b.prototype.lookup=function(a){var g=this._cache[a];if(!g){if("."==a)g=this.view;else for(var c=this;c;){if(0<a.indexOf("."))for(var g=c.view,d=a.split("."),b=0;g&&b<d.length;)g=g[d[b++]];else g=c.view[a];if(null!=g)break;c=c.parent}this._cache[a]=g}"function"===typeof g&&(g=g.call(this.view));return g};c.prototype.clearCache=function(){this._cache={};this._partialCache={}};c.prototype.compile=function(a,g){var c=this._cache[a];c||(c=h.parse(a,g),c=this._cache[a]=
this.compileTokens(c,a));return c};c.prototype.compilePartial=function(a,g,c){g=this.compile(g,c);return this._partialCache[a]=g};c.prototype.getPartial=function(a){!(a in this._partialCache)&&this._loadPartial&&this.compilePartial(a,this._loadPartial(a));return this._partialCache[a]};c.prototype.compileTokens=function(a,g){var c=this;return function(d,k){if(k)if("function"===typeof k)c._loadPartial=k;else for(var f in k)c.compilePartial(f,k[f]);return e(a,c,b.make(d),g)}};c.prototype.render=function(a,
g,c){return this.compile(a)(g,c)};h.parse=function(a,g){a=a||"";g=g||h.tags;"string"===typeof g&&(g=g.split(n));if(2!==g.length)throw Error("Invalid tags: "+g.join(", "));for(var c=k(g),b=new f(a),e=[],r=[],w=[],t=!1,v=!1,y,q,x,A;!b.eos();){y=b.pos;if(x=b.scanUntil(c[0])){A=0;for(var C=x.length;A<C;++A)if(q=x.charAt(A),u.call(m,q)?v=!0:w.push(r.length),r.push(["text",q,y,y+1]),y+=1,"\n"==q){if(t&&!v)for(;w.length;)delete r[w.pop()];else w=[];v=t=!1}}if(!b.scan(c[0]))break;t=!0;q=b.scan(B)||"name";
b.scan(l);"="===q?(x=b.scanUntil(p),b.scan(p),b.scanUntil(c[1])):"{"===q?(x=b.scanUntil(RegExp("\\s*"+d("}"+g[1]))),b.scan(s),b.scanUntil(c[1]),q="&"):x=b.scanUntil(c[1]);if(!b.scan(c[1]))throw Error("Unclosed tag at "+b.pos);A=[q,x,y,b.pos];r.push(A);if("#"===q||"^"===q)e.push(A);else if("/"===q){if(0===e.length)throw Error('Unopened section "'+x+'" at '+y);q=e.pop();if(q[1]!==x)throw Error('Unclosed section "'+q[1]+'" at '+y);}else if("name"===q||"{"===q||"&"===q)v=!0;else if("="===q){g=x.split(n);
if(2!==g.length)throw Error("Invalid tags at "+y+": "+g.join(", "));c=k(g)}}if(q=e.pop())throw Error('Unclosed section "'+q[1]+'" at '+b.pos);for(var c=r,b=[],z,r=0,w=c.length;r<w;++r)if(e=c[r])"text"===e[0]&&z&&"text"===z[0]?(z[1]+=e[1],z[3]=e[3]):(z=e,b.push(e));z=b;b=c=[];e=[];w=0;for(t=z.length;w<t;++w)switch(r=z[w],r[0]){case "#":case "^":e.push(r);b.push(r);b=r[4]=[];break;case "/":e.pop()[5]=r[2];b=0<e.length?e[e.length-1][4]:c;break;default:b.push(r)}return c};var g=new c;h.clearCache=function(){return g.clearCache()};
h.compile=function(a,c){return g.compile(a,c)};h.compilePartial=function(a,c,b){return g.compilePartial(a,c,b)};h.compileTokens=function(a,c){return g.compileTokens(a,c)};h.render=function(a,c,b){return g.render(a,c,b)};h.to_html=function(a,g,c,b){a=h.render(a,g,c);if("function"===typeof b)b(a);else return a};return h}());var dateFormat=function(){var d=/d{1,4}|m{1,4}|yy(?:yy)?|([HhMsTt])\1?|[LloSZ]|"[^"]*"|'[^']*'/g,f=/\b(?:[PMCEA][SDP]T|(?:Pacific|Mountain|Central|Eastern|Atlantic) (?:Standard|Daylight|Prevailing) Time|(?:GMT|UTC)(?:[-+]\d{4})?)\b/g,b=/[^-+\dA-Z]/g,c=function(c,b){c=String(c);for(b=b||2;c.length<b;)c="0"+c;return c};return function(e,k,h){var l=dateFormat;1==arguments.length&&("[object String]"==Object.prototype.toString.call(e)&&!/\d/.test(e))&&(k=e,e=void 0);e=e?new Date(e):new Date;if(isNaN(e))throw SyntaxError("invalid date");
k=String(l.masks[k]||k||l.masks["default"]);"UTC:"==k.slice(0,4)&&(k=k.slice(4),h=!0);var n=h?"getUTC":"get",m=e[n+"Date"](),p=e[n+"Day"](),s=e[n+"Month"](),B=e[n+"FullYear"](),u=e[n+"Hours"](),v=e[n+"Minutes"](),t=e[n+"Seconds"](),n=e[n+"Milliseconds"](),a=h?0:e.getTimezoneOffset(),g={d:m,dd:c(m),ddd:l.i18n.dayNames[p],dddd:l.i18n.dayNames[p+7],m:s+1,mm:c(s+1),mmm:l.i18n.monthNames[s],mmmm:l.i18n.monthNames[s+12],yy:String(B).slice(2),yyyy:B,h:u%12||12,hh:c(u%12||12),H:u,HH:c(u),M:v,MM:c(v),s:t,
ss:c(t),l:c(n,3),L:c(99<n?Math.round(n/10):n),t:12>u?"a":"p",tt:12>u?"am":"pm",T:12>u?"A":"P",TT:12>u?"AM":"PM",Z:h?"UTC":(String(e).match(f)||[""]).pop().replace(b,""),o:(0<a?"-":"+")+c(100*Math.floor(Math.abs(a)/60)+Math.abs(a)%60,4),S:["th","st","nd","rd"][3<m%10?0:(10!=m%100-m%10)*m%10]};return k.replace(d,function(a){return a in g?g[a]:a.slice(1,a.length-1)})}}();
dateFormat.masks={"default":"ddd mmm dd yyyy HH:MM:ss",shortDate:"m/d/yy",mediumDate:"mmm d, yyyy",longDate:"mmmm d, yyyy",fullDate:"dddd, mmmm d, yyyy",shortTime:"h:MM TT",mediumTime:"h:MM:ss TT",longTime:"h:MM:ss TT Z",isoDate:"yyyy-mm-dd",isoTime:"HH:MM:ss",isoDateTime:"yyyy-mm-dd'T'HH:MM:ss",isoUtcDateTime:"UTC:yyyy-mm-dd'T'HH:MM:ss'Z'"};dateFormat.i18n={dayNames:"Sun Mon Tue Wed Thu Fri Sat Sunday Monday Tuesday Wednesday Thursday Friday Saturday".split(" "),monthNames:"Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec January February March April May June July August September October November December".split(" ")};
Date.prototype.format=function(d,f){return dateFormat(this,d,f)};var lunr=function(d){var f=new lunr.Index;return f.pipeline.add(lunr.stopWordFilter,lunr.stemmer),d&&d.call(f,f),f};lunr.version="0.2.0";lunr.tokenizer=function(d){return Array.isArray(d)?d:d.split(/\s+/).map(function(d){return d.replace(/^\W+/,"").replace(/\W+$/,"").toLowerCase()})};lunr.Pipeline=function(){this._stack=[]};lunr.Pipeline.prototype.add=function(){var d=Array.prototype.slice.call(arguments);Array.prototype.push.apply(this._stack,d)};
lunr.Pipeline.prototype.after=function(d,f){var b=this._stack.indexOf(d)+1;this._stack.splice(b,0,f)};lunr.Pipeline.prototype.before=function(d,f){var b=this._stack.indexOf(d);this._stack.splice(b,0,f)};lunr.Pipeline.prototype.remove=function(d){d=this._stack.indexOf(d);this._stack.splice(d,1)};lunr.Pipeline.prototype.run=function(d){for(var f=[],b=d.length,c=this._stack.length,e=0;e<b;e++){for(var k=d[e],h=0;h<c&&!(k=this._stack[h](k,e,d),void 0===k);h++);void 0!==k&&f.push(k)}return f};
lunr.Vector=function(d){this.elements=d;for(var f=0;f<d.length;f++)f in this.elements||(this.elements[f]=0)};lunr.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var d=0,f=this.elements,b=f.length,c,e=0;e<b;e++)c=f[e],d+=c*c;return this._magnitude=Math.sqrt(d)};lunr.Vector.prototype.dot=function(d){var f=this.elements;d=d.elements;for(var b=f.length,c=0,e=0;e<b;e++)c+=f[e]*d[e];return c};
lunr.Vector.prototype.similarity=function(d){return this.dot(d)/(this.magnitude()*d.magnitude())};lunr.Vector.prototype.toArray=function(){return this.elements};lunr.SortedSet=function(){this.length=0;this.elements=[]};lunr.SortedSet.prototype.add=function(){Array.prototype.slice.call(arguments).forEach(function(d){~this.elements.indexOf(d)||this.elements.splice(this.locationFor(d),0,d)},this);this.length=this.elements.length};lunr.SortedSet.prototype.toArray=function(){return this.elements.slice()};
lunr.SortedSet.prototype.map=function(d,f){return this.elements.map(d,f)};lunr.SortedSet.prototype.forEach=function(d,f){return this.elements.forEach(d,f)};lunr.SortedSet.prototype.indexOf=function(d,f){return this.elements.indexOf(d)};lunr.SortedSet.prototype.locationFor=function(d,f,b){f=f||0;b=b||this.elements.length;var c=b-f,e=f+Math.floor(c/2),k=this.elements[e];if(1>=c){if(k>d)return e;if(k<d)return e+1}if(k<d)return this.locationFor(d,e,b);if(k>d)return this.locationFor(d,f,e)};
lunr.SortedSet.prototype.intersect=function(d){var f=new lunr.SortedSet,b=0,c=0,e=this.length,k=d.length,h=this.elements;for(d=d.elements;!(b>e-1||c>k-1);)h[b]===d[c]?(f.add(h[b]),b++,c++):h[b]<d[c]?b++:h[b]>d[c]&&c++;return f};lunr.SortedSet.prototype.clone=function(){var d=new lunr.SortedSet;return d.elements=this.toArray(),d.length=d.elements.length,d};
lunr.SortedSet.prototype.union=function(d){var f,b,c;return this.length>=d.length?(f=this,b=d):(f=d,b=this),c=f.clone(),c.add.apply(c,b.toArray()),c};lunr.Index=function(){this._fields=[];this._ref="id";this.pipeline=new lunr.Pipeline;this.documentStore=new lunr.Store;this.tokenStore=new lunr.TokenStore;this.corpusTokens=new lunr.SortedSet};lunr.Index.prototype.field=function(d,f){f=f||{};return this._fields.push({name:d,boost:f.boost||1}),this};
lunr.Index.prototype.ref=function(d){return this._ref=d,this};
lunr.Index.prototype.add=function(d){var f={},b=new lunr.SortedSet,c=d[this._ref];this._fields.forEach(function(c){var e=this.pipeline.run(lunr.tokenizer(d[c.name]));f[c.name]=e;lunr.SortedSet.prototype.add.apply(b,e)},this);this.documentStore.set(c,b);lunr.SortedSet.prototype.add.apply(this.corpusTokens,b.toArray());for(var e=0;e<b.length;e++){var k=b.elements[e],h=this._fields.reduce(function(c,b){var d=f[b.name].filter(function(c){return c===k}).length;return c+d/f[b.name].length*b.boost},0);this.tokenStore.add(k,
{ref:c,tf:h})}};lunr.Index.prototype.remove=function(d){var f=d[this._ref];d=this.documentStore.get(f);this.documentStore.remove(f);d.forEach(function(b){this.tokenStore.remove(b,f)},this)};lunr.Index.prototype.update=function(d){this.remove(d);this.add(d)};lunr.Index.prototype.idf=function(d){d=Object.keys(this.tokenStore.get(d)).length;return 0===d?1:1+Math.log(this.tokenStore.length/d)};
lunr.Index.prototype.search=function(d){d=this.pipeline.run(lunr.tokenizer(d));var f=Array(this.corpusTokens.length),b=[],c=this._fields.reduce(function(c,b){return c+b.boost},0);if(!d.some(lunr.TokenStore.prototype.has,this.tokenStore))return[];d.forEach(function(d,e,l){var n=1/l.length*this._fields.length*c,m=this;d=this.tokenStore.expand(d).reduce(function(c,b){var d=m.corpusTokens.indexOf(b),e=m.idf(b),k=new lunr.SortedSet;return-1<d&&(f[d]=n*e),Object.keys(m.tokenStore.get(b)).forEach(function(c){k.add(c)}),
c.union(k)},new lunr.SortedSet);b.push(d)},this);d=b.reduce(function(c,b){return c.intersect(b)});var e=new lunr.Vector(f);return d.map(function(c){return{ref:c,score:e.similarity(this.documentVector(c))}},this).sort(function(c,b){return b.score-c.score})};lunr.Index.prototype.documentVector=function(d){for(var f=this.documentStore.get(d),b=f.length,c=Array(this.corpusTokens.length),e=0;e<b;e++){var k=f.elements[e],h=this.tokenStore.get(k)[d].tf,l=this.idf(k);c[this.corpusTokens.indexOf(k)]=h*l}return new lunr.Vector(c)};
lunr.Store=function(){this.store={};this.length=0};lunr.Store.prototype.set=function(d,f){this.store[d]=f;this.length=Object.keys(this.store).length};lunr.Store.prototype.get=function(d){return this.store[d]};lunr.Store.prototype.has=function(d){return d in this.store};lunr.Store.prototype.remove=function(d){this.has(d)&&(delete this.store[d],this.length--)};
lunr.stemmer=function(){var d={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},f={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""};return function(b){var c,e,k,h,l,n;if(3>b.length)return b;k=b.substr(0,1);"y"==k&&(b=k.toUpperCase()+b.substr(1));h=/^(.+?)(ss|i)es$/;e=/^(.+?)([^s])s$/;
h.test(b)?b=b.replace(h,"$1$2"):e.test(b)&&(b=b.replace(e,"$1$2"));h=/^(.+?)eed$/;e=/^(.+?)(ed|ing)$/;if(h.test(b)){var m=h.exec(b);h=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/;h.test(m[1])&&(h=/.$/,b=b.replace(h,""))}else e.test(b)&&(m=e.exec(b),c=m[1],e=/^([^aeiou][^aeiouy]*)?[aeiouy]/,e.test(c)&&(b=c,e=/(at|bl|iz)$/,l=/([^aeiouylsz])\1$/,n=/^[^aeiou][^aeiouy]*[aeiouy][^aeiouwxy]$/,e.test(b)?b+="e":l.test(b)?(h=/.$/,b=b.replace(h,"")):n.test(b)&&(b+="e")));h=/^(.+?)y$/;h.test(b)&&
(m=h.exec(b),c=m[1],h=/^([^aeiou][^aeiouy]*)?[aeiouy]/,h.test(c)&&(b=c+"i"));h=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/;h.test(b)&&(m=h.exec(b),c=m[1],e=m[2],h=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,h.test(c)&&(b=c+d[e]));h=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/;h.test(b)&&(m=h.exec(b),c=m[1],e=m[2],h=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,h.test(c)&&
(b=c+f[e]));h=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/;e=/^(.+?)(s|t)(ion)$/;h.test(b)?(m=h.exec(b),c=m[1],h=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,h.test(c)&&(b=c)):e.test(b)&&(m=e.exec(b),c=m[1]+m[2],e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,e.test(c)&&(b=c));h=/^(.+?)e$/;if(h.test(b)&&(m=h.exec(b),c=m[1],h=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,
e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*([aeiouy][aeiou]*)?$/,l=/^[^aeiou][^aeiouy]*[aeiouy][^aeiouwxy]$/,h.test(c)||e.test(c)&&!l.test(c)))b=c;return h=/ll$/,e=/^([^aeiou][^aeiouy]*)?[aeiouy][aeiou]*[^aeiou][^aeiouy]*[aeiouy][aeiou]*[^aeiou][^aeiouy]*/,h.test(b)&&e.test(b)&&(h=/.$/,b=b.replace(h,"")),"y"==k&&(b=k.toLowerCase()+b.substr(1)),b}}();lunr.stopWordFilter=function(d){if(-1==="a able about across after all almost also am among an and any are as at be because been but by can cannot could dear did do does either else ever every for from get got had has have he her hers him his how however i if in into is it its just least let like likely may me might most must my neither no nor not of off often on only or other our own rather said say says she should since so some than that the their them then there these they this tis to too twas us wants was we were what when where which while who whom why will with would yet you your".split(" ").indexOf(d))return d};
lunr.TokenStore=function(){this.root={docs:{}};this.length=0};lunr.TokenStore.prototype.add=function(d,f,b){b=b||this.root;var c=d[0];d=d.slice(1);c in b||(b[c]={docs:{}});if(0===d.length)b[c].docs[f.ref]=f,this.length+=1;else return this.add(d,f,b[c])};lunr.TokenStore.prototype.has=function(d,f){f=f||this.root;var b=d[0],c=d.slice(1);return b in f?0===c.length?!0:this.has(c,f[b]):!1};
lunr.TokenStore.prototype.getNode=function(d,f){f=f||this.root;var b=d[0],c=d.slice(1);return b in f?0===c.length?f[b]:this.getNode(c,f[b]):{}};lunr.TokenStore.prototype.get=function(d,f){return this.getNode(d).docs||{}};lunr.TokenStore.prototype.remove=function(d,f,b){b=b||this.root;var c=d[0];d=d.slice(1);if(c in b)if(0===d.length)delete b[c].docs[f];else return this.remove(d,f,b[c])};
lunr.TokenStore.prototype.expand=function(d,f){var b=this.getNode(d),c=b.docs||{};f=f||[];return Object.keys(c).length&&f.push(d),Object.keys(b).forEach(function(c){"docs"!==c&&f.concat(this.expand(d+c,f))},this),f};(function(d,f){"object"===typeof exports?module.exports=f(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"===typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],f):d.URI=f(d.punycode,d.IPv6,d.SecondLevelDomains)})(this,function(d,f,b){function c(a,g){if(!(this instanceof c))return new c(a,g);void 0===a&&(a="undefined"!==typeof location?location.href+"":"");this.href(a);return void 0!==g?this.absoluteTo(g):this}function e(a){return a.replace(/([.*+?^=!:${}()|[\]\/\\])/g,
"\\$1")}function k(a){return"[object Array]"===String(Object.prototype.toString.call(a))}function h(a){return encodeURIComponent(a).replace(/[!'()*]/g,escape).replace(/\*/g,"%2A")}var l=c.prototype,n=Object.prototype.hasOwnProperty;c._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:c.duplicateQueryParameters}};c.duplicateQueryParameters=!1;c.protocol_expression=/^[a-z][a-z0-9-+-]*$/i;c.idn_expression=
/[^a-z0-9\.-]/i;c.punycode_expression=/(xn--)/i;c.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;c.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/;
c.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?\u00ab\u00bb\u201c\u201d\u2018\u2019]))/ig;c.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"};c.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/;c.encode=h;c.decode=decodeURIComponent;c.iso8859=function(){c.encode=escape;c.decode=unescape};c.unicode=function(){c.encode=
h;c.decode=decodeURIComponent};c.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/ig,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/ig,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+",
"%2C":",","%3B":";","%3D":"="}}}};c.encodeQuery=function(a){return c.encode(a+"").replace(/%20/g,"+")};c.decodeQuery=function(a){return c.decode((a+"").replace(/\+/g,"%20"))};c.recodePath=function(a){a=(a+"").split("/");for(var g=0,b=a.length;g<b;g++)a[g]=c.encodePathSegment(c.decode(a[g]));return a.join("/")};c.decodePath=function(a){a=(a+"").split("/");for(var g=0,b=a.length;g<b;g++)a[g]=c.decodePathSegment(a[g]);return a.join("/")};var m={encode:"encode",decode:"decode"},p,s=function(a,g){return function(b){return c[g](b+
"").replace(c.characters[a][g].expression,function(b){return c.characters[a][g].map[b]})}};for(p in m)c[p+"PathSegment"]=s("pathname",m[p]);c.encodeReserved=s("reserved","encode");c.parse=function(a,g){var b;g||(g={});b=a.indexOf("#");-1<b&&(g.fragment=a.substring(b+1)||null,a=a.substring(0,b));b=a.indexOf("?");-1<b&&(g.query=a.substring(b+1)||null,a=a.substring(0,b));"//"===a.substring(0,2)?(g.protocol="",a=a.substring(2),a=c.parseAuthority(a,g)):(b=a.indexOf(":"),-1<b&&(g.protocol=a.substring(0,
b),g.protocol&&!g.protocol.match(c.protocol_expression)?g.protocol=void 0:"file"===g.protocol?a=a.substring(b+3):"//"===a.substring(b+1,b+3)?(a=a.substring(b+3),a=c.parseAuthority(a,g)):(a=a.substring(b+1),g.urn=!0)));g.path=a;return g};c.parseHost=function(a,g){var c=a.indexOf("/"),b;-1===c&&(c=a.length);"["===a.charAt(0)?(b=a.indexOf("]"),g.hostname=a.substring(1,b)||null,g.port=a.substring(b+2,c)||null):a.indexOf(":")!==a.lastIndexOf(":")?(g.hostname=a.substring(0,c)||null,g.port=null):(b=a.substring(0,
c).split(":"),g.hostname=b[0]||null,g.port=b[1]||null);g.hostname&&"/"!==a.substring(c).charAt(0)&&(c++,a="/"+a);return a.substring(c)||"/"};c.parseAuthority=function(a,g){a=c.parseUserinfo(a,g);return c.parseHost(a,g)};c.parseUserinfo=function(a,g){var b=a.indexOf("@"),d=a.indexOf("/");-1<b&&(-1===d||b<d)?(d=a.substring(0,b).split(":"),g.username=d[0]?c.decode(d[0]):null,d.shift(),g.password=d[0]?c.decode(d.join(":")):null,a=a.substring(b+1)):(g.username=null,g.password=null);return a};c.parseQuery=
function(a){if(!a)return{};a=a.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,"");if(!a)return{};var g={};a=a.split("&");for(var b=a.length,d,e,f=0;f<b;f++)d=a[f].split("="),e=c.decodeQuery(d.shift()),d=d.length?c.decodeQuery(d.join("=")):null,g[e]?("string"===typeof g[e]&&(g[e]=[g[e]]),g[e].push(d)):g[e]=d;return g};c.build=function(a){var g="";a.protocol&&(g+=a.protocol+":");if(!a.urn&&(g||a.hostname))g+="//";g+=c.buildAuthority(a)||"";"string"===typeof a.path&&("/"!==a.path.charAt(0)&&"string"===typeof a.hostname&&
(g+="/"),g+=a.path);"string"===typeof a.query&&a.query&&(g+="?"+a.query);"string"===typeof a.fragment&&a.fragment&&(g+="#"+a.fragment);return g};c.buildHost=function(a){var g="";if(a.hostname)c.ip6_expression.test(a.hostname)?g=a.port?g+("["+a.hostname+"]:"+a.port):g+a.hostname:(g+=a.hostname,a.port&&(g+=":"+a.port));else return"";return g};c.buildAuthority=function(a){return c.buildUserinfo(a)+c.buildHost(a)};c.buildUserinfo=function(a){var g="";a.username&&(g+=c.encode(a.username),a.password&&(g+=
":"+c.encode(a.password)),g+="@");return g};c.buildQuery=function(a,g){var b="",d,e,f,h;for(e in a)if(n.call(a,e)&&e)if(k(a[e])){d={};f=0;for(h=a[e].length;f<h;f++)void 0!==a[e][f]&&void 0===d[a[e][f]+""]&&(b+="&"+c.buildQueryParameter(e,a[e][f]),!0!==g&&(d[a[e][f]+""]=!0))}else void 0!==a[e]&&(b+="&"+c.buildQueryParameter(e,a[e]));return b.substring(1)};c.buildQueryParameter=function(a,g){return c.encodeQuery(a)+(null!==g?"="+c.encodeQuery(g):"")};c.addQuery=function(a,g,b){if("object"===typeof g)for(var d in g)n.call(g,
d)&&c.addQuery(a,d,g[d]);else if("string"===typeof g)void 0===a[g]?a[g]=b:("string"===typeof a[g]&&(a[g]=[a[g]]),k(b)||(b=[b]),a[g]=a[g].concat(b));else throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");};c.removeQuery=function(a,g,b){var d;if(k(g)){b=0;for(d=g.length;b<d;b++)a[g[b]]=void 0}else if("object"===typeof g)for(d in g)n.call(g,d)&&c.removeQuery(a,d,g[d]);else if("string"===typeof g)if(void 0!==b)if(a[g]===b)a[g]=void 0;else{if(k(a[g])){d=a[g];var e={},
f,h;if(k(b)){f=0;for(h=b.length;f<h;f++)e[b[f]]=!0}else e[b]=!0;f=0;for(h=d.length;f<h;f++)void 0!==e[d[f]]&&(d.splice(f,1),h--,f--);a[g]=d}}else a[g]=void 0;else throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");};c.commonPath=function(a,c){var b=Math.min(a.length,c.length),d;for(d=0;d<b;d++)if(a.charAt(d)!==c.charAt(d)){d--;break}if(1>d)return a.charAt(0)===c.charAt(0)&&"/"===a.charAt(0)?"/":"";"/"!==a.charAt(d)&&(d=a.substring(0,d).lastIndexOf("/"));return a.substring(0,
d+1)};c.withinString=function(a,g){return a.replace(c.find_uri_expression,g)};c.ensureValidHostname=function(a){if(a.match(c.invalid_hostname_characters)){if(!d)throw new TypeError("Hostname '"+a+"' contains characters other than [A-Z0-9.-] and Punycode.js is not available");if(d.toASCII(a).match(c.invalid_hostname_characters))throw new TypeError("Hostname '"+a+"' contains characters other than [A-Z0-9.-]");}};l.build=function(a){if(!0===a)this._deferred_build=!0;else if(void 0===a||this._deferred_build)this._string=
c.build(this._parts),this._deferred_build=!1;return this};l.clone=function(){return new c(this)};l.valueOf=l.toString=function(){return this.build(!1)._string};m={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"};s=function(a){return function(c,b){if(void 0===c)return this._parts[a]||"";this._parts[a]=c;this.build(!b);return this}};for(p in m)l[p]=s(m[p]);m={query:"?",fragment:"#"};s=function(a,c){return function(b,d){if(void 0===b)return this._parts[a]||
"";null!==b&&(b+="",b.charAt(0)===c&&(b=b.substring(1)));this._parts[a]=b;this.build(!d);return this}};for(p in m)l[p]=s(p,m[p]);m={search:["?","query"],hash:["#","fragment"]};s=function(a,c){return function(b,d){var e=this[a](b,d);return"string"===typeof e&&e.length?c+e:e}};for(p in m)l[p]=s(m[p][1],m[p][0]);l.pathname=function(a,g){if(void 0===a||!0===a){var b=this._parts.path||(this._parts.urn?"":"/");return a?c.decodePath(b):b}this._parts.path=a?c.recodePath(a):"/";this.build(!g);return this};
l.path=l.pathname;l.href=function(a,g){var b;if(void 0===a)return this.toString();this._string="";this._parts=c._parts();var d=a instanceof c,e="object"===typeof a&&(a.hostname||a.path);!d&&e&&void 0!==a.pathname&&(a=a.toString());if("string"===typeof a)this._parts=c.parse(a,this._parts);else if(d||e)for(b in d=d?a._parts:a,d)n.call(this._parts,b)&&(this._parts[b]=d[b]);else throw new TypeError("invalid input");this.build(!g);return this};l.is=function(a){var g=!1,d=!1,e=!1,f=!1,k=!1,h=!1,l=!1,m=
!this._parts.urn;this._parts.hostname&&(m=!1,d=c.ip4_expression.test(this._parts.hostname),e=c.ip6_expression.test(this._parts.hostname),g=d||e,k=(f=!g)&&b&&b.has(this._parts.hostname),h=f&&c.idn_expression.test(this._parts.hostname),l=f&&c.punycode_expression.test(this._parts.hostname));switch(a.toLowerCase()){case "relative":return m;case "absolute":return!m;case "domain":case "name":return f;case "sld":return k;case "ip":return g;case "ip4":case "ipv4":case "inet4":return d;case "ip6":case "ipv6":case "inet6":return e;
case "idn":return h;case "url":return!this._parts.urn;case "urn":return!!this._parts.urn;case "punycode":return l}return null};var B=l.protocol,u=l.port,v=l.hostname;l.protocol=function(a,c){if(void 0!==a&&a&&(a=a.replace(/:(\/\/)?$/,""),a.match(/[^a-zA-z0-9\.+-]/)))throw new TypeError("Protocol '"+a+"' contains characters other than [A-Z0-9.+-]");return B.call(this,a,c)};l.scheme=l.protocol;l.port=function(a,c){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a&&(0===a&&(a=null),a&&(a+="",
":"===a.charAt(0)&&(a=a.substring(1)),a.match(/[^0-9]/))))throw new TypeError("Port '"+a+"' contains characters other than [0-9]");return u.call(this,a,c)};l.hostname=function(a,g){if(this._parts.urn)return void 0===a?"":this;if(void 0!==a){var b={};c.parseHost(a,b);a=b.hostname}return v.call(this,a,g)};l.host=function(a,g){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?c.buildHost(this._parts):"";c.parseHost(a,this._parts);this.build(!g);return this};l.authority=
function(a,g){if(this._parts.urn)return void 0===a?"":this;if(void 0===a)return this._parts.hostname?c.buildAuthority(this._parts):"";c.parseAuthority(a,this._parts);this.build(!g);return this};l.userinfo=function(a,g){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.username)return"";var b=c.buildUserinfo(this._parts);return b.substring(0,b.length-1)}"@"!==a[a.length-1]&&(a+="@");c.parseUserinfo(a,this._parts);this.build(!g);return this};l.resource=function(a,g){var b;
if(void 0===a)return this.path()+this.search()+this.hash();b=c.parse(a);this._parts.path=b.path;this._parts.query=b.query;this._parts.fragment=b.fragment;this.build(!g);return this};l.subdomain=function(a,g){if(this._parts.urn)return void 0===a?"":this;if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var b=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,b)||""}b=this._parts.hostname.length-this.domain().length;b=this._parts.hostname.substring(0,
b);b=RegExp("^"+e(b));a&&"."!==a.charAt(a.length-1)&&(a+=".");a&&c.ensureValidHostname(a);this._parts.hostname=this._parts.hostname.replace(b,a);this.build(!g);return this};l.domain=function(a,b){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(b=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.match(/\./g);if(d&&2>d.length)return this._parts.hostname;d=this._parts.hostname.length-this.tld(b).length-1;d=this._parts.hostname.lastIndexOf(".",
d-1)+1;return this._parts.hostname.substring(d)||""}if(!a)throw new TypeError("cannot set domain empty");c.ensureValidHostname(a);!this._parts.hostname||this.is("IP")?this._parts.hostname=a:(d=RegExp(e(this.domain())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a));this.build(!b);return this};l.tld=function(a,c){if(this._parts.urn)return void 0===a?"":this;"boolean"===typeof a&&(c=a,a=void 0);if(void 0===a){if(!this._parts.hostname||this.is("IP"))return"";var d=this._parts.hostname.lastIndexOf("."),
d=this._parts.hostname.substring(d+1);return!0!==c&&b&&b.list[d.toLowerCase()]?b.get(this._parts.hostname)||d:d}if(a)if(a.match(/[^a-zA-Z0-9-]/))if(b&&b.is(a))d=RegExp(e(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(d,a);else throw new TypeError("TLD '"+a+"' contains characters other than [A-Z0-9]");else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");d=RegExp(e(this.tld())+"$");this._parts.hostname=this._parts.hostname.replace(d,
a)}else throw new TypeError("cannot set TLD empty");this.build(!c);return this};l.directory=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var d=this._parts.path.length-this.filename().length-1,d=this._parts.path.substring(0,d)||(this._parts.hostname?"/":"");return a?c.decodePath(d):d}d=this._parts.path.length-this.filename().length;d=this._parts.path.substring(0,d);d=RegExp("^"+
e(d));this.is("relative")||(a||(a="/"),"/"!==a.charAt(0)&&(a="/"+a));a&&"/"!==a.charAt(a.length-1)&&(a+="/");a=c.recodePath(a);this._parts.path=this._parts.path.replace(d,a);this.build(!b);return this};l.filename=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this._parts.path.lastIndexOf("/"),d=this._parts.path.substring(d+1);return a?c.decodePathSegment(d):d}d=!1;"/"===a.charAt(0)&&(a=a.substring(1));a.match(/\.?\//)&&
(d=!0);var f=RegExp(e(this.filename())+"$");a=c.recodePath(a);this._parts.path=this._parts.path.replace(f,a);d?this.normalizePath(b):this.build(!b);return this};l.suffix=function(a,b){if(this._parts.urn)return void 0===a?"":this;if(void 0===a||!0===a){if(!this._parts.path||"/"===this._parts.path)return"";var d=this.filename(),f=d.lastIndexOf(".");if(-1===f)return"";d=d.substring(f+1);d=/^[a-z0-9%]+$/i.test(d)?d:"";return a?c.decodePathSegment(d):d}"."===a.charAt(0)&&(a=a.substring(1));if(d=this.suffix())f=
a?RegExp(e(d)+"$"):RegExp(e("."+d)+"$");else{if(!a)return this;this._parts.path+="."+c.recodePath(a)}f&&(a=c.recodePath(a),this._parts.path=this._parts.path.replace(f,a));this.build(!b);return this};l.segment=function(a,c,b){var d=this._parts.urn?":":"/",e=this.path(),f="/"===e.substring(0,1),e=e.split(d);"number"!==typeof a&&(b=c,c=a,a=void 0);if(void 0!==a&&"number"!==typeof a)throw Error("Bad segment '"+a+"', must be 0-based integer");f&&e.shift();0>a&&(a=Math.max(e.length+a,0));if(void 0===c)return void 0===
a?e:e[a];if(null===a||void 0===e[a])if(k(c))e=c;else{if(c||"string"===typeof c&&c.length)""===e[e.length-1]?e[e.length-1]=c:e.push(c)}else c||"string"===typeof c&&c.length?e[a]=c:e.splice(a,1);f&&e.unshift("");return this.path(e.join(d),b)};var t=l.query;l.query=function(a,b){if(!0===a)return c.parseQuery(this._parts.query);if("function"===typeof a){var d=c.parseQuery(this._parts.query),e=a.call(this,d);this._parts.query=c.buildQuery(e||d,this._parts.duplicateQueryParameters);this.build(!b);return this}return void 0!==
a&&"string"!==typeof a?(this._parts.query=c.buildQuery(a,this._parts.duplicateQueryParameters),this.build(!b),this):t.call(this,a,b)};l.setQuery=function(a,b,d){var e=c.parseQuery(this._parts.query);if("object"===typeof a)for(var f in a)n.call(a,f)&&(e[f]=a[f]);else if("string"===typeof a)e[a]=void 0!==b?b:null;else throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");this._parts.query=c.buildQuery(e,this._parts.duplicateQueryParameters);"string"!==typeof a&&(d=b);
this.build(!d);return this};l.addQuery=function(a,b,d){var e=c.parseQuery(this._parts.query);c.addQuery(e,a,void 0===b?null:b);this._parts.query=c.buildQuery(e,this._parts.duplicateQueryParameters);"string"!==typeof a&&(d=b);this.build(!d);return this};l.removeQuery=function(a,b,d){var e=c.parseQuery(this._parts.query);c.removeQuery(e,a,b);this._parts.query=c.buildQuery(e,this._parts.duplicateQueryParameters);"string"!==typeof a&&(d=b);this.build(!d);return this};l.setSearch=l.setQuery;l.addSearch=
l.addQuery;l.removeSearch=l.removeQuery;l.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()};l.normalizeProtocol=function(a){"string"===typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!a));return this};l.normalizeHostname=function(a){this._parts.hostname&&
(this.is("IDN")&&d?this._parts.hostname=d.toASCII(this._parts.hostname):this.is("IPv6")&&f&&(this._parts.hostname=f.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!a));return this};l.normalizePort=function(a){"string"===typeof this._parts.protocol&&this._parts.port===c.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!a));return this};l.normalizePath=function(a){if(this._parts.urn||!this._parts.path||"/"===this._parts.path)return this;
var b,d,e=this._parts.path,f,k;"/"!==e.charAt(0)&&("."===e.charAt(0)&&(d=e.substring(0,e.indexOf("/"))),b=!0,e="/"+e);for(e=e.replace(/(\/(\.\/)+)|\/{2,}/g,"/");;){f=e.indexOf("/../");if(-1===f)break;else if(0===f){e=e.substring(3);break}k=e.substring(0,f).lastIndexOf("/");-1===k&&(k=f);e=e.substring(0,k)+e.substring(f+3)}b&&this.is("relative")&&(e=d?d+e:e.substring(1));e=c.recodePath(e);this._parts.path=e;this.build(!a);return this};l.normalizePathname=l.normalizePath;l.normalizeQuery=function(a){"string"===
typeof this._parts.query&&(this._parts.query.length?this.query(c.parseQuery(this._parts.query)):this._parts.query=null,this.build(!a));return this};l.normalizeFragment=function(a){this._parts.fragment||(this._parts.fragment=null,this.build(!a));return this};l.normalizeSearch=l.normalizeQuery;l.normalizeHash=l.normalizeFragment;l.iso8859=function(){var a=c.encode,b=c.decode;c.encode=escape;c.decode=decodeURIComponent;this.normalize();c.encode=a;c.decode=b;return this};l.unicode=function(){var a=c.encode,
b=c.decode;c.encode=h;c.decode=unescape;this.normalize();c.encode=a;c.decode=b;return this};l.readable=function(){var a=this.clone();a.username("").password("").normalize();var b="";a._parts.protocol&&(b+=a._parts.protocol+"://");a._parts.hostname&&(a.is("punycode")&&d?(b+=d.toUnicode(a._parts.hostname),a._parts.port&&(b+=":"+a._parts.port)):b+=a.host());a._parts.hostname&&a._parts.path&&"/"!==a._parts.path.charAt(0)&&(b+="/");b+=a.path(!0);if(a._parts.query){for(var e="",f=0,k=a._parts.query.split("&"),
h=k.length;f<h;f++){var l=(k[f]||"").split("="),e=e+("&"+c.decodeQuery(l[0]).replace(/&/g,"%26"));void 0!==l[1]&&(e+="="+c.decodeQuery(l[1]).replace(/&/g,"%26"))}b+="?"+e.substring(1)}return b+a.hash()};l.absoluteTo=function(a){var b=this.clone(),d=["protocol","username","password","hostname","port"],e,f;if(this._parts.urn)throw Error("URNs do not have any generally defined hierachical components");if(this._parts.hostname)return b;a instanceof c||(a=new c(a));e=0;for(f;f=d[e];e++)b._parts[f]=a._parts[f];
d=["query","path"];e=0;for(f;f=d[e];e++)!b._parts[f]&&a._parts[f]&&(b._parts[f]=a._parts[f]);"/"!==b.path().charAt(0)&&(a=a.directory(),b._parts.path=(a?a+"/":"")+b._parts.path,b.normalizePath());b.build();return b};l.relativeTo=function(a){var b=this.clone(),d=["protocol","username","password","hostname","port"],f;if(this._parts.urn)throw Error("URNs do not have any generally defined hierachical components");a instanceof c||(a=new c(a));if("/"!==this.path().charAt(0)||"/"!==a.path().charAt(0))throw Error("Cannot calculate common path from non-relative URLs");
f=c.commonPath(b.path(),a.path());if(!f||"/"===f)return b;for(var k=0,h;h=d[k];k++)b._parts[h]=null;a=a.directory();d=this.directory();if(a===d)return b._parts.path="./"+b.filename(),b.build();a.substring(f.length);d=d.substring(f.length);if(a+"/"===f)return d&&(d+="/"),b._parts.path="./"+d+b.filename(),b.build();d="../";f=RegExp("^"+e(f));for(a=a.replace(f,"/").match(/\//g).length-1;a--;)d+="../";b._parts.path=b._parts.path.replace(f,d);return b.build()};l.equals=function(a){var b=this.clone(),d=
new c(a),e={},f={};a={};var h;b.normalize();d.normalize();if(b.toString()===d.toString())return!0;e=b.query();f=d.query();b.query("");d.query("");if(b.toString()!==d.toString()||e.length!==f.length)return!1;e=c.parseQuery(e);f=c.parseQuery(f);for(h in e)if(n.call(e,h)){if(k(e[h])){if(!k(f[h])||e[h].length!==f[h].length)return!1;e[h].sort();f[h].sort();b=0;for(d=e[h].length;b<d;b++)if(e[h][b]!==f[h][b])return!1}else if(e[h]!==f[h])return!1;a[h]=!0}for(h in f)if(n.call(f,h)&&!a[h])return!1;return!0};
l.duplicateQueryParameters=function(a){this._parts.duplicateQueryParameters=!!a;return this};return c});(function(d){var f=function(b){var c,d=Array.prototype.slice;return function(){var f=d.call(arguments),n=this;clearTimeout(c);c=setTimeout(function(){b.apply(n,f)},100)}},b=function(b){b=b.match(/(\d+)/g);return new Date(b[0],b[1]-1,b[2])},c=function(){function c(b,e){this.$elem=b;this.$results=d(e.results);this.$entries=d(e.entries,this.$results);this.indexDataUrl=e.indexUrl;this.index=this.createIndex();this.template=this.compileTemplate(d(e.template));this.initialize()}c.prototype.initialize=function(){var b=
this;this.loadIndexData(function(c){b.populateIndex(c);b.populateSearchFromQuery();b.bindKeypress()})};c.prototype.createIndex=function(){return lunr(function(){this.field("title",{boost:10});this.field("body");this.ref("id")})};c.prototype.compileTemplate=function(b){return Mustache.compile(b.text())};c.prototype.loadIndexData=function(b){d.getJSON(this.indexDataUrl,b)};c.prototype.populateIndex=function(b){var c=this.index;this.entries=d.map(b.entries,this.createEntry);d.each(this.entries,function(b,
d){c.add(d)})};c.prototype.createEntry=function(c,e){var f=d.extend({id:e+1},c);c.date&&d.extend(f,{date:b(c.date),pubdate:function(){return dateFormat(b(c.date),"yyyy-mm-dd")},displaydate:function(){return dateFormat(b(c.date),"mmm dd, yyyy")}});return f};c.prototype.bindKeypress=function(){var b=this;this.$elem.bind("keyup",f(function(){b.search(d(this).val())}))};c.prototype.search=function(b){var c=this.entries;2>=b.length?(this.$results.hide(),this.$entries.empty()):(b=d.map(this.index.search(b),
function(b){return d.grep(c,function(c){return c.id===parseInt(b.ref,10)})[0]}),this.displayResults(b))};c.prototype.displayResults=function(b){var c=this.$entries,d=this.$results;c.empty();0===b.length?c.append("<p>Nothing found.</p>"):c.append(this.template({entries:b}));d.show()};c.prototype.populateSearchFromQuery=function(){var b=(new URI(window.location.search.toString())).search(!0);b.hasOwnProperty("q")&&(this.$elem.val(b.q),this.search(b.q.toString()))};return c}();d.fn.lunrSearch=function(b){b=
d.extend({},d.fn.lunrSearch.defaults,b);new c(this,b);return this};d.fn.lunrSearch.defaults={indexUrl:"/search.json",results:"#search-results",entries:".entries",template:"#search-results-template"}})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment