Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ specs, ! choices -> queries and grouping of categories

  • Loading branch information...
commit 6251fb696761f41b8409ba947aa8c22ee78580ae 1 parent 16f0531
@floere authored
View
36 client/javascripts/picky.min.js
@@ -1,19 +1,19 @@
-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),g=dictionary,h=0,m=k.length;h<m;h++){g=g[k[h]];if(g==undefined){g="Translation missing: "+a+"."+b;break}}return g};function Allocation(a,b,k,g,h,m){var o=this;this.type=a;this.weight=b;this.count=k;this.combination=g;this.ids=h||[];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 g=a[b];this.allocations.push(new Allocation(g[0],g[1],g[2],g[3],g[4],g[5]))}this.length=this.allocations.length;this.remove=function(h){this.allocations.splice(h,1)};this.each=function(h){this.allocations.each(h)}}
-function PickyData(a){var b=a.total,k=a.duration,g=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=g;this.allocations=h;this.renderedAmount=function(){var m=0;h.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,g=b.input,h=b.reset,m=b.button,o=b.counter,u=b.dashboard,y=b.moreSelector,s=b.results,w=b.noResults,z=new PickyAddination(this,s),j=new PickyAllocationsCloud(this,b),e=new PickyResultsRenderer(z,b),d=function(){h.fadeTo(166,1)},n=function(){j.hide();s.empty();w.hide()},i=function(f){g.val(f);h.fadeTo(166,0);p("empty");o.empty();n()};this.reset=i;var q=function(){return g.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){g.val(f);g.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();g.focus()}else{var v=$(y).position().top;z.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(){g.keyup(function(f){if(q()==""){i();a.searchTextCleared()}else d();a.searchTextEntered(q(),f)});o.click(function(){a.searchButtonClicked(q())});m.click(function(){a.searchButtonClicked(q())});h.click(function(){i("");a.clearButtonClicked();
-g.focus()})})();g.focus()};var PickyBackend=function(a){var b=function(k,g,h){var m=h||{};m=$.extend({query:k},h);$.getJSON(a,m,function(o){g&&g(new PickyData(o))})};this.search=function(k,g,h,m){b(k,function(o){g&&g(m,o)},h)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(g,h,m,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);k.search(g,function(u,y){if(!u.live||u.live==latestRequestTimestamp)h&&
-h(y)},m,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(g,h,m,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);k.search(g,function(u,y){if(!u.full||u.full==latestRequestTimestamp)h&&h(y)},m,o)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,g=a.beforeInsert||function(){},h=a.before||function(){},m=a.success||function(){},o=a.after||function(){},u=a.liveRendered||false,y=a.liveSearchInterval||180,s,w=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var z=function(){var c=window.History&&window.History.getState();return w(c&&c.url)};this.lastFullQuery=z;var j=function(c,p,f,v){var x=
-h(p,v);if(x!=undefined)p=x;s=[c,p,f,v];x=p;if(x!=z()){x=x==""?"":"?q="+escape(x).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,x)}if(p=="")b.reset();else(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,y);clearInterval(i);var r=function(c,p,f){var v=g(c);if(v!=undefined)c=v;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,y)}};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!=undefined&&c!=(s&&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)};
+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};Array.prototype.map=function(a){for(var b=0,k=this.length;b<k;b++)this[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),i=dictionary,j=0,n=k.length;j<n;j++){i=i[k[j]];if(i==undefined){i="Translation missing: "+a+"."+b;break}}return i};function Allocation(a,b,k,i,j,n){var p=this;this.type=a;this.weight=b;this.count=k;this.combination=i;this.ids=j||[];this.entries=this.rendered=n||[];this.isType=function(u){return u==p.type}}function Allocations(a){this.allocations=[];for(var b=0,k=a.length;b<k;b++){var i=a[b];this.allocations.push(new Allocation(i[0],i[1],i[2],i[3],i[4],i[5]))}this.length=this.allocations.length;this.remove=function(j){this.allocations.splice(j,1)};this.each=function(j){this.allocations.each(j)}}
+function PickyData(a){var b=a.total,k=a.duration,i=a.offset,j=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=i;this.allocations=j;this.renderedAmount=function(){var n=0;j.each(function(p,u){n+=u.rendered.length});return n};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var k=b.showResultsLimit||10,i=b.input,j=b.reset,n=b.button,p=b.counter,u=b.dashboard,x=b.moreSelector,s=b.results,w=b.noResults,y=new PickyAddination(this,s),e=new PickyAllocationsCloud(this,b),c=new PickyResultsRenderer(y,b),g=function(){j.fadeTo(166,1)},o=function(){e.hide();s.empty();w.hide()},m=function(f){i.val(f);j.fadeTo(166,0);q("empty");p.empty();o()};this.reset=m;var h=function(){return i.val()};this.text=h;var r=function(f){p.text(f);f>0&&f<=5&&p.fadeTo("fast",
+0.5).fadeTo("fast",1)},d=function(f){if(f.isEmpty())return"none";if(f.total>k&&f.allocations.length>1)return"support";return"ok"},q=function(f){u.attr("class","dashboard "+f)};this.insert=function(f){i.val(f);i.select()};this.fullResultsCallback=function(f){q(d(f));if(f.isEmpty()){o();r(0);w.show();g()}else if(f.total>k&&f.allocations.length>1){o();g();e.show(f);r(f.total)}else if(f.offset==0){o();r(f.total);c.render(s,f);s.show();g();i.focus()}else{var v=$(x).position().top;y.remove();c.render(s,
+f);$("body").animate({scrollTop:v-12},500)}};this.liveResultsCallback=function(f){q(d(f));r(f.total)};this.allocationChosen=function(f){f=f.data.query;a.insert(f);a.allocationChosen(f)};this.addinationClicked=function(f){a.addinationClicked(h(),f)};(function(){i.keyup(function(f){if(h()==""){m();a.searchTextCleared()}else g();a.searchTextEntered(h(),f)});p.click(function(){a.searchButtonClicked(h())});n.click(function(){a.searchButtonClicked(h())});j.click(function(){m("");a.clearButtonClicked();
+i.focus()})})();i.focus()};var PickyBackend=function(a){var b=function(k,i,j){var n=j||{};n=$.extend({query:k},j);$.getJSON(a,n,function(p){i&&i(new PickyData(p))})};this.search=function(k,i,j,n){b(k,function(p){i&&i(n,p)},j)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(i,j,n,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;n=$.extend({ids:a.liveResults||0,offset:0},n);k.search(i,function(u,x){if(!u.live||u.live==latestRequestTimestamp)j&&
+j(x)},n,p)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(i,j,n,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;n=$.extend({ids:a.fullResults||20,offset:0},n);k.search(i,function(u,x){if(!u.full||u.full==latestRequestTimestamp)j&&j(x)},n,p)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,i=a.beforeInsert||function(){},j=a.before||function(){},n=a.success||function(){},p=a.after||function(){},u=a.liveRendered||false,x=a.liveSearchInterval||180,s,w=function(d){return(d=d&&d.match(/q=([^&]+)/))&&decodeURIComponent(d[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var y=function(){var d=window.History&&window.History.getState();return w(d&&d.url)};this.lastFullQuery=y;var e=function(d,q,f,v){var z=
+j(q,v);if(z!=undefined)q=z;s=[d,q,f,v];z=q;if(z!=y()){z=z==""?"":"?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}if(q=="")b.reset();else(d=k[d])&&d.search(q,f,v)};this.resend=function(){s&&e.apply(this,s)};var c=function(d,q){d=n(d,q)||d;b.fullResultsCallback(d);p(d,q)},g=function(d,q){clearInterval(m);e("full",d,c,q||{})};a=function(d,q){d=n(d,q)||d;b.liveResultsCallback(d);p(d,q)};var o=u?c:a,m,h=function(){var d=
+b.text();e("live",d,o,{});clearInterval(m)};m=setInterval(h,x);clearInterval(m);var r=function(d,q,f){var v=i(d);if(v!=undefined)d=v;b.insert(d);f&&g(d,q)};this.insert=r;this.clearButtonClicked=function(){clearInterval(m)};this.searchTextCleared=function(){clearInterval(m)};this.searchTextEntered=function(d,q){if($.inArray(q.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(q.keyCode==13)g(d);else{clearInterval(m);
+m=setInterval(h,x)}};this.searchButtonClicked=function(d){g(d)};this.allocationChosen=function(d){g(d)};this.addinationClicked=function(d,q){g(d,{offset:q.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var d=window.History.getState();d=w(d.url);d!=undefined&&d!=(s&&s.length>1&&s[1])&&r(d,{},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 k=a.controller&&new a.controller(a)||new PickyController(a);var g=this.insert=function(h,m,o){k.insert(h,m||{},o||true)};this.resend=k.resend;
-this.insertFromURL=function(h){if(h)g(h);else(h=k.lastFullQuery())&&g(h)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var g=k.total,h,m=k.renderedAmount();h=k.offset+m;m=h+m;k=k.total;if(k<m)m=k;h={offset:h,start:h+1,end:m};if(h.offset<g){g=$("<div class='addination'>"+t("results.addination.more")+"</div>");g.bind("click",{offset:h.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,g=b.explanations||{},h=b.explanation_delimiters||{},m=b.resultsDivider,o=b.wrapResults,u=b.nonPartial,y=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=y;var s=function(e){for(var d=g[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 z=function(e,d){var n=h[k],i="",q=[],r=[];s(y(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 x=w(i,q.join(" "));q=[];q.push(v);i=f;r.push(x)}});r.push(w(i,q.join(" ")));r=r.join(" "+n+" ");return r='<span class="explanation">'+e+" "+r+"</span>"};this.explain=z;var j=function(e,
-d){var n='<div class="header">';n+=z(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 g(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],x=f[2];if(r.filter)x=r.filter(x);v=y[v]||v;if(q&&!(r&&r.ignoreSingle))return c=x+"&nbsp;("+v+")";x=x.replace(/[\w,]+:(.+)/,"$1");c=c.replace(RegExp("%"+(p+1)+"\\$s","g"),x)});return c}function h(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];z.include(f[0])||(f[1]=f[1].valueOf()+"...");return e}function m(j){var e=[];h(j).each(function(d,n){e.push(g(n))});return e.join(" ")}var o=a.locale,u=a.qualifiers&&a.qualifiers[o]||{},y=a.explanations&&a.explanations[o]||{},s=a.groups||[],w=a.choices&&a.choices[o]||{},z=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=g;this.groupify=
-h;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,g=b.shownAllocations,h=b.showMoreAllocations,m=b.hiddenAllocations,o=b.maxSuggestions,u=function(){k.hide()},y=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},y);e.push(i)});return e},z=function(j){if(j.length==0)return k.hide();
-g.empty();h.hide();m.empty().hide();if(j.length>o){$.each(j.slice(0,o-1),function(e,d){g.append(d)});$.each(j.slice(o-1),function(e,d){m.append(d)});h.show()}else $.each(j,function(e,d){g.append(d)});return k.show()};h.click(function(){h.hide();m.show()});this.hide=u;this.show=function(j){z(w(j.allocations));k.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 i=this.insert=function(j,n,p){k.insert(j,n||{},p||true)};this.resend=k.resend;
+this.insertFromURL=function(j){if(j)i(j);else(j=k.lastFullQuery())&&i(j)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var i=k.total,j,n=k.renderedAmount();j=k.offset+n;n=j+n;k=k.total;if(k<n)n=k;j={offset:j,start:j+1,end:n};if(j.offset<i){i=$("<div class='addination'>"+t("results.addination.more")+"</div>");i.bind("click",{offset:j.offset},a.addinationClicked);return i}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,i=b.explanations||{},j=b.explanation_delimiters||{},n=b.resultsDivider,p=b.wrapResults,u=b.nonPartial,x=function(c){var g=c[c.length-1];if(g===undefined)return[];c=c.slice(0,c.length-1);if(c==[])c=[c];if(!u.include(g[0]))if(g[1].match(/[^\*~]$/))g[1]+="*";c.push(g);return c};this.asteriskifyLastToken=x;var s=function(c){for(var g=i[k]||{},o=[],m,h=0,r=c.length;h<r;h++){m=c[h];var d=m[0];d=g[d]||d;o.push([d,m[1]])}return o};this.explainCategory=
+s;var w=function(c,g){return[c.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),g].join(" ")};this.strongify=w;var y=function(c,g){var o=j[k],m="",h=[],r=[];s(x(g)).each(function(d,q){var f=q[0],v=q[1];v=v.replace(/[\w,]+:(.+)/,"$1");if(m==""||f==m){h.push(v);m=f}else{var z=w(m,h.join(" "));h=[];h.push(v);m=f;r.push(z)}});r.push(w(m,h.join(" ")));r=r.join(" "+o+" ");return r='<span class="explanation">'+c+" "+r+"</span>"};this.explain=y;var e=function(c,
+g){var o='<div class="header">';o+=y(g.type,g.combination);if(c.offset>0)o+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';o+="</div>";return o};this.renderHeader=e;this.render=function(c,g){g.allocations.each(function(o,m){if(m.entries.length>0){c.append(e(g,m)).append(m.entries.join(n));c.children("li").wrapAll(p)}});c.append(a.render(g))}};function AllocationRenderer(a){function b(e){var c={},g={},o={},m=[],h;h=0;for(l=e.length;h<l;h++){var r=e[h][0];if(r in c){c[r].push(e[h][1]);g[r].push(e[h][2]);m.push(h)}else{c[r]=[e[h][1]];g[r]=[e[h][2]];o[h]=r}}for(h in o){e[h][1]=c[o[h]];e[h][2]=g[o[h]]}for(h=m.length-1;h>=0;h--)e.remove(m[h]);return e}function k(e){e.map(function(c){return"%"+(c+1)+"$s"});return e.join(" ")}function i(e){if(e.length==0)return"";e=b(e);e.sort(function(d,q){return d[0]<q[0]?-1:1});for(var c=[],g=0,o=e.length;g<
+o;g++)c.push(e[g][0]);var m=c.length==1,h=w[c.join(",")];if(h===undefined)h=w[c]=k(c);if(typeof h==="string"){w[c]={format:h,ignoreSingle:true};h=w[c]}var r=h.format;e.each(function(d,q){var f=q[0],v=q[2];h.filter&&v.map(function(z,A){return h.filter(A)});if(m&&!(h&&h.ignoreSingle)){f=x[f]||f;return r=v.join("&nbsp;")+"&nbsp;("+f+")"}v.map(function(z,A){return A.replace(/[\w,]+:(.+)/,"$1")});r=r.replace(RegExp("%"+(d+1)+"\\$s","g"),v.join("&nbsp;"))});return r}function j(e){for(var c=[],g=0,o=s.length;g<
+o;g++)c.push([]);c.push([]);g=0;for(o=e.length;g<o;g++){for(var m=e[g],h=m[0],r=false,d=0,q=s.length;d<q;d++)if(s[d].include(h)){c[d].push(m);r=true;break}r||c[c.length-1].push(m)}var f;for(e=c.length-1;e>=0;e--){f=c[e];if(f.length>0)break}f=f[f.length-1];y.include(f[0])||(f[1]=f[1].valueOf()+"...");return c}function n(e){var c=[];j(e).each(function(g,o){var m=i(o);m&&c.push(m)});return c.join(" ")}var p=a.locale,u=a.qualifiers&&a.qualifiers[p]||{},x=a.explanations&&a.explanations[p]||{},s=a.groups||
+[],w=a.choices&&a.choices[p]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=i;this.groupify=j;this.querify=function(e){var c=[],g,o,m;for(m in e){g=e[m][0];g=u[g]||g;o=(o=e[m][1])||"";o=o.charAt(o.length-1)=="*"?"*":"";c[m]=g+":"+e[m][2]+o}return c.join(" ")};this.suggestify=n;this.render=function(e){return n(e.combination)}};var PickyAllocationsCloud=function(a,b){var k=b.allocations,i=b.shownAllocations,j=b.showMoreAllocations,n=b.hiddenAllocations,p=b.maxSuggestions,u=function(){k.hide()},x=function(e){u();a.allocationChosen(e)},s=new AllocationRenderer(b),w=function(e){var c=[];e.each(function(g,o){var m=s.querify(o.combination),h=s.render(o);h=$('<li><div class="text">'+h+'</div><div class="count">'+o.count+"</div></li>");h.bind("click",{query:m},x);c.push(h)});return c},y=function(e){if(e.length==0)return k.hide();
+i.empty();j.hide();n.empty().hide();if(e.length>p){$.each(e.slice(0,p-1),function(c,g){i.append(g)});$.each(e.slice(p-1),function(c,g){n.append(g)});j.show()}else $.each(e,function(c,g){i.append(g)});return k.show()};j.click(function(){j.hide();n.show()});this.hide=u;this.show=function(e){y(w(e.allocations));k.show()}};
View
BIN  client/javascripts/picky.source.js.tar
Binary file not shown
View
83 client/javascripts/source/picky.allocation_renderer.js
@@ -17,7 +17,16 @@ function AllocationRenderer(config) {
this.query = '';
this.explanation = '';
- // Contracts the originals of the zipped.
+ // Contracts the originals/parsed of the zipped into
+ // an array of originals/parsed.
+ //
+ // Example:
+ // ['cat2', 'Orig1', 'parsed1'],
+ // ['cat1', 'Orig2', 'parsed2'],
+ // ['cat2', 'Orig3', 'parsed3']
+ // becomes
+ // ['cat2', ['Orig1', 'Orig3'], ['parsed1', 'parsed3']],
+ // ['cat1', ['Orig2'], ['parsed2']]
//
function contract(zipped) {
var originals = {}; // Remembers the combined values.
@@ -31,12 +40,12 @@ function AllocationRenderer(config) {
for (i = 0, l = zipped.length; i < l; i++) {
var key = zipped[i][0];
if (key in originals) {
- originals[key] = originals[key] + ' ' + zipped[i][1];
- // parsed[key] = parsed[key] + ' ' + zipped[i][2];
+ originals[key].push(zipped[i][1]);
+ parsed[key].push(zipped[i][2]);
remove.push(i);
} else {
- originals[key] = zipped[i][1];
- // parsed[key] = zipped[i][2];
+ originals[key] = [zipped[i][1]];
+ parsed[key] = [zipped[i][2]];
insert[i] = key;
}
}
@@ -45,7 +54,7 @@ function AllocationRenderer(config) {
//
for (i in insert) {
zipped[i][1] = originals[insert[i]];
- // zipped[i][2] = parsed[insert[i]];
+ zipped[i][2] = parsed[insert[i]];
}
// Remove the ones from zipped we don't like. From the end.
@@ -62,22 +71,21 @@ function AllocationRenderer(config) {
// choice formatting defined in the config.
//
function makeUpMissingFormat(keys) {
- var result = [];
- keys.each(function(i, _) {
- result.push('%' + (i+1) + '$s');
+ keys.map(function(i, _) {
+ return '%' + (i+1) + '$s';
});
- return result.join(' ');
+ return keys.join(' ');
};
this.makeUpMissingFormat = makeUpMissingFormat;
//
//
- function rendered(zipped) {
+ function rendered(allocation) {
// Return an empty string if there are no combinations.
//
- if (zipped.length == 0) { return ''; };
+ if (allocation.length == 0) { return ''; };
- zipped = contract(zipped);
+ var zipped = contract(allocation);
var key_ary = zipped;
key_ary.sort(function(zipped1, zipped2) {
@@ -99,11 +107,16 @@ function AllocationRenderer(config) {
// Get the formatting to be replaced.
//
- var formatting = choices[keys.join(',')] || (choices[keys] = makeUpMissingFormat(keys));
+ var formatting = choices[keys.join(',')]
+ if (formatting === undefined) { formatting = (choices[keys] = makeUpMissingFormat(keys)) };
+
// If someone uses the simple format, change into complex format.
//
if (typeof formatting === "string") {
- choices[keys] = { format: formatting };
+ choices[keys] = {
+ format: formatting,
+ ignoreSingle: true
+ };
formatting = choices[keys];
};
@@ -114,20 +127,28 @@ function AllocationRenderer(config) {
//
zipped.each(function(i, original_token) {
var category = original_token[0];
- var word = original_token[2];
+ var words = original_token[2];
- if (formatting.filter) { word = formatting.filter(word); }
+ if (formatting.filter) {
+ words.map(function(i, word) {
+ return formatting.filter(word);
+ });
+ }
- var explanation = explanations[category] || category;
if (single && !(formatting && formatting.ignoreSingle)) {
- result = word + '&nbsp;(' + explanation + ')';
+ var explanation = explanations[category] || category;
+ result = words.join('&nbsp;') + '&nbsp;(' + explanation + ')';
return result;
}
-
- word = word.replace(/[\w,]+:(.+)/, "$1");
+
+ // Remove the category.
+ //
+ words.map(function(i, word) {
+ return word.replace(/[\w,]+:(.+)/, "$1");
+ });
var regexp = new RegExp("%" + (i+1) + "\\$s", "g");
- result = result.replace(regexp, word);
+ result = result.replace(regexp, words.join('&nbsp;'));
});
return result;
@@ -188,7 +209,7 @@ function AllocationRenderer(config) {
//
last_part = last_part[last_part.length-1];
- // And append ellipses. TODO Duplicate text!
+ // And append "ellipses".
//
if (!nonPartial.include(last_part[0])) { last_part[1] = last_part[1].valueOf() + '...'; }
@@ -198,14 +219,19 @@ function AllocationRenderer(config) {
// Creates a query string from combination and originals.
//
- function querify(zipped) {
+ function querify(combination) {
var query_parts = [];
var qualifier;
+ var original;
- for (var i in zipped) {
- qualifier = zipped[i][0];
+ for (var i in combination) {
+ qualifier = combination[i][0];
qualifier = qualifiers[qualifier] || qualifier; // Use the returned qualifier if none is given.
- query_parts[i] = qualifier + ':' + zipped[i][2]; // TODO Use original.
+ original = combination[i][1];
+ original = original || "";
+
+ var partial = original.charAt(original.length - 1) == '*' ? '*' : ''; // TODO This is not the way to do this!
+ query_parts[i] = qualifier + ':' + combination[i][2] + partial;
};
return query_parts.join(' ');
@@ -221,7 +247,8 @@ function AllocationRenderer(config) {
//
var result = [];
groups.each(function(i, group) {
- result.push(rendered(group));
+ var render = rendered(group);
+ if (render) { result.push(render); }
});
return result.join(' ');
View
2  client/javascripts/source/picky.allocations_cloud.js
@@ -45,8 +45,8 @@ var PickyAllocationsCloud = function(view, config) {
var shown = [];
allocations.each(function(i, allocation) {
- var rendered = allocationRenderer.render(allocation);
var query = allocationRenderer.querify(allocation.combination);
+ var rendered = allocationRenderer.render(allocation); // Note: Render destroys the data.
rendered = listItem(rendered, allocation.count);
rendered.bind('click', { query: query }, allocationChosenCallback);
View
7 client/javascripts/source/picky.extensions.js
@@ -23,4 +23,11 @@ Array.prototype.each = function(callback) {
callback(i, this[i]);
}
return this;
+}
+
+Array.prototype.map = function(callback) {
+ for(var i = 0, l = this.length; i < l; i++) {
+ this[i] = callback(i, this[i]);
+ }
+ return this;
}
View
103 client/javascripts/spec/picky.allocation_renderer.spec.js
@@ -4,6 +4,7 @@ describe(
function() {
renderer = new AllocationRenderer({
locale: 'en',
+ groups: [['invisible']], // Invisible is first, always.
choices: {
en:{
'title': {
@@ -16,7 +17,9 @@ describe(
filter: function(text) { return text.toLowerCase(); },
ignoreSingle: true
},
+ 'invisible': '', // Not visible.
'author,title': '%1$s, who wrote %2$s',
+ 'invisible,title': 'only %2$s is visible'
}
}
});
@@ -47,8 +50,8 @@ describe(
['cat1', 'Orig2', 'parsed2'],
['cat2', 'Orig3', 'parsed3']
]).compare([
- ['cat2', 'Orig1 Orig3', 'parsed1 parsed3'], // TODO Should this be an array? Is just parsed1 ok? Do we care?
- ['cat1', 'Orig2', 'parsed2']
+ ['cat2', ['Orig1', 'Orig3'], ['parsed1', 'parsed3']],
+ ['cat1', ['Orig2'], ['parsed2']]
]);
});
it("is correct", function() {
@@ -58,30 +61,36 @@ describe(
['cat2', 'Orig3', 'parsed3'],
['cat1', 'Orig4', 'parsed4']
]).compare([
- ['cat2', 'Orig1 Orig3', 'parsed1 parsed3'], // TODO Is just parsed1 ok? Do we care?
- ['cat1', 'Orig2 Orig4', 'parsed2 parsed4']
+ ['cat2', ['Orig1', 'Orig3'], ['parsed1', 'parsed3']],
+ ['cat1', ['Orig2', 'Orig4'], ['parsed2', 'parsed4']]
]);
});
});
describe("rendered", null, function() {
it("is correct", function() {
- return renderer.rendered([['cat1', 'Orig1 Orig2', 'parsed1']]) == "parsed1&nbsp;(cat1)";
- });
- it("is correct", function() {
return renderer.rendered([
- ['cat1', 'Orig1 Orig2', 'parsed1'],
- ['cat2', 'Orig3 Orig4', 'parsed2']
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat2', 'Orig2', 'parsed2']
]) == "parsed1 parsed2";
});
it("is correct", function() {
+ return renderer.rendered(
+ [
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat1', 'Orig2', 'parsed2']
+ ]
+ ) == "parsed1&nbsp;parsed2";
+ });
+ it("is correct", function() {
return renderer.rendered([
['title', 'Title1', 'title1']
]) == "TITLE1&nbsp;(title)";
});
it("is correct", function() {
return renderer.rendered([
- ['title', 'Title1 Title2', 'title1 title2']
- ]) == "TITLE1 TITLE2&nbsp;(title)";
+ ['title', 'Title1', 'title1'],
+ ['title', 'Title2', 'title2']
+ ]) == "TITLE1&nbsp;TITLE2&nbsp;(title)";
});
it("is correct", function() {
return renderer.rendered([
@@ -90,8 +99,9 @@ describe(
});
it("is correct", function() {
return renderer.rendered([
- ['author', 'Author1 Author2', 'author1 author2']
- ]) == "<em>author1 author2</em>";
+ ['author', 'Author1', 'author1'],
+ ['author', 'Author2', 'author2']
+ ]) == "<em>author1&nbsp;author2</em>";
});
it("is correct", function() {
return renderer.rendered([
@@ -105,32 +115,75 @@ describe(
['author', 'Author1', 'author:author1']
]) == "author1, who wrote title1";
});
+ it("is correct", function() {
+ return renderer.rendered([
+ ['invisible', 'Invisible1', 'invisible:invisible1'],
+ ['title', 'Title1', 'title:title1']
+ ]) == "only title1 is visible";
+ });
+ it("is correct", function() {
+ return renderer.rendered([
+ ['invisible', 'Invisible1', 'invisible:invisible1'],
+ ['invisible', 'Invisible2', 'invisible:invisible2'],
+ ['title', 'Title1', 'title:title1']
+ ]) == "only title1 is visible";
+ });
+ it("is correct", function() {
+ return renderer.rendered([
+ ['title', 'Title1', 'title:title1'],
+ ['invisible', 'Invisible1', 'invisible:invisible1'],
+ ['invisible', 'Invisible2', 'invisible:invisible2']
+ ]) == "only title1 is visible";
+ });
});
describe("groupify", null, function() {
it("is correct", function() {
return renderer.groupify([
['cat1', 'Orig1', 'parsed1']
- ]).compare([['cat1', 'Orig1...', 'parsed1']]);
+ ]).compare([
+ ['cat1', 'Orig1...', 'parsed1']
+ ]);
});
it("is correct", function() {
return renderer.groupify([
['cat1', 'Orig1', 'parsed1'],
['cat2', 'Orig2', 'parsed2']
]).compare([
- ['cat1', 'Orig1', 'parsed1'],
- ['cat2', 'Orig2...', 'parsed2']
- ]);
+ [],
+ [
+ ['cat1', 'Orig1', 'parsed1'], // Both in the second group.
+ ['cat2', 'Orig2...', 'parsed2']
+ ]
+ ]);
});
it("is correct", function() {
return renderer.groupify([
['cat1', 'Orig1', 'parsed1'],
['cat2', 'Orig2', 'parsed2'],
- ['cat1', 'Orig3', 'parsed3']
+ ['cat1', 'Orig3', 'parsed3']
+ ]).compare([
+ [],
+ [
+ ['cat1', 'Orig1', 'parsed1'], // All in the second group.
+ ['cat2', 'Orig2', 'parsed2'],
+ ['cat1', 'Orig3...', 'parsed3']
+ ]
+ ]);
+ });
+ it("is correct", function() {
+ return renderer.groupify([
+ ['cat1', 'Orig1', 'parsed1'],
+ ['invisible', 'Invisible2', 'invisible2'],
+ ['cat1', 'Orig2', 'parsed2']
]).compare([
- ['cat1', 'Orig1', 'parsed1'],
- ['cat2', 'Orig2', 'parsed2'],
- ['cat1', 'Orig3...', 'parsed3']
- ]);
+ [
+ ['invisible', 'Invisible2', 'invisible2']
+ ],
+ [
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat1', 'Orig2...', 'parsed2']
+ ]
+ ]);
});
});
describe("querify", null, function() {
@@ -141,7 +194,7 @@ describe(
});
it("is correct", function() {
return renderer.querify([
- ['cat1', 'Orig1*', 'parsed1*']
+ ['cat1', 'Orig1*', 'parsed1']
]) == "cat1:parsed1*";
});
it("is correct", function() {
@@ -152,7 +205,7 @@ describe(
});
it("is correct", function() {
return renderer.querify([
- ['cat1', 'Orig1*', 'parsed1*'],
+ ['cat1', 'Orig1*', 'parsed1'],
['cat2', 'Orig2', 'parsed2']
]) == "cat1:parsed1* cat2:parsed2";
});
@@ -161,7 +214,7 @@ describe(
it("is correct", function() {
return renderer.suggestify([
['cat1', 'Orig1', 'parsed1']
- ]) == "parsed1&nbsp;(cat1)";
+ ]) == "parsed1";
});
it("is correct", function() {
return renderer.suggestify([
View
83 client/test_project/javascripts/picky.allocation_renderer.js
@@ -17,7 +17,16 @@ function AllocationRenderer(config) {
this.query = '';
this.explanation = '';
- // Contracts the originals of the zipped.
+ // Contracts the originals/parsed of the zipped into
+ // an array of originals/parsed.
+ //
+ // Example:
+ // ['cat2', 'Orig1', 'parsed1'],
+ // ['cat1', 'Orig2', 'parsed2'],
+ // ['cat2', 'Orig3', 'parsed3']
+ // becomes
+ // ['cat2', ['Orig1', 'Orig3'], ['parsed1', 'parsed3']],
+ // ['cat1', ['Orig2'], ['parsed2']]
//
function contract(zipped) {
var originals = {}; // Remembers the combined values.
@@ -31,12 +40,12 @@ function AllocationRenderer(config) {
for (i = 0, l = zipped.length; i < l; i++) {
var key = zipped[i][0];
if (key in originals) {
- originals[key] = originals[key] + ' ' + zipped[i][1];
- // parsed[key] = parsed[key] + ' ' + zipped[i][2];
+ originals[key].push(zipped[i][1]);
+ parsed[key].push(zipped[i][2]);
remove.push(i);
} else {
- originals[key] = zipped[i][1];
- // parsed[key] = zipped[i][2];
+ originals[key] = [zipped[i][1]];
+ parsed[key] = [zipped[i][2]];
insert[i] = key;
}
}
@@ -45,7 +54,7 @@ function AllocationRenderer(config) {
//
for (i in insert) {
zipped[i][1] = originals[insert[i]];
- // zipped[i][2] = parsed[insert[i]];
+ zipped[i][2] = parsed[insert[i]];
}
// Remove the ones from zipped we don't like. From the end.
@@ -62,22 +71,21 @@ function AllocationRenderer(config) {
// choice formatting defined in the config.
//
function makeUpMissingFormat(keys) {
- var result = [];
- keys.each(function(i, _) {
- result.push('%' + (i+1) + '$s');
+ keys.map(function(i, _) {
+ return '%' + (i+1) + '$s';
});
- return result.join(' ');
+ return keys.join(' ');
};
this.makeUpMissingFormat = makeUpMissingFormat;
//
//
- function rendered(zipped) {
+ function rendered(allocation) {
// Return an empty string if there are no combinations.
//
- if (zipped.length == 0) { return ''; };
+ if (allocation.length == 0) { return ''; };
- zipped = contract(zipped);
+ var zipped = contract(allocation);
var key_ary = zipped;
key_ary.sort(function(zipped1, zipped2) {
@@ -99,11 +107,16 @@ function AllocationRenderer(config) {
// Get the formatting to be replaced.
//
- var formatting = choices[keys.join(',')] || (choices[keys] = makeUpMissingFormat(keys));
+ var formatting = choices[keys.join(',')]
+ if (formatting === undefined) { formatting = (choices[keys] = makeUpMissingFormat(keys)) };
+
// If someone uses the simple format, change into complex format.
//
if (typeof formatting === "string") {
- choices[keys] = { format: formatting };
+ choices[keys] = {
+ format: formatting,
+ ignoreSingle: true
+ };
formatting = choices[keys];
};
@@ -114,20 +127,28 @@ function AllocationRenderer(config) {
//
zipped.each(function(i, original_token) {
var category = original_token[0];
- var word = original_token[2];
+ var words = original_token[2];
- if (formatting.filter) { word = formatting.filter(word); }
+ if (formatting.filter) {
+ words.map(function(i, word) {
+ return formatting.filter(word);
+ });
+ }
- var explanation = explanations[category] || category;
if (single && !(formatting && formatting.ignoreSingle)) {
- result = word + '&nbsp;(' + explanation + ')';
+ var explanation = explanations[category] || category;
+ result = words.join('&nbsp;') + '&nbsp;(' + explanation + ')';
return result;
}
-
- word = word.replace(/[\w,]+:(.+)/, "$1");
+
+ // Remove the category.
+ //
+ words.map(function(i, word) {
+ return word.replace(/[\w,]+:(.+)/, "$1");
+ });
var regexp = new RegExp("%" + (i+1) + "\\$s", "g");
- result = result.replace(regexp, word);
+ result = result.replace(regexp, words.join('&nbsp;'));
});
return result;
@@ -188,7 +209,7 @@ function AllocationRenderer(config) {
//
last_part = last_part[last_part.length-1];
- // And append ellipses. TODO Duplicate text!
+ // And append "ellipses".
//
if (!nonPartial.include(last_part[0])) { last_part[1] = last_part[1].valueOf() + '...'; }
@@ -198,14 +219,19 @@ function AllocationRenderer(config) {
// Creates a query string from combination and originals.
//
- function querify(zipped) {
+ function querify(combination) {
var query_parts = [];
var qualifier;
+ var original;
- for (var i in zipped) {
- qualifier = zipped[i][0];
+ for (var i in combination) {
+ qualifier = combination[i][0];
qualifier = qualifiers[qualifier] || qualifier; // Use the returned qualifier if none is given.
- query_parts[i] = qualifier + ':' + zipped[i][2]; // TODO Use original.
+ original = combination[i][1];
+ original = original || "";
+
+ var partial = original.charAt(original.length - 1) == '*' ? '*' : ''; // TODO This is not the way to do this!
+ query_parts[i] = qualifier + ':' + combination[i][2] + partial;
};
return query_parts.join(' ');
@@ -221,7 +247,8 @@ function AllocationRenderer(config) {
//
var result = [];
groups.each(function(i, group) {
- result.push(rendered(group));
+ var render = rendered(group);
+ if (render) { result.push(render); }
});
return result.join(' ');
View
2  client/test_project/javascripts/picky.allocations_cloud.js
@@ -45,8 +45,8 @@ var PickyAllocationsCloud = function(view, config) {
var shown = [];
allocations.each(function(i, allocation) {
- var rendered = allocationRenderer.render(allocation);
var query = allocationRenderer.querify(allocation.combination);
+ var rendered = allocationRenderer.render(allocation); // Note: Render destroys the data.
rendered = listItem(rendered, allocation.count);
rendered.bind('click', { query: query }, allocationChosenCallback);
View
7 client/test_project/javascripts/picky.extensions.js
@@ -23,4 +23,11 @@ Array.prototype.each = function(callback) {
callback(i, this[i]);
}
return this;
+}
+
+Array.prototype.map = function(callback) {
+ for(var i = 0, l = this.length; i < l; i++) {
+ this[i] = callback(i, this[i]);
+ }
+ return this;
}
View
36 generators/prototypes/client/sinatra/javascripts/picky.min.js
@@ -1,19 +1,19 @@
-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),g=dictionary,h=0,m=k.length;h<m;h++){g=g[k[h]];if(g==undefined){g="Translation missing: "+a+"."+b;break}}return g};function Allocation(a,b,k,g,h,m){var o=this;this.type=a;this.weight=b;this.count=k;this.combination=g;this.ids=h||[];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 g=a[b];this.allocations.push(new Allocation(g[0],g[1],g[2],g[3],g[4],g[5]))}this.length=this.allocations.length;this.remove=function(h){this.allocations.splice(h,1)};this.each=function(h){this.allocations.each(h)}}
-function PickyData(a){var b=a.total,k=a.duration,g=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=g;this.allocations=h;this.renderedAmount=function(){var m=0;h.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,g=b.input,h=b.reset,m=b.button,o=b.counter,u=b.dashboard,y=b.moreSelector,s=b.results,w=b.noResults,z=new PickyAddination(this,s),j=new PickyAllocationsCloud(this,b),e=new PickyResultsRenderer(z,b),d=function(){h.fadeTo(166,1)},n=function(){j.hide();s.empty();w.hide()},i=function(f){g.val(f);h.fadeTo(166,0);p("empty");o.empty();n()};this.reset=i;var q=function(){return g.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){g.val(f);g.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();g.focus()}else{var v=$(y).position().top;z.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(){g.keyup(function(f){if(q()==""){i();a.searchTextCleared()}else d();a.searchTextEntered(q(),f)});o.click(function(){a.searchButtonClicked(q())});m.click(function(){a.searchButtonClicked(q())});h.click(function(){i("");a.clearButtonClicked();
-g.focus()})})();g.focus()};var PickyBackend=function(a){var b=function(k,g,h){var m=h||{};m=$.extend({query:k},h);$.getJSON(a,m,function(o){g&&g(new PickyData(o))})};this.search=function(k,g,h,m){b(k,function(o){g&&g(m,o)},h)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(g,h,m,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);k.search(g,function(u,y){if(!u.live||u.live==latestRequestTimestamp)h&&
-h(y)},m,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(g,h,m,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);k.search(g,function(u,y){if(!u.full||u.full==latestRequestTimestamp)h&&h(y)},m,o)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,g=a.beforeInsert||function(){},h=a.before||function(){},m=a.success||function(){},o=a.after||function(){},u=a.liveRendered||false,y=a.liveSearchInterval||180,s,w=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var z=function(){var c=window.History&&window.History.getState();return w(c&&c.url)};this.lastFullQuery=z;var j=function(c,p,f,v){var x=
-h(p,v);if(x!=undefined)p=x;s=[c,p,f,v];x=p;if(x!=z()){x=x==""?"":"?q="+escape(x).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,x)}if(p=="")b.reset();else(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,y);clearInterval(i);var r=function(c,p,f){var v=g(c);if(v!=undefined)c=v;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,y)}};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!=undefined&&c!=(s&&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)};
+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};Array.prototype.map=function(a){for(var b=0,k=this.length;b<k;b++)this[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),i=dictionary,j=0,n=k.length;j<n;j++){i=i[k[j]];if(i==undefined){i="Translation missing: "+a+"."+b;break}}return i};function Allocation(a,b,k,i,j,n){var p=this;this.type=a;this.weight=b;this.count=k;this.combination=i;this.ids=j||[];this.entries=this.rendered=n||[];this.isType=function(u){return u==p.type}}function Allocations(a){this.allocations=[];for(var b=0,k=a.length;b<k;b++){var i=a[b];this.allocations.push(new Allocation(i[0],i[1],i[2],i[3],i[4],i[5]))}this.length=this.allocations.length;this.remove=function(j){this.allocations.splice(j,1)};this.each=function(j){this.allocations.each(j)}}
+function PickyData(a){var b=a.total,k=a.duration,i=a.offset,j=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=k;this.offset=i;this.allocations=j;this.renderedAmount=function(){var n=0;j.each(function(p,u){n+=u.rendered.length});return n};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var k=b.showResultsLimit||10,i=b.input,j=b.reset,n=b.button,p=b.counter,u=b.dashboard,x=b.moreSelector,s=b.results,w=b.noResults,y=new PickyAddination(this,s),e=new PickyAllocationsCloud(this,b),c=new PickyResultsRenderer(y,b),g=function(){j.fadeTo(166,1)},o=function(){e.hide();s.empty();w.hide()},m=function(f){i.val(f);j.fadeTo(166,0);q("empty");p.empty();o()};this.reset=m;var h=function(){return i.val()};this.text=h;var r=function(f){p.text(f);f>0&&f<=5&&p.fadeTo("fast",
+0.5).fadeTo("fast",1)},d=function(f){if(f.isEmpty())return"none";if(f.total>k&&f.allocations.length>1)return"support";return"ok"},q=function(f){u.attr("class","dashboard "+f)};this.insert=function(f){i.val(f);i.select()};this.fullResultsCallback=function(f){q(d(f));if(f.isEmpty()){o();r(0);w.show();g()}else if(f.total>k&&f.allocations.length>1){o();g();e.show(f);r(f.total)}else if(f.offset==0){o();r(f.total);c.render(s,f);s.show();g();i.focus()}else{var v=$(x).position().top;y.remove();c.render(s,
+f);$("body").animate({scrollTop:v-12},500)}};this.liveResultsCallback=function(f){q(d(f));r(f.total)};this.allocationChosen=function(f){f=f.data.query;a.insert(f);a.allocationChosen(f)};this.addinationClicked=function(f){a.addinationClicked(h(),f)};(function(){i.keyup(function(f){if(h()==""){m();a.searchTextCleared()}else g();a.searchTextEntered(h(),f)});p.click(function(){a.searchButtonClicked(h())});n.click(function(){a.searchButtonClicked(h())});j.click(function(){m("");a.clearButtonClicked();
+i.focus()})})();i.focus()};var PickyBackend=function(a){var b=function(k,i,j){var n=j||{};n=$.extend({query:k},j);$.getJSON(a,n,function(p){i&&i(new PickyData(p))})};this.search=function(k,i,j,n){b(k,function(p){i&&i(n,p)},j)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),k=new PickyBackend(b);this.search=function(i,j,n,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;n=$.extend({ids:a.liveResults||0,offset:0},n);k.search(i,function(u,x){if(!u.live||u.live==latestRequestTimestamp)j&&
+j(x)},n,p)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),k=new PickyBackend(b);this.search=function(i,j,n,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;n=$.extend({ids:a.fullResults||20,offset:0},n);k.search(i,function(u,x){if(!u.full||u.full==latestRequestTimestamp)j&&j(x)},n,p)}};var PickyController=function(a){var b=new PickyView(this,a),k=a.backends,i=a.beforeInsert||function(){},j=a.before||function(){},n=a.success||function(){},p=a.after||function(){},u=a.liveRendered||false,x=a.liveSearchInterval||180,s,w=function(d){return(d=d&&d.match(/q=([^&]+)/))&&decodeURIComponent(d[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var y=function(){var d=window.History&&window.History.getState();return w(d&&d.url)};this.lastFullQuery=y;var e=function(d,q,f,v){var z=
+j(q,v);if(z!=undefined)q=z;s=[d,q,f,v];z=q;if(z!=y()){z=z==""?"":"?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}if(q=="")b.reset();else(d=k[d])&&d.search(q,f,v)};this.resend=function(){s&&e.apply(this,s)};var c=function(d,q){d=n(d,q)||d;b.fullResultsCallback(d);p(d,q)},g=function(d,q){clearInterval(m);e("full",d,c,q||{})};a=function(d,q){d=n(d,q)||d;b.liveResultsCallback(d);p(d,q)};var o=u?c:a,m,h=function(){var d=
+b.text();e("live",d,o,{});clearInterval(m)};m=setInterval(h,x);clearInterval(m);var r=function(d,q,f){var v=i(d);if(v!=undefined)d=v;b.insert(d);f&&g(d,q)};this.insert=r;this.clearButtonClicked=function(){clearInterval(m)};this.searchTextCleared=function(){clearInterval(m)};this.searchTextEntered=function(d,q){if($.inArray(q.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(q.keyCode==13)g(d);else{clearInterval(m);
+m=setInterval(h,x)}};this.searchButtonClicked=function(d){g(d)};this.allocationChosen=function(d){g(d)};this.addinationClicked=function(d,q){g(d,{offset:q.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var d=window.History.getState();d=w(d.url);d!=undefined&&d!=(s&&s.length>1&&s[1])&&r(d,{},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 k=a.controller&&new a.controller(a)||new PickyController(a);var g=this.insert=function(h,m,o){k.insert(h,m||{},o||true)};this.resend=k.resend;
-this.insertFromURL=function(h){if(h)g(h);else(h=k.lastFullQuery())&&g(h)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var g=k.total,h,m=k.renderedAmount();h=k.offset+m;m=h+m;k=k.total;if(k<m)m=k;h={offset:h,start:h+1,end:m};if(h.offset<g){g=$("<div class='addination'>"+t("results.addination.more")+"</div>");g.bind("click",{offset:h.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,g=b.explanations||{},h=b.explanation_delimiters||{},m=b.resultsDivider,o=b.wrapResults,u=b.nonPartial,y=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=y;var s=function(e){for(var d=g[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 z=function(e,d){var n=h[k],i="",q=[],r=[];s(y(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 x=w(i,q.join(" "));q=[];q.push(v);i=f;r.push(x)}});r.push(w(i,q.join(" ")));r=r.join(" "+n+" ");return r='<span class="explanation">'+e+" "+r+"</span>"};this.explain=z;var j=function(e,
-d){var n='<div class="header">';n+=z(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 g(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],x=f[2];if(r.filter)x=r.filter(x);v=y[v]||v;if(q&&!(r&&r.ignoreSingle))return c=x+"&nbsp;("+v+")";x=x.replace(/[\w,]+:(.+)/,"$1");c=c.replace(RegExp("%"+(p+1)+"\\$s","g"),x)});return c}function h(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];z.include(f[0])||(f[1]=f[1].valueOf()+"...");return e}function m(j){var e=[];h(j).each(function(d,n){e.push(g(n))});return e.join(" ")}var o=a.locale,u=a.qualifiers&&a.qualifiers[o]||{},y=a.explanations&&a.explanations[o]||{},s=a.groups||[],w=a.choices&&a.choices[o]||{},z=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=g;this.groupify=
-h;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,g=b.shownAllocations,h=b.showMoreAllocations,m=b.hiddenAllocations,o=b.maxSuggestions,u=function(){k.hide()},y=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},y);e.push(i)});return e},z=function(j){if(j.length==0)return k.hide();
-g.empty();h.hide();m.empty().hide();if(j.length>o){$.each(j.slice(0,o-1),function(e,d){g.append(d)});$.each(j.slice(o-1),function(e,d){m.append(d)});h.show()}else $.each(j,function(e,d){g.append(d)});return k.show()};h.click(function(){h.hide();m.show()});this.hide=u;this.show=function(j){z(w(j.allocations));k.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 i=this.insert=function(j,n,p){k.insert(j,n||{},p||true)};this.resend=k.resend;
+this.insertFromURL=function(j){if(j)i(j);else(j=k.lastFullQuery())&&i(j)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(k){var i=k.total,j,n=k.renderedAmount();j=k.offset+n;n=j+n;k=k.total;if(k<n)n=k;j={offset:j,start:j+1,end:n};if(j.offset<i){i=$("<div class='addination'>"+t("results.addination.more")+"</div>");i.bind("click",{offset:j.offset},a.addinationClicked);return i}else return""}};var PickyResultsRenderer=function(a,b){var k=b.locale,i=b.explanations||{},j=b.explanation_delimiters||{},n=b.resultsDivider,p=b.wrapResults,u=b.nonPartial,x=function(c){var g=c[c.length-1];if(g===undefined)return[];c=c.slice(0,c.length-1);if(c==[])c=[c];if(!u.include(g[0]))if(g[1].match(/[^\*~]$/))g[1]+="*";c.push(g);return c};this.asteriskifyLastToken=x;var s=function(c){for(var g=i[k]||{},o=[],m,h=0,r=c.length;h<r;h++){m=c[h];var d=m[0];d=g[d]||d;o.push([d,m[1]])}return o};this.explainCategory=
+s;var w=function(c,g){return[c.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),g].join(" ")};this.strongify=w;var y=function(c,g){var o=j[k],m="",h=[],r=[];s(x(g)).each(function(d,q){var f=q[0],v=q[1];v=v.replace(/[\w,]+:(.+)/,"$1");if(m==""||f==m){h.push(v);m=f}else{var z=w(m,h.join(" "));h=[];h.push(v);m=f;r.push(z)}});r.push(w(m,h.join(" ")));r=r.join(" "+o+" ");return r='<span class="explanation">'+c+" "+r+"</span>"};this.explain=y;var e=function(c,
+g){var o='<div class="header">';o+=y(g.type,g.combination);if(c.offset>0)o+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';o+="</div>";return o};this.renderHeader=e;this.render=function(c,g){g.allocations.each(function(o,m){if(m.entries.length>0){c.append(e(g,m)).append(m.entries.join(n));c.children("li").wrapAll(p)}});c.append(a.render(g))}};function AllocationRenderer(a){function b(e){var c={},g={},o={},m=[],h;h=0;for(l=e.length;h<l;h++){var r=e[h][0];if(r in c){c[r].push(e[h][1]);g[r].push(e[h][2]);m.push(h)}else{c[r]=[e[h][1]];g[r]=[e[h][2]];o[h]=r}}for(h in o){e[h][1]=c[o[h]];e[h][2]=g[o[h]]}for(h=m.length-1;h>=0;h--)e.remove(m[h]);return e}function k(e){e.map(function(c){return"%"+(c+1)+"$s"});return e.join(" ")}function i(e){if(e.length==0)return"";e=b(e);e.sort(function(d,q){return d[0]<q[0]?-1:1});for(var c=[],g=0,o=e.length;g<
+o;g++)c.push(e[g][0]);var m=c.length==1,h=w[c.join(",")];if(h===undefined)h=w[c]=k(c);if(typeof h==="string"){w[c]={format:h,ignoreSingle:true};h=w[c]}var r=h.format;e.each(function(d,q){var f=q[0],v=q[2];h.filter&&v.map(function(z,A){return h.filter(A)});if(m&&!(h&&h.ignoreSingle)){f=x[f]||f;return r=v.join("&nbsp;")+"&nbsp;("+f+")"}v.map(function(z,A){return A.replace(/[\w,]+:(.+)/,"$1")});r=r.replace(RegExp("%"+(d+1)+"\\$s","g"),v.join("&nbsp;"))});return r}function j(e){for(var c=[],g=0,o=s.length;g<
+o;g++)c.push([]);c.push([]);g=0;for(o=e.length;g<o;g++){for(var m=e[g],h=m[0],r=false,d=0,q=s.length;d<q;d++)if(s[d].include(h)){c[d].push(m);r=true;break}r||c[c.length-1].push(m)}var f;for(e=c.length-1;e>=0;e--){f=c[e];if(f.length>0)break}f=f[f.length-1];y.include(f[0])||(f[1]=f[1].valueOf()+"...");return c}function n(e){var c=[];j(e).each(function(g,o){var m=i(o);m&&c.push(m)});return c.join(" ")}var p=a.locale,u=a.qualifiers&&a.qualifiers[p]||{},x=a.explanations&&a.explanations[p]||{},s=a.groups||
+[],w=a.choices&&a.choices[p]||{},y=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=k;this.rendered=i;this.groupify=j;this.querify=function(e){var c=[],g,o,m;for(m in e){g=e[m][0];g=u[g]||g;o=(o=e[m][1])||"";o=o.charAt(o.length-1)=="*"?"*":"";c[m]=g+":"+e[m][2]+o}return c.join(" ")};this.suggestify=n;this.render=function(e){return n(e.combination)}};var PickyAllocationsCloud=function(a,b){var k=b.allocations,i=b.shownAllocations,j=b.showMoreAllocations,n=b.hiddenAllocations,p=b.maxSuggestions,u=function(){k.hide()},x=function(e){u();a.allocationChosen(e)},s=new AllocationRenderer(b),w=function(e){var c=[];e.each(function(g,o){var m=s.querify(o.combination),h=s.render(o);h=$('<li><div class="text">'+h+'</div><div class="count">'+o.count+"</div></li>");h.bind("click",{query:m},x);c.push(h)});return c},y=function(e){if(e.length==0)return k.hide();
+i.empty();j.hide();n.empty().hide();if(e.length>p){$.each(e.slice(0,p-1),function(c,g){i.append(g)});$.each(e.slice(p-1),function(c,g){n.append(g)});j.show()}else $.each(e,function(c,g){i.append(g)});return k.show()};j.click(function(){j.hide();n.show()});this.hide=u;this.show=function(e){y(w(e.allocations));k.show()}};

0 comments on commit 6251fb6

Please sign in to comment.
Something went wrong with that request. Please try again.