Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- Localization

  • Loading branch information...
commit 1b3f2927205f0177466656fbf055bc7d31acb164 1 parent e1509f2
@floere authored
View
36 client/javascripts/picky.min.js
@@ -1,19 +1,19 @@
-Array.prototype.index=function(a){for(var b=0,i=this.length;b<i;b++)if(this[b]==a)return b;return null};Array.prototype.include=function(a){return this.index(a)!==null};Array.prototype.remove=function(a){this.splice(a,1);return this};Array.prototype.compare=function(a){return this.join("")==a.join("")};Array.prototype.each=function(a){for(var b=0,i=this.length;b<i;b++)a(b,this[b]);return this};var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(a){for(var b=PickyI18n.locale||
-"en",i=a.split(".").concat(b),f=dictionary,e=0,k=i.length;e<k;e++){f=f[i[e]];if(f==undefined){f="Translation missing: "+a+"."+b;break}}return f};function Allocation(a,b,i,f,e,k){var q=this;this.type=a;this.weight=b;this.count=i;this.combination=f;this.ids=e||[];this.entries=this.rendered=k||[];this.isType=function(s){return s==q.type}}function Allocations(a){this.allocations=[];for(var b=0,i=a.length;b<i;b++){var f=a[b];this.allocations.push(new Allocation(f[0],f[1],f[2],f[3],f[4],f[5]))}this.length=this.allocations.length;this.remove=function(e){this.allocations.splice(e,1)};this.each=function(e){this.allocations.each(e)}}
-function PickyData(a){var b=a.total,i=a.duration,f=a.offset,e=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=i;this.offset=f;this.allocations=e;this.renderedAmount=function(){var k=0;e.each(function(q,s){k+=s.rendered.length});return k};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var i=b.showResultsLimit||10,f=b.input,e=b.reset,k=b.button,q=b.counter,s=b.dashboard,x=b.moreSelector,v=b.results,y=b.noResults,r=new PickyAddination(this,v),p=new PickyAllocationsCloud(this,b),g=new PickyResultsRenderer(r,b),d=function(){e.fadeTo(166,1)},j=function(){p.hide();v.empty();y.hide()},m=function(h){f.val(h);e.fadeTo(166,0);o("empty");q.empty();j()},n=function(){return f.val()};this.text=n;var u=function(h){q.text(h);h>0&&h<=5&&q.fadeTo("fast",0.5).fadeTo("fast",
-1)},c=function(h){if(h.isEmpty())return"none";if(h.total>i&&h.allocations.length>1)return"support";return"ok"},o=function(h){s.attr("class","dashboard "+h)};this.insert=function(h){f.val(h);f.select()};this.fullResultsCallback=function(h){o(c(h));if(h.isEmpty()){j();u(0);y.show();d()}else if(h.total>i&&h.allocations.length>1){j();d();p.show(h);u(h.total)}else if(h.offset==0){j();u(h.total);g.render(v,h);v.show();d();f.focus()}else{var w=$(x).position().top;r.remove();g.render(v,h);$("body").animate({scrollTop:w-
-12},500)}};this.liveResultsCallback=function(h){o(c(h));u(h.total)};this.allocationChosen=function(h){h=h.data.query;a.insert(h);a.allocationChosen(h)};this.addinationClicked=function(h){a.addinationClicked(n(),h)};(function(){f.keyup(function(h){if(n()==""){m();a.searchTextCleared()}else{a.searchTextEntered(n(),h);d()}});q.click(function(){n()==""||a.searchButtonClicked(n())});k.click(function(){n()==""||a.searchButtonClicked(n())});e.click(function(){m("");a.clearButtonClicked();f.focus()})})();
-f.focus()};var PickyBackend=function(a){var b=function(i,f,e){var k=e||{};k=$.extend({query:i},e);$.getJSON(a,k,function(q){f&&f(new PickyData(q))})};this.search=function(i,f,e,k){b(i,function(q){f&&f(k,q)},e)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),i=new PickyBackend(b);this.search=function(f,e,k,q){q=q||{};latestRequestTimestamp=new Date;q.live=latestRequestTimestamp;k=$.extend({ids:a.liveResults||0,offset:0},k);i.search(f,function(s,x){if(!s.live||s.live==latestRequestTimestamp)e&&
-e(x)},k,q)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),i=new PickyBackend(b);this.search=function(f,e,k,q){q=q||{};latestRequestTimestamp=new Date;q.full=latestRequestTimestamp;k=$.extend({ids:a.fullResults||20,offset:0},k);i.search(f,function(s,x){if(!s.full||s.full==latestRequestTimestamp)e&&e(x)},k,q)}};var PickyController=function(a){var b=new PickyView(this,a),i=a.backends,f=a.beforeInsert||function(){},e=a.before||function(){},k=a.success||function(){},q=a.after||function(){},s=a.liveRendered||false,x=a.liveSearchInterval||180,v,y=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=y;var r=function(){var c=window.History&&window.History.getState();return y(c&&c.url)};this.lastFullQuery=r;var p=function(c,o,h,w){o=e(o,
-w)||o;v=[c,o,h,w];var z=o;if(z!=r()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=i[c])&&c.search(o,h,w)};this.resend=function(){v&&p.apply(this,v)};var g=function(c,o){c=k(c,o)||c;b.fullResultsCallback(c);q(c,o)},d=function(c,o){clearInterval(m);p("full",c,g,o||{})};a=function(c,o){c=k(c,o)||c;b.liveResultsCallback(c);q(c,o)};var j=s?g:a,m,n=function(){var c=b.text();p("live",c,j,{});clearInterval(m)};
-m=setInterval(n,x);clearInterval(m);var u=function(c,o,h){c=f(c)||c;b.insert(c);h&&d(c,o)};this.insert=u;this.clearButtonClicked=function(){clearInterval(m)};this.searchTextCleared=function(){clearInterval(m)};this.searchTextEntered=function(c,o){if($.inArray(o.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(o.keyCode==13)d(c);else{clearInterval(m);m=setInterval(n,x)}};this.searchButtonClicked=function(c){d(c)};
-this.allocationChosen=function(c){d(c)};this.addinationClicked=function(c,o){d(c,{offset:o.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(v.length>1&&v[1])&&u(c,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};
+Array.prototype.index=function(a){for(var b=0,k=this.length;b<k;b++)if(this[b]==a)return b;return null};Array.prototype.include=function(a){return this.index(a)!==null};Array.prototype.remove=function(a){this.splice(a,1);return this};Array.prototype.compare=function(a){return this.join("")==a.join("")};Array.prototype.each=function(a){for(var b=0,k=this.length;b<k;b++)a(b,this[b]);return this};var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(a){for(var b=PickyI18n.locale||
+"en",k=a.split(".").concat(b),h=dictionary,g=0,m=k.length;g<m;g++){h=h[k[g]];if(h==undefined){h="Translation missing: "+a+"."+b;break}}return h};function Allocation(a,b,k,h,g,m){var o=this;this.type=a;this.weight=b;this.count=k;this.combination=h;this.ids=g||[];this.entries=this.rendered=m||[];this.isType=function(u){return u==o.type}}function Allocations(a){this.allocations=[];for(var b=0,k=a.length;b<k;b++){var h=a[b];this.allocations.push(new Allocation(h[0],h[1],h[2],h[3],h[4],h[5]))}this.length=this.allocations.length;this.remove=function(g){this.allocations.splice(g,1)};this.each=function(g){this.allocations.each(g)}}
+function PickyData(a){var b=a.total,k=a.duration,h=a.offset,g=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=h;this.allocations=g;this.renderedAmount=function(){var m=0;g.each(function(o,u){m+=u.rendered.length});return m};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var k=b.showResultsLimit||10,h=b.input,g=b.reset,m=b.button,o=b.counter,u=b.dashboard,x=b.moreSelector,s=b.results,w=b.noResults,y=new PickyAddination(this,s),j=new PickyAllocationsCloud(this,b),e=new PickyResultsRenderer(y,b),d=function(){g.fadeTo(166,1)},n=function(){j.hide();s.empty();w.hide()},i=function(f){h.val(f);g.fadeTo(166,0);p("empty");o.empty();n()},q=function(){return h.val()};this.text=q;var r=function(f){o.text(f);f>0&&f<=5&&o.fadeTo("fast",0.5).fadeTo("fast",
+1)},c=function(f){if(f.isEmpty())return"none";if(f.total>k&&f.allocations.length>1)return"support";return"ok"},p=function(f){u.attr("class","dashboard "+f)};this.insert=function(f){h.val(f);h.select()};this.fullResultsCallback=function(f){p(c(f));if(f.isEmpty()){n();r(0);w.show();d()}else if(f.total>k&&f.allocations.length>1){n();d();j.show(f);r(f.total)}else if(f.offset==0){n();r(f.total);e.render(s,f);s.show();d();h.focus()}else{var v=$(x).position().top;y.remove();e.render(s,f);$("body").animate({scrollTop:v-
+12},500)}};this.liveResultsCallback=function(f){p(c(f));r(f.total)};this.allocationChosen=function(f){f=f.data.query;a.insert(f);a.allocationChosen(f)};this.addinationClicked=function(f){a.addinationClicked(q(),f)};(function(){h.keyup(function(f){if(q()==""){i();a.searchTextCleared()}else{a.searchTextEntered(q(),f);d()}});o.click(function(){q()==""||a.searchButtonClicked(q())});m.click(function(){q()==""||a.searchButtonClicked(q())});g.click(function(){i("");a.clearButtonClicked();h.focus()})})();
+h.focus()};var PickyBackend=function(a){var b=function(k,h,g){var m=g||{};m=$.extend({query:k},g);$.getJSON(a,m,function(o){h&&h(new PickyData(o))})};this.search=function(k,h,g,m){b(k,function(o){h&&h(m,o)},g)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(h,g,m,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);k.search(h,function(u,x){if(!u.live||u.live==latestRequestTimestamp)g&&
+g(x)},m,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(h,g,m,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);k.search(h,function(u,x){if(!u.full||u.full==latestRequestTimestamp)g&&g(x)},m,o)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,h=a.beforeInsert||function(){},g=a.before||function(){},m=a.success||function(){},o=a.after||function(){},u=a.liveRendered||false,x=a.liveSearchInterval||180,s,w=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var y=function(){var c=window.History&&window.History.getState();return w(c&&c.url)};this.lastFullQuery=y;var j=function(c,p,f,v){p=g(p,
+v)||p;s=[c,p,f,v];var z=p;if(z!=y()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=k[c])&&c.search(p,f,v)};this.resend=function(){s&&j.apply(this,s)};var e=function(c,p){c=m(c,p)||c;b.fullResultsCallback(c);o(c,p)},d=function(c,p){clearInterval(i);j("full",c,e,p||{})};a=function(c,p){c=m(c,p)||c;b.liveResultsCallback(c);o(c,p)};var n=u?e:a,i,q=function(){var c=b.text();j("live",c,n,{});clearInterval(i)};
+i=setInterval(q,x);clearInterval(i);var r=function(c,p,f){c=h(c)||c;b.insert(c);f&&d(c,p)};this.insert=r;this.clearButtonClicked=function(){clearInterval(i)};this.searchTextCleared=function(){clearInterval(i)};this.searchTextEntered=function(c,p){if($.inArray(p.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(p.keyCode==13)d(c);else{clearInterval(i);i=setInterval(q,x)}};this.searchButtonClicked=function(c){d(c)};
+this.allocationChosen=function(c){d(c)};this.addinationClicked=function(c,p){d(c,{offset:p.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=w(c.url))&&c!=(s.length>1&&s[1])&&r(c,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};
b=a.enclosingSelector||"#picky";a.input=$(a.inputSelector||b+" input.query");a.reset=$(a.resetSelector||b+" div.reset");a.button=$(a.buttonSelector||b+" input.search_button");a.counter=$(a.counterSelector||b+" div.status");a.dashboard=$(a.dashboardSelector||b+" .dashboard");a.results=$(a.resultsSelector||b+" div.results");a.noResults=$(a.noResultsSelector||b+" .no_results");a.moreSelector=a.moreSelector||b+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||b+" .allocations");
-a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var i=a.controller&&new a.controller(a)||new PickyController(a);var f=this.insert=function(e,k,q){i.insert(e,k||{},q||true)};this.resend=i.resend;
-this.insertFromURL=function(e){if(e&&e!="")f(e);else(e=i.lastFullQuery())&&f(e)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(i){var f=i.total,e,k=i.renderedAmount();e=i.offset+k;k=e+k;i=i.total;if(i<k)k=i;e={offset:e,start:e+1,end:k};if(e.offset<f){f=$("<div class='addination'>"+t("results.addination.more")+"</div>");f.bind("click",{offset:e.offset},a.addinationClicked);return f}else return""}};var PickyResultsRenderer=function(a,b){var i=b.locale,f=b.resultsDivider,e=b.wrapResults,k=b.nonPartial,q=function(r){var p=r[r.length-1];if(p===undefined)return[];r=r.slice(0,r.length-1);if(r==[])r=[r];if(!k.include(p[0]))if(p[1].match(/[^\*~]$/))p[1]+="*";r.push(p);return r};this.asteriskifyLastToken=q;var s=function(r){for(var p=Localization.explanations&&Localization.explanations[i]||{},g=[],d,j=0,m=r.length;j<m;j++){d=r[j];var n=d[0];n=p[n]||n;g.push([n,d[1]])}return g};this.explainCategory=
-s;var x=function(r,p){return[r.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),p].join(" ")};this.strongify=x;var v=function(r,p){var g=Localization.explanation_delimiters[i],d="",j=[],m=[];s(q(p)).each(function(n,u){var c=u[0],o=u[1];if(d==""||c==d){o=o.replace(/[\w,]+:(.+)/,"$1");j.push(o);d=c}else{var h=x(d,j.join(" "));j=[];j.push(o);d=c;m.push(h)}});m.push(x(d,j.join(" ")));m=m.join(" "+g+" ");return m='<span class="explanation">'+r+" "+m+"</span>"};
-this.explain=v;var y=function(r,p){var g='<div class="header">';g+=v(p.type,p.combination);if(r.offset>0)g+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';g+="</div>";return g};this.renderHeader=y;this.render=function(r,p){p.allocations.each(function(g,d){if(d.entries.length>0){r.append(y(p,d)).append(d.entries.join(f));r.children("li").wrapAll(e)}});r.append(a.render(p))}};function AllocationRenderer(a,b){function i(g){var d={},j={},m=[],n;n=0;for(l=g.length;n<l;n++){var u=g[n][0];if(u in d){d[u]=d[u]+" "+g[n][1];m.push(n)}else{d[u]=g[n][1];j[n]=u}}for(n in j)g[n][1]=d[j[n]];for(n=m.length-1;n>=0;n--)g.remove(m[n]);return g}function f(g){var d=[];g.each(function(j){d.push("%"+(j+1)+"$s")});return d.join(" ")}function e(g){if(g.length==0)return"";var d=g=i(g);d.sort(function(h,w){return h[0]<w[0]?-1:1});for(var j=[],m=0,n=d.length;m<n;m++)j.push(d[m][0]);var u=j.length==
-1,c=r[j.join(",")]||(r[j]=f(j));if(typeof c==="string"){r[j]={format:c};c=r[j]}var o=c.format;g.each(function(h,w){var z=w[0],A=w[2];if(c.filter)A=c.filter(A);z=v[z]||z;if(u&&!(c&&c.ignoreSingle))return o=A+"&nbsp;("+z+")";o=o.replace(RegExp("%"+(h+1)+"\\$s","g"),A)});return o}function k(g){for(var d=[],j=0,m=y.length;j<m;j++)d.push([]);d.push([]);j=0;for(m=g.length;j<m;j++){for(var n=g[j],u=n[0],c=false,o=0,h=y.length;o<h;o++)if(y[o].include(u)){d[o].push(n);c=true;break}c||d[d.length-1].push(n)}var w;
-for(g=d.length-1;g>=0;g--){w=d[g];if(w.length>0)break}w=w[w.length-1];p.include(w[0])||(w[1]+="...");var z=[];d.each(function(A,B){z.push(e(B))});return z}function q(g){return k(g).join(" ")}var s=b.locale,x=b.qualifiers&&b.qualifiers[s]||{},v=b.explanations&&b.explanations[s]||{},y=b.groups||[],r=b.choices&&b.choices[s]||{},p=b.nonPartial||[];this.explanation=this.query=this.text="";this.contract=i;this.makeUpMissingFormat=f;this.rendered=e;this.groupify=k;this.querify=function(g){var d=[],j,m;for(m in g){j=
-g[m][0];j=x[j]||j;d[m]=j+":"+g[m][2]}return d.join(" ")};this.suggestify=q;this.render=function(g){return q(g.combination)}};var PickyAllocationsCloud=function(a,b){var i=b.allocations,f=b.shownAllocations,e=b.showMoreAllocations,k=b.hiddenAllocations,q=b.maxSuggestions,s=function(){i.hide()},x=function(p){s();a.allocationChosen(p)},v=new AllocationRenderer(b),y=function(p){var g=[];p.each(function(d,j){var m=v.render(j),n=v.querify(j.combination);m=$('<li><div class="text">'+m+'</div><div class="count">'+j.count+"</div></li>");m.bind("click",{query:n},x);g.push(m)});return g},r=function(p){if(p.length==0)return i.hide();
-f.empty();e.hide();k.empty().hide();if(p.length>q){$.each(p.slice(0,q-1),function(g,d){f.append(d)});$.each(p.slice(q-1),function(g,d){k.append(d)});e.show()}else $.each(p,function(g,d){f.append(d)});return i.show()};e.click(function(){e.hide();k.show()});this.hide=s;this.show=function(p){r(y(p.allocations));i.show()}};
+a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var k=a.controller&&new a.controller(a)||new PickyController(a);var h=this.insert=function(g,m,o){k.insert(g,m||{},o||true)};this.resend=k.resend;
+this.insertFromURL=function(g){if(g&&g!="")h(g);else(g=k.lastFullQuery())&&h(g)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var h=k.total,g,m=k.renderedAmount();g=k.offset+m;m=g+m;k=k.total;if(k<m)m=k;g={offset:g,start:g+1,end:m};if(g.offset<h){h=$("<div class='addination'>"+t("results.addination.more")+"</div>");h.bind("click",{offset:g.offset},a.addinationClicked);return h}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,h=b.explanations||{},g=b.explanation_delimiters||{},m=b.resultsDivider,o=b.wrapResults,u=b.nonPartial,x=function(e){var d=e[e.length-1];if(d===undefined)return[];e=e.slice(0,e.length-1);if(e==[])e=[e];if(!u.include(d[0]))if(d[1].match(/[^\*~]$/))d[1]+="*";e.push(d);return e};this.asteriskifyLastToken=x;var s=function(e){for(var d=h[k]||{},n=[],i,q=0,r=e.length;q<r;q++){i=e[q];var c=i[0];c=d[c]||c;n.push([c,i[1]])}return n};this.explainCategory=
+s;var w=function(e,d){return[e.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),d].join(" ")};this.strongify=w;var y=function(e,d){var n=g[k],i="",q=[],r=[];s(x(d)).each(function(c,p){var f=p[0],v=p[1];v=v.replace(/[\w,]+:(.+)/,"$1");if(i==""||f==i){q.push(v);i=f}else{var z=w(i,q.join(" "));q=[];q.push(v);i=f;r.push(z)}});r.push(w(i,q.join(" ")));r=r.join(" "+n+" ");return r='<span class="explanation">'+e+" "+r+"</span>"};this.explain=y;var j=function(e,
+d){var n='<div class="header">';n+=y(d.type,d.combination);if(e.offset>0)n+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';n+="</div>";return n};this.renderHeader=j;this.render=function(e,d){d.allocations.each(function(n,i){if(i.entries.length>0){e.append(j(d,i)).append(i.entries.join(m));e.children("li").wrapAll(o)}});e.append(a.render(d))}};function AllocationRenderer(a){function b(j){var e={},d={},n=[],i;i=0;for(l=j.length;i<l;i++){var q=j[i][0];if(q in e){e[q]=e[q]+" "+j[i][1];n.push(i)}else{e[q]=j[i][1];d[i]=q}}for(i in d)j[i][1]=e[d[i]];for(i=n.length-1;i>=0;i--)j.remove(n[i]);return j}function k(j){var e=[];j.each(function(d){e.push("%"+(d+1)+"$s")});return e.join(" ")}function h(j){if(j.length==0)return"";var e=j=b(j);e.sort(function(p,f){return p[0]<f[0]?-1:1});for(var d=[],n=0,i=e.length;n<i;n++)d.push(e[n][0]);var q=d.length==
+1,r=w[d.join(",")]||(w[d]=k(d));if(typeof r==="string"){w[d]={format:r};r=w[d]}var c=r.format;j.each(function(p,f){var v=f[0],z=f[2];if(r.filter)z=r.filter(z);v=x[v]||v;if(q&&!(r&&r.ignoreSingle))return c=z+"&nbsp;("+v+")";c=c.replace(RegExp("%"+(p+1)+"\\$s","g"),z)});return c}function g(j){for(var e=[],d=0,n=s.length;d<n;d++)e.push([]);e.push([]);d=0;for(n=j.length;d<n;d++){for(var i=j[d],q=i[0],r=false,c=0,p=s.length;c<p;c++)if(s[c].include(q)){e[c].push(i);r=true;break}r||e[e.length-1].push(i)}var f;
+for(j=e.length-1;j>=0;j--){f=e[j];if(f.length>0)break}f=f[f.length-1];y.include(f[0])||(f[1]+="...");var v=[];e.each(function(z,A){v.push(h(A))});return v}function m(j){return g(j).join(" ")}var o=a.locale,u=a.qualifiers&&a.qualifiers[o]||{},x=a.explanations&&a.explanations[o]||{},s=a.groups||[],w=a.choices&&a.choices[o]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=h;this.groupify=g;this.querify=function(j){var e=[],d,n;for(n in j){d=
+j[n][0];d=u[d]||d;e[n]=d+":"+j[n][2]}return e.join(" ")};this.suggestify=m;this.render=function(j){return m(j.combination)}};var PickyAllocationsCloud=function(a,b){var k=b.allocations,h=b.shownAllocations,g=b.showMoreAllocations,m=b.hiddenAllocations,o=b.maxSuggestions,u=function(){k.hide()},x=function(j){u();a.allocationChosen(j)},s=new AllocationRenderer(b),w=function(j){var e=[];j.each(function(d,n){var i=s.render(n),q=s.querify(n.combination);i=$('<li><div class="text">'+i+'</div><div class="count">'+n.count+"</div></li>");i.bind("click",{query:q},x);e.push(i)});return e},y=function(j){if(j.length==0)return k.hide();
+h.empty();g.hide();m.empty().hide();if(j.length>o){$.each(j.slice(0,o-1),function(e,d){h.append(d)});$.each(j.slice(o-1),function(e,d){m.append(d)});g.show()}else $.each(j,function(e,d){h.append(d)});return k.show()};g.click(function(){g.hide();m.show()});this.hide=u;this.show=function(j){y(w(j.allocations));k.show()}};
View
BIN  client/javascripts/picky.source.js.tar
Binary file not shown
View
2  client/javascripts/source/picky.allocation_renderer.js
@@ -1,4 +1,4 @@
-function AllocationRenderer(allocationChosenCallback, config) {
+function AllocationRenderer(config) {
var self = this;
var locale = config.locale;
View
2  client/javascripts/source/picky.client.js
@@ -42,7 +42,7 @@ var PickyClient = function(config) {
// Delimiters for connecting explanations.
//
config['explanation_delimiters'] = {
- ch:'und',
+ ch:'und',
de:'und',
en:'and',
fr:'et',
View
39 client/javascripts/source/picky.results_renderer.js
@@ -2,6 +2,9 @@ var PickyResultsRenderer = function(addination, config) {
var locale = config.locale;
+ var explanations = config.explanations || {};
+ var explanation_delimiters = config.explanation_delimiters || {};
+
var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
var nonPartial = config['nonPartial'];
@@ -26,14 +29,14 @@ var PickyResultsRenderer = function(addination, config) {
// Replaces the category with an explanation of the category.
//
var explainCategory = function(combination) {
- var explanations = Localization.explanations && Localization.explanations[locale] || {}; // TODO
+ var localized_explanations = explanations[locale] || {};
var parts = [];
var combo;
for (var i = 0, l = combination.length; i < l; i++) {
combo = combination[i];
var explanation = combo[0];
- explanation = explanations[explanation] || explanation;
+ explanation = localized_explanations[explanation] || explanation;
parts.push([explanation, combo[1]]);
}
@@ -53,7 +56,7 @@ var PickyResultsRenderer = function(addination, config) {
// Note: Accumulates same categories using a whitespace.
//
var explain = function(type, combinations) {
- var explanation_delimiter = Localization.explanation_delimiters[locale];
+ var explanation_delimiter = explanation_delimiters[locale];
var parts = explainCategory(asteriskifyLastToken(combinations));
var lastCategory = '';
@@ -66,25 +69,25 @@ var PickyResultsRenderer = function(addination, config) {
var category = part[0];
var token = part[1];
+ // Remove categorization (including commas)
+ // before the token.
+ //
+ token = token.replace(/[\w,]+:(.+)/, "$1");
+
+ // Accumulate same categories.
+ //
if (lastCategory == '' || category == lastCategory) {
- // Remove categorization (including commas)
- // before the token.
- //
- token = token.replace(/[\w,]+:(.+)/, "$1");
-
tokenAccumulator.push(token);
lastCategory = category;
-
- return;
- }
+ } else {
+ var result = strongify(lastCategory, tokenAccumulator.join(' '));
- var result = strongify(lastCategory, tokenAccumulator.join(' '));
-
- tokenAccumulator = [];
- tokenAccumulator.push(token);
- lastCategory = category;
+ tokenAccumulator = [];
+ tokenAccumulator.push(token);
+ lastCategory = category;
- replaced.push(result);
+ replaced.push(result);
+ }
});
// there might be something in the accumulator
@@ -93,7 +96,7 @@ var PickyResultsRenderer = function(addination, config) {
replaced = replaced.join(' ' + explanation_delimiter + ' ');
replaced = '<span class="explanation">' + type + ' ' + replaced + '</span>';
-
+
return replaced;
};
this.explain = explain; // Note: Only exposed for testing.
View
4 client/javascripts/spec/picky.allocation_renderer.spec.js
@@ -2,9 +2,7 @@ var renderer;
describe(
"AllocationRenderer",
function() {
- renderer = new AllocationRenderer(function() {
- //
- }, {
+ renderer = new AllocationRenderer({
locale: 'en',
choices: {
en:{
View
12 client/javascripts/spec/picky.results_renderer.spec.js
@@ -107,6 +107,18 @@ describe(
['cat2', 'Orig2', 'parsed2']
]) == '<span class="explanation">type1 <strong>done by</strong> Orig1 and <strong>cat2</strong> Orig2*</span>';
});
+ it("is correct", function() {
+ return renderer.explain("type1", [
+ ['cat1', 'cat1:Orig1', 'parsed1'],
+ ['cat2', 'cat2:Orig2', 'parsed2']
+ ]) == '<span class="explanation">type1 <strong>done by</strong> Orig1 and <strong>cat2</strong> Orig2*</span>';
+ });
+ it("is correct", function() {
+ return renderer.explain("type1", [
+ ['cat1', 'cat1:Orig1', 'parsed1'],
+ ['cat2', 'cat2,cat3:Orig2', 'parsed2']
+ ]) == '<span class="explanation">type1 <strong>done by</strong> Orig1 and <strong>cat2</strong> Orig2*</span>';
+ });
}
);
describe("renderHeader", null,
View
2  client/test_project/javascripts/picky.allocation_renderer.js
@@ -1,4 +1,4 @@
-function AllocationRenderer(allocationChosenCallback, config) {
+function AllocationRenderer(config) {
var self = this;
var locale = config.locale;
View
2  client/test_project/javascripts/picky.client.js
@@ -42,7 +42,7 @@ var PickyClient = function(config) {
// Delimiters for connecting explanations.
//
config['explanation_delimiters'] = {
- ch:'und',
+ ch:'und',
de:'und',
en:'and',
fr:'et',
View
39 client/test_project/javascripts/picky.results_renderer.js
@@ -2,6 +2,9 @@ var PickyResultsRenderer = function(addination, config) {
var locale = config.locale;
+ var explanations = config.explanations || {};
+ var explanation_delimiters = config.explanation_delimiters || {};
+
var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
var nonPartial = config['nonPartial'];
@@ -26,14 +29,14 @@ var PickyResultsRenderer = function(addination, config) {
// Replaces the category with an explanation of the category.
//
var explainCategory = function(combination) {
- var explanations = Localization.explanations && Localization.explanations[locale] || {}; // TODO
+ var localized_explanations = explanations[locale] || {};
var parts = [];
var combo;
for (var i = 0, l = combination.length; i < l; i++) {
combo = combination[i];
var explanation = combo[0];
- explanation = explanations[explanation] || explanation;
+ explanation = localized_explanations[explanation] || explanation;
parts.push([explanation, combo[1]]);
}
@@ -53,7 +56,7 @@ var PickyResultsRenderer = function(addination, config) {
// Note: Accumulates same categories using a whitespace.
//
var explain = function(type, combinations) {
- var explanation_delimiter = Localization.explanation_delimiters[locale];
+ var explanation_delimiter = explanation_delimiters[locale];
var parts = explainCategory(asteriskifyLastToken(combinations));
var lastCategory = '';
@@ -66,25 +69,25 @@ var PickyResultsRenderer = function(addination, config) {
var category = part[0];
var token = part[1];
+ // Remove categorization (including commas)
+ // before the token.
+ //
+ token = token.replace(/[\w,]+:(.+)/, "$1");
+
+ // Accumulate same categories.
+ //
if (lastCategory == '' || category == lastCategory) {
- // Remove categorization (including commas)
- // before the token.
- //
- token = token.replace(/[\w,]+:(.+)/, "$1");
-
tokenAccumulator.push(token);
lastCategory = category;
-
- return;
- }
+ } else {
+ var result = strongify(lastCategory, tokenAccumulator.join(' '));
- var result = strongify(lastCategory, tokenAccumulator.join(' '));
-
- tokenAccumulator = [];
- tokenAccumulator.push(token);
- lastCategory = category;
+ tokenAccumulator = [];
+ tokenAccumulator.push(token);
+ lastCategory = category;
- replaced.push(result);
+ replaced.push(result);
+ }
});
// there might be something in the accumulator
@@ -93,7 +96,7 @@ var PickyResultsRenderer = function(addination, config) {
replaced = replaced.join(' ' + explanation_delimiter + ' ');
replaced = '<span class="explanation">' + type + ' ' + replaced + '</span>';
-
+
return replaced;
};
this.explain = explain; // Note: Only exposed for testing.
View
36 generators/prototypes/client/sinatra/javascripts/picky.min.js
@@ -1,19 +1,19 @@
-Array.prototype.index=function(a){for(var b=0,i=this.length;b<i;b++)if(this[b]==a)return b;return null};Array.prototype.include=function(a){return this.index(a)!==null};Array.prototype.remove=function(a){this.splice(a,1);return this};Array.prototype.compare=function(a){return this.join("")==a.join("")};Array.prototype.each=function(a){for(var b=0,i=this.length;b<i;b++)a(b,this[b]);return this};var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(a){for(var b=PickyI18n.locale||
-"en",i=a.split(".").concat(b),f=dictionary,e=0,k=i.length;e<k;e++){f=f[i[e]];if(f==undefined){f="Translation missing: "+a+"."+b;break}}return f};function Allocation(a,b,i,f,e,k){var q=this;this.type=a;this.weight=b;this.count=i;this.combination=f;this.ids=e||[];this.entries=this.rendered=k||[];this.isType=function(s){return s==q.type}}function Allocations(a){this.allocations=[];for(var b=0,i=a.length;b<i;b++){var f=a[b];this.allocations.push(new Allocation(f[0],f[1],f[2],f[3],f[4],f[5]))}this.length=this.allocations.length;this.remove=function(e){this.allocations.splice(e,1)};this.each=function(e){this.allocations.each(e)}}
-function PickyData(a){var b=a.total,i=a.duration,f=a.offset,e=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=i;this.offset=f;this.allocations=e;this.renderedAmount=function(){var k=0;e.each(function(q,s){k+=s.rendered.length});return k};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var i=b.showResultsLimit||10,f=b.input,e=b.reset,k=b.button,q=b.counter,s=b.dashboard,x=b.moreSelector,v=b.results,y=b.noResults,r=new PickyAddination(this,v),p=new PickyAllocationsCloud(this,b),g=new PickyResultsRenderer(r,b),d=function(){e.fadeTo(166,1)},j=function(){p.hide();v.empty();y.hide()},m=function(h){f.val(h);e.fadeTo(166,0);o("empty");q.empty();j()},n=function(){return f.val()};this.text=n;var u=function(h){q.text(h);h>0&&h<=5&&q.fadeTo("fast",0.5).fadeTo("fast",
-1)},c=function(h){if(h.isEmpty())return"none";if(h.total>i&&h.allocations.length>1)return"support";return"ok"},o=function(h){s.attr("class","dashboard "+h)};this.insert=function(h){f.val(h);f.select()};this.fullResultsCallback=function(h){o(c(h));if(h.isEmpty()){j();u(0);y.show();d()}else if(h.total>i&&h.allocations.length>1){j();d();p.show(h);u(h.total)}else if(h.offset==0){j();u(h.total);g.render(v,h);v.show();d();f.focus()}else{var w=$(x).position().top;r.remove();g.render(v,h);$("body").animate({scrollTop:w-
-12},500)}};this.liveResultsCallback=function(h){o(c(h));u(h.total)};this.allocationChosen=function(h){h=h.data.query;a.insert(h);a.allocationChosen(h)};this.addinationClicked=function(h){a.addinationClicked(n(),h)};(function(){f.keyup(function(h){if(n()==""){m();a.searchTextCleared()}else{a.searchTextEntered(n(),h);d()}});q.click(function(){n()==""||a.searchButtonClicked(n())});k.click(function(){n()==""||a.searchButtonClicked(n())});e.click(function(){m("");a.clearButtonClicked();f.focus()})})();
-f.focus()};var PickyBackend=function(a){var b=function(i,f,e){var k=e||{};k=$.extend({query:i},e);$.getJSON(a,k,function(q){f&&f(new PickyData(q))})};this.search=function(i,f,e,k){b(i,function(q){f&&f(k,q)},e)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),i=new PickyBackend(b);this.search=function(f,e,k,q){q=q||{};latestRequestTimestamp=new Date;q.live=latestRequestTimestamp;k=$.extend({ids:a.liveResults||0,offset:0},k);i.search(f,function(s,x){if(!s.live||s.live==latestRequestTimestamp)e&&
-e(x)},k,q)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),i=new PickyBackend(b);this.search=function(f,e,k,q){q=q||{};latestRequestTimestamp=new Date;q.full=latestRequestTimestamp;k=$.extend({ids:a.fullResults||20,offset:0},k);i.search(f,function(s,x){if(!s.full||s.full==latestRequestTimestamp)e&&e(x)},k,q)}};var PickyController=function(a){var b=new PickyView(this,a),i=a.backends,f=a.beforeInsert||function(){},e=a.before||function(){},k=a.success||function(){},q=a.after||function(){},s=a.liveRendered||false,x=a.liveSearchInterval||180,v,y=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=y;var r=function(){var c=window.History&&window.History.getState();return y(c&&c.url)};this.lastFullQuery=r;var p=function(c,o,h,w){o=e(o,
-w)||o;v=[c,o,h,w];var z=o;if(z!=r()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=i[c])&&c.search(o,h,w)};this.resend=function(){v&&p.apply(this,v)};var g=function(c,o){c=k(c,o)||c;b.fullResultsCallback(c);q(c,o)},d=function(c,o){clearInterval(m);p("full",c,g,o||{})};a=function(c,o){c=k(c,o)||c;b.liveResultsCallback(c);q(c,o)};var j=s?g:a,m,n=function(){var c=b.text();p("live",c,j,{});clearInterval(m)};
-m=setInterval(n,x);clearInterval(m);var u=function(c,o,h){c=f(c)||c;b.insert(c);h&&d(c,o)};this.insert=u;this.clearButtonClicked=function(){clearInterval(m)};this.searchTextCleared=function(){clearInterval(m)};this.searchTextEntered=function(c,o){if($.inArray(o.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(o.keyCode==13)d(c);else{clearInterval(m);m=setInterval(n,x)}};this.searchButtonClicked=function(c){d(c)};
-this.allocationChosen=function(c){d(c)};this.addinationClicked=function(c,o){d(c,{offset:o.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(v.length>1&&v[1])&&u(c,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};
+Array.prototype.index=function(a){for(var b=0,k=this.length;b<k;b++)if(this[b]==a)return b;return null};Array.prototype.include=function(a){return this.index(a)!==null};Array.prototype.remove=function(a){this.splice(a,1);return this};Array.prototype.compare=function(a){return this.join("")==a.join("")};Array.prototype.each=function(a){for(var b=0,k=this.length;b<k;b++)a(b,this[b]);return this};var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(a){for(var b=PickyI18n.locale||
+"en",k=a.split(".").concat(b),h=dictionary,g=0,m=k.length;g<m;g++){h=h[k[g]];if(h==undefined){h="Translation missing: "+a+"."+b;break}}return h};function Allocation(a,b,k,h,g,m){var o=this;this.type=a;this.weight=b;this.count=k;this.combination=h;this.ids=g||[];this.entries=this.rendered=m||[];this.isType=function(u){return u==o.type}}function Allocations(a){this.allocations=[];for(var b=0,k=a.length;b<k;b++){var h=a[b];this.allocations.push(new Allocation(h[0],h[1],h[2],h[3],h[4],h[5]))}this.length=this.allocations.length;this.remove=function(g){this.allocations.splice(g,1)};this.each=function(g){this.allocations.each(g)}}
+function PickyData(a){var b=a.total,k=a.duration,h=a.offset,g=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=h;this.allocations=g;this.renderedAmount=function(){var m=0;g.each(function(o,u){m+=u.rendered.length});return m};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var k=b.showResultsLimit||10,h=b.input,g=b.reset,m=b.button,o=b.counter,u=b.dashboard,x=b.moreSelector,s=b.results,w=b.noResults,y=new PickyAddination(this,s),j=new PickyAllocationsCloud(this,b),e=new PickyResultsRenderer(y,b),d=function(){g.fadeTo(166,1)},n=function(){j.hide();s.empty();w.hide()},i=function(f){h.val(f);g.fadeTo(166,0);p("empty");o.empty();n()},q=function(){return h.val()};this.text=q;var r=function(f){o.text(f);f>0&&f<=5&&o.fadeTo("fast",0.5).fadeTo("fast",
+1)},c=function(f){if(f.isEmpty())return"none";if(f.total>k&&f.allocations.length>1)return"support";return"ok"},p=function(f){u.attr("class","dashboard "+f)};this.insert=function(f){h.val(f);h.select()};this.fullResultsCallback=function(f){p(c(f));if(f.isEmpty()){n();r(0);w.show();d()}else if(f.total>k&&f.allocations.length>1){n();d();j.show(f);r(f.total)}else if(f.offset==0){n();r(f.total);e.render(s,f);s.show();d();h.focus()}else{var v=$(x).position().top;y.remove();e.render(s,f);$("body").animate({scrollTop:v-
+12},500)}};this.liveResultsCallback=function(f){p(c(f));r(f.total)};this.allocationChosen=function(f){f=f.data.query;a.insert(f);a.allocationChosen(f)};this.addinationClicked=function(f){a.addinationClicked(q(),f)};(function(){h.keyup(function(f){if(q()==""){i();a.searchTextCleared()}else{a.searchTextEntered(q(),f);d()}});o.click(function(){q()==""||a.searchButtonClicked(q())});m.click(function(){q()==""||a.searchButtonClicked(q())});g.click(function(){i("");a.clearButtonClicked();h.focus()})})();
+h.focus()};var PickyBackend=function(a){var b=function(k,h,g){var m=g||{};m=$.extend({query:k},g);$.getJSON(a,m,function(o){h&&h(new PickyData(o))})};this.search=function(k,h,g,m){b(k,function(o){h&&h(m,o)},g)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(h,g,m,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);k.search(h,function(u,x){if(!u.live||u.live==latestRequestTimestamp)g&&
+g(x)},m,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(h,g,m,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);k.search(h,function(u,x){if(!u.full||u.full==latestRequestTimestamp)g&&g(x)},m,o)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,h=a.beforeInsert||function(){},g=a.before||function(){},m=a.success||function(){},o=a.after||function(){},u=a.liveRendered||false,x=a.liveSearchInterval||180,s,w=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var y=function(){var c=window.History&&window.History.getState();return w(c&&c.url)};this.lastFullQuery=y;var j=function(c,p,f,v){p=g(p,
+v)||p;s=[c,p,f,v];var z=p;if(z!=y()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=k[c])&&c.search(p,f,v)};this.resend=function(){s&&j.apply(this,s)};var e=function(c,p){c=m(c,p)||c;b.fullResultsCallback(c);o(c,p)},d=function(c,p){clearInterval(i);j("full",c,e,p||{})};a=function(c,p){c=m(c,p)||c;b.liveResultsCallback(c);o(c,p)};var n=u?e:a,i,q=function(){var c=b.text();j("live",c,n,{});clearInterval(i)};
+i=setInterval(q,x);clearInterval(i);var r=function(c,p,f){c=h(c)||c;b.insert(c);f&&d(c,p)};this.insert=r;this.clearButtonClicked=function(){clearInterval(i)};this.searchTextCleared=function(){clearInterval(i)};this.searchTextEntered=function(c,p){if($.inArray(p.keyCode,[0,8,13,32,46,48,49,50,51,52,53,54,55,56,57,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(p.keyCode==13)d(c);else{clearInterval(i);i=setInterval(q,x)}};this.searchButtonClicked=function(c){d(c)};
+this.allocationChosen=function(c){d(c)};this.addinationClicked=function(c,p){d(c,{offset:p.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=w(c.url))&&c!=(s.length>1&&s[1])&&r(c,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};
b=a.enclosingSelector||"#picky";a.input=$(a.inputSelector||b+" input.query");a.reset=$(a.resetSelector||b+" div.reset");a.button=$(a.buttonSelector||b+" input.search_button");a.counter=$(a.counterSelector||b+" div.status");a.dashboard=$(a.dashboardSelector||b+" .dashboard");a.results=$(a.resultsSelector||b+" div.results");a.noResults=$(a.noResultsSelector||b+" .no_results");a.moreSelector=a.moreSelector||b+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||b+" .allocations");
-a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var i=a.controller&&new a.controller(a)||new PickyController(a);var f=this.insert=function(e,k,q){i.insert(e,k||{},q||true)};this.resend=i.resend;
-this.insertFromURL=function(e){if(e&&e!="")f(e);else(e=i.lastFullQuery())&&f(e)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(i){var f=i.total,e,k=i.renderedAmount();e=i.offset+k;k=e+k;i=i.total;if(i<k)k=i;e={offset:e,start:e+1,end:k};if(e.offset<f){f=$("<div class='addination'>"+t("results.addination.more")+"</div>");f.bind("click",{offset:e.offset},a.addinationClicked);return f}else return""}};var PickyResultsRenderer=function(a,b){var i=b.locale,f=b.resultsDivider,e=b.wrapResults,k=b.nonPartial,q=function(r){var p=r[r.length-1];if(p===undefined)return[];r=r.slice(0,r.length-1);if(r==[])r=[r];if(!k.include(p[0]))if(p[1].match(/[^\*~]$/))p[1]+="*";r.push(p);return r};this.asteriskifyLastToken=q;var s=function(r){for(var p=Localization.explanations&&Localization.explanations[i]||{},g=[],d,j=0,m=r.length;j<m;j++){d=r[j];var n=d[0];n=p[n]||n;g.push([n,d[1]])}return g};this.explainCategory=
-s;var x=function(r,p){return[r.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),p].join(" ")};this.strongify=x;var v=function(r,p){var g=Localization.explanation_delimiters[i],d="",j=[],m=[];s(q(p)).each(function(n,u){var c=u[0],o=u[1];if(d==""||c==d){o=o.replace(/[\w,]+:(.+)/,"$1");j.push(o);d=c}else{var h=x(d,j.join(" "));j=[];j.push(o);d=c;m.push(h)}});m.push(x(d,j.join(" ")));m=m.join(" "+g+" ");return m='<span class="explanation">'+r+" "+m+"</span>"};
-this.explain=v;var y=function(r,p){var g='<div class="header">';g+=v(p.type,p.combination);if(r.offset>0)g+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';g+="</div>";return g};this.renderHeader=y;this.render=function(r,p){p.allocations.each(function(g,d){if(d.entries.length>0){r.append(y(p,d)).append(d.entries.join(f));r.children("li").wrapAll(e)}});r.append(a.render(p))}};function AllocationRenderer(a,b){function i(g){var d={},j={},m=[],n;n=0;for(l=g.length;n<l;n++){var u=g[n][0];if(u in d){d[u]=d[u]+" "+g[n][1];m.push(n)}else{d[u]=g[n][1];j[n]=u}}for(n in j)g[n][1]=d[j[n]];for(n=m.length-1;n>=0;n--)g.remove(m[n]);return g}function f(g){var d=[];g.each(function(j){d.push("%"+(j+1)+"$s")});return d.join(" ")}function e(g){if(g.length==0)return"";var d=g=i(g);d.sort(function(h,w){return h[0]<w[0]?-1:1});for(var j=[],m=0,n=d.length;m<n;m++)j.push(d[m][0]);var u=j.length==
-1,c=r[j.join(",")]||(r[j]=f(j));if(typeof c==="string"){r[j]={format:c};c=r[j]}var o=c.format;g.each(function(h,w){var z=w[0],A=w[2];if(c.filter)A=c.filter(A);z=v[z]||z;if(u&&!(c&&c.ignoreSingle))return o=A+"&nbsp;("+z+")";o=o.replace(RegExp("%"+(h+1)+"\\$s","g"),A)});return o}function k(g){for(var d=[],j=0,m=y.length;j<m;j++)d.push([]);d.push([]);j=0;for(m=g.length;j<m;j++){for(var n=g[j],u=n[0],c=false,o=0,h=y.length;o<h;o++)if(y[o].include(u)){d[o].push(n);c=true;break}c||d[d.length-1].push(n)}var w;
-for(g=d.length-1;g>=0;g--){w=d[g];if(w.length>0)break}w=w[w.length-1];p.include(w[0])||(w[1]+="...");var z=[];d.each(function(A,B){z.push(e(B))});return z}function q(g){return k(g).join(" ")}var s=b.locale,x=b.qualifiers&&b.qualifiers[s]||{},v=b.explanations&&b.explanations[s]||{},y=b.groups||[],r=b.choices&&b.choices[s]||{},p=b.nonPartial||[];this.explanation=this.query=this.text="";this.contract=i;this.makeUpMissingFormat=f;this.rendered=e;this.groupify=k;this.querify=function(g){var d=[],j,m;for(m in g){j=
-g[m][0];j=x[j]||j;d[m]=j+":"+g[m][2]}return d.join(" ")};this.suggestify=q;this.render=function(g){return q(g.combination)}};var PickyAllocationsCloud=function(a,b){var i=b.allocations,f=b.shownAllocations,e=b.showMoreAllocations,k=b.hiddenAllocations,q=b.maxSuggestions,s=function(){i.hide()},x=function(p){s();a.allocationChosen(p)},v=new AllocationRenderer(b),y=function(p){var g=[];p.each(function(d,j){var m=v.render(j),n=v.querify(j.combination);m=$('<li><div class="text">'+m+'</div><div class="count">'+j.count+"</div></li>");m.bind("click",{query:n},x);g.push(m)});return g},r=function(p){if(p.length==0)return i.hide();
-f.empty();e.hide();k.empty().hide();if(p.length>q){$.each(p.slice(0,q-1),function(g,d){f.append(d)});$.each(p.slice(q-1),function(g,d){k.append(d)});e.show()}else $.each(p,function(g,d){f.append(d)});return i.show()};e.click(function(){e.hide();k.show()});this.hide=s;this.show=function(p){r(y(p.allocations));i.show()}};
+a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var k=a.controller&&new a.controller(a)||new PickyController(a);var h=this.insert=function(g,m,o){k.insert(g,m||{},o||true)};this.resend=k.resend;
+this.insertFromURL=function(g){if(g&&g!="")h(g);else(g=k.lastFullQuery())&&h(g)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var h=k.total,g,m=k.renderedAmount();g=k.offset+m;m=g+m;k=k.total;if(k<m)m=k;g={offset:g,start:g+1,end:m};if(g.offset<h){h=$("<div class='addination'>"+t("results.addination.more")+"</div>");h.bind("click",{offset:g.offset},a.addinationClicked);return h}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,h=b.explanations||{},g=b.explanation_delimiters||{},m=b.resultsDivider,o=b.wrapResults,u=b.nonPartial,x=function(e){var d=e[e.length-1];if(d===undefined)return[];e=e.slice(0,e.length-1);if(e==[])e=[e];if(!u.include(d[0]))if(d[1].match(/[^\*~]$/))d[1]+="*";e.push(d);return e};this.asteriskifyLastToken=x;var s=function(e){for(var d=h[k]||{},n=[],i,q=0,r=e.length;q<r;q++){i=e[q];var c=i[0];c=d[c]||c;n.push([c,i[1]])}return n};this.explainCategory=
+s;var w=function(e,d){return[e.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),d].join(" ")};this.strongify=w;var y=function(e,d){var n=g[k],i="",q=[],r=[];s(x(d)).each(function(c,p){var f=p[0],v=p[1];v=v.replace(/[\w,]+:(.+)/,"$1");if(i==""||f==i){q.push(v);i=f}else{var z=w(i,q.join(" "));q=[];q.push(v);i=f;r.push(z)}});r.push(w(i,q.join(" ")));r=r.join(" "+n+" ");return r='<span class="explanation">'+e+" "+r+"</span>"};this.explain=y;var j=function(e,
+d){var n='<div class="header">';n+=y(d.type,d.combination);if(e.offset>0)n+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';n+="</div>";return n};this.renderHeader=j;this.render=function(e,d){d.allocations.each(function(n,i){if(i.entries.length>0){e.append(j(d,i)).append(i.entries.join(m));e.children("li").wrapAll(o)}});e.append(a.render(d))}};function AllocationRenderer(a){function b(j){var e={},d={},n=[],i;i=0;for(l=j.length;i<l;i++){var q=j[i][0];if(q in e){e[q]=e[q]+" "+j[i][1];n.push(i)}else{e[q]=j[i][1];d[i]=q}}for(i in d)j[i][1]=e[d[i]];for(i=n.length-1;i>=0;i--)j.remove(n[i]);return j}function k(j){var e=[];j.each(function(d){e.push("%"+(d+1)+"$s")});return e.join(" ")}function h(j){if(j.length==0)return"";var e=j=b(j);e.sort(function(p,f){return p[0]<f[0]?-1:1});for(var d=[],n=0,i=e.length;n<i;n++)d.push(e[n][0]);var q=d.length==
+1,r=w[d.join(",")]||(w[d]=k(d));if(typeof r==="string"){w[d]={format:r};r=w[d]}var c=r.format;j.each(function(p,f){var v=f[0],z=f[2];if(r.filter)z=r.filter(z);v=x[v]||v;if(q&&!(r&&r.ignoreSingle))return c=z+"&nbsp;("+v+")";c=c.replace(RegExp("%"+(p+1)+"\\$s","g"),z)});return c}function g(j){for(var e=[],d=0,n=s.length;d<n;d++)e.push([]);e.push([]);d=0;for(n=j.length;d<n;d++){for(var i=j[d],q=i[0],r=false,c=0,p=s.length;c<p;c++)if(s[c].include(q)){e[c].push(i);r=true;break}r||e[e.length-1].push(i)}var f;
+for(j=e.length-1;j>=0;j--){f=e[j];if(f.length>0)break}f=f[f.length-1];y.include(f[0])||(f[1]+="...");var v=[];e.each(function(z,A){v.push(h(A))});return v}function m(j){return g(j).join(" ")}var o=a.locale,u=a.qualifiers&&a.qualifiers[o]||{},x=a.explanations&&a.explanations[o]||{},s=a.groups||[],w=a.choices&&a.choices[o]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=h;this.groupify=g;this.querify=function(j){var e=[],d,n;for(n in j){d=
+j[n][0];d=u[d]||d;e[n]=d+":"+j[n][2]}return e.join(" ")};this.suggestify=m;this.render=function(j){return m(j.combination)}};var PickyAllocationsCloud=function(a,b){var k=b.allocations,h=b.shownAllocations,g=b.showMoreAllocations,m=b.hiddenAllocations,o=b.maxSuggestions,u=function(){k.hide()},x=function(j){u();a.allocationChosen(j)},s=new AllocationRenderer(b),w=function(j){var e=[];j.each(function(d,n){var i=s.render(n),q=s.querify(n.combination);i=$('<li><div class="text">'+i+'</div><div class="count">'+n.count+"</div></li>");i.bind("click",{query:q},x);e.push(i)});return e},y=function(j){if(j.length==0)return k.hide();
+h.empty();g.hide();m.empty().hide();if(j.length>o){$.each(j.slice(0,o-1),function(e,d){h.append(d)});$.each(j.slice(o-1),function(e,d){m.append(d)});g.show()}else $.each(j,function(e,d){h.append(d)});return k.show()};g.click(function(){g.hide();m.show()});this.hide=u;this.show=function(j){y(w(j.allocations));k.show()}};
Please sign in to comment.
Something went wrong with that request. Please try again.