jazzy 0.13.4 → 0.13.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +27 -0
- data/Gemfile.lock +13 -13
- data/README.md +7 -0
- data/Rakefile +8 -3
- data/lib/jazzy/config.rb +7 -0
- data/lib/jazzy/doc_builder.rb +6 -0
- data/lib/jazzy/gem_version.rb +1 -1
- data/lib/jazzy/source_declaration.rb +15 -2
- data/lib/jazzy/source_declaration/type.rb +30 -0
- data/lib/jazzy/sourcekitten.rb +2 -1
- data/lib/jazzy/themes/apple/assets/css/jazzy.css.scss +75 -2
- data/lib/jazzy/themes/apple/assets/img/spinner.gif +0 -0
- data/lib/jazzy/themes/apple/assets/js/jazzy.search.js +70 -0
- data/lib/jazzy/themes/apple/assets/js/lunr.min.js +6 -0
- data/lib/jazzy/themes/apple/assets/js/typeahead.jquery.js +1694 -0
- data/lib/jazzy/themes/apple/templates/doc.mustache +35 -0
- data/lib/jazzy/themes/apple/templates/header.mustache +7 -0
- data/lib/jazzy/themes/apple/templates/task.mustache +1 -1
- data/lib/jazzy/themes/fullwidth/templates/doc.mustache +30 -0
- data/lib/jazzy/themes/fullwidth/templates/task.mustache +1 -1
- data/lib/jazzy/themes/jony/assets/css/jazzy.css.scss +8 -0
- data/lib/jazzy/themes/jony/templates/doc.mustache +30 -0
- data/lib/jazzy/themes/jony/templates/task.mustache +1 -1
- metadata +6 -2
Binary file
|
@@ -0,0 +1,70 @@
|
|
1
|
+
$(function(){
|
2
|
+
var $typeahead = $('[data-typeahead]');
|
3
|
+
var $form = $typeahead.parents('form');
|
4
|
+
var searchURL = $form.attr('action');
|
5
|
+
|
6
|
+
function displayTemplate(result) {
|
7
|
+
return result.name;
|
8
|
+
}
|
9
|
+
|
10
|
+
function suggestionTemplate(result) {
|
11
|
+
var t = '<div class="list-group-item clearfix">';
|
12
|
+
t += '<span class="doc-name">' + result.name + '</span>';
|
13
|
+
if (result.parent_name) {
|
14
|
+
t += '<span class="doc-parent-name label">' + result.parent_name + '</span>';
|
15
|
+
}
|
16
|
+
t += '</div>';
|
17
|
+
return t;
|
18
|
+
}
|
19
|
+
|
20
|
+
$typeahead.one('focus', function() {
|
21
|
+
$form.addClass('loading');
|
22
|
+
|
23
|
+
$.getJSON(searchURL).then(function(searchData) {
|
24
|
+
const searchIndex = lunr(function() {
|
25
|
+
this.ref('url');
|
26
|
+
this.field('name');
|
27
|
+
this.field('abstract');
|
28
|
+
for (const [url, doc] of Object.entries(searchData)) {
|
29
|
+
this.add({url: url, name: doc.name, abstract: doc.abstract});
|
30
|
+
}
|
31
|
+
});
|
32
|
+
|
33
|
+
$typeahead.typeahead(
|
34
|
+
{
|
35
|
+
highlight: true,
|
36
|
+
minLength: 3,
|
37
|
+
autoselect: true
|
38
|
+
},
|
39
|
+
{
|
40
|
+
limit: 10,
|
41
|
+
display: displayTemplate,
|
42
|
+
templates: { suggestion: suggestionTemplate },
|
43
|
+
source: function(query, sync) {
|
44
|
+
const lcSearch = query.toLowerCase();
|
45
|
+
const results = searchIndex.query(function(q) {
|
46
|
+
q.term(lcSearch, { boost: 100 });
|
47
|
+
q.term(lcSearch, {
|
48
|
+
boost: 10,
|
49
|
+
wildcard: lunr.Query.wildcard.TRAILING
|
50
|
+
});
|
51
|
+
}).map(function(result) {
|
52
|
+
var doc = searchData[result.ref];
|
53
|
+
doc.url = result.ref;
|
54
|
+
return doc;
|
55
|
+
});
|
56
|
+
sync(results);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
);
|
60
|
+
$form.removeClass('loading');
|
61
|
+
$typeahead.trigger('focus');
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
var baseURL = searchURL.slice(0, -"search.json".length);
|
66
|
+
|
67
|
+
$typeahead.on('typeahead:select', function(e, result) {
|
68
|
+
window.location = baseURL + result.url;
|
69
|
+
});
|
70
|
+
});
|
@@ -0,0 +1,6 @@
|
|
1
|
+
/**
|
2
|
+
* lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 2.3.7
|
3
|
+
* Copyright (C) 2019 Oliver Nightingale
|
4
|
+
* @license MIT
|
5
|
+
*/
|
6
|
+
!function(){var e=function(t){var r=new e.Builder;return r.pipeline.add(e.trimmer,e.stopWordFilter,e.stemmer),r.searchPipeline.add(e.stemmer),t.call(r,r),r.build()};e.version="2.3.7",e.utils={},e.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),e.utils.asString=function(e){return void 0===e||null===e?"":e.toString()},e.utils.clone=function(e){if(null===e||void 0===e)return e;for(var t=Object.create(null),r=Object.keys(e),i=0;i<r.length;i++){var n=r[i],s=e[n];if(Array.isArray(s))t[n]=s.slice();else{if("string"!=typeof s&&"number"!=typeof s&&"boolean"!=typeof s)throw new TypeError("clone is not deep and does not support nested objects");t[n]=s}}return t},e.FieldRef=function(e,t,r){this.docRef=e,this.fieldName=t,this._stringValue=r},e.FieldRef.joiner="/",e.FieldRef.fromString=function(t){var r=t.indexOf(e.FieldRef.joiner);if(r===-1)throw"malformed field ref string";var i=t.slice(0,r),n=t.slice(r+1);return new e.FieldRef(n,i,t)},e.FieldRef.prototype.toString=function(){return void 0==this._stringValue&&(this._stringValue=this.fieldName+e.FieldRef.joiner+this.docRef),this._stringValue},e.Set=function(e){if(this.elements=Object.create(null),e){this.length=e.length;for(var t=0;t<this.length;t++)this.elements[e[t]]=!0}else this.length=0},e.Set.complete={intersect:function(e){return e},union:function(e){return e},contains:function(){return!0}},e.Set.empty={intersect:function(){return this},union:function(e){return e},contains:function(){return!1}},e.Set.prototype.contains=function(e){return!!this.elements[e]},e.Set.prototype.intersect=function(t){var r,i,n,s=[];if(t===e.Set.complete)return this;if(t===e.Set.empty)return t;this.length<t.length?(r=this,i=t):(r=t,i=this),n=Object.keys(r.elements);for(var o=0;o<n.length;o++){var a=n[o];a in i.elements&&s.push(a)}return new e.Set(s)},e.Set.prototype.union=function(t){return t===e.Set.complete?e.Set.complete:t===e.Set.empty?this:new e.Set(Object.keys(this.elements).concat(Object.keys(t.elements)))},e.idf=function(e,t){var r=0;for(var i in e)"_index"!=i&&(r+=Object.keys(e[i]).length);var n=(t-r+.5)/(r+.5);return Math.log(1+Math.abs(n))},e.Token=function(e,t){this.str=e||"",this.metadata=t||{}},e.Token.prototype.toString=function(){return this.str},e.Token.prototype.update=function(e){return this.str=e(this.str,this.metadata),this},e.Token.prototype.clone=function(t){return t=t||function(e){return e},new e.Token(t(this.str,this.metadata),this.metadata)},e.tokenizer=function(t,r){if(null==t||void 0==t)return[];if(Array.isArray(t))return t.map(function(t){return new e.Token(e.utils.asString(t).toLowerCase(),e.utils.clone(r))});for(var i=t.toString().toLowerCase(),n=i.length,s=[],o=0,a=0;o<=n;o++){var u=i.charAt(o),l=o-a;if(u.match(e.tokenizer.separator)||o==n){if(l>0){var c=e.utils.clone(r)||{};c.position=[a,l],c.index=s.length,s.push(new e.Token(i.slice(a,o),c))}a=o+1}}return s},e.tokenizer.separator=/[\s\-]+/,e.Pipeline=function(){this._stack=[]},e.Pipeline.registeredFunctions=Object.create(null),e.Pipeline.registerFunction=function(t,r){r in this.registeredFunctions&&e.utils.warn("Overwriting existing registered function: "+r),t.label=r,e.Pipeline.registeredFunctions[t.label]=t},e.Pipeline.warnIfFunctionNotRegistered=function(t){var r=t.label&&t.label in this.registeredFunctions;r||e.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",t)},e.Pipeline.load=function(t){var r=new e.Pipeline;return t.forEach(function(t){var i=e.Pipeline.registeredFunctions[t];if(!i)throw new Error("Cannot load unregistered function: "+t);r.add(i)}),r},e.Pipeline.prototype.add=function(){var t=Array.prototype.slice.call(arguments);t.forEach(function(t){e.Pipeline.warnIfFunctionNotRegistered(t),this._stack.push(t)},this)},e.Pipeline.prototype.after=function(t,r){e.Pipeline.warnIfFunctionNotRegistered(r);var i=this._stack.indexOf(t);if(i==-1)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,r)},e.Pipeline.prototype.before=function(t,r){e.Pipeline.warnIfFunctionNotRegistered(r);var i=this._stack.indexOf(t);if(i==-1)throw new Error("Cannot find existingFn");this._stack.splice(i,0,r)},e.Pipeline.prototype.remove=function(e){var t=this._stack.indexOf(e);t!=-1&&this._stack.splice(t,1)},e.Pipeline.prototype.run=function(e){for(var t=this._stack.length,r=0;r<t;r++){for(var i=this._stack[r],n=[],s=0;s<e.length;s++){var o=i(e[s],s,e);if(null!==o&&void 0!==o&&""!==o)if(Array.isArray(o))for(var a=0;a<o.length;a++)n.push(o[a]);else n.push(o)}e=n}return e},e.Pipeline.prototype.runString=function(t,r){var i=new e.Token(t,r);return this.run([i]).map(function(e){return e.toString()})},e.Pipeline.prototype.reset=function(){this._stack=[]},e.Pipeline.prototype.toJSON=function(){return this._stack.map(function(t){return e.Pipeline.warnIfFunctionNotRegistered(t),t.label})},e.Vector=function(e){this._magnitude=0,this.elements=e||[]},e.Vector.prototype.positionForIndex=function(e){if(0==this.elements.length)return 0;for(var t=0,r=this.elements.length/2,i=r-t,n=Math.floor(i/2),s=this.elements[2*n];i>1&&(s<e&&(t=n),s>e&&(r=n),s!=e);)i=r-t,n=t+Math.floor(i/2),s=this.elements[2*n];return s==e?2*n:s>e?2*n:s<e?2*(n+1):void 0},e.Vector.prototype.insert=function(e,t){this.upsert(e,t,function(){throw"duplicate index"})},e.Vector.prototype.upsert=function(e,t,r){this._magnitude=0;var i=this.positionForIndex(e);this.elements[i]==e?this.elements[i+1]=r(this.elements[i+1],t):this.elements.splice(i,0,e,t)},e.Vector.prototype.magnitude=function(){if(this._magnitude)return this._magnitude;for(var e=0,t=this.elements.length,r=1;r<t;r+=2){var i=this.elements[r];e+=i*i}return this._magnitude=Math.sqrt(e)},e.Vector.prototype.dot=function(e){for(var t=0,r=this.elements,i=e.elements,n=r.length,s=i.length,o=0,a=0,u=0,l=0;u<n&&l<s;)o=r[u],a=i[l],o<a?u+=2:o>a?l+=2:o==a&&(t+=r[u+1]*i[l+1],u+=2,l+=2);return t},e.Vector.prototype.similarity=function(e){return this.dot(e)/this.magnitude()||0},e.Vector.prototype.toArray=function(){for(var e=new Array(this.elements.length/2),t=1,r=0;t<this.elements.length;t+=2,r++)e[r]=this.elements[t];return e},e.Vector.prototype.toJSON=function(){return this.elements},e.stemmer=function(){var e={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"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},r="[^aeiou]",i="[aeiouy]",n=r+"[^aeiouy]*",s=i+"[aeiou]*",o="^("+n+")?"+s+n,a="^("+n+")?"+s+n+"("+s+")?$",u="^("+n+")?"+s+n+s+n,l="^("+n+")?"+i,c=new RegExp(o),h=new RegExp(u),d=new RegExp(a),f=new RegExp(l),p=/^(.+?)(ss|i)es$/,y=/^(.+?)([^s])s$/,m=/^(.+?)eed$/,v=/^(.+?)(ed|ing)$/,g=/.$/,x=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),Q=new RegExp("^"+n+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,S=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,L=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,b=/^(.+?)(s|t)(ion)$/,P=/^(.+?)e$/,T=/ll$/,O=new RegExp("^"+n+i+"[^aeiouwxy]$"),I=function(r){var i,n,s,o,a,u,l;if(r.length<3)return r;if(s=r.substr(0,1),"y"==s&&(r=s.toUpperCase()+r.substr(1)),o=p,a=y,o.test(r)?r=r.replace(o,"$1$2"):a.test(r)&&(r=r.replace(a,"$1$2")),o=m,a=v,o.test(r)){var I=o.exec(r);o=c,o.test(I[1])&&(o=g,r=r.replace(o,""))}else if(a.test(r)){var I=a.exec(r);i=I[1],a=f,a.test(i)&&(r=i,a=x,u=w,l=Q,a.test(r)?r+="e":u.test(r)?(o=g,r=r.replace(o,"")):l.test(r)&&(r+="e"))}if(o=k,o.test(r)){var I=o.exec(r);i=I[1],r=i+"i"}if(o=S,o.test(r)){var I=o.exec(r);i=I[1],n=I[2],o=c,o.test(i)&&(r=i+e[n])}if(o=E,o.test(r)){var I=o.exec(r);i=I[1],n=I[2],o=c,o.test(i)&&(r=i+t[n])}if(o=L,a=b,o.test(r)){var I=o.exec(r);i=I[1],o=h,o.test(i)&&(r=i)}else if(a.test(r)){var I=a.exec(r);i=I[1]+I[2],a=h,a.test(i)&&(r=i)}if(o=P,o.test(r)){var I=o.exec(r);i=I[1],o=h,a=d,u=O,(o.test(i)||a.test(i)&&!u.test(i))&&(r=i)}return o=T,a=h,o.test(r)&&a.test(r)&&(o=g,r=r.replace(o,"")),"y"==s&&(r=s.toLowerCase()+r.substr(1)),r};return function(e){return e.update(I)}}(),e.Pipeline.registerFunction(e.stemmer,"stemmer"),e.generateStopWordFilter=function(e){var t=e.reduce(function(e,t){return e[t]=t,e},{});return function(e){if(e&&t[e.toString()]!==e.toString())return e}},e.stopWordFilter=e.generateStopWordFilter(["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"]),e.Pipeline.registerFunction(e.stopWordFilter,"stopWordFilter"),e.trimmer=function(e){return e.update(function(e){return e.replace(/^\W+/,"").replace(/\W+$/,"")})},e.Pipeline.registerFunction(e.trimmer,"trimmer"),e.TokenSet=function(){this["final"]=!1,this.edges={},this.id=e.TokenSet._nextId,e.TokenSet._nextId+=1},e.TokenSet._nextId=1,e.TokenSet.fromArray=function(t){for(var r=new e.TokenSet.Builder,i=0,n=t.length;i<n;i++)r.insert(t[i]);return r.finish(),r.root},e.TokenSet.fromClause=function(t){return"editDistance"in t?e.TokenSet.fromFuzzyString(t.term,t.editDistance):e.TokenSet.fromString(t.term)},e.TokenSet.fromFuzzyString=function(t,r){for(var i=new e.TokenSet,n=[{node:i,editsRemaining:r,str:t}];n.length;){var s=n.pop();if(s.str.length>0){var o,a=s.str.charAt(0);a in s.node.edges?o=s.node.edges[a]:(o=new e.TokenSet,s.node.edges[a]=o),1==s.str.length&&(o["final"]=!0),n.push({node:o,editsRemaining:s.editsRemaining,str:s.str.slice(1)})}if(0!=s.editsRemaining){if("*"in s.node.edges)var u=s.node.edges["*"];else{var u=new e.TokenSet;s.node.edges["*"]=u}if(0==s.str.length&&(u["final"]=!0),n.push({node:u,editsRemaining:s.editsRemaining-1,str:s.str}),s.str.length>1&&n.push({node:s.node,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)}),1==s.str.length&&(s.node["final"]=!0),s.str.length>=1){if("*"in s.node.edges)var l=s.node.edges["*"];else{var l=new e.TokenSet;s.node.edges["*"]=l}1==s.str.length&&(l["final"]=!0),n.push({node:l,editsRemaining:s.editsRemaining-1,str:s.str.slice(1)})}if(s.str.length>1){var c,h=s.str.charAt(0),d=s.str.charAt(1);d in s.node.edges?c=s.node.edges[d]:(c=new e.TokenSet,s.node.edges[d]=c),1==s.str.length&&(c["final"]=!0),n.push({node:c,editsRemaining:s.editsRemaining-1,str:h+s.str.slice(2)})}}}return i},e.TokenSet.fromString=function(t){for(var r=new e.TokenSet,i=r,n=0,s=t.length;n<s;n++){var o=t[n],a=n==s-1;if("*"==o)r.edges[o]=r,r["final"]=a;else{var u=new e.TokenSet;u["final"]=a,r.edges[o]=u,r=u}}return i},e.TokenSet.prototype.toArray=function(){for(var e=[],t=[{prefix:"",node:this}];t.length;){var r=t.pop(),i=Object.keys(r.node.edges),n=i.length;r.node["final"]&&(r.prefix.charAt(0),e.push(r.prefix));for(var s=0;s<n;s++){var o=i[s];t.push({prefix:r.prefix.concat(o),node:r.node.edges[o]})}}return e},e.TokenSet.prototype.toString=function(){if(this._str)return this._str;for(var e=this["final"]?"1":"0",t=Object.keys(this.edges).sort(),r=t.length,i=0;i<r;i++){var n=t[i],s=this.edges[n];e=e+n+s.id}return e},e.TokenSet.prototype.intersect=function(t){for(var r=new e.TokenSet,i=void 0,n=[{qNode:t,output:r,node:this}];n.length;){i=n.pop();for(var s=Object.keys(i.qNode.edges),o=s.length,a=Object.keys(i.node.edges),u=a.length,l=0;l<o;l++)for(var c=s[l],h=0;h<u;h++){var d=a[h];if(d==c||"*"==c){var f=i.node.edges[d],p=i.qNode.edges[c],y=f["final"]&&p["final"],m=void 0;d in i.output.edges?(m=i.output.edges[d],m["final"]=m["final"]||y):(m=new e.TokenSet,m["final"]=y,i.output.edges[d]=m),n.push({qNode:p,output:m,node:f})}}}return r},e.TokenSet.Builder=function(){this.previousWord="",this.root=new e.TokenSet,this.uncheckedNodes=[],this.minimizedNodes={}},e.TokenSet.Builder.prototype.insert=function(t){var r,i=0;if(t<this.previousWord)throw new Error("Out of order word insertion");for(var n=0;n<t.length&&n<this.previousWord.length&&t[n]==this.previousWord[n];n++)i++;this.minimize(i),r=0==this.uncheckedNodes.length?this.root:this.uncheckedNodes[this.uncheckedNodes.length-1].child;for(var n=i;n<t.length;n++){var s=new e.TokenSet,o=t[n];r.edges[o]=s,this.uncheckedNodes.push({parent:r,"char":o,child:s}),r=s}r["final"]=!0,this.previousWord=t},e.TokenSet.Builder.prototype.finish=function(){this.minimize(0)},e.TokenSet.Builder.prototype.minimize=function(e){for(var t=this.uncheckedNodes.length-1;t>=e;t--){var r=this.uncheckedNodes[t],i=r.child.toString();i in this.minimizedNodes?r.parent.edges[r["char"]]=this.minimizedNodes[i]:(r.child._str=i,this.minimizedNodes[i]=r.child),this.uncheckedNodes.pop()}},e.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},e.Index.prototype.search=function(t){return this.query(function(r){var i=new e.QueryParser(t,r);i.parse()})},e.Index.prototype.query=function(t){for(var r=new e.Query(this.fields),i=Object.create(null),n=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),u=0;u<this.fields.length;u++)n[this.fields[u]]=new e.Vector;t.call(r,r);for(var u=0;u<r.clauses.length;u++){var l=r.clauses[u],c=null,h=e.Set.complete;c=l.usePipeline?this.pipeline.runString(l.term,{fields:l.fields}):[l.term];for(var d=0;d<c.length;d++){var f=c[d];l.term=f;var p=e.TokenSet.fromClause(l),y=this.tokenSet.intersect(p).toArray();if(0===y.length&&l.presence===e.Query.presence.REQUIRED){for(var m=0;m<l.fields.length;m++){var v=l.fields[m];o[v]=e.Set.empty}break}for(var g=0;g<y.length;g++)for(var x=y[g],w=this.invertedIndex[x],Q=w._index,m=0;m<l.fields.length;m++){var v=l.fields[m],k=w[v],S=Object.keys(k),E=x+"/"+v,L=new e.Set(S);if(l.presence==e.Query.presence.REQUIRED&&(h=h.union(L),void 0===o[v]&&(o[v]=e.Set.complete)),l.presence!=e.Query.presence.PROHIBITED){if(n[v].upsert(Q,l.boost,function(e,t){return e+t}),!s[E]){for(var b=0;b<S.length;b++){var P,T=S[b],O=new e.FieldRef(T,v),I=k[T];void 0===(P=i[O])?i[O]=new e.MatchData(x,v,I):P.add(x,v,I)}s[E]=!0}}else void 0===a[v]&&(a[v]=e.Set.empty),a[v]=a[v].union(L)}}if(l.presence===e.Query.presence.REQUIRED)for(var m=0;m<l.fields.length;m++){var v=l.fields[m];o[v]=o[v].intersect(h)}}for(var R=e.Set.complete,F=e.Set.empty,u=0;u<this.fields.length;u++){var v=this.fields[u];o[v]&&(R=R.intersect(o[v])),a[v]&&(F=F.union(a[v]))}var C=Object.keys(i),N=[],_=Object.create(null);if(r.isNegated()){C=Object.keys(this.fieldVectors);for(var u=0;u<C.length;u++){var O=C[u],j=e.FieldRef.fromString(O);i[O]=new e.MatchData}}for(var u=0;u<C.length;u++){var j=e.FieldRef.fromString(C[u]),D=j.docRef;if(R.contains(D)&&!F.contains(D)){var A,B=this.fieldVectors[j],V=n[j.fieldName].similarity(B);if(void 0!==(A=_[D]))A.score+=V,A.matchData.combine(i[j]);else{var z={ref:D,score:V,matchData:i[j]};_[D]=z,N.push(z)}}}return N.sort(function(e,t){return t.score-e.score})},e.Index.prototype.toJSON=function(){var t=Object.keys(this.invertedIndex).sort().map(function(e){return[e,this.invertedIndex[e]]},this),r=Object.keys(this.fieldVectors).map(function(e){return[e,this.fieldVectors[e].toJSON()]},this);return{version:e.version,fields:this.fields,fieldVectors:r,invertedIndex:t,pipeline:this.pipeline.toJSON()}},e.Index.load=function(t){var r={},i={},n=t.fieldVectors,s=Object.create(null),o=t.invertedIndex,a=new e.TokenSet.Builder,u=e.Pipeline.load(t.pipeline);t.version!=e.version&&e.utils.warn("Version mismatch when loading serialised index. Current version of lunr '"+e.version+"' does not match serialized index '"+t.version+"'");for(var l=0;l<n.length;l++){var c=n[l],h=c[0],d=c[1];i[h]=new e.Vector(d)}for(var l=0;l<o.length;l++){var c=o[l],f=c[0],p=c[1];a.insert(f),s[f]=p}return a.finish(),r.fields=t.fields,r.fieldVectors=i,r.invertedIndex=s,r.tokenSet=a.root,r.pipeline=u,new e.Index(r)},e.Builder=function(){this._ref="id",this._fields=Object.create(null),this._documents=Object.create(null),this.invertedIndex=Object.create(null),this.fieldTermFrequencies={},this.fieldLengths={},this.tokenizer=e.tokenizer,this.pipeline=new e.Pipeline,this.searchPipeline=new e.Pipeline,this.documentCount=0,this._b=.75,this._k1=1.2,this.termIndex=0,this.metadataWhitelist=[]},e.Builder.prototype.ref=function(e){this._ref=e},e.Builder.prototype.field=function(e,t){if(/\//.test(e))throw new RangeError("Field '"+e+"' contains illegal character '/'");this._fields[e]=t||{}},e.Builder.prototype.b=function(e){e<0?this._b=0:e>1?this._b=1:this._b=e},e.Builder.prototype.k1=function(e){this._k1=e},e.Builder.prototype.add=function(t,r){var i=t[this._ref],n=Object.keys(this._fields);this._documents[i]=r||{},this.documentCount+=1;for(var s=0;s<n.length;s++){var o=n[s],a=this._fields[o].extractor,u=a?a(t):t[o],l=this.tokenizer(u,{fields:[o]}),c=this.pipeline.run(l),h=new e.FieldRef(i,o),d=Object.create(null);this.fieldTermFrequencies[h]=d,this.fieldLengths[h]=0,this.fieldLengths[h]+=c.length;for(var f=0;f<c.length;f++){var p=c[f];if(void 0==d[p]&&(d[p]=0),d[p]+=1,void 0==this.invertedIndex[p]){var y=Object.create(null);y._index=this.termIndex,this.termIndex+=1;for(var m=0;m<n.length;m++)y[n[m]]=Object.create(null);this.invertedIndex[p]=y}void 0==this.invertedIndex[p][o][i]&&(this.invertedIndex[p][o][i]=Object.create(null));for(var v=0;v<this.metadataWhitelist.length;v++){var g=this.metadataWhitelist[v],x=p.metadata[g];void 0==this.invertedIndex[p][o][i][g]&&(this.invertedIndex[p][o][i][g]=[]),this.invertedIndex[p][o][i][g].push(x)}}}},e.Builder.prototype.calculateAverageFieldLengths=function(){for(var t=Object.keys(this.fieldLengths),r=t.length,i={},n={},s=0;s<r;s++){var o=e.FieldRef.fromString(t[s]),a=o.fieldName;n[a]||(n[a]=0),n[a]+=1,i[a]||(i[a]=0),i[a]+=this.fieldLengths[o]}for(var u=Object.keys(this._fields),s=0;s<u.length;s++){var l=u[s];i[l]=i[l]/n[l]}this.averageFieldLength=i},e.Builder.prototype.createFieldVectors=function(){for(var t={},r=Object.keys(this.fieldTermFrequencies),i=r.length,n=Object.create(null),s=0;s<i;s++){for(var o=e.FieldRef.fromString(r[s]),a=o.fieldName,u=this.fieldLengths[o],l=new e.Vector,c=this.fieldTermFrequencies[o],h=Object.keys(c),d=h.length,f=this._fields[a].boost||1,p=this._documents[o.docRef].boost||1,y=0;y<d;y++){var m,v,g,x=h[y],w=c[x],Q=this.invertedIndex[x]._index;void 0===n[x]?(m=e.idf(this.invertedIndex[x],this.documentCount),n[x]=m):m=n[x],v=m*((this._k1+1)*w)/(this._k1*(1-this._b+this._b*(u/this.averageFieldLength[a]))+w),v*=f,v*=p,g=Math.round(1e3*v)/1e3,l.insert(Q,g)}t[o]=l}this.fieldVectors=t},e.Builder.prototype.createTokenSet=function(){this.tokenSet=e.TokenSet.fromArray(Object.keys(this.invertedIndex).sort())},e.Builder.prototype.build=function(){return this.calculateAverageFieldLengths(),this.createFieldVectors(),this.createTokenSet(),new e.Index({invertedIndex:this.invertedIndex,fieldVectors:this.fieldVectors,tokenSet:this.tokenSet,fields:Object.keys(this._fields),pipeline:this.searchPipeline})},e.Builder.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},e.MatchData=function(e,t,r){for(var i=Object.create(null),n=Object.keys(r||{}),s=0;s<n.length;s++){var o=n[s];i[o]=r[o].slice()}this.metadata=Object.create(null),void 0!==e&&(this.metadata[e]=Object.create(null),this.metadata[e][t]=i)},e.MatchData.prototype.combine=function(e){for(var t=Object.keys(e.metadata),r=0;r<t.length;r++){var i=t[r],n=Object.keys(e.metadata[i]);void 0==this.metadata[i]&&(this.metadata[i]=Object.create(null));for(var s=0;s<n.length;s++){var o=n[s],a=Object.keys(e.metadata[i][o]);void 0==this.metadata[i][o]&&(this.metadata[i][o]=Object.create(null));for(var u=0;u<a.length;u++){var l=a[u];void 0==this.metadata[i][o][l]?this.metadata[i][o][l]=e.metadata[i][o][l]:this.metadata[i][o][l]=this.metadata[i][o][l].concat(e.metadata[i][o][l])}}}},e.MatchData.prototype.add=function(e,t,r){if(!(e in this.metadata))return this.metadata[e]=Object.create(null),void(this.metadata[e][t]=r);if(!(t in this.metadata[e]))return void(this.metadata[e][t]=r);for(var i=Object.keys(r),n=0;n<i.length;n++){var s=i[n];s in this.metadata[e][t]?this.metadata[e][t][s]=this.metadata[e][t][s].concat(r[s]):this.metadata[e][t][s]=r[s]}},e.Query=function(e){this.clauses=[],this.allFields=e},e.Query.wildcard=new String("*"),e.Query.wildcard.NONE=0,e.Query.wildcard.LEADING=1,e.Query.wildcard.TRAILING=2,e.Query.presence={OPTIONAL:1,REQUIRED:2,PROHIBITED:3},e.Query.prototype.clause=function(t){return"fields"in t||(t.fields=this.allFields),"boost"in t||(t.boost=1),"usePipeline"in t||(t.usePipeline=!0),"wildcard"in t||(t.wildcard=e.Query.wildcard.NONE),t.wildcard&e.Query.wildcard.LEADING&&t.term.charAt(0)!=e.Query.wildcard&&(t.term="*"+t.term),t.wildcard&e.Query.wildcard.TRAILING&&t.term.slice(-1)!=e.Query.wildcard&&(t.term=""+t.term+"*"),"presence"in t||(t.presence=e.Query.presence.OPTIONAL),this.clauses.push(t),this},e.Query.prototype.isNegated=function(){for(var t=0;t<this.clauses.length;t++)if(this.clauses[t].presence!=e.Query.presence.PROHIBITED)return!1;return!0},e.Query.prototype.term=function(t,r){if(Array.isArray(t))return t.forEach(function(t){this.term(t,e.utils.clone(r))},this),this;var i=r||{};return i.term=t.toString(),this.clause(i),this},e.QueryParseError=function(e,t,r){this.name="QueryParseError",this.message=e,this.start=t,this.end=r},e.QueryParseError.prototype=new Error,e.QueryLexer=function(e){this.lexemes=[],this.str=e,this.length=e.length,this.pos=0,this.start=0,this.escapeCharPositions=[]},e.QueryLexer.prototype.run=function(){for(var t=e.QueryLexer.lexText;t;)t=t(this)},e.QueryLexer.prototype.sliceString=function(){for(var e=[],t=this.start,r=this.pos,i=0;i<this.escapeCharPositions.length;i++)r=this.escapeCharPositions[i],e.push(this.str.slice(t,r)),t=r+1;return e.push(this.str.slice(t,this.pos)),this.escapeCharPositions.length=0,e.join("")},e.QueryLexer.prototype.emit=function(e){this.lexemes.push({type:e,str:this.sliceString(),start:this.start,end:this.pos}),this.start=this.pos},e.QueryLexer.prototype.escapeCharacter=function(){this.escapeCharPositions.push(this.pos-1),this.pos+=1},e.QueryLexer.prototype.next=function(){if(this.pos>=this.length)return e.QueryLexer.EOS;var t=this.str.charAt(this.pos);return this.pos+=1,t},e.QueryLexer.prototype.width=function(){return this.pos-this.start},e.QueryLexer.prototype.ignore=function(){this.start==this.pos&&(this.pos+=1),this.start=this.pos},e.QueryLexer.prototype.backup=function(){this.pos-=1},e.QueryLexer.prototype.acceptDigitRun=function(){var t,r;do t=this.next(),r=t.charCodeAt(0);while(r>47&&r<58);t!=e.QueryLexer.EOS&&this.backup()},e.QueryLexer.prototype.more=function(){return this.pos<this.length},e.QueryLexer.EOS="EOS",e.QueryLexer.FIELD="FIELD",e.QueryLexer.TERM="TERM",e.QueryLexer.EDIT_DISTANCE="EDIT_DISTANCE",e.QueryLexer.BOOST="BOOST",e.QueryLexer.PRESENCE="PRESENCE",e.QueryLexer.lexField=function(t){return t.backup(),t.emit(e.QueryLexer.FIELD),t.ignore(),e.QueryLexer.lexText},e.QueryLexer.lexTerm=function(t){if(t.width()>1&&(t.backup(),t.emit(e.QueryLexer.TERM)),t.ignore(),t.more())return e.QueryLexer.lexText},e.QueryLexer.lexEditDistance=function(t){return t.ignore(),t.acceptDigitRun(),t.emit(e.QueryLexer.EDIT_DISTANCE),e.QueryLexer.lexText},e.QueryLexer.lexBoost=function(t){return t.ignore(),t.acceptDigitRun(),t.emit(e.QueryLexer.BOOST),e.QueryLexer.lexText},e.QueryLexer.lexEOS=function(t){t.width()>0&&t.emit(e.QueryLexer.TERM)},e.QueryLexer.termSeparator=e.tokenizer.separator,e.QueryLexer.lexText=function(t){for(;;){var r=t.next();if(r==e.QueryLexer.EOS)return e.QueryLexer.lexEOS;if(92!=r.charCodeAt(0)){if(":"==r)return e.QueryLexer.lexField;if("~"==r)return t.backup(),t.width()>0&&t.emit(e.QueryLexer.TERM),e.QueryLexer.lexEditDistance;if("^"==r)return t.backup(),t.width()>0&&t.emit(e.QueryLexer.TERM),e.QueryLexer.lexBoost;if("+"==r&&1===t.width())return t.emit(e.QueryLexer.PRESENCE),e.QueryLexer.lexText;if("-"==r&&1===t.width())return t.emit(e.QueryLexer.PRESENCE),e.QueryLexer.lexText;if(r.match(e.QueryLexer.termSeparator))return e.QueryLexer.lexTerm}else t.escapeCharacter()}},e.QueryParser=function(t,r){this.lexer=new e.QueryLexer(t),this.query=r,this.currentClause={},this.lexemeIdx=0},e.QueryParser.prototype.parse=function(){this.lexer.run(),this.lexemes=this.lexer.lexemes;for(var t=e.QueryParser.parseClause;t;)t=t(this);return this.query},e.QueryParser.prototype.peekLexeme=function(){return this.lexemes[this.lexemeIdx]},e.QueryParser.prototype.consumeLexeme=function(){var e=this.peekLexeme();return this.lexemeIdx+=1,e},e.QueryParser.prototype.nextClause=function(){var e=this.currentClause;this.query.clause(e),this.currentClause={}},e.QueryParser.parseClause=function(t){var r=t.peekLexeme();if(void 0!=r)switch(r.type){case e.QueryLexer.PRESENCE:return e.QueryParser.parsePresence;case e.QueryLexer.FIELD:return e.QueryParser.parseField;case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var i="expected either a field or a term, found "+r.type;throw r.str.length>=1&&(i+=" with value '"+r.str+"'"),new e.QueryParseError(i,r.start,r.end)}},e.QueryParser.parsePresence=function(t){var r=t.consumeLexeme();if(void 0!=r){switch(r.str){case"-":t.currentClause.presence=e.Query.presence.PROHIBITED;break;case"+":t.currentClause.presence=e.Query.presence.REQUIRED;break;default:var i="unrecognised presence operator'"+r.str+"'";throw new e.QueryParseError(i,r.start,r.end)}var n=t.peekLexeme();if(void 0==n){var i="expecting term or field, found nothing";throw new e.QueryParseError(i,r.start,r.end)}switch(n.type){case e.QueryLexer.FIELD:return e.QueryParser.parseField;case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var i="expecting term or field, found '"+n.type+"'";throw new e.QueryParseError(i,n.start,n.end)}}},e.QueryParser.parseField=function(t){var r=t.consumeLexeme();if(void 0!=r){if(t.query.allFields.indexOf(r.str)==-1){var i=t.query.allFields.map(function(e){return"'"+e+"'"}).join(", "),n="unrecognised field '"+r.str+"', possible fields: "+i;throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.fields=[r.str];var s=t.peekLexeme();if(void 0==s){var n="expecting term, found nothing";throw new e.QueryParseError(n,r.start,r.end)}switch(s.type){case e.QueryLexer.TERM:return e.QueryParser.parseTerm;default:var n="expecting term, found '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},e.QueryParser.parseTerm=function(t){var r=t.consumeLexeme();if(void 0!=r){t.currentClause.term=r.str.toLowerCase(),r.str.indexOf("*")!=-1&&(t.currentClause.usePipeline=!1);var i=t.peekLexeme();if(void 0==i)return void t.nextClause();switch(i.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+i.type+"'";throw new e.QueryParseError(n,i.start,i.end)}}},e.QueryParser.parseEditDistance=function(t){var r=t.consumeLexeme();if(void 0!=r){var i=parseInt(r.str,10);if(isNaN(i)){var n="edit distance must be numeric";throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.editDistance=i;var s=t.peekLexeme();if(void 0==s)return void t.nextClause();switch(s.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},e.QueryParser.parseBoost=function(t){var r=t.consumeLexeme();if(void 0!=r){var i=parseInt(r.str,10);if(isNaN(i)){var n="boost must be numeric";throw new e.QueryParseError(n,r.start,r.end)}t.currentClause.boost=i;var s=t.peekLexeme();if(void 0==s)return void t.nextClause();switch(s.type){case e.QueryLexer.TERM:return t.nextClause(),e.QueryParser.parseTerm;case e.QueryLexer.FIELD:return t.nextClause(),e.QueryParser.parseField;case e.QueryLexer.EDIT_DISTANCE:return e.QueryParser.parseEditDistance;case e.QueryLexer.BOOST:return e.QueryParser.parseBoost;case e.QueryLexer.PRESENCE:return t.nextClause(),e.QueryParser.parsePresence;default:var n="Unexpected lexeme type '"+s.type+"'";throw new e.QueryParseError(n,s.start,s.end)}}},function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports?module.exports=t():e.lunr=t()}(this,function(){return e})}();
|
@@ -0,0 +1,1694 @@
|
|
1
|
+
/*!
|
2
|
+
* typeahead.js 1.3.1
|
3
|
+
* https://github.com/corejavascript/typeahead.js
|
4
|
+
* Copyright 2013-2020 Twitter, Inc. and other contributors; Licensed MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
|
8
|
+
(function(root, factory) {
|
9
|
+
if (typeof define === "function" && define.amd) {
|
10
|
+
define([ "jquery" ], function(a0) {
|
11
|
+
return factory(a0);
|
12
|
+
});
|
13
|
+
} else if (typeof module === "object" && module.exports) {
|
14
|
+
module.exports = factory(require("jquery"));
|
15
|
+
} else {
|
16
|
+
factory(root["jQuery"]);
|
17
|
+
}
|
18
|
+
})(this, function($) {
|
19
|
+
var _ = function() {
|
20
|
+
"use strict";
|
21
|
+
return {
|
22
|
+
isMsie: function() {
|
23
|
+
return /(msie|trident)/i.test(navigator.userAgent) ? navigator.userAgent.match(/(msie |rv:)(\d+(.\d+)?)/i)[2] : false;
|
24
|
+
},
|
25
|
+
isBlankString: function(str) {
|
26
|
+
return !str || /^\s*$/.test(str);
|
27
|
+
},
|
28
|
+
escapeRegExChars: function(str) {
|
29
|
+
return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
30
|
+
},
|
31
|
+
isString: function(obj) {
|
32
|
+
return typeof obj === "string";
|
33
|
+
},
|
34
|
+
isNumber: function(obj) {
|
35
|
+
return typeof obj === "number";
|
36
|
+
},
|
37
|
+
isArray: $.isArray,
|
38
|
+
isFunction: $.isFunction,
|
39
|
+
isObject: $.isPlainObject,
|
40
|
+
isUndefined: function(obj) {
|
41
|
+
return typeof obj === "undefined";
|
42
|
+
},
|
43
|
+
isElement: function(obj) {
|
44
|
+
return !!(obj && obj.nodeType === 1);
|
45
|
+
},
|
46
|
+
isJQuery: function(obj) {
|
47
|
+
return obj instanceof $;
|
48
|
+
},
|
49
|
+
toStr: function toStr(s) {
|
50
|
+
return _.isUndefined(s) || s === null ? "" : s + "";
|
51
|
+
},
|
52
|
+
bind: $.proxy,
|
53
|
+
each: function(collection, cb) {
|
54
|
+
$.each(collection, reverseArgs);
|
55
|
+
function reverseArgs(index, value) {
|
56
|
+
return cb(value, index);
|
57
|
+
}
|
58
|
+
},
|
59
|
+
map: $.map,
|
60
|
+
filter: $.grep,
|
61
|
+
every: function(obj, test) {
|
62
|
+
var result = true;
|
63
|
+
if (!obj) {
|
64
|
+
return result;
|
65
|
+
}
|
66
|
+
$.each(obj, function(key, val) {
|
67
|
+
if (!(result = test.call(null, val, key, obj))) {
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
});
|
71
|
+
return !!result;
|
72
|
+
},
|
73
|
+
some: function(obj, test) {
|
74
|
+
var result = false;
|
75
|
+
if (!obj) {
|
76
|
+
return result;
|
77
|
+
}
|
78
|
+
$.each(obj, function(key, val) {
|
79
|
+
if (result = test.call(null, val, key, obj)) {
|
80
|
+
return false;
|
81
|
+
}
|
82
|
+
});
|
83
|
+
return !!result;
|
84
|
+
},
|
85
|
+
mixin: $.extend,
|
86
|
+
identity: function(x) {
|
87
|
+
return x;
|
88
|
+
},
|
89
|
+
clone: function(obj) {
|
90
|
+
return $.extend(true, {}, obj);
|
91
|
+
},
|
92
|
+
getIdGenerator: function() {
|
93
|
+
var counter = 0;
|
94
|
+
return function() {
|
95
|
+
return counter++;
|
96
|
+
};
|
97
|
+
},
|
98
|
+
templatify: function templatify(obj) {
|
99
|
+
return $.isFunction(obj) ? obj : template;
|
100
|
+
function template() {
|
101
|
+
return String(obj);
|
102
|
+
}
|
103
|
+
},
|
104
|
+
defer: function(fn) {
|
105
|
+
setTimeout(fn, 0);
|
106
|
+
},
|
107
|
+
debounce: function(func, wait, immediate) {
|
108
|
+
var timeout, result;
|
109
|
+
return function() {
|
110
|
+
var context = this, args = arguments, later, callNow;
|
111
|
+
later = function() {
|
112
|
+
timeout = null;
|
113
|
+
if (!immediate) {
|
114
|
+
result = func.apply(context, args);
|
115
|
+
}
|
116
|
+
};
|
117
|
+
callNow = immediate && !timeout;
|
118
|
+
clearTimeout(timeout);
|
119
|
+
timeout = setTimeout(later, wait);
|
120
|
+
if (callNow) {
|
121
|
+
result = func.apply(context, args);
|
122
|
+
}
|
123
|
+
return result;
|
124
|
+
};
|
125
|
+
},
|
126
|
+
throttle: function(func, wait) {
|
127
|
+
var context, args, timeout, result, previous, later;
|
128
|
+
previous = 0;
|
129
|
+
later = function() {
|
130
|
+
previous = new Date();
|
131
|
+
timeout = null;
|
132
|
+
result = func.apply(context, args);
|
133
|
+
};
|
134
|
+
return function() {
|
135
|
+
var now = new Date(), remaining = wait - (now - previous);
|
136
|
+
context = this;
|
137
|
+
args = arguments;
|
138
|
+
if (remaining <= 0) {
|
139
|
+
clearTimeout(timeout);
|
140
|
+
timeout = null;
|
141
|
+
previous = now;
|
142
|
+
result = func.apply(context, args);
|
143
|
+
} else if (!timeout) {
|
144
|
+
timeout = setTimeout(later, remaining);
|
145
|
+
}
|
146
|
+
return result;
|
147
|
+
};
|
148
|
+
},
|
149
|
+
stringify: function(val) {
|
150
|
+
return _.isString(val) ? val : JSON.stringify(val);
|
151
|
+
},
|
152
|
+
guid: function() {
|
153
|
+
function _p8(s) {
|
154
|
+
var p = (Math.random().toString(16) + "000000000").substr(2, 8);
|
155
|
+
return s ? "-" + p.substr(0, 4) + "-" + p.substr(4, 4) : p;
|
156
|
+
}
|
157
|
+
return "tt-" + _p8() + _p8(true) + _p8(true) + _p8();
|
158
|
+
},
|
159
|
+
noop: function() {}
|
160
|
+
};
|
161
|
+
}();
|
162
|
+
var WWW = function() {
|
163
|
+
"use strict";
|
164
|
+
var defaultClassNames = {
|
165
|
+
wrapper: "twitter-typeahead",
|
166
|
+
input: "tt-input",
|
167
|
+
hint: "tt-hint",
|
168
|
+
menu: "tt-menu",
|
169
|
+
dataset: "tt-dataset",
|
170
|
+
suggestion: "tt-suggestion",
|
171
|
+
selectable: "tt-selectable",
|
172
|
+
empty: "tt-empty",
|
173
|
+
open: "tt-open",
|
174
|
+
cursor: "tt-cursor",
|
175
|
+
highlight: "tt-highlight"
|
176
|
+
};
|
177
|
+
return build;
|
178
|
+
function build(o) {
|
179
|
+
var www, classes;
|
180
|
+
classes = _.mixin({}, defaultClassNames, o);
|
181
|
+
www = {
|
182
|
+
css: buildCss(),
|
183
|
+
classes: classes,
|
184
|
+
html: buildHtml(classes),
|
185
|
+
selectors: buildSelectors(classes)
|
186
|
+
};
|
187
|
+
return {
|
188
|
+
css: www.css,
|
189
|
+
html: www.html,
|
190
|
+
classes: www.classes,
|
191
|
+
selectors: www.selectors,
|
192
|
+
mixin: function(o) {
|
193
|
+
_.mixin(o, www);
|
194
|
+
}
|
195
|
+
};
|
196
|
+
}
|
197
|
+
function buildHtml(c) {
|
198
|
+
return {
|
199
|
+
wrapper: '<span class="' + c.wrapper + '"></span>',
|
200
|
+
menu: '<div role="listbox" class="' + c.menu + '"></div>'
|
201
|
+
};
|
202
|
+
}
|
203
|
+
function buildSelectors(classes) {
|
204
|
+
var selectors = {};
|
205
|
+
_.each(classes, function(v, k) {
|
206
|
+
selectors[k] = "." + v;
|
207
|
+
});
|
208
|
+
return selectors;
|
209
|
+
}
|
210
|
+
function buildCss() {
|
211
|
+
var css = {
|
212
|
+
wrapper: {
|
213
|
+
position: "relative",
|
214
|
+
display: "inline-block"
|
215
|
+
},
|
216
|
+
hint: {
|
217
|
+
position: "absolute",
|
218
|
+
top: "0",
|
219
|
+
left: "0",
|
220
|
+
borderColor: "transparent",
|
221
|
+
boxShadow: "none",
|
222
|
+
opacity: "1"
|
223
|
+
},
|
224
|
+
input: {
|
225
|
+
position: "relative",
|
226
|
+
verticalAlign: "top",
|
227
|
+
backgroundColor: "transparent"
|
228
|
+
},
|
229
|
+
inputWithNoHint: {
|
230
|
+
position: "relative",
|
231
|
+
verticalAlign: "top"
|
232
|
+
},
|
233
|
+
menu: {
|
234
|
+
position: "absolute",
|
235
|
+
top: "100%",
|
236
|
+
left: "0",
|
237
|
+
zIndex: "100",
|
238
|
+
display: "none"
|
239
|
+
},
|
240
|
+
ltr: {
|
241
|
+
left: "0",
|
242
|
+
right: "auto"
|
243
|
+
},
|
244
|
+
rtl: {
|
245
|
+
left: "auto",
|
246
|
+
right: " 0"
|
247
|
+
}
|
248
|
+
};
|
249
|
+
if (_.isMsie()) {
|
250
|
+
_.mixin(css.input, {
|
251
|
+
backgroundImage: "url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"
|
252
|
+
});
|
253
|
+
}
|
254
|
+
return css;
|
255
|
+
}
|
256
|
+
}();
|
257
|
+
var EventBus = function() {
|
258
|
+
"use strict";
|
259
|
+
var namespace, deprecationMap;
|
260
|
+
namespace = "typeahead:";
|
261
|
+
deprecationMap = {
|
262
|
+
render: "rendered",
|
263
|
+
cursorchange: "cursorchanged",
|
264
|
+
select: "selected",
|
265
|
+
autocomplete: "autocompleted"
|
266
|
+
};
|
267
|
+
function EventBus(o) {
|
268
|
+
if (!o || !o.el) {
|
269
|
+
$.error("EventBus initialized without el");
|
270
|
+
}
|
271
|
+
this.$el = $(o.el);
|
272
|
+
}
|
273
|
+
_.mixin(EventBus.prototype, {
|
274
|
+
_trigger: function(type, args) {
|
275
|
+
var $e = $.Event(namespace + type);
|
276
|
+
this.$el.trigger.call(this.$el, $e, args || []);
|
277
|
+
return $e;
|
278
|
+
},
|
279
|
+
before: function(type) {
|
280
|
+
var args, $e;
|
281
|
+
args = [].slice.call(arguments, 1);
|
282
|
+
$e = this._trigger("before" + type, args);
|
283
|
+
return $e.isDefaultPrevented();
|
284
|
+
},
|
285
|
+
trigger: function(type) {
|
286
|
+
var deprecatedType;
|
287
|
+
this._trigger(type, [].slice.call(arguments, 1));
|
288
|
+
if (deprecatedType = deprecationMap[type]) {
|
289
|
+
this._trigger(deprecatedType, [].slice.call(arguments, 1));
|
290
|
+
}
|
291
|
+
}
|
292
|
+
});
|
293
|
+
return EventBus;
|
294
|
+
}();
|
295
|
+
var EventEmitter = function() {
|
296
|
+
"use strict";
|
297
|
+
var splitter = /\s+/, nextTick = getNextTick();
|
298
|
+
return {
|
299
|
+
onSync: onSync,
|
300
|
+
onAsync: onAsync,
|
301
|
+
off: off,
|
302
|
+
trigger: trigger
|
303
|
+
};
|
304
|
+
function on(method, types, cb, context) {
|
305
|
+
var type;
|
306
|
+
if (!cb) {
|
307
|
+
return this;
|
308
|
+
}
|
309
|
+
types = types.split(splitter);
|
310
|
+
cb = context ? bindContext(cb, context) : cb;
|
311
|
+
this._callbacks = this._callbacks || {};
|
312
|
+
while (type = types.shift()) {
|
313
|
+
this._callbacks[type] = this._callbacks[type] || {
|
314
|
+
sync: [],
|
315
|
+
async: []
|
316
|
+
};
|
317
|
+
this._callbacks[type][method].push(cb);
|
318
|
+
}
|
319
|
+
return this;
|
320
|
+
}
|
321
|
+
function onAsync(types, cb, context) {
|
322
|
+
return on.call(this, "async", types, cb, context);
|
323
|
+
}
|
324
|
+
function onSync(types, cb, context) {
|
325
|
+
return on.call(this, "sync", types, cb, context);
|
326
|
+
}
|
327
|
+
function off(types) {
|
328
|
+
var type;
|
329
|
+
if (!this._callbacks) {
|
330
|
+
return this;
|
331
|
+
}
|
332
|
+
types = types.split(splitter);
|
333
|
+
while (type = types.shift()) {
|
334
|
+
delete this._callbacks[type];
|
335
|
+
}
|
336
|
+
return this;
|
337
|
+
}
|
338
|
+
function trigger(types) {
|
339
|
+
var type, callbacks, args, syncFlush, asyncFlush;
|
340
|
+
if (!this._callbacks) {
|
341
|
+
return this;
|
342
|
+
}
|
343
|
+
types = types.split(splitter);
|
344
|
+
args = [].slice.call(arguments, 1);
|
345
|
+
while ((type = types.shift()) && (callbacks = this._callbacks[type])) {
|
346
|
+
syncFlush = getFlush(callbacks.sync, this, [ type ].concat(args));
|
347
|
+
asyncFlush = getFlush(callbacks.async, this, [ type ].concat(args));
|
348
|
+
syncFlush() && nextTick(asyncFlush);
|
349
|
+
}
|
350
|
+
return this;
|
351
|
+
}
|
352
|
+
function getFlush(callbacks, context, args) {
|
353
|
+
return flush;
|
354
|
+
function flush() {
|
355
|
+
var cancelled;
|
356
|
+
for (var i = 0, len = callbacks.length; !cancelled && i < len; i += 1) {
|
357
|
+
cancelled = callbacks[i].apply(context, args) === false;
|
358
|
+
}
|
359
|
+
return !cancelled;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
function getNextTick() {
|
363
|
+
var nextTickFn;
|
364
|
+
if (window.setImmediate) {
|
365
|
+
nextTickFn = function nextTickSetImmediate(fn) {
|
366
|
+
setImmediate(function() {
|
367
|
+
fn();
|
368
|
+
});
|
369
|
+
};
|
370
|
+
} else {
|
371
|
+
nextTickFn = function nextTickSetTimeout(fn) {
|
372
|
+
setTimeout(function() {
|
373
|
+
fn();
|
374
|
+
}, 0);
|
375
|
+
};
|
376
|
+
}
|
377
|
+
return nextTickFn;
|
378
|
+
}
|
379
|
+
function bindContext(fn, context) {
|
380
|
+
return fn.bind ? fn.bind(context) : function() {
|
381
|
+
fn.apply(context, [].slice.call(arguments, 0));
|
382
|
+
};
|
383
|
+
}
|
384
|
+
}();
|
385
|
+
var highlight = function(doc) {
|
386
|
+
"use strict";
|
387
|
+
var defaults = {
|
388
|
+
node: null,
|
389
|
+
pattern: null,
|
390
|
+
tagName: "strong",
|
391
|
+
className: null,
|
392
|
+
wordsOnly: false,
|
393
|
+
caseSensitive: false,
|
394
|
+
diacriticInsensitive: false
|
395
|
+
};
|
396
|
+
var accented = {
|
397
|
+
A: "[AaªÀ-Åà-åĀ-ąǍǎȀ-ȃȦȧᴬᵃḀḁẚẠ-ảₐ℀℁℻⒜Ⓐⓐ㍱-㍴㎀-㎄㎈㎉㎩-㎯㏂㏊㏟㏿Aa]",
|
398
|
+
B: "[BbᴮᵇḂ-ḇℬ⒝Ⓑⓑ㍴㎅-㎇㏃㏈㏔㏝Bb]",
|
399
|
+
C: "[CcÇçĆ-čᶜ℀ℂ℃℅℆ℭⅭⅽ⒞Ⓒⓒ㍶㎈㎉㎝㎠㎤㏄-㏇Cc]",
|
400
|
+
D: "[DdĎďDŽ-džDZ-dzᴰᵈḊ-ḓⅅⅆⅮⅾ⒟Ⓓⓓ㋏㍲㍷-㍹㎗㎭-㎯㏅㏈Dd]",
|
401
|
+
E: "[EeÈ-Ëè-ëĒ-ěȄ-ȇȨȩᴱᵉḘ-ḛẸ-ẽₑ℡ℯℰⅇ⒠Ⓔⓔ㉐㋍㋎Ee]",
|
402
|
+
F: "[FfᶠḞḟ℉ℱ℻⒡Ⓕⓕ㎊-㎌㎙ff-fflFf]",
|
403
|
+
G: "[GgĜ-ģǦǧǴǵᴳᵍḠḡℊ⒢Ⓖⓖ㋌㋍㎇㎍-㎏㎓㎬㏆㏉㏒㏿Gg]",
|
404
|
+
H: "[HhĤĥȞȟʰᴴḢ-ḫẖℋ-ℎ⒣Ⓗⓗ㋌㍱㎐-㎔㏊㏋㏗Hh]",
|
405
|
+
I: "[IiÌ-Ïì-ïĨ-İIJijǏǐȈ-ȋᴵᵢḬḭỈ-ịⁱℐℑℹⅈⅠ-ⅣⅥ-ⅨⅪⅫⅰ-ⅳⅵ-ⅸⅺⅻ⒤Ⓘⓘ㍺㏌㏕fiffiIi]",
|
406
|
+
J: "[JjIJ-ĵLJ-njǰʲᴶⅉ⒥ⒿⓙⱼJj]",
|
407
|
+
K: "[KkĶķǨǩᴷᵏḰ-ḵK⒦Ⓚⓚ㎄㎅㎉㎏㎑㎘㎞㎢㎦㎪㎸㎾㏀㏆㏍-㏏Kk]",
|
408
|
+
L: "[LlĹ-ŀLJ-ljˡᴸḶḷḺ-ḽℒℓ℡Ⅼⅼ⒧Ⓛⓛ㋏㎈㎉㏐-㏓㏕㏖㏿flfflLl]",
|
409
|
+
M: "[MmᴹᵐḾ-ṃ℠™ℳⅯⅿ⒨Ⓜⓜ㍷-㍹㎃㎆㎎㎒㎖㎙-㎨㎫㎳㎷㎹㎽㎿㏁㏂㏎㏐㏔-㏖㏘㏙㏞㏟Mm]",
|
410
|
+
N: "[NnÑñŃ-ʼnNJ-njǸǹᴺṄ-ṋⁿℕ№⒩Ⓝⓝ㎁㎋㎚㎱㎵㎻㏌㏑Nn]",
|
411
|
+
O: "[OoºÒ-Öò-öŌ-őƠơǑǒǪǫȌ-ȏȮȯᴼᵒỌ-ỏₒ℅№ℴ⒪Ⓞⓞ㍵㏇㏒㏖Oo]",
|
412
|
+
P: "[PpᴾᵖṔ-ṗℙ⒫Ⓟⓟ㉐㍱㍶㎀㎊㎩-㎬㎰㎴㎺㏋㏗-㏚Pp]",
|
413
|
+
Q: "[Qqℚ⒬Ⓠⓠ㏃Qq]",
|
414
|
+
R: "[RrŔ-řȐ-ȓʳᴿᵣṘ-ṛṞṟ₨ℛ-ℝ⒭Ⓡⓡ㋍㍴㎭-㎯㏚㏛Rr]",
|
415
|
+
S: "[SsŚ-šſȘșˢṠ-ṣ₨℁℠⒮Ⓢⓢ㎧㎨㎮-㎳㏛㏜stSs]",
|
416
|
+
T: "[TtŢ-ťȚțᵀᵗṪ-ṱẗ℡™⒯Ⓣⓣ㉐㋏㎔㏏ſtstTt]",
|
417
|
+
U: "[UuÙ-Üù-üŨ-ųƯưǓǔȔ-ȗᵁᵘᵤṲ-ṷỤ-ủ℆⒰Ⓤⓤ㍳㍺Uu]",
|
418
|
+
V: "[VvᵛᵥṼ-ṿⅣ-Ⅷⅳ-ⅷ⒱Ⓥⓥⱽ㋎㍵㎴-㎹㏜㏞Vv]",
|
419
|
+
W: "[WwŴŵʷᵂẀ-ẉẘ⒲Ⓦⓦ㎺-㎿㏝Ww]",
|
420
|
+
X: "[XxˣẊ-ẍₓ℻Ⅸ-Ⅻⅸ-ⅻ⒳Ⓧⓧ㏓Xx]",
|
421
|
+
Y: "[YyÝýÿŶ-ŸȲȳʸẎẏẙỲ-ỹ⒴Ⓨⓨ㏉Yy]",
|
422
|
+
Z: "[ZzŹ-žDZ-dzᶻẐ-ẕℤℨ⒵Ⓩⓩ㎐-㎔Zz]"
|
423
|
+
};
|
424
|
+
return function hightlight(o) {
|
425
|
+
var regex;
|
426
|
+
o = _.mixin({}, defaults, o);
|
427
|
+
if (!o.node || !o.pattern) {
|
428
|
+
return;
|
429
|
+
}
|
430
|
+
o.pattern = _.isArray(o.pattern) ? o.pattern : [ o.pattern ];
|
431
|
+
regex = getRegex(o.pattern, o.caseSensitive, o.wordsOnly, o.diacriticInsensitive);
|
432
|
+
traverse(o.node, hightlightTextNode);
|
433
|
+
function hightlightTextNode(textNode) {
|
434
|
+
var match, patternNode, wrapperNode;
|
435
|
+
if (match = regex.exec(textNode.data)) {
|
436
|
+
wrapperNode = doc.createElement(o.tagName);
|
437
|
+
o.className && (wrapperNode.className = o.className);
|
438
|
+
patternNode = textNode.splitText(match.index);
|
439
|
+
patternNode.splitText(match[0].length);
|
440
|
+
wrapperNode.appendChild(patternNode.cloneNode(true));
|
441
|
+
textNode.parentNode.replaceChild(wrapperNode, patternNode);
|
442
|
+
}
|
443
|
+
return !!match;
|
444
|
+
}
|
445
|
+
function traverse(el, hightlightTextNode) {
|
446
|
+
var childNode, TEXT_NODE_TYPE = 3;
|
447
|
+
for (var i = 0; i < el.childNodes.length; i++) {
|
448
|
+
childNode = el.childNodes[i];
|
449
|
+
if (childNode.nodeType === TEXT_NODE_TYPE) {
|
450
|
+
i += hightlightTextNode(childNode) ? 1 : 0;
|
451
|
+
} else {
|
452
|
+
traverse(childNode, hightlightTextNode);
|
453
|
+
}
|
454
|
+
}
|
455
|
+
}
|
456
|
+
};
|
457
|
+
function accent_replacer(chr) {
|
458
|
+
return accented[chr.toUpperCase()] || chr;
|
459
|
+
}
|
460
|
+
function getRegex(patterns, caseSensitive, wordsOnly, diacriticInsensitive) {
|
461
|
+
var escapedPatterns = [], regexStr;
|
462
|
+
for (var i = 0, len = patterns.length; i < len; i++) {
|
463
|
+
var escapedWord = _.escapeRegExChars(patterns[i]);
|
464
|
+
if (diacriticInsensitive) {
|
465
|
+
escapedWord = escapedWord.replace(/\S/g, accent_replacer);
|
466
|
+
}
|
467
|
+
escapedPatterns.push(escapedWord);
|
468
|
+
}
|
469
|
+
regexStr = wordsOnly ? "\\b(" + escapedPatterns.join("|") + ")\\b" : "(" + escapedPatterns.join("|") + ")";
|
470
|
+
return caseSensitive ? new RegExp(regexStr) : new RegExp(regexStr, "i");
|
471
|
+
}
|
472
|
+
}(window.document);
|
473
|
+
var Input = function() {
|
474
|
+
"use strict";
|
475
|
+
var specialKeyCodeMap;
|
476
|
+
specialKeyCodeMap = {
|
477
|
+
9: "tab",
|
478
|
+
27: "esc",
|
479
|
+
37: "left",
|
480
|
+
39: "right",
|
481
|
+
13: "enter",
|
482
|
+
38: "up",
|
483
|
+
40: "down"
|
484
|
+
};
|
485
|
+
function Input(o, www) {
|
486
|
+
var id;
|
487
|
+
o = o || {};
|
488
|
+
if (!o.input) {
|
489
|
+
$.error("input is missing");
|
490
|
+
}
|
491
|
+
www.mixin(this);
|
492
|
+
this.$hint = $(o.hint);
|
493
|
+
this.$input = $(o.input);
|
494
|
+
this.$menu = $(o.menu);
|
495
|
+
id = this.$input.attr("id") || _.guid();
|
496
|
+
this.$menu.attr("id", id + "_listbox");
|
497
|
+
this.$hint.attr({
|
498
|
+
"aria-hidden": true
|
499
|
+
});
|
500
|
+
this.$input.attr({
|
501
|
+
"aria-owns": id + "_listbox",
|
502
|
+
role: "combobox",
|
503
|
+
"aria-autocomplete": "list",
|
504
|
+
"aria-expanded": false
|
505
|
+
});
|
506
|
+
this.query = this.$input.val();
|
507
|
+
this.queryWhenFocused = this.hasFocus() ? this.query : null;
|
508
|
+
this.$overflowHelper = buildOverflowHelper(this.$input);
|
509
|
+
this._checkLanguageDirection();
|
510
|
+
if (this.$hint.length === 0) {
|
511
|
+
this.setHint = this.getHint = this.clearHint = this.clearHintIfInvalid = _.noop;
|
512
|
+
}
|
513
|
+
this.onSync("cursorchange", this._updateDescendent);
|
514
|
+
}
|
515
|
+
Input.normalizeQuery = function(str) {
|
516
|
+
return _.toStr(str).replace(/^\s*/g, "").replace(/\s{2,}/g, " ");
|
517
|
+
};
|
518
|
+
_.mixin(Input.prototype, EventEmitter, {
|
519
|
+
_onBlur: function onBlur() {
|
520
|
+
this.resetInputValue();
|
521
|
+
this.trigger("blurred");
|
522
|
+
},
|
523
|
+
_onFocus: function onFocus() {
|
524
|
+
this.queryWhenFocused = this.query;
|
525
|
+
this.trigger("focused");
|
526
|
+
},
|
527
|
+
_onKeydown: function onKeydown($e) {
|
528
|
+
var keyName = specialKeyCodeMap[$e.which || $e.keyCode];
|
529
|
+
this._managePreventDefault(keyName, $e);
|
530
|
+
if (keyName && this._shouldTrigger(keyName, $e)) {
|
531
|
+
this.trigger(keyName + "Keyed", $e);
|
532
|
+
}
|
533
|
+
},
|
534
|
+
_onInput: function onInput() {
|
535
|
+
this._setQuery(this.getInputValue());
|
536
|
+
this.clearHintIfInvalid();
|
537
|
+
this._checkLanguageDirection();
|
538
|
+
},
|
539
|
+
_managePreventDefault: function managePreventDefault(keyName, $e) {
|
540
|
+
var preventDefault;
|
541
|
+
switch (keyName) {
|
542
|
+
case "up":
|
543
|
+
case "down":
|
544
|
+
preventDefault = !withModifier($e);
|
545
|
+
break;
|
546
|
+
|
547
|
+
default:
|
548
|
+
preventDefault = false;
|
549
|
+
}
|
550
|
+
preventDefault && $e.preventDefault();
|
551
|
+
},
|
552
|
+
_shouldTrigger: function shouldTrigger(keyName, $e) {
|
553
|
+
var trigger;
|
554
|
+
switch (keyName) {
|
555
|
+
case "tab":
|
556
|
+
trigger = !withModifier($e);
|
557
|
+
break;
|
558
|
+
|
559
|
+
default:
|
560
|
+
trigger = true;
|
561
|
+
}
|
562
|
+
return trigger;
|
563
|
+
},
|
564
|
+
_checkLanguageDirection: function checkLanguageDirection() {
|
565
|
+
var dir = (this.$input.css("direction") || "ltr").toLowerCase();
|
566
|
+
if (this.dir !== dir) {
|
567
|
+
this.dir = dir;
|
568
|
+
this.$hint.attr("dir", dir);
|
569
|
+
this.trigger("langDirChanged", dir);
|
570
|
+
}
|
571
|
+
},
|
572
|
+
_setQuery: function setQuery(val, silent) {
|
573
|
+
var areEquivalent, hasDifferentWhitespace;
|
574
|
+
areEquivalent = areQueriesEquivalent(val, this.query);
|
575
|
+
hasDifferentWhitespace = areEquivalent ? this.query.length !== val.length : false;
|
576
|
+
this.query = val;
|
577
|
+
if (!silent && !areEquivalent) {
|
578
|
+
this.trigger("queryChanged", this.query);
|
579
|
+
} else if (!silent && hasDifferentWhitespace) {
|
580
|
+
this.trigger("whitespaceChanged", this.query);
|
581
|
+
}
|
582
|
+
},
|
583
|
+
_updateDescendent: function updateDescendent(event, id) {
|
584
|
+
this.$input.attr("aria-activedescendant", id);
|
585
|
+
},
|
586
|
+
bind: function() {
|
587
|
+
var that = this, onBlur, onFocus, onKeydown, onInput;
|
588
|
+
onBlur = _.bind(this._onBlur, this);
|
589
|
+
onFocus = _.bind(this._onFocus, this);
|
590
|
+
onKeydown = _.bind(this._onKeydown, this);
|
591
|
+
onInput = _.bind(this._onInput, this);
|
592
|
+
this.$input.on("blur.tt", onBlur).on("focus.tt", onFocus).on("keydown.tt", onKeydown);
|
593
|
+
if (!_.isMsie() || _.isMsie() > 9) {
|
594
|
+
this.$input.on("input.tt", onInput);
|
595
|
+
} else {
|
596
|
+
this.$input.on("keydown.tt keypress.tt cut.tt paste.tt", function($e) {
|
597
|
+
if (specialKeyCodeMap[$e.which || $e.keyCode]) {
|
598
|
+
return;
|
599
|
+
}
|
600
|
+
_.defer(_.bind(that._onInput, that, $e));
|
601
|
+
});
|
602
|
+
}
|
603
|
+
return this;
|
604
|
+
},
|
605
|
+
focus: function focus() {
|
606
|
+
this.$input.focus();
|
607
|
+
},
|
608
|
+
blur: function blur() {
|
609
|
+
this.$input.blur();
|
610
|
+
},
|
611
|
+
getLangDir: function getLangDir() {
|
612
|
+
return this.dir;
|
613
|
+
},
|
614
|
+
getQuery: function getQuery() {
|
615
|
+
return this.query || "";
|
616
|
+
},
|
617
|
+
setQuery: function setQuery(val, silent) {
|
618
|
+
this.setInputValue(val);
|
619
|
+
this._setQuery(val, silent);
|
620
|
+
},
|
621
|
+
hasQueryChangedSinceLastFocus: function hasQueryChangedSinceLastFocus() {
|
622
|
+
return this.query !== this.queryWhenFocused;
|
623
|
+
},
|
624
|
+
getInputValue: function getInputValue() {
|
625
|
+
return this.$input.val();
|
626
|
+
},
|
627
|
+
setInputValue: function setInputValue(value) {
|
628
|
+
this.$input.val(value);
|
629
|
+
this.clearHintIfInvalid();
|
630
|
+
this._checkLanguageDirection();
|
631
|
+
},
|
632
|
+
resetInputValue: function resetInputValue() {
|
633
|
+
this.setInputValue(this.query);
|
634
|
+
},
|
635
|
+
getHint: function getHint() {
|
636
|
+
return this.$hint.val();
|
637
|
+
},
|
638
|
+
setHint: function setHint(value) {
|
639
|
+
this.$hint.val(value);
|
640
|
+
},
|
641
|
+
clearHint: function clearHint() {
|
642
|
+
this.setHint("");
|
643
|
+
},
|
644
|
+
clearHintIfInvalid: function clearHintIfInvalid() {
|
645
|
+
var val, hint, valIsPrefixOfHint, isValid;
|
646
|
+
val = this.getInputValue();
|
647
|
+
hint = this.getHint();
|
648
|
+
valIsPrefixOfHint = val !== hint && hint.indexOf(val) === 0;
|
649
|
+
isValid = val !== "" && valIsPrefixOfHint && !this.hasOverflow();
|
650
|
+
!isValid && this.clearHint();
|
651
|
+
},
|
652
|
+
hasFocus: function hasFocus() {
|
653
|
+
return this.$input.is(":focus");
|
654
|
+
},
|
655
|
+
hasOverflow: function hasOverflow() {
|
656
|
+
var constraint = this.$input.width() - 2;
|
657
|
+
this.$overflowHelper.text(this.getInputValue());
|
658
|
+
return this.$overflowHelper.width() >= constraint;
|
659
|
+
},
|
660
|
+
isCursorAtEnd: function() {
|
661
|
+
var valueLength, selectionStart, range;
|
662
|
+
valueLength = this.$input.val().length;
|
663
|
+
selectionStart = this.$input[0].selectionStart;
|
664
|
+
if (_.isNumber(selectionStart)) {
|
665
|
+
return selectionStart === valueLength;
|
666
|
+
} else if (document.selection) {
|
667
|
+
range = document.selection.createRange();
|
668
|
+
range.moveStart("character", -valueLength);
|
669
|
+
return valueLength === range.text.length;
|
670
|
+
}
|
671
|
+
return true;
|
672
|
+
},
|
673
|
+
destroy: function destroy() {
|
674
|
+
this.$hint.off(".tt");
|
675
|
+
this.$input.off(".tt");
|
676
|
+
this.$overflowHelper.remove();
|
677
|
+
this.$hint = this.$input = this.$overflowHelper = $("<div>");
|
678
|
+
},
|
679
|
+
setAriaExpanded: function setAriaExpanded(value) {
|
680
|
+
this.$input.attr("aria-expanded", value);
|
681
|
+
}
|
682
|
+
});
|
683
|
+
return Input;
|
684
|
+
function buildOverflowHelper($input) {
|
685
|
+
return $('<pre aria-hidden="true"></pre>').css({
|
686
|
+
position: "absolute",
|
687
|
+
visibility: "hidden",
|
688
|
+
whiteSpace: "pre",
|
689
|
+
fontFamily: $input.css("font-family"),
|
690
|
+
fontSize: $input.css("font-size"),
|
691
|
+
fontStyle: $input.css("font-style"),
|
692
|
+
fontVariant: $input.css("font-variant"),
|
693
|
+
fontWeight: $input.css("font-weight"),
|
694
|
+
wordSpacing: $input.css("word-spacing"),
|
695
|
+
letterSpacing: $input.css("letter-spacing"),
|
696
|
+
textIndent: $input.css("text-indent"),
|
697
|
+
textRendering: $input.css("text-rendering"),
|
698
|
+
textTransform: $input.css("text-transform")
|
699
|
+
}).insertAfter($input);
|
700
|
+
}
|
701
|
+
function areQueriesEquivalent(a, b) {
|
702
|
+
return Input.normalizeQuery(a) === Input.normalizeQuery(b);
|
703
|
+
}
|
704
|
+
function withModifier($e) {
|
705
|
+
return $e.altKey || $e.ctrlKey || $e.metaKey || $e.shiftKey;
|
706
|
+
}
|
707
|
+
}();
|
708
|
+
var Dataset = function() {
|
709
|
+
"use strict";
|
710
|
+
var keys, nameGenerator;
|
711
|
+
keys = {
|
712
|
+
dataset: "tt-selectable-dataset",
|
713
|
+
val: "tt-selectable-display",
|
714
|
+
obj: "tt-selectable-object"
|
715
|
+
};
|
716
|
+
nameGenerator = _.getIdGenerator();
|
717
|
+
function Dataset(o, www) {
|
718
|
+
o = o || {};
|
719
|
+
o.templates = o.templates || {};
|
720
|
+
o.templates.notFound = o.templates.notFound || o.templates.empty;
|
721
|
+
if (!o.source) {
|
722
|
+
$.error("missing source");
|
723
|
+
}
|
724
|
+
if (!o.node) {
|
725
|
+
$.error("missing node");
|
726
|
+
}
|
727
|
+
if (o.name && !isValidName(o.name)) {
|
728
|
+
$.error("invalid dataset name: " + o.name);
|
729
|
+
}
|
730
|
+
www.mixin(this);
|
731
|
+
this.highlight = !!o.highlight;
|
732
|
+
this.name = _.toStr(o.name || nameGenerator());
|
733
|
+
this.limit = o.limit || 5;
|
734
|
+
this.displayFn = getDisplayFn(o.display || o.displayKey);
|
735
|
+
this.templates = getTemplates(o.templates, this.displayFn);
|
736
|
+
this.source = o.source.__ttAdapter ? o.source.__ttAdapter() : o.source;
|
737
|
+
this.async = _.isUndefined(o.async) ? this.source.length > 2 : !!o.async;
|
738
|
+
this._resetLastSuggestion();
|
739
|
+
this.$el = $(o.node).attr("role", "presentation").addClass(this.classes.dataset).addClass(this.classes.dataset + "-" + this.name);
|
740
|
+
}
|
741
|
+
Dataset.extractData = function extractData(el) {
|
742
|
+
var $el = $(el);
|
743
|
+
if ($el.data(keys.obj)) {
|
744
|
+
return {
|
745
|
+
dataset: $el.data(keys.dataset) || "",
|
746
|
+
val: $el.data(keys.val) || "",
|
747
|
+
obj: $el.data(keys.obj) || null
|
748
|
+
};
|
749
|
+
}
|
750
|
+
return null;
|
751
|
+
};
|
752
|
+
_.mixin(Dataset.prototype, EventEmitter, {
|
753
|
+
_overwrite: function overwrite(query, suggestions) {
|
754
|
+
suggestions = suggestions || [];
|
755
|
+
if (suggestions.length) {
|
756
|
+
this._renderSuggestions(query, suggestions);
|
757
|
+
} else if (this.async && this.templates.pending) {
|
758
|
+
this._renderPending(query);
|
759
|
+
} else if (!this.async && this.templates.notFound) {
|
760
|
+
this._renderNotFound(query);
|
761
|
+
} else {
|
762
|
+
this._empty();
|
763
|
+
}
|
764
|
+
this.trigger("rendered", suggestions, false, this.name);
|
765
|
+
},
|
766
|
+
_append: function append(query, suggestions) {
|
767
|
+
suggestions = suggestions || [];
|
768
|
+
if (suggestions.length && this.$lastSuggestion.length) {
|
769
|
+
this._appendSuggestions(query, suggestions);
|
770
|
+
} else if (suggestions.length) {
|
771
|
+
this._renderSuggestions(query, suggestions);
|
772
|
+
} else if (!this.$lastSuggestion.length && this.templates.notFound) {
|
773
|
+
this._renderNotFound(query);
|
774
|
+
}
|
775
|
+
this.trigger("rendered", suggestions, true, this.name);
|
776
|
+
},
|
777
|
+
_renderSuggestions: function renderSuggestions(query, suggestions) {
|
778
|
+
var $fragment;
|
779
|
+
$fragment = this._getSuggestionsFragment(query, suggestions);
|
780
|
+
this.$lastSuggestion = $fragment.children().last();
|
781
|
+
this.$el.html($fragment).prepend(this._getHeader(query, suggestions)).append(this._getFooter(query, suggestions));
|
782
|
+
},
|
783
|
+
_appendSuggestions: function appendSuggestions(query, suggestions) {
|
784
|
+
var $fragment, $lastSuggestion;
|
785
|
+
$fragment = this._getSuggestionsFragment(query, suggestions);
|
786
|
+
$lastSuggestion = $fragment.children().last();
|
787
|
+
this.$lastSuggestion.after($fragment);
|
788
|
+
this.$lastSuggestion = $lastSuggestion;
|
789
|
+
},
|
790
|
+
_renderPending: function renderPending(query) {
|
791
|
+
var template = this.templates.pending;
|
792
|
+
this._resetLastSuggestion();
|
793
|
+
template && this.$el.html(template({
|
794
|
+
query: query,
|
795
|
+
dataset: this.name
|
796
|
+
}));
|
797
|
+
},
|
798
|
+
_renderNotFound: function renderNotFound(query) {
|
799
|
+
var template = this.templates.notFound;
|
800
|
+
this._resetLastSuggestion();
|
801
|
+
template && this.$el.html(template({
|
802
|
+
query: query,
|
803
|
+
dataset: this.name
|
804
|
+
}));
|
805
|
+
},
|
806
|
+
_empty: function empty() {
|
807
|
+
this.$el.empty();
|
808
|
+
this._resetLastSuggestion();
|
809
|
+
},
|
810
|
+
_getSuggestionsFragment: function getSuggestionsFragment(query, suggestions) {
|
811
|
+
var that = this, fragment;
|
812
|
+
fragment = document.createDocumentFragment();
|
813
|
+
_.each(suggestions, function getSuggestionNode(suggestion) {
|
814
|
+
var $el, context;
|
815
|
+
context = that._injectQuery(query, suggestion);
|
816
|
+
$el = $(that.templates.suggestion(context)).data(keys.dataset, that.name).data(keys.obj, suggestion).data(keys.val, that.displayFn(suggestion)).addClass(that.classes.suggestion + " " + that.classes.selectable);
|
817
|
+
fragment.appendChild($el[0]);
|
818
|
+
});
|
819
|
+
this.highlight && highlight({
|
820
|
+
className: this.classes.highlight,
|
821
|
+
node: fragment,
|
822
|
+
pattern: query
|
823
|
+
});
|
824
|
+
return $(fragment);
|
825
|
+
},
|
826
|
+
_getFooter: function getFooter(query, suggestions) {
|
827
|
+
return this.templates.footer ? this.templates.footer({
|
828
|
+
query: query,
|
829
|
+
suggestions: suggestions,
|
830
|
+
dataset: this.name
|
831
|
+
}) : null;
|
832
|
+
},
|
833
|
+
_getHeader: function getHeader(query, suggestions) {
|
834
|
+
return this.templates.header ? this.templates.header({
|
835
|
+
query: query,
|
836
|
+
suggestions: suggestions,
|
837
|
+
dataset: this.name
|
838
|
+
}) : null;
|
839
|
+
},
|
840
|
+
_resetLastSuggestion: function resetLastSuggestion() {
|
841
|
+
this.$lastSuggestion = $();
|
842
|
+
},
|
843
|
+
_injectQuery: function injectQuery(query, obj) {
|
844
|
+
return _.isObject(obj) ? _.mixin({
|
845
|
+
_query: query
|
846
|
+
}, obj) : obj;
|
847
|
+
},
|
848
|
+
update: function update(query) {
|
849
|
+
var that = this, canceled = false, syncCalled = false, rendered = 0;
|
850
|
+
this.cancel();
|
851
|
+
this.cancel = function cancel() {
|
852
|
+
canceled = true;
|
853
|
+
that.cancel = $.noop;
|
854
|
+
that.async && that.trigger("asyncCanceled", query, that.name);
|
855
|
+
};
|
856
|
+
this.source(query, sync, async);
|
857
|
+
!syncCalled && sync([]);
|
858
|
+
function sync(suggestions) {
|
859
|
+
if (syncCalled) {
|
860
|
+
return;
|
861
|
+
}
|
862
|
+
syncCalled = true;
|
863
|
+
suggestions = (suggestions || []).slice(0, that.limit);
|
864
|
+
rendered = suggestions.length;
|
865
|
+
that._overwrite(query, suggestions);
|
866
|
+
if (rendered < that.limit && that.async) {
|
867
|
+
that.trigger("asyncRequested", query, that.name);
|
868
|
+
}
|
869
|
+
}
|
870
|
+
function async(suggestions) {
|
871
|
+
suggestions = suggestions || [];
|
872
|
+
if (!canceled && rendered < that.limit) {
|
873
|
+
that.cancel = $.noop;
|
874
|
+
var idx = Math.abs(rendered - that.limit);
|
875
|
+
rendered += idx;
|
876
|
+
that._append(query, suggestions.slice(0, idx));
|
877
|
+
that.async && that.trigger("asyncReceived", query, that.name);
|
878
|
+
}
|
879
|
+
}
|
880
|
+
},
|
881
|
+
cancel: $.noop,
|
882
|
+
clear: function clear() {
|
883
|
+
this._empty();
|
884
|
+
this.cancel();
|
885
|
+
this.trigger("cleared");
|
886
|
+
},
|
887
|
+
isEmpty: function isEmpty() {
|
888
|
+
return this.$el.is(":empty");
|
889
|
+
},
|
890
|
+
destroy: function destroy() {
|
891
|
+
this.$el = $("<div>");
|
892
|
+
}
|
893
|
+
});
|
894
|
+
return Dataset;
|
895
|
+
function getDisplayFn(display) {
|
896
|
+
display = display || _.stringify;
|
897
|
+
return _.isFunction(display) ? display : displayFn;
|
898
|
+
function displayFn(obj) {
|
899
|
+
return obj[display];
|
900
|
+
}
|
901
|
+
}
|
902
|
+
function getTemplates(templates, displayFn) {
|
903
|
+
return {
|
904
|
+
notFound: templates.notFound && _.templatify(templates.notFound),
|
905
|
+
pending: templates.pending && _.templatify(templates.pending),
|
906
|
+
header: templates.header && _.templatify(templates.header),
|
907
|
+
footer: templates.footer && _.templatify(templates.footer),
|
908
|
+
suggestion: templates.suggestion ? userSuggestionTemplate : suggestionTemplate
|
909
|
+
};
|
910
|
+
function userSuggestionTemplate(context) {
|
911
|
+
var template = templates.suggestion;
|
912
|
+
return $(template(context)).attr("id", _.guid());
|
913
|
+
}
|
914
|
+
function suggestionTemplate(context) {
|
915
|
+
return $('<div role="option">').attr("id", _.guid()).text(displayFn(context));
|
916
|
+
}
|
917
|
+
}
|
918
|
+
function isValidName(str) {
|
919
|
+
return /^[_a-zA-Z0-9-]+$/.test(str);
|
920
|
+
}
|
921
|
+
}();
|
922
|
+
var Menu = function() {
|
923
|
+
"use strict";
|
924
|
+
function Menu(o, www) {
|
925
|
+
var that = this;
|
926
|
+
o = o || {};
|
927
|
+
if (!o.node) {
|
928
|
+
$.error("node is required");
|
929
|
+
}
|
930
|
+
www.mixin(this);
|
931
|
+
this.$node = $(o.node);
|
932
|
+
this.query = null;
|
933
|
+
this.datasets = _.map(o.datasets, initializeDataset);
|
934
|
+
function initializeDataset(oDataset) {
|
935
|
+
var node = that.$node.find(oDataset.node).first();
|
936
|
+
oDataset.node = node.length ? node : $("<div>").appendTo(that.$node);
|
937
|
+
return new Dataset(oDataset, www);
|
938
|
+
}
|
939
|
+
}
|
940
|
+
_.mixin(Menu.prototype, EventEmitter, {
|
941
|
+
_onSelectableClick: function onSelectableClick($e) {
|
942
|
+
this.trigger("selectableClicked", $($e.currentTarget));
|
943
|
+
},
|
944
|
+
_onRendered: function onRendered(type, dataset, suggestions, async) {
|
945
|
+
this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty());
|
946
|
+
this.trigger("datasetRendered", dataset, suggestions, async);
|
947
|
+
},
|
948
|
+
_onCleared: function onCleared() {
|
949
|
+
this.$node.toggleClass(this.classes.empty, this._allDatasetsEmpty());
|
950
|
+
this.trigger("datasetCleared");
|
951
|
+
},
|
952
|
+
_propagate: function propagate() {
|
953
|
+
this.trigger.apply(this, arguments);
|
954
|
+
},
|
955
|
+
_allDatasetsEmpty: function allDatasetsEmpty() {
|
956
|
+
return _.every(this.datasets, _.bind(function isDatasetEmpty(dataset) {
|
957
|
+
var isEmpty = dataset.isEmpty();
|
958
|
+
this.$node.attr("aria-expanded", !isEmpty);
|
959
|
+
return isEmpty;
|
960
|
+
}, this));
|
961
|
+
},
|
962
|
+
_getSelectables: function getSelectables() {
|
963
|
+
return this.$node.find(this.selectors.selectable);
|
964
|
+
},
|
965
|
+
_removeCursor: function _removeCursor() {
|
966
|
+
var $selectable = this.getActiveSelectable();
|
967
|
+
$selectable && $selectable.removeClass(this.classes.cursor);
|
968
|
+
},
|
969
|
+
_ensureVisible: function ensureVisible($el) {
|
970
|
+
var elTop, elBottom, nodeScrollTop, nodeHeight;
|
971
|
+
elTop = $el.position().top;
|
972
|
+
elBottom = elTop + $el.outerHeight(true);
|
973
|
+
nodeScrollTop = this.$node.scrollTop();
|
974
|
+
nodeHeight = this.$node.height() + parseInt(this.$node.css("paddingTop"), 10) + parseInt(this.$node.css("paddingBottom"), 10);
|
975
|
+
if (elTop < 0) {
|
976
|
+
this.$node.scrollTop(nodeScrollTop + elTop);
|
977
|
+
} else if (nodeHeight < elBottom) {
|
978
|
+
this.$node.scrollTop(nodeScrollTop + (elBottom - nodeHeight));
|
979
|
+
}
|
980
|
+
},
|
981
|
+
bind: function() {
|
982
|
+
var that = this, onSelectableClick;
|
983
|
+
onSelectableClick = _.bind(this._onSelectableClick, this);
|
984
|
+
this.$node.on("click.tt", this.selectors.selectable, onSelectableClick);
|
985
|
+
this.$node.on("mouseover", this.selectors.selectable, function() {
|
986
|
+
that.setCursor($(this));
|
987
|
+
});
|
988
|
+
this.$node.on("mouseleave", function() {
|
989
|
+
that._removeCursor();
|
990
|
+
});
|
991
|
+
_.each(this.datasets, function(dataset) {
|
992
|
+
dataset.onSync("asyncRequested", that._propagate, that).onSync("asyncCanceled", that._propagate, that).onSync("asyncReceived", that._propagate, that).onSync("rendered", that._onRendered, that).onSync("cleared", that._onCleared, that);
|
993
|
+
});
|
994
|
+
return this;
|
995
|
+
},
|
996
|
+
isOpen: function isOpen() {
|
997
|
+
return this.$node.hasClass(this.classes.open);
|
998
|
+
},
|
999
|
+
open: function open() {
|
1000
|
+
this.$node.scrollTop(0);
|
1001
|
+
this.$node.addClass(this.classes.open);
|
1002
|
+
},
|
1003
|
+
close: function close() {
|
1004
|
+
this.$node.attr("aria-expanded", false);
|
1005
|
+
this.$node.removeClass(this.classes.open);
|
1006
|
+
this._removeCursor();
|
1007
|
+
},
|
1008
|
+
setLanguageDirection: function setLanguageDirection(dir) {
|
1009
|
+
this.$node.attr("dir", dir);
|
1010
|
+
},
|
1011
|
+
selectableRelativeToCursor: function selectableRelativeToCursor(delta) {
|
1012
|
+
var $selectables, $oldCursor, oldIndex, newIndex;
|
1013
|
+
$oldCursor = this.getActiveSelectable();
|
1014
|
+
$selectables = this._getSelectables();
|
1015
|
+
oldIndex = $oldCursor ? $selectables.index($oldCursor) : -1;
|
1016
|
+
newIndex = oldIndex + delta;
|
1017
|
+
newIndex = (newIndex + 1) % ($selectables.length + 1) - 1;
|
1018
|
+
newIndex = newIndex < -1 ? $selectables.length - 1 : newIndex;
|
1019
|
+
return newIndex === -1 ? null : $selectables.eq(newIndex);
|
1020
|
+
},
|
1021
|
+
setCursor: function setCursor($selectable) {
|
1022
|
+
this._removeCursor();
|
1023
|
+
if ($selectable = $selectable && $selectable.first()) {
|
1024
|
+
$selectable.addClass(this.classes.cursor);
|
1025
|
+
this._ensureVisible($selectable);
|
1026
|
+
}
|
1027
|
+
},
|
1028
|
+
getSelectableData: function getSelectableData($el) {
|
1029
|
+
return $el && $el.length ? Dataset.extractData($el) : null;
|
1030
|
+
},
|
1031
|
+
getActiveSelectable: function getActiveSelectable() {
|
1032
|
+
var $selectable = this._getSelectables().filter(this.selectors.cursor).first();
|
1033
|
+
return $selectable.length ? $selectable : null;
|
1034
|
+
},
|
1035
|
+
getTopSelectable: function getTopSelectable() {
|
1036
|
+
var $selectable = this._getSelectables().first();
|
1037
|
+
return $selectable.length ? $selectable : null;
|
1038
|
+
},
|
1039
|
+
update: function update(query) {
|
1040
|
+
var isValidUpdate = query !== this.query;
|
1041
|
+
if (isValidUpdate) {
|
1042
|
+
this.query = query;
|
1043
|
+
_.each(this.datasets, updateDataset);
|
1044
|
+
}
|
1045
|
+
return isValidUpdate;
|
1046
|
+
function updateDataset(dataset) {
|
1047
|
+
dataset.update(query);
|
1048
|
+
}
|
1049
|
+
},
|
1050
|
+
empty: function empty() {
|
1051
|
+
_.each(this.datasets, clearDataset);
|
1052
|
+
this.query = null;
|
1053
|
+
this.$node.addClass(this.classes.empty);
|
1054
|
+
function clearDataset(dataset) {
|
1055
|
+
dataset.clear();
|
1056
|
+
}
|
1057
|
+
},
|
1058
|
+
destroy: function destroy() {
|
1059
|
+
this.$node.off(".tt");
|
1060
|
+
this.$node = $("<div>");
|
1061
|
+
_.each(this.datasets, destroyDataset);
|
1062
|
+
function destroyDataset(dataset) {
|
1063
|
+
dataset.destroy();
|
1064
|
+
}
|
1065
|
+
}
|
1066
|
+
});
|
1067
|
+
return Menu;
|
1068
|
+
}();
|
1069
|
+
var Status = function() {
|
1070
|
+
"use strict";
|
1071
|
+
function Status(options) {
|
1072
|
+
this.$el = $("<span></span>", {
|
1073
|
+
role: "status",
|
1074
|
+
"aria-live": "polite"
|
1075
|
+
}).css({
|
1076
|
+
position: "absolute",
|
1077
|
+
padding: "0",
|
1078
|
+
border: "0",
|
1079
|
+
height: "1px",
|
1080
|
+
width: "1px",
|
1081
|
+
"margin-bottom": "-1px",
|
1082
|
+
"margin-right": "-1px",
|
1083
|
+
overflow: "hidden",
|
1084
|
+
clip: "rect(0 0 0 0)",
|
1085
|
+
"white-space": "nowrap"
|
1086
|
+
});
|
1087
|
+
options.$input.after(this.$el);
|
1088
|
+
_.each(options.menu.datasets, _.bind(function(dataset) {
|
1089
|
+
if (dataset.onSync) {
|
1090
|
+
dataset.onSync("rendered", _.bind(this.update, this));
|
1091
|
+
dataset.onSync("cleared", _.bind(this.cleared, this));
|
1092
|
+
}
|
1093
|
+
}, this));
|
1094
|
+
}
|
1095
|
+
_.mixin(Status.prototype, {
|
1096
|
+
update: function update(event, suggestions) {
|
1097
|
+
var length = suggestions.length;
|
1098
|
+
var words;
|
1099
|
+
if (length === 1) {
|
1100
|
+
words = {
|
1101
|
+
result: "result",
|
1102
|
+
is: "is"
|
1103
|
+
};
|
1104
|
+
} else {
|
1105
|
+
words = {
|
1106
|
+
result: "results",
|
1107
|
+
is: "are"
|
1108
|
+
};
|
1109
|
+
}
|
1110
|
+
this.$el.text(length + " " + words.result + " " + words.is + " available, use up and down arrow keys to navigate.");
|
1111
|
+
},
|
1112
|
+
cleared: function() {
|
1113
|
+
this.$el.text("");
|
1114
|
+
}
|
1115
|
+
});
|
1116
|
+
return Status;
|
1117
|
+
}();
|
1118
|
+
var DefaultMenu = function() {
|
1119
|
+
"use strict";
|
1120
|
+
var s = Menu.prototype;
|
1121
|
+
function DefaultMenu() {
|
1122
|
+
Menu.apply(this, [].slice.call(arguments, 0));
|
1123
|
+
}
|
1124
|
+
_.mixin(DefaultMenu.prototype, Menu.prototype, {
|
1125
|
+
open: function open() {
|
1126
|
+
!this._allDatasetsEmpty() && this._show();
|
1127
|
+
return s.open.apply(this, [].slice.call(arguments, 0));
|
1128
|
+
},
|
1129
|
+
close: function close() {
|
1130
|
+
this._hide();
|
1131
|
+
return s.close.apply(this, [].slice.call(arguments, 0));
|
1132
|
+
},
|
1133
|
+
_onRendered: function onRendered() {
|
1134
|
+
if (this._allDatasetsEmpty()) {
|
1135
|
+
this._hide();
|
1136
|
+
} else {
|
1137
|
+
this.isOpen() && this._show();
|
1138
|
+
}
|
1139
|
+
return s._onRendered.apply(this, [].slice.call(arguments, 0));
|
1140
|
+
},
|
1141
|
+
_onCleared: function onCleared() {
|
1142
|
+
if (this._allDatasetsEmpty()) {
|
1143
|
+
this._hide();
|
1144
|
+
} else {
|
1145
|
+
this.isOpen() && this._show();
|
1146
|
+
}
|
1147
|
+
return s._onCleared.apply(this, [].slice.call(arguments, 0));
|
1148
|
+
},
|
1149
|
+
setLanguageDirection: function setLanguageDirection(dir) {
|
1150
|
+
this.$node.css(dir === "ltr" ? this.css.ltr : this.css.rtl);
|
1151
|
+
return s.setLanguageDirection.apply(this, [].slice.call(arguments, 0));
|
1152
|
+
},
|
1153
|
+
_hide: function hide() {
|
1154
|
+
this.$node.hide();
|
1155
|
+
},
|
1156
|
+
_show: function show() {
|
1157
|
+
this.$node.css("display", "block");
|
1158
|
+
}
|
1159
|
+
});
|
1160
|
+
return DefaultMenu;
|
1161
|
+
}();
|
1162
|
+
var Typeahead = function() {
|
1163
|
+
"use strict";
|
1164
|
+
function Typeahead(o, www) {
|
1165
|
+
var onFocused, onBlurred, onEnterKeyed, onTabKeyed, onEscKeyed, onUpKeyed, onDownKeyed, onLeftKeyed, onRightKeyed, onQueryChanged, onWhitespaceChanged;
|
1166
|
+
o = o || {};
|
1167
|
+
if (!o.input) {
|
1168
|
+
$.error("missing input");
|
1169
|
+
}
|
1170
|
+
if (!o.menu) {
|
1171
|
+
$.error("missing menu");
|
1172
|
+
}
|
1173
|
+
if (!o.eventBus) {
|
1174
|
+
$.error("missing event bus");
|
1175
|
+
}
|
1176
|
+
www.mixin(this);
|
1177
|
+
this.eventBus = o.eventBus;
|
1178
|
+
this.minLength = _.isNumber(o.minLength) ? o.minLength : 1;
|
1179
|
+
this.input = o.input;
|
1180
|
+
this.menu = o.menu;
|
1181
|
+
this.enabled = true;
|
1182
|
+
this.autoselect = !!o.autoselect;
|
1183
|
+
this.active = false;
|
1184
|
+
this.input.hasFocus() && this.activate();
|
1185
|
+
this.dir = this.input.getLangDir();
|
1186
|
+
this._hacks();
|
1187
|
+
this.menu.bind().onSync("selectableClicked", this._onSelectableClicked, this).onSync("asyncRequested", this._onAsyncRequested, this).onSync("asyncCanceled", this._onAsyncCanceled, this).onSync("asyncReceived", this._onAsyncReceived, this).onSync("datasetRendered", this._onDatasetRendered, this).onSync("datasetCleared", this._onDatasetCleared, this);
|
1188
|
+
onFocused = c(this, "activate", "open", "_onFocused");
|
1189
|
+
onBlurred = c(this, "deactivate", "_onBlurred");
|
1190
|
+
onEnterKeyed = c(this, "isActive", "isOpen", "_onEnterKeyed");
|
1191
|
+
onTabKeyed = c(this, "isActive", "isOpen", "_onTabKeyed");
|
1192
|
+
onEscKeyed = c(this, "isActive", "_onEscKeyed");
|
1193
|
+
onUpKeyed = c(this, "isActive", "open", "_onUpKeyed");
|
1194
|
+
onDownKeyed = c(this, "isActive", "open", "_onDownKeyed");
|
1195
|
+
onLeftKeyed = c(this, "isActive", "isOpen", "_onLeftKeyed");
|
1196
|
+
onRightKeyed = c(this, "isActive", "isOpen", "_onRightKeyed");
|
1197
|
+
onQueryChanged = c(this, "_openIfActive", "_onQueryChanged");
|
1198
|
+
onWhitespaceChanged = c(this, "_openIfActive", "_onWhitespaceChanged");
|
1199
|
+
this.input.bind().onSync("focused", onFocused, this).onSync("blurred", onBlurred, this).onSync("enterKeyed", onEnterKeyed, this).onSync("tabKeyed", onTabKeyed, this).onSync("escKeyed", onEscKeyed, this).onSync("upKeyed", onUpKeyed, this).onSync("downKeyed", onDownKeyed, this).onSync("leftKeyed", onLeftKeyed, this).onSync("rightKeyed", onRightKeyed, this).onSync("queryChanged", onQueryChanged, this).onSync("whitespaceChanged", onWhitespaceChanged, this).onSync("langDirChanged", this._onLangDirChanged, this);
|
1200
|
+
}
|
1201
|
+
_.mixin(Typeahead.prototype, {
|
1202
|
+
_hacks: function hacks() {
|
1203
|
+
var $input, $menu;
|
1204
|
+
$input = this.input.$input || $("<div>");
|
1205
|
+
$menu = this.menu.$node || $("<div>");
|
1206
|
+
$input.on("blur.tt", function($e) {
|
1207
|
+
var active, isActive, hasActive;
|
1208
|
+
active = document.activeElement;
|
1209
|
+
isActive = $menu.is(active);
|
1210
|
+
hasActive = $menu.has(active).length > 0;
|
1211
|
+
if (_.isMsie() && (isActive || hasActive)) {
|
1212
|
+
$e.preventDefault();
|
1213
|
+
$e.stopImmediatePropagation();
|
1214
|
+
_.defer(function() {
|
1215
|
+
$input.focus();
|
1216
|
+
});
|
1217
|
+
}
|
1218
|
+
});
|
1219
|
+
$menu.on("mousedown.tt", function($e) {
|
1220
|
+
$e.preventDefault();
|
1221
|
+
});
|
1222
|
+
},
|
1223
|
+
_onSelectableClicked: function onSelectableClicked(type, $el) {
|
1224
|
+
this.select($el);
|
1225
|
+
},
|
1226
|
+
_onDatasetCleared: function onDatasetCleared() {
|
1227
|
+
this._updateHint();
|
1228
|
+
},
|
1229
|
+
_onDatasetRendered: function onDatasetRendered(type, suggestions, async, dataset) {
|
1230
|
+
this._updateHint();
|
1231
|
+
if (this.autoselect) {
|
1232
|
+
var cursorClass = this.selectors.cursor.substr(1);
|
1233
|
+
this.menu.$node.find(this.selectors.suggestion).first().addClass(cursorClass);
|
1234
|
+
}
|
1235
|
+
this.eventBus.trigger("render", suggestions, async, dataset);
|
1236
|
+
},
|
1237
|
+
_onAsyncRequested: function onAsyncRequested(type, dataset, query) {
|
1238
|
+
this.eventBus.trigger("asyncrequest", query, dataset);
|
1239
|
+
},
|
1240
|
+
_onAsyncCanceled: function onAsyncCanceled(type, dataset, query) {
|
1241
|
+
this.eventBus.trigger("asynccancel", query, dataset);
|
1242
|
+
},
|
1243
|
+
_onAsyncReceived: function onAsyncReceived(type, dataset, query) {
|
1244
|
+
this.eventBus.trigger("asyncreceive", query, dataset);
|
1245
|
+
},
|
1246
|
+
_onFocused: function onFocused() {
|
1247
|
+
this._minLengthMet() && this.menu.update(this.input.getQuery());
|
1248
|
+
},
|
1249
|
+
_onBlurred: function onBlurred() {
|
1250
|
+
if (this.input.hasQueryChangedSinceLastFocus()) {
|
1251
|
+
this.eventBus.trigger("change", this.input.getQuery());
|
1252
|
+
}
|
1253
|
+
},
|
1254
|
+
_onEnterKeyed: function onEnterKeyed(type, $e) {
|
1255
|
+
var $selectable;
|
1256
|
+
if ($selectable = this.menu.getActiveSelectable()) {
|
1257
|
+
if (this.select($selectable)) {
|
1258
|
+
$e.preventDefault();
|
1259
|
+
$e.stopPropagation();
|
1260
|
+
}
|
1261
|
+
} else if (this.autoselect) {
|
1262
|
+
if (this.select(this.menu.getTopSelectable())) {
|
1263
|
+
$e.preventDefault();
|
1264
|
+
$e.stopPropagation();
|
1265
|
+
}
|
1266
|
+
}
|
1267
|
+
},
|
1268
|
+
_onTabKeyed: function onTabKeyed(type, $e) {
|
1269
|
+
var $selectable;
|
1270
|
+
if ($selectable = this.menu.getActiveSelectable()) {
|
1271
|
+
this.select($selectable) && $e.preventDefault();
|
1272
|
+
} else if (this.autoselect) {
|
1273
|
+
if ($selectable = this.menu.getTopSelectable()) {
|
1274
|
+
this.autocomplete($selectable) && $e.preventDefault();
|
1275
|
+
}
|
1276
|
+
}
|
1277
|
+
},
|
1278
|
+
_onEscKeyed: function onEscKeyed() {
|
1279
|
+
this.close();
|
1280
|
+
},
|
1281
|
+
_onUpKeyed: function onUpKeyed() {
|
1282
|
+
this.moveCursor(-1);
|
1283
|
+
},
|
1284
|
+
_onDownKeyed: function onDownKeyed() {
|
1285
|
+
this.moveCursor(+1);
|
1286
|
+
},
|
1287
|
+
_onLeftKeyed: function onLeftKeyed() {
|
1288
|
+
if (this.dir === "rtl" && this.input.isCursorAtEnd()) {
|
1289
|
+
this.autocomplete(this.menu.getActiveSelectable() || this.menu.getTopSelectable());
|
1290
|
+
}
|
1291
|
+
},
|
1292
|
+
_onRightKeyed: function onRightKeyed() {
|
1293
|
+
if (this.dir === "ltr" && this.input.isCursorAtEnd()) {
|
1294
|
+
this.autocomplete(this.menu.getActiveSelectable() || this.menu.getTopSelectable());
|
1295
|
+
}
|
1296
|
+
},
|
1297
|
+
_onQueryChanged: function onQueryChanged(e, query) {
|
1298
|
+
this._minLengthMet(query) ? this.menu.update(query) : this.menu.empty();
|
1299
|
+
},
|
1300
|
+
_onWhitespaceChanged: function onWhitespaceChanged() {
|
1301
|
+
this._updateHint();
|
1302
|
+
},
|
1303
|
+
_onLangDirChanged: function onLangDirChanged(e, dir) {
|
1304
|
+
if (this.dir !== dir) {
|
1305
|
+
this.dir = dir;
|
1306
|
+
this.menu.setLanguageDirection(dir);
|
1307
|
+
}
|
1308
|
+
},
|
1309
|
+
_openIfActive: function openIfActive() {
|
1310
|
+
this.isActive() && this.open();
|
1311
|
+
},
|
1312
|
+
_minLengthMet: function minLengthMet(query) {
|
1313
|
+
query = _.isString(query) ? query : this.input.getQuery() || "";
|
1314
|
+
return query.length >= this.minLength;
|
1315
|
+
},
|
1316
|
+
_updateHint: function updateHint() {
|
1317
|
+
var $selectable, data, val, query, escapedQuery, frontMatchRegEx, match;
|
1318
|
+
$selectable = this.menu.getTopSelectable();
|
1319
|
+
data = this.menu.getSelectableData($selectable);
|
1320
|
+
val = this.input.getInputValue();
|
1321
|
+
if (data && !_.isBlankString(val) && !this.input.hasOverflow()) {
|
1322
|
+
query = Input.normalizeQuery(val);
|
1323
|
+
escapedQuery = _.escapeRegExChars(query);
|
1324
|
+
frontMatchRegEx = new RegExp("^(?:" + escapedQuery + ")(.+$)", "i");
|
1325
|
+
match = frontMatchRegEx.exec(data.val);
|
1326
|
+
match && this.input.setHint(val + match[1]);
|
1327
|
+
} else {
|
1328
|
+
this.input.clearHint();
|
1329
|
+
}
|
1330
|
+
},
|
1331
|
+
isEnabled: function isEnabled() {
|
1332
|
+
return this.enabled;
|
1333
|
+
},
|
1334
|
+
enable: function enable() {
|
1335
|
+
this.enabled = true;
|
1336
|
+
},
|
1337
|
+
disable: function disable() {
|
1338
|
+
this.enabled = false;
|
1339
|
+
},
|
1340
|
+
isActive: function isActive() {
|
1341
|
+
return this.active;
|
1342
|
+
},
|
1343
|
+
activate: function activate() {
|
1344
|
+
if (this.isActive()) {
|
1345
|
+
return true;
|
1346
|
+
} else if (!this.isEnabled() || this.eventBus.before("active")) {
|
1347
|
+
return false;
|
1348
|
+
} else {
|
1349
|
+
this.active = true;
|
1350
|
+
this.eventBus.trigger("active");
|
1351
|
+
return true;
|
1352
|
+
}
|
1353
|
+
},
|
1354
|
+
deactivate: function deactivate() {
|
1355
|
+
if (!this.isActive()) {
|
1356
|
+
return true;
|
1357
|
+
} else if (this.eventBus.before("idle")) {
|
1358
|
+
return false;
|
1359
|
+
} else {
|
1360
|
+
this.active = false;
|
1361
|
+
this.close();
|
1362
|
+
this.eventBus.trigger("idle");
|
1363
|
+
return true;
|
1364
|
+
}
|
1365
|
+
},
|
1366
|
+
isOpen: function isOpen() {
|
1367
|
+
return this.menu.isOpen();
|
1368
|
+
},
|
1369
|
+
open: function open() {
|
1370
|
+
if (!this.isOpen() && !this.eventBus.before("open")) {
|
1371
|
+
this.input.setAriaExpanded(true);
|
1372
|
+
this.menu.open();
|
1373
|
+
this._updateHint();
|
1374
|
+
this.eventBus.trigger("open");
|
1375
|
+
}
|
1376
|
+
return this.isOpen();
|
1377
|
+
},
|
1378
|
+
close: function close() {
|
1379
|
+
if (this.isOpen() && !this.eventBus.before("close")) {
|
1380
|
+
this.input.setAriaExpanded(false);
|
1381
|
+
this.menu.close();
|
1382
|
+
this.input.clearHint();
|
1383
|
+
this.input.resetInputValue();
|
1384
|
+
this.eventBus.trigger("close");
|
1385
|
+
}
|
1386
|
+
return !this.isOpen();
|
1387
|
+
},
|
1388
|
+
setVal: function setVal(val) {
|
1389
|
+
this.input.setQuery(_.toStr(val));
|
1390
|
+
},
|
1391
|
+
getVal: function getVal() {
|
1392
|
+
return this.input.getQuery();
|
1393
|
+
},
|
1394
|
+
select: function select($selectable) {
|
1395
|
+
var data = this.menu.getSelectableData($selectable);
|
1396
|
+
if (data && !this.eventBus.before("select", data.obj, data.dataset)) {
|
1397
|
+
this.input.setQuery(data.val, true);
|
1398
|
+
this.eventBus.trigger("select", data.obj, data.dataset);
|
1399
|
+
this.close();
|
1400
|
+
return true;
|
1401
|
+
}
|
1402
|
+
return false;
|
1403
|
+
},
|
1404
|
+
autocomplete: function autocomplete($selectable) {
|
1405
|
+
var query, data, isValid;
|
1406
|
+
query = this.input.getQuery();
|
1407
|
+
data = this.menu.getSelectableData($selectable);
|
1408
|
+
isValid = data && query !== data.val;
|
1409
|
+
if (isValid && !this.eventBus.before("autocomplete", data.obj, data.dataset)) {
|
1410
|
+
this.input.setQuery(data.val);
|
1411
|
+
this.eventBus.trigger("autocomplete", data.obj, data.dataset);
|
1412
|
+
return true;
|
1413
|
+
}
|
1414
|
+
return false;
|
1415
|
+
},
|
1416
|
+
moveCursor: function moveCursor(delta) {
|
1417
|
+
var query, $candidate, data, suggestion, datasetName, cancelMove, id;
|
1418
|
+
query = this.input.getQuery();
|
1419
|
+
$candidate = this.menu.selectableRelativeToCursor(delta);
|
1420
|
+
data = this.menu.getSelectableData($candidate);
|
1421
|
+
suggestion = data ? data.obj : null;
|
1422
|
+
datasetName = data ? data.dataset : null;
|
1423
|
+
id = $candidate ? $candidate.attr("id") : null;
|
1424
|
+
this.input.trigger("cursorchange", id);
|
1425
|
+
cancelMove = this._minLengthMet() && this.menu.update(query);
|
1426
|
+
if (!cancelMove && !this.eventBus.before("cursorchange", suggestion, datasetName)) {
|
1427
|
+
this.menu.setCursor($candidate);
|
1428
|
+
if (data) {
|
1429
|
+
if (typeof data.val === "string") {
|
1430
|
+
this.input.setInputValue(data.val);
|
1431
|
+
}
|
1432
|
+
} else {
|
1433
|
+
this.input.resetInputValue();
|
1434
|
+
this._updateHint();
|
1435
|
+
}
|
1436
|
+
this.eventBus.trigger("cursorchange", suggestion, datasetName);
|
1437
|
+
return true;
|
1438
|
+
}
|
1439
|
+
return false;
|
1440
|
+
},
|
1441
|
+
destroy: function destroy() {
|
1442
|
+
this.input.destroy();
|
1443
|
+
this.menu.destroy();
|
1444
|
+
}
|
1445
|
+
});
|
1446
|
+
return Typeahead;
|
1447
|
+
function c(ctx) {
|
1448
|
+
var methods = [].slice.call(arguments, 1);
|
1449
|
+
return function() {
|
1450
|
+
var args = [].slice.call(arguments);
|
1451
|
+
_.each(methods, function(method) {
|
1452
|
+
return ctx[method].apply(ctx, args);
|
1453
|
+
});
|
1454
|
+
};
|
1455
|
+
}
|
1456
|
+
}();
|
1457
|
+
(function() {
|
1458
|
+
"use strict";
|
1459
|
+
var old, keys, methods;
|
1460
|
+
old = $.fn.typeahead;
|
1461
|
+
keys = {
|
1462
|
+
www: "tt-www",
|
1463
|
+
attrs: "tt-attrs",
|
1464
|
+
typeahead: "tt-typeahead"
|
1465
|
+
};
|
1466
|
+
methods = {
|
1467
|
+
initialize: function initialize(o, datasets) {
|
1468
|
+
var www;
|
1469
|
+
datasets = _.isArray(datasets) ? datasets : [].slice.call(arguments, 1);
|
1470
|
+
o = o || {};
|
1471
|
+
www = WWW(o.classNames);
|
1472
|
+
return this.each(attach);
|
1473
|
+
function attach() {
|
1474
|
+
var $input, $wrapper, $hint, $menu, defaultHint, defaultMenu, eventBus, input, menu, status, typeahead, MenuConstructor;
|
1475
|
+
_.each(datasets, function(d) {
|
1476
|
+
d.highlight = !!o.highlight;
|
1477
|
+
});
|
1478
|
+
$input = $(this);
|
1479
|
+
$wrapper = $(www.html.wrapper);
|
1480
|
+
$hint = $elOrNull(o.hint);
|
1481
|
+
$menu = $elOrNull(o.menu);
|
1482
|
+
defaultHint = o.hint !== false && !$hint;
|
1483
|
+
defaultMenu = o.menu !== false && !$menu;
|
1484
|
+
defaultHint && ($hint = buildHintFromInput($input, www));
|
1485
|
+
defaultMenu && ($menu = $(www.html.menu).css(www.css.menu));
|
1486
|
+
$hint && $hint.val("");
|
1487
|
+
$input = prepInput($input, www);
|
1488
|
+
if (defaultHint || defaultMenu) {
|
1489
|
+
$wrapper.css(www.css.wrapper);
|
1490
|
+
$input.css(defaultHint ? www.css.input : www.css.inputWithNoHint);
|
1491
|
+
$input.wrap($wrapper).parent().prepend(defaultHint ? $hint : null).append(defaultMenu ? $menu : null);
|
1492
|
+
}
|
1493
|
+
MenuConstructor = defaultMenu ? DefaultMenu : Menu;
|
1494
|
+
eventBus = new EventBus({
|
1495
|
+
el: $input
|
1496
|
+
});
|
1497
|
+
input = new Input({
|
1498
|
+
hint: $hint,
|
1499
|
+
input: $input,
|
1500
|
+
menu: $menu
|
1501
|
+
}, www);
|
1502
|
+
menu = new MenuConstructor({
|
1503
|
+
node: $menu,
|
1504
|
+
datasets: datasets
|
1505
|
+
}, www);
|
1506
|
+
status = new Status({
|
1507
|
+
$input: $input,
|
1508
|
+
menu: menu
|
1509
|
+
});
|
1510
|
+
typeahead = new Typeahead({
|
1511
|
+
input: input,
|
1512
|
+
menu: menu,
|
1513
|
+
eventBus: eventBus,
|
1514
|
+
minLength: o.minLength,
|
1515
|
+
autoselect: o.autoselect
|
1516
|
+
}, www);
|
1517
|
+
$input.data(keys.www, www);
|
1518
|
+
$input.data(keys.typeahead, typeahead);
|
1519
|
+
}
|
1520
|
+
},
|
1521
|
+
isEnabled: function isEnabled() {
|
1522
|
+
var enabled;
|
1523
|
+
ttEach(this.first(), function(t) {
|
1524
|
+
enabled = t.isEnabled();
|
1525
|
+
});
|
1526
|
+
return enabled;
|
1527
|
+
},
|
1528
|
+
enable: function enable() {
|
1529
|
+
ttEach(this, function(t) {
|
1530
|
+
t.enable();
|
1531
|
+
});
|
1532
|
+
return this;
|
1533
|
+
},
|
1534
|
+
disable: function disable() {
|
1535
|
+
ttEach(this, function(t) {
|
1536
|
+
t.disable();
|
1537
|
+
});
|
1538
|
+
return this;
|
1539
|
+
},
|
1540
|
+
isActive: function isActive() {
|
1541
|
+
var active;
|
1542
|
+
ttEach(this.first(), function(t) {
|
1543
|
+
active = t.isActive();
|
1544
|
+
});
|
1545
|
+
return active;
|
1546
|
+
},
|
1547
|
+
activate: function activate() {
|
1548
|
+
ttEach(this, function(t) {
|
1549
|
+
t.activate();
|
1550
|
+
});
|
1551
|
+
return this;
|
1552
|
+
},
|
1553
|
+
deactivate: function deactivate() {
|
1554
|
+
ttEach(this, function(t) {
|
1555
|
+
t.deactivate();
|
1556
|
+
});
|
1557
|
+
return this;
|
1558
|
+
},
|
1559
|
+
isOpen: function isOpen() {
|
1560
|
+
var open;
|
1561
|
+
ttEach(this.first(), function(t) {
|
1562
|
+
open = t.isOpen();
|
1563
|
+
});
|
1564
|
+
return open;
|
1565
|
+
},
|
1566
|
+
open: function open() {
|
1567
|
+
ttEach(this, function(t) {
|
1568
|
+
t.open();
|
1569
|
+
});
|
1570
|
+
return this;
|
1571
|
+
},
|
1572
|
+
close: function close() {
|
1573
|
+
ttEach(this, function(t) {
|
1574
|
+
t.close();
|
1575
|
+
});
|
1576
|
+
return this;
|
1577
|
+
},
|
1578
|
+
select: function select(el) {
|
1579
|
+
var success = false, $el = $(el);
|
1580
|
+
ttEach(this.first(), function(t) {
|
1581
|
+
success = t.select($el);
|
1582
|
+
});
|
1583
|
+
return success;
|
1584
|
+
},
|
1585
|
+
autocomplete: function autocomplete(el) {
|
1586
|
+
var success = false, $el = $(el);
|
1587
|
+
ttEach(this.first(), function(t) {
|
1588
|
+
success = t.autocomplete($el);
|
1589
|
+
});
|
1590
|
+
return success;
|
1591
|
+
},
|
1592
|
+
moveCursor: function moveCursoe(delta) {
|
1593
|
+
var success = false;
|
1594
|
+
ttEach(this.first(), function(t) {
|
1595
|
+
success = t.moveCursor(delta);
|
1596
|
+
});
|
1597
|
+
return success;
|
1598
|
+
},
|
1599
|
+
val: function val(newVal) {
|
1600
|
+
var query;
|
1601
|
+
if (!arguments.length) {
|
1602
|
+
ttEach(this.first(), function(t) {
|
1603
|
+
query = t.getVal();
|
1604
|
+
});
|
1605
|
+
return query;
|
1606
|
+
} else {
|
1607
|
+
ttEach(this, function(t) {
|
1608
|
+
t.setVal(_.toStr(newVal));
|
1609
|
+
});
|
1610
|
+
return this;
|
1611
|
+
}
|
1612
|
+
},
|
1613
|
+
destroy: function destroy() {
|
1614
|
+
ttEach(this, function(typeahead, $input) {
|
1615
|
+
revert($input);
|
1616
|
+
typeahead.destroy();
|
1617
|
+
});
|
1618
|
+
return this;
|
1619
|
+
}
|
1620
|
+
};
|
1621
|
+
$.fn.typeahead = function(method) {
|
1622
|
+
if (methods[method]) {
|
1623
|
+
return methods[method].apply(this, [].slice.call(arguments, 1));
|
1624
|
+
} else {
|
1625
|
+
return methods.initialize.apply(this, arguments);
|
1626
|
+
}
|
1627
|
+
};
|
1628
|
+
$.fn.typeahead.noConflict = function noConflict() {
|
1629
|
+
$.fn.typeahead = old;
|
1630
|
+
return this;
|
1631
|
+
};
|
1632
|
+
function ttEach($els, fn) {
|
1633
|
+
$els.each(function() {
|
1634
|
+
var $input = $(this), typeahead;
|
1635
|
+
(typeahead = $input.data(keys.typeahead)) && fn(typeahead, $input);
|
1636
|
+
});
|
1637
|
+
}
|
1638
|
+
function buildHintFromInput($input, www) {
|
1639
|
+
return $input.clone().addClass(www.classes.hint).removeData().css(www.css.hint).css(getBackgroundStyles($input)).prop({
|
1640
|
+
readonly: true,
|
1641
|
+
required: false
|
1642
|
+
}).removeAttr("id name placeholder").removeClass("required").attr({
|
1643
|
+
spellcheck: "false",
|
1644
|
+
tabindex: -1
|
1645
|
+
});
|
1646
|
+
}
|
1647
|
+
function prepInput($input, www) {
|
1648
|
+
$input.data(keys.attrs, {
|
1649
|
+
dir: $input.attr("dir"),
|
1650
|
+
autocomplete: $input.attr("autocomplete"),
|
1651
|
+
spellcheck: $input.attr("spellcheck"),
|
1652
|
+
style: $input.attr("style")
|
1653
|
+
});
|
1654
|
+
$input.addClass(www.classes.input).attr({
|
1655
|
+
spellcheck: false
|
1656
|
+
});
|
1657
|
+
try {
|
1658
|
+
!$input.attr("dir") && $input.attr("dir", "auto");
|
1659
|
+
} catch (e) {}
|
1660
|
+
return $input;
|
1661
|
+
}
|
1662
|
+
function getBackgroundStyles($el) {
|
1663
|
+
return {
|
1664
|
+
backgroundAttachment: $el.css("background-attachment"),
|
1665
|
+
backgroundClip: $el.css("background-clip"),
|
1666
|
+
backgroundColor: $el.css("background-color"),
|
1667
|
+
backgroundImage: $el.css("background-image"),
|
1668
|
+
backgroundOrigin: $el.css("background-origin"),
|
1669
|
+
backgroundPosition: $el.css("background-position"),
|
1670
|
+
backgroundRepeat: $el.css("background-repeat"),
|
1671
|
+
backgroundSize: $el.css("background-size")
|
1672
|
+
};
|
1673
|
+
}
|
1674
|
+
function revert($input) {
|
1675
|
+
var www, $wrapper;
|
1676
|
+
www = $input.data(keys.www);
|
1677
|
+
$wrapper = $input.parent().filter(www.selectors.wrapper);
|
1678
|
+
_.each($input.data(keys.attrs), function(val, key) {
|
1679
|
+
_.isUndefined(val) ? $input.removeAttr(key) : $input.attr(key, val);
|
1680
|
+
});
|
1681
|
+
$input.removeData(keys.typeahead).removeData(keys.www).removeData(keys.attr).removeClass(www.classes.input);
|
1682
|
+
if ($wrapper.length) {
|
1683
|
+
$input.detach().insertAfter($wrapper);
|
1684
|
+
$wrapper.remove();
|
1685
|
+
}
|
1686
|
+
}
|
1687
|
+
function $elOrNull(obj) {
|
1688
|
+
var isValid, $el;
|
1689
|
+
isValid = _.isJQuery(obj) || _.isElement(obj);
|
1690
|
+
$el = isValid ? $(obj).first() : [];
|
1691
|
+
return $el.length ? $el : null;
|
1692
|
+
}
|
1693
|
+
})();
|
1694
|
+
});
|