Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ more tests for the client JS

  • Loading branch information...
commit 6bc9e9a7bbcc6212d9839425339c5f0179dc10e4 1 parent e7ac35e
Florian R. Hanke authored
Showing with 568 additions and 94 deletions.
  1. +19 −20 client/javascripts/picky.min.js
  2. BIN  client/javascripts/picky.source.js.tar
  3. +2 −0  client/javascripts/source/picky.addination.js
  4. +1 −1  client/javascripts/source/picky.allocation_renderer.js
  5. +7 −6 client/javascripts/source/picky.client.js
  6. +6 −4 client/javascripts/source/picky.data.js
  7. +37 −16 client/javascripts/source/picky.results_renderer.js
  8. +3 −0  client/javascripts/source/picky.translations.js
  9. +65 −0 client/javascripts/spec/picky.allocation.spec.js
  10. +80 −0 client/javascripts/spec/picky.allocations.spec.js
  11. +35 −0 client/javascripts/spec/picky.client.spec.js
  12. +29 −0 client/javascripts/spec/picky.controller.spec.js
  13. +65 −2 client/javascripts/spec/picky.data.spec.js
  14. +122 −0 client/javascripts/spec/picky.results_renderer.spec.js
  15. +28 −0 client/javascripts/specs
  16. +2 −0  client/test_project/javascripts/picky.addination.js
  17. +1 −1  client/test_project/javascripts/picky.allocation_renderer.js
  18. +7 −6 client/test_project/javascripts/picky.client.js
  19. +4 −4 client/test_project/javascripts/picky.data.js
  20. +33 −14 client/test_project/javascripts/picky.results_renderer.js
  21. +3 −0  client/test_project/javascripts/picky.translations.js
  22. +19 −20 generators/prototypes/client/sinatra/javascripts/picky.min.js
39 client/javascripts/picky.min.js
View
@@ -1,20 +1,19 @@
-Array.prototype.index=function(a){for(var b=0,h=this.length;b<h;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,h=this.length;b<h;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",h=a.split(".").concat(b),g=dictionary,e=0,n=h.length;e<n;e++){g=g[h[e]];if(g==undefined){g="Translation missing: "+a+"."+b;break}}return g};function Allocation(a,b,h,g,e,n){var p=this;this.type=a;this.weight=b;this.count=h;this.combination=g;this.ids=e||[];this.entries=this.rendered=n;this.isType=function(s){return s==p.type}}function Allocations(a){this.allocations=[];for(var b=0,h=a.length;b<h;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(e){this.allocations.splice(e,1)};this.each=function(e){this.allocations.each(e)}}
-function PickyData(a){var b=a.total,h=a.duration,g=a.offset,e=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=h;this.offset=g;this.allocations=e;this.renderedAmount=function(){var n=0;e.each(function(p,s){n+=s.rendered.length});return n};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var h=b.showResultsLimit||10,g=b.input,e=b.reset,n=b.button,p=b.counter,s=b.dashboard,w=b.moreSelector,x=b.results,y=b.noResults,j=new PickyAddination(this,x),r=new PickyAllocationsCloud(this,b),d=new PickyResultsRenderer(j,b),f=function(){e.fadeTo(166,1)},k=function(){r.hide();x.empty();y.hide()},o=function(i){g.val(i);e.fadeTo(166,0);q("empty");p.empty();k()},m=function(){return g.val()};this.text=m;var u=function(i){p.text(i);i>0&&i<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
-1)},c=function(i){if(i.isEmpty())return"none";if(i.total>h&&i.allocations.length>1)return"support";return"ok"},q=function(i){s.attr("class","dashboard "+i)};this.insert=function(i){g.val(i);g.select()};this.fullResultsCallback=function(i){q(c(i));if(i.isEmpty()){k();u(0);y.show();f()}else if(i.total>h&&i.allocations.length>1){k();f();r.show(i);u(i.total)}else if(i.offset==0){k();u(i.total);d.render(i);x.show();f();g.focus()}else{var v=$(w).position().top;j.remove();d.render(i);$("body").animate({scrollTop:v-
-12},500)}};this.liveResultsCallback=function(i){q(c(i));u(i.total)};this.allocationChosen=function(i){i=i.data.query;a.insert(i);a.allocationChosen(i)};this.addinationClicked=function(i){a.addinationClicked(m(),i)};(function(){g.keyup(function(i){if(m()==""){o();a.searchTextCleared()}else{a.searchTextEntered(m(),i);f()}});p.click(function(){m()==""||a.searchButtonClicked(m())});n.click(function(){m()==""||a.searchButtonClicked(m())});e.click(function(){o("");a.clearButtonClicked();g.focus()})})();
-g.focus()};var PickyBackend=function(a){var b=function(h,g,e){var n=e||{};n=$.extend({query:h},e);$.getJSON(a,n,function(p){g&&g(new PickyData(p))})};this.search=function(h,g,e,n){b(h,function(p){g&&g(n,p)},e)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),h=new PickyBackend(b);this.search=function(g,e,n,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;n=$.extend({ids:a.liveResults||0,offset:0},n);h.search(g,function(s,w){if(!s.live||s.live==latestRequestTimestamp)e&&
-e(w)},n,p)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),h=new PickyBackend(b);this.search=function(g,e,n,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;n=$.extend({ids:a.fullResults||20,offset:0},n);h.search(g,function(s,w){if(!s.full||s.full==latestRequestTimestamp)e&&e(w)},n,p)}};var PickyController=function(a){var b=new PickyView(this,a),h=a.backends,g=a.beforeInsert||function(){},e=a.before||function(){},n=a.success||function(){},p=a.after||function(){},s=a.liveRendered||false,w=a.liveSearchInterval||180,x,y=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=y;var j=function(){var c=window.History&&window.History.getState();return y(c&&c.url)};this.lastFullQuery=j;var r=function(c,q,i,v){q=e(q,
-v)||q;x=[c,q,i,v];var z=q;if(z!=j()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=h[c])&&c.search(q,i,v)};this.resend=function(){x&&r.apply(this,x)};var d=function(c,q){c=n(c,q)||c;b.fullResultsCallback(c);p(c,q)},f=function(c,q){clearInterval(o);r("full",c,d,q||{})};a=function(c,q){c=n(c,q)||c;b.liveResultsCallback(c);p(c,q)};var k=s?d:a,o,m=function(){var c=b.text();r("live",c,k,{});clearInterval(o)};
-o=setInterval(m,w);clearInterval(o);var u=function(c,q,i){c=g(c)||c;b.insert(c);i&&f(c,q)};this.insert=u;this.clearButtonClicked=function(){clearInterval(o)};this.searchTextCleared=function(){clearInterval(o)};this.searchTextEntered=function(c,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)f(c);else{clearInterval(o);o=setInterval(m,w)}};this.searchButtonClicked=function(c){f(c)};
-this.allocationChosen=function(c){f(c)};this.addinationClicked=function(c,q){f(c,{offset:q.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(x.length>1&&x[1])&&u(c,{},true)})};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
-var PickyClient=function(a){Localization.qualifiers=a.qualifiers||{};Localization.explanations=a.explanations||{};Localization.choices=a.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};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.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var h=a.controller&&new a.controller(a)||new PickyController(a);var g=this.insert=function(e,n,p){h.insert(e,n||{},p||true)};this.resend=h.resend;this.insertFromURL=function(e){if(e&&e!="")g(e);else(e=h.lastFullQuery())&&
-g(e)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(h){var g=h.total,e,n=h.renderedAmount();e=h.offset+n;n=e+n;h=h.total;if(h<n)n=h;e={offset:e,start:e+1,end:n};if(e.offset<g){g=$("<div class='addination'>"+t("results.addination.more")+"</div>");g.bind("click",{offset:e.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,b){var h=b.results,g=b.resultsDivider,e=b.wrapResults,n=b.noAsterisks,p=function(j){var r=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!n.include(r[0]))if(r[1].match(/[^\*~]$/))r[1]+="*";j.push(r);return j},s=function(j){for(var r=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},d=[],f,k=0,o=j.length;k<o;k++){f=j[k];var m=f[0];m=r[m]||m;d.push([m,f[1]])}return d},w=function(j,r){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),r].join(" ")},x=function(j,r){var d=Localization.explanation_delimiters[PickyI18n.locale],f=s(p(r)),k="",o=[];f=$.map(f,function(m){var u=m[0];m=m[1];if(k==""||u==k){m=m.replace(/[\w,]+:(.+)/,"$1");o.push(m);k=u}else{var c=w(k,o.join(" "));o=[];o.push(m);k=u;return c}});f.push(w(k,o.join(" ")));f=f.join(" "+d+" ");return'<span class="explanation">'+j+" "+f+"</span>"},y=function(j,r){var d='<div class="header">';d+=x(r.type,r.combination);if(j.offset>0)d+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return d};this.render=function(j){j.allocations.each(function(r,d){if(d.entries.length>0){h.append(y(j,d)).append(d.entries.join(g));h.children("li").wrapAll(e)}});h.append(a.render(j))}};function AllocationRenderer(a,b){function h(d){var f={},k={},o=[],m;m=0;for(l=d.length;m<l;m++){var u=d[m][0];if(u in f){f[u]=f[u]+" "+d[m][1];o.push(m)}else{f[u]=d[m][1];k[m]=u}}for(m in k)d[m][1]=f[k[m]];for(m=o.length-1;m>=0;m--)d.remove(o[m]);return d}function g(d){return $.map(d,function(f,k){return"%"+(k+1)+"$s"}).join(" ")}function e(d){if(d.length==0)return"";var f=d=h(d);f.sort(function(v,z){return v[0]<z[0]?-1:1});for(var k=[],o=0,m=f.length;o<m;o++)k.push(f[o][0]);var u=k.length==1,c=j[k]||
-(j[k]=g(k));if($.type(c)==="string"){j[k]={format:c};c=j[k]}var q=1,i=c.format;$.each(d,function(v,z){var A=z[0],B=z[2];if(c.filter)B=c.filter(B);A=x[A]||A;if(u&&!(c&&c.ignoreSingle))return i=B+"&nbsp;("+A+")";i=i.replace(RegExp("%"+q+"\\$s","g"),B);q+=1;return q});return i}function n(d){for(var f=[],k=0,o=y.length;k<o;k++)f.push([]);f.push([]);k=0;for(o=d.length;k<o;k++){for(var m=d[k],u=m[0],c=false,q=0,i=y.length;q<i;q++)if(y[q].include(u)){f[q].push(m);c=true;break}c||f[f.length-1].push(m)}var v;
-for(d=f.length-1;d>=0;d--){v=f[d];if(v.length>0)break}v=v[v.length-1];r.include(v[0])||(v[1]+="...");return $.map(f,function(z){return e(z)})}function p(d){var f=[],k,o;for(o in d){k=d[o][0];k=w[k]||k;f[o]=k+":"+d[o][2]}return f.join(" ")}var s=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[s]||{},x=Localization.explanations&&Localization.explanations[s]||{},y=b.groups||[],j=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var r=["street_number",
-"zipcode"];this.contract=h;this.rendered=e;this.groupify=n;this.querify=p;this.render=function(d){var f=d.combination,k=d.count;d=p(f);f=n(f).join(" ");f=$('<li><div class="text">'+f+'</div><div class="count">'+k+"</div></li>");f.bind("click",{query:d},a);return f}};var PickyAllocationsCloud=function(a,b){var h=b.allocations,g=b.shownAllocations,e=b.showMoreAllocations,n=b.hiddenAllocations,p=b.maxSuggestions,s=function(){h.hide()},w=new AllocationRenderer(function(j){s();a.allocationChosen(j)},b),x=function(j){var r=[];j.each(function(d,f){r.push(w.render(f))});return r},y=function(j){if(j.length==0)return h.hide();g.empty();e.hide();n.empty().hide();if(j.length>p){$.each(j.slice(0,p-1),function(r,d){g.append(d)});$.each(j.slice(p-1),function(r,d){n.append(d)});
-e.show()}else $.each(j,function(r,d){g.append(d)});return h.show()};e.click(function(){e.hide();n.show()});this.hide=s;this.show=function(j){y(x(j.allocations));h.show()}};
+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,g=0,m=i.length;g<m;g++){f=f[i[g]];if(f==undefined){f="Translation missing: "+a+"."+b;break}}return f};function Allocation(a,b,i,f,g,m){var q=this;this.type=a;this.weight=b;this.count=i;this.combination=f;this.ids=g||[];this.entries=this.rendered=m||[];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(g){this.allocations.splice(g,1)};this.each=function(g){this.allocations.each(g)}}
+function PickyData(a){var b=a.total,i=a.duration,f=a.offset,g=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=i;this.offset=f;this.allocations=g;this.renderedAmount=function(){var m=0;g.each(function(q,s){m+=s.rendered.length});return m};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var i=b.showResultsLimit||10,f=b.input,g=b.reset,m=b.button,q=b.counter,s=b.dashboard,x=b.moreSelector,w=b.results,y=b.noResults,r=new PickyAddination(this,w),n=new PickyAllocationsCloud(this,b),d=new PickyResultsRenderer(r,b),e=function(){g.fadeTo(166,1)},j=function(){n.hide();w.empty();y.hide()},p=function(h){f.val(h);g.fadeTo(166,0);o("empty");q.empty();j()},k=function(){return f.val()};this.text=k;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();e()}else if(h.total>i&&h.allocations.length>1){j();e();n.show(h);u(h.total)}else if(h.offset==0){j();u(h.total);d.render(h);w.show();e();f.focus()}else{var v=$(x).position().top;r.remove();d.render(h);$("body").animate({scrollTop:v-
+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(k(),h)};(function(){f.keyup(function(h){if(k()==""){p();a.searchTextCleared()}else{a.searchTextEntered(k(),h);e()}});q.click(function(){k()==""||a.searchButtonClicked(k())});m.click(function(){k()==""||a.searchButtonClicked(k())});g.click(function(){p("");a.clearButtonClicked();f.focus()})})();
+f.focus()};var PickyBackend=function(a){var b=function(i,f,g){var m=g||{};m=$.extend({query:i},g);$.getJSON(a,m,function(q){f&&f(new PickyData(q))})};this.search=function(i,f,g,m){b(i,function(q){f&&f(m,q)},g)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),i=new PickyBackend(b);this.search=function(f,g,m,q){q=q||{};latestRequestTimestamp=new Date;q.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);i.search(f,function(s,x){if(!s.live||s.live==latestRequestTimestamp)g&&
+g(x)},m,q)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),i=new PickyBackend(b);this.search=function(f,g,m,q){q=q||{};latestRequestTimestamp=new Date;q.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);i.search(f,function(s,x){if(!s.full||s.full==latestRequestTimestamp)g&&g(x)},m,q)}};var PickyController=function(a){var b=new PickyView(this,a),i=a.backends,f=a.beforeInsert||function(){},g=a.before||function(){},m=a.success||function(){},q=a.after||function(){},s=a.liveRendered||false,x=a.liveSearchInterval||180,w,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 n=function(c,o,h,v){o=g(o,
+v)||o;w=[c,o,h,v];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,v)};this.resend=function(){w&&n.apply(this,w)};var d=function(c,o){c=m(c,o)||c;b.fullResultsCallback(c);q(c,o)},e=function(c,o){clearInterval(p);n("full",c,d,o||{})};a=function(c,o){c=m(c,o)||c;b.liveResultsCallback(c);q(c,o)};var j=s?d:a,p,k=function(){var c=b.text();n("live",c,j,{});clearInterval(p)};
+p=setInterval(k,x);clearInterval(p);var u=function(c,o,h){c=f(c)||c;b.insert(c);h&&e(c,o)};this.insert=u;this.clearButtonClicked=function(){clearInterval(p)};this.searchTextCleared=function(){clearInterval(p)};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)e(c);else{clearInterval(p);p=setInterval(k,x)}};this.searchButtonClicked=function(c){e(c)};
+this.allocationChosen=function(c){e(c)};this.addinationClicked=function(c,o){e(c,{offset:o.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(w.length>1&&w[1])&&u(c,{},true)})};var Localization={},PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;Localization.qualifiers=a.qualifiers||{};Localization.explanations=a.explanations||{};Localization.choices=a.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};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.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var i=a.controller&&new a.controller(a)||new PickyController(a);var f=this.insert=function(g,m,q){i.insert(g,
+m||{},q||true)};this.resend=i.resend;this.insertFromURL=function(g){if(g&&g!="")f(g);else(g=i.lastFullQuery())&&f(g)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(i){var f=i.total,g,m=i.renderedAmount();g=i.offset+m;m=g+m;i=i.total;if(i<m)m=i;g={offset:g,start:g+1,end:m};if(g.offset<f){f=$("<div class='addination'>"+t("results.addination.more")+"</div>");f.bind("click",{offset:g.offset},a.addinationClicked);return f}else return""}};var PickyResultsRenderer=function(a,b){var i=b.locale,f=b.results,g=b.resultsDivider,m=b.wrapResults,q=b.noAsterisks,s=function(n){var d=n[n.length-1];if(d===undefined)return[];n=n.slice(0,n.length-1);if(n==[])n=[n];if(!q.include(d[0]))if(d[1].match(/[^\*~]$/))d[1]+="*";n.push(d);return n};this.asteriskifyLastToken=s;var x=function(n){for(var d=Localization.explanations&&Localization.explanations[i]||{},e=[],j,p=0,k=n.length;p<k;p++){j=n[p];var u=j[0];u=d[u]||u;e.push([u,j[1]])}return e};this.explainCategory=
+x;var w=function(n,d){return[n.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),d].join(" ")};this.strongify=w;var y=function(n,d){var e=Localization.explanation_delimiters[i],j="",p=[],k=[];x(s(d)).each(function(u,c){var o=c[0],h=c[1];if(j==""||o==j){h=h.replace(/[\w,]+:(.+)/,"$1");p.push(h);j=o;k.push(undefined)}else{var v=w(j,p.join(" "));p=[];p.push(h);j=o;k.push(v)}});k.push(w(j,p.join(" ")));k=k.join(" "+e+" ");return k='<span class="explanation">'+
+n+" "+k+"</span>"};this.explain=y;var r=function(n,d){var e='<div class="header">';e+=y(d.type,d.combination);if(n.offset>0)e+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';return e};this.render=function(n){n.allocations.each(function(d,e){if(e.entries.length>0){f.append(r(n,e)).append(e.entries.join(g));f.children("li").wrapAll(m)}});f.append(a.render(n))}};function AllocationRenderer(a,b){function i(d){var e={},j={},p=[],k;k=0;for(l=d.length;k<l;k++){var u=d[k][0];if(u in e){e[u]=e[u]+" "+d[k][1];p.push(k)}else{e[u]=d[k][1];j[k]=u}}for(k in j)d[k][1]=e[j[k]];for(k=p.length-1;k>=0;k--)d.remove(p[k]);return d}function f(d){return $.map(d,function(e,j){return"%"+(j+1)+"$s"}).join(" ")}function g(d){if(d.length==0)return"";var e=d=i(d);e.sort(function(v,z){return v[0]<z[0]?-1:1});for(var j=[],p=0,k=e.length;p<k;p++)j.push(e[p][0]);var u=j.length==1,c=r[j]||
+(r[j]=f(j));if($.type(c)==="string"){r[j]={format:c};c=r[j]}var o=1,h=c.format;$.each(d,function(v,z){var A=z[0],B=z[2];if(c.filter)B=c.filter(B);A=w[A]||A;if(u&&!(c&&c.ignoreSingle))return h=B+"&nbsp;("+A+")";h=h.replace(RegExp("%"+o+"\\$s","g"),B);o+=1;return o});return h}function m(d){for(var e=[],j=0,p=y.length;j<p;j++)e.push([]);e.push([]);j=0;for(p=d.length;j<p;j++){for(var k=d[j],u=k[0],c=false,o=0,h=y.length;o<h;o++)if(y[o].include(u)){e[o].push(k);c=true;break}c||e[e.length-1].push(k)}var v;
+for(d=e.length-1;d>=0;d--){v=e[d];if(v.length>0)break}v=v[v.length-1];n.include(v[0])||(v[1]+="...");return $.map(e,function(z){return g(z)})}function q(d){var e=[],j,p;for(p in d){j=d[p][0];j=x[j]||j;e[p]=j+":"+d[p][2]}return e.join(" ")}var s=b.locale,x=Localization.qualifiers&&Localization.qualifiers[s]||{},w=Localization.explanations&&Localization.explanations[s]||{},y=b.groups||[],r=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var n=["street_number",
+"zipcode"];this.contract=i;this.rendered=g;this.groupify=m;this.querify=q;this.render=function(d){var e=d.combination,j=d.count;d=q(e);e=m(e).join(" ");e=$('<li><div class="text">'+e+'</div><div class="count">'+j+"</div></li>");e.bind("click",{query:d},a);return e}};var PickyAllocationsCloud=function(a,b){var i=b.allocations,f=b.shownAllocations,g=b.showMoreAllocations,m=b.hiddenAllocations,q=b.maxSuggestions,s=function(){i.hide()},x=new AllocationRenderer(function(r){s();a.allocationChosen(r)},b),w=function(r){var n=[];r.each(function(d,e){n.push(x.render(e))});return n},y=function(r){if(r.length==0)return i.hide();f.empty();g.hide();m.empty().hide();if(r.length>q){$.each(r.slice(0,q-1),function(n,d){f.append(d)});$.each(r.slice(q-1),function(n,d){m.append(d)});
+g.show()}else $.each(r,function(n,d){f.append(d)});return i.show()};g.click(function(){g.hide();m.show()});this.hide=s;this.show=function(r){y(w(r.allocations));i.show()}};
BIN  client/javascripts/picky.source.js.tar
View
Binary file not shown
2  client/javascripts/source/picky.addination.js
View
@@ -24,6 +24,8 @@ var PickyAddination = function(view, results) {
var total = data.total;
var range = calculateRange(data);
if (range.offset < total) {
+ // TODO Use an actual link for the addination.
+ //
var result = $("<div class='addination'>" + t('results.addination.more') + "</div>");
result.bind('click', { offset: range.offset }, view.addinationClicked);
return result;
2  client/javascripts/source/picky.allocation_renderer.js
View
@@ -1,7 +1,7 @@
function AllocationRenderer(allocationChosenCallback, config) {
var self = this;
- var locale = PickyI18n.locale;
+ var locale = config.locale;
var qualifiers = Localization.qualifiers && Localization.qualifiers[locale] || {};
var explanations = Localization.explanations && Localization.explanations[locale] || {};
13 client/javascripts/source/picky.client.js
View
@@ -1,12 +1,6 @@
var Localization = {};
var PickyI18n = { };
-// Set the correct locale for all js code.
-//
-$(function() {
- PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
-});
-
// The client handles parameters and
// offers an insert method.
//
@@ -16,6 +10,13 @@ var PickyClient = function(config) {
// jQuery selectors are executed.
//
+ // The locale is by default extracted from the html attribute.
+ //
+ // TODO Remove.
+ //
+ PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
+ config['locale'] = config['locale'] || PickyI18n.locale;
+
// This is used to generate the correct query strings, localized.
//
// e.g with locale it:
10 client/javascripts/source/picky.data.js
View
@@ -3,6 +3,8 @@
// Container for an allocation.
//
+// TODO Rename to combinations.
+//
function Allocation(type, weight, count, combination, ids, rendered) {
var self = this;
@@ -11,9 +13,9 @@ function Allocation(type, weight, count, combination, ids, rendered) {
this.count = count; // 14
this.combination = combination; // [['title', 'Old', 'old'], ['title', 'Man', 'man']]
this.ids = ids || [];
- this.rendered = rendered;
+ this.rendered = rendered || [];
this.entries = this.rendered; // TODO Remove?
-
+
this.isType = function(name) {
return name == self.type;
};
@@ -25,7 +27,7 @@ function Allocation(type, weight, count, combination, ids, rendered) {
//
function Allocations(allocations) {
var self = this;
-
+
this.allocations = [];
// Wrap and save the allocations.
@@ -76,7 +78,7 @@ function PickyData(data) {
var renderedAmount = function() {
var sum = 0;
allocations.each(function(i, allocation) {
- sum += allocation.rendered.length;
+ sum += allocation.rendered.length;
});
return sum;
};
53 client/javascripts/source/picky.results_renderer.js
View
@@ -1,5 +1,7 @@
var PickyResultsRenderer = function(addination, config) {
+ var locale = config.locale;
+
var results = config['results'];
var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
@@ -7,9 +9,10 @@ var PickyResultsRenderer = function(addination, config) {
// Adds asterisks to the last token.
//
- var asteriskifyLastToken = function(combination) {
- var last_part = combination[combination.length-1];
- var parts = combination.slice(0, combination.length-1);
+ var asteriskifyLastToken = function(combinations) {
+ var last_part = combinations[combinations.length-1];
+ if (last_part === undefined) { return []; }
+ var parts = combinations.slice(0, combinations.length-1);
if (parts == []) { parts = [parts]; }
if (!noAsterisks.include(last_part[0])) {
// Replace with * unless there is already one or a tilde.
@@ -19,11 +22,12 @@ var PickyResultsRenderer = function(addination, config) {
parts.push(last_part);
return parts;
};
+ this.asteriskifyLastToken = asteriskifyLastToken; // Note: For tests.
// Replaces the category with an explanation of the category.
//
var explainCategory = function(combination) {
- var explanations = Localization.explanations && Localization.explanations[PickyI18n.locale] || {}; // TODO
+ var explanations = Localization.explanations && Localization.explanations[locale] || {}; // TODO
var parts = [];
var combo;
@@ -33,24 +37,33 @@ var PickyResultsRenderer = function(addination, config) {
explanation = explanations[explanation] || explanation;
parts.push([explanation, combo[1]]);
}
+
return parts;
};
+ this.explainCategory = explainCategory; // Note: Only exposed for testing.
- // Puts together an explanation.
//
- // Note: Accumulates same categories using a whitespace.
//
var strongify = function(category, joinedTokens) {
- return [category.replace(/([\w\sÄäÖöÜüéèà]+)/, "<strong>$1</strong>"), joinedTokens].join(' ');
+ return [category.replace(/([\w\sÄäÖöÜüéèà\,]+)/, "<strong>$1</strong>"), joinedTokens].join(' ');
};
- var explain = function(type, combination) {
- var explanation_delimiter = Localization.explanation_delimiters[PickyI18n.locale];
+ this.strongify = strongify; // Note: Only exposed for testing.
+
+ // Puts together an explanation.
+ //
+ // Note: Accumulates same categories using a whitespace.
+ //
+ var explain = function(type, combinations) {
+ var explanation_delimiter = Localization.explanation_delimiters[locale];
- var parts = explainCategory(asteriskifyLastToken(combination));
+ var parts = explainCategory(asteriskifyLastToken(combinations));
var lastCategory = '';
var tokenAccumulator = [];
var joinedTokens = '';
- var replaced = $.map(parts, function(part) {
+ var replaced = []
+
+ // Note: Was $.map
+ parts.each(function(i, part) {
var category = part[0];
var token = part[1];
@@ -63,7 +76,7 @@ var PickyResultsRenderer = function(addination, config) {
tokenAccumulator.push(token);
lastCategory = category;
- return undefined;
+ return;
}
var result = strongify(lastCategory, tokenAccumulator.join(' '));
@@ -72,16 +85,19 @@ var PickyResultsRenderer = function(addination, config) {
tokenAccumulator.push(token);
lastCategory = category;
- return result;
+ replaced.push(result);
});
+
// there might be something in the accumulator
//
replaced.push(strongify(lastCategory, tokenAccumulator.join(' ')));
replaced = replaced.join(' ' + explanation_delimiter + ' ');
+ replaced = '<span class="explanation">' + type + ' ' + replaced + '</span>';
- return '<span class="explanation">' + type + ' ' + replaced + '</span>';
+ return replaced;
};
+ this.explain = explain; // Note: Only exposed for testing.
// TODO Make customizable.
//
@@ -89,13 +105,18 @@ var PickyResultsRenderer = function(addination, config) {
// TODO Make type definable. (Mapping, i18n)
//
var header_html = '<div class="header">';
- header_html += explain(allocation.type, allocation.combination);
+ header_html += explain(allocation.type, allocation.combination); // TODO Rename to combinations?
if (data.offset > 0) {
- header_html += '<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>'; // searchEngine.focus();
+ // TODO Add the class to the link. Remove the div.
+ //
+ header_html += '<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
+ // searchEngine.focus();
}
+ header_html += '</div>';
return header_html;
};
+ this.renderHeader = renderHeader;
// Render results with the data.
//
3  client/javascripts/source/picky.translations.js
View
@@ -1,5 +1,7 @@
// Translations
//
+// TODO Still needed?
+//
var dictionary = {
common:{
@@ -39,5 +41,6 @@ var t = function(key) {
break;
}
};
+
return current;
};
65 client/javascripts/spec/picky.allocation.spec.js
View
@@ -0,0 +1,65 @@
+var allocation;
+describe(
+ "Empty allocation",
+ function() {
+ allocation = new Allocation(
+ 'test',
+ 3.14,
+ 123,
+ [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']],
+ [1,2,3],
+ ['a', 'b', 'c']
+ );
+ },
+ function() {
+ describe(
+ "type", null,
+ function() {
+ it("is correct", function() {
+ return allocation.type == 'test';
+ });
+ }
+ );
+ describe(
+ "weight", null,
+ function() {
+ it("is correct", function() {
+ return allocation.weight == 3.14;
+ });
+ }
+ );
+ describe(
+ "count", null,
+ function() {
+ it("is correct", function() {
+ return allocation.count == 123;
+ });
+ }
+ );
+ describe(
+ "ids", null,
+ function() {
+ it("is correct", function() {
+ return allocation.ids[1] == 2;
+ });
+ }
+ );
+ describe(
+ "rendered", null,
+ function() {
+ it("is correct", function() {
+ return allocation.rendered[1] == 'b';
+ });
+ }
+ );
+ describe(
+ "isType",
+ null,
+ function() {
+ it("is correct", function() {
+ return allocation.isType('test');
+ });
+ }
+ );
+ }
+);
80 client/javascripts/spec/picky.allocations.spec.js
View
@@ -0,0 +1,80 @@
+var allocations;
+describe(
+ "Empty allocations",
+ function() {
+ allocations = new Allocations([]);
+ },
+ function() {
+ describe(
+ "length",
+ null,
+ function() {
+ it("is correct", function() {
+ return allocations.length == 0;
+ });
+ }
+ );
+ describe(
+ "each",
+ null,
+ function() {
+ it("is correct", function() {
+ var result = true;
+ allocations.each(function() {
+ result = false; // It should not be called.
+ });
+ return result;
+ });
+ }
+ );
+ }
+);
+describe(
+ "Non-Empty allocations",
+ function() {
+ allocations = new Allocations(
+ [
+ [
+ 'test',
+ 3.14,
+ 123,
+ [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']],
+ [1,2,3]
+ ]
+ ]
+ );
+ },
+ function() {
+ describe(
+ "length",
+ null,
+ function() {
+ it("is correct", function() {
+ return allocations.length == 1;
+ });
+ }
+ );
+ // describe(
+ // "remove",
+ // null,
+ // function() {
+ // it("is correct", function() {
+ // return allocations.remove(0) == [];
+ // });
+ // }
+ // );
+ describe(
+ "each",
+ null,
+ function() {
+ it("is correct", function() {
+ var result = false;
+ allocations.each(function() {
+ result = true;
+ });
+ return result; // Needs to be called.
+ });
+ }
+ );
+ }
+);
35 client/javascripts/spec/picky.client.spec.js
View
@@ -0,0 +1,35 @@
+// TODO Define $.
+//
+
+var client;
+describe(
+ "Mocked controller",
+ function() {
+ client = new PickyClient({
+ controller: {
+ resend: function() { return true; }
+ insert: function() { return true; }
+ }
+ });
+ },
+ function() {
+ describe(
+ "resend",
+ null,
+ function() {
+ it("delegates", function() {
+ return controller.resend();
+ });
+ }
+ );
+ describe(
+ "insert",
+ null,
+ function() {
+ it("delegates", function() {
+ return controller.insert();
+ });
+ }
+ );
+ }
+);
29 client/javascripts/spec/picky.controller.spec.js
View
@@ -0,0 +1,29 @@
+var controller;
+describe(
+ "Mocked controller",
+ function() {
+ controller = new PickyController({
+
+ });
+ },
+ function() {
+ describe(
+ "resend",
+ null,
+ function() {
+ it("delegates", function() {
+ return controller.resend();
+ });
+ }
+ );
+ describe(
+ "insert",
+ null,
+ function() {
+ it("delegates", function() {
+ return controller.insert();
+ });
+ }
+ );
+ }
+);
67 client/javascripts/spec/picky.data.spec.js
View
@@ -1,12 +1,43 @@
var data;
describe(
- "Non-Empty Data",
+ "Empty non-rendered Data",
+ function() {
+ data = new PickyData({
+ total: 0,
+ duration: 0.000123,
+ offset: 12,
+ allocations: []
+ });
+ },
+ function() {
+ describe(
+ "isEmpty",
+ null,
+ function() {
+ it("is correct", function() {
+ return data.isEmpty();
+ });
+ }
+ );
+ describe(
+ "renderedAmount",
+ null,
+ function() {
+ it("is correct", function() {
+ return data.renderedAmount() == 0;
+ });
+ }
+ );
+ }
+);
+describe(
+ "Non-Empty non-rendered Data",
function() {
data = new PickyData({
total: 123,
duration: 0.000123,
offset: 12,
- allocations: ['test', 3.14, 123, [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']]]
+ allocations: [['test', 3.14, 123, [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']], [1,2,3]]]
});
},
function() {
@@ -30,3 +61,35 @@ describe(
);
}
);
+describe(
+ "Non-Empty non-rendered Data",
+ function() {
+ data = new PickyData({
+ total: 123,
+ duration: 0.000123,
+ offset: 12,
+ allocations: [['test', 3.14, 123, [['attr1', 'Original1', 'parsed1'], ['attr2', 'Original2', 'parsed2']], [1,2,3], ['a', 'b', 'c']]]
+ });
+ },
+ function() {
+ describe(
+ "isEmpty",
+ null,
+ function() {
+ it("is correct", function() {
+ return !data.isEmpty();
+ });
+ }
+ );
+ describe(
+ "renderedAmount",
+ null,
+ function() {
+ it("is correct", function() {
+ return data.renderedAmount() == 3;
+ });
+ }
+ );
+ }
+);
+
122 client/javascripts/spec/picky.results_renderer.spec.js
View
@@ -0,0 +1,122 @@
+var renderer;
+describe(
+ "Mocked controller",
+ function() {
+ renderer = new PickyResultsRenderer(
+ null,
+ {
+ locale: 'en',
+ noAsterisks: ['noAsterisksCategory']
+ }
+ );
+ },
+ function() {
+ describe("asteriskifyLastToken", null,
+ function() {
+ it("is correct", function() {
+ return renderer.asteriskifyLastToken([]).compare([]);
+ });
+ it("is correct", function() {
+ return renderer.asteriskifyLastToken([['cat1', 'Orig1', 'parsed1']]).compare([['cat1', 'Orig1*', 'parsed1']]);
+ });
+ it("is correct", function() {
+ return renderer.asteriskifyLastToken([
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat2', 'Orig2', 'parsed2']
+ ]).compare([
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat2', 'Orig2*', 'parsed2']
+ ]);
+ });
+ }
+ );
+ describe("explainCategory", null,
+ function() {
+ Localization = {
+ explanations: {
+ en: {
+ cat1: 'done by'
+ }
+ }
+ }
+ it("is correct", function() {
+ return renderer.explainCategory([
+ ['cat1', 'Orig1', 'parsed1']
+ ]).compare([
+ ['done by', 'Orig1']
+ ]);
+ });
+ it("is correct", function() {
+ return renderer.explainCategory([
+ ['cat2', 'Orig1', 'parsed1']
+ ]).compare([
+ ['cat2', 'Orig1']
+ ]);
+ });
+ }
+ );
+ describe("strongify", null,
+ function() {
+ it("is correct", function() {
+ return renderer.strongify("cat1", 'joinedTokens') == "<strong>cat1</strong> joinedTokens";
+ });
+ it("is correct", function() {
+ return renderer.strongify("cät1", 'joinedTokens') == "<strong>cät1</strong> joinedTokens";
+ });
+ it("is correct", function() {
+ return renderer.strongify("cat1,cat2", 'joinedTokens') == "<strong>cat1,cat2</strong> joinedTokens";
+ });
+ }
+ );
+ describe("explain", null,
+ function() {
+ Localization = {
+ explanations: {
+ en: {
+ cat1: 'done by'
+ }
+ },
+ explanation_delimiters: {
+ en: 'and'
+ }
+ }
+ it("is correct", function() {
+ return renderer.explain("type1", [
+ ['cat1', 'Orig1', 'parsed1']
+ ]) == '<span class="explanation">type1 <strong>done by</strong> Orig1*</span>';
+ });
+ it("is correct", function() {
+ return renderer.explain("type1", [
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat2', 'Orig2', 'parsed2']
+ ]) == '<span class="explanation">type1 <strong>done by</strong> Orig1 and <strong>cat2</strong> Orig2*</span>';
+ });
+ }
+ );
+ describe("renderHeader", null,
+ function() {
+ it("is correct", function() {
+ return renderer.renderHeader(
+ { offset: 0 },
+ {
+ type: 'type1',
+ combination: [['cat1', 'Orig1', 'parsed1']]
+ }
+ ) == '<div class="header"><span class="explanation">type1 <strong>done by</strong> Orig1*</span></div>';
+ });
+ it("is correct", function() {
+ return renderer.renderHeader(
+ { offset: 0 },
+ {
+ type: 'type1',
+ combination: [
+ ['cat1', 'Orig1', 'parsed1'],
+ ['cat2', 'Orig2', 'parsed2']
+ ]
+ }
+ ) == '<div class="header"><span class="explanation">type1 <strong>done by</strong> Orig1 and <strong>cat2</strong> Orig2*</span></div>';
+ });
+ }
+ );
+ }
+);
28 client/javascripts/specs
View
@@ -11,3 +11,31 @@ js -f spec_helper.js \
-f source/picky.extensions.js \
-f source/picky.data.js \
spec/picky.data.spec.js
+
+js -f spec_helper.js \
+ -f source/picky.extensions.js \
+ -f source/picky.data.js \
+ spec/picky.allocations.spec.js
+
+js -f spec_helper.js \
+ -f source/picky.extensions.js \
+ -f source/picky.data.js \
+ spec/picky.allocation.spec.js
+
+js -f spec_helper.js \
+ -f source/picky.extensions.js \
+ -f source/picky.results_renderer.js \
+ spec/picky.results_renderer.spec.js
+
+# js -f spec_helper.js \
+# -f source/picky.client.js \
+# spec/picky.client.spec.js
+
+# js -f spec_helper.js \
+# -f source/picky.extensions.js \
+# -f source/picky.allocation_renderer.js \
+# -f source/picky.allocations_cloud.js \
+# -f source/picky.addination.js \
+# -f source/picky.view.js \
+# -f source/picky.controller.js \
+# spec/picky.controller.spec.js
2  client/test_project/javascripts/picky.addination.js
View
@@ -24,6 +24,8 @@ var PickyAddination = function(view, results) {
var total = data.total;
var range = calculateRange(data);
if (range.offset < total) {
+ // TODO Use an actual link for the addination.
+ //
var result = $("<div class='addination'>" + t('results.addination.more') + "</div>");
result.bind('click', { offset: range.offset }, view.addinationClicked);
return result;
2  client/test_project/javascripts/picky.allocation_renderer.js
View
@@ -1,7 +1,7 @@
function AllocationRenderer(allocationChosenCallback, config) {
var self = this;
- var locale = PickyI18n.locale;
+ var locale = config.locale;
var qualifiers = Localization.qualifiers && Localization.qualifiers[locale] || {};
var explanations = Localization.explanations && Localization.explanations[locale] || {};
13 client/test_project/javascripts/picky.client.js
View
@@ -1,12 +1,6 @@
var Localization = {};
var PickyI18n = { };
-// Set the correct locale for all js code.
-//
-$(function() {
- PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
-});
-
// The client handles parameters and
// offers an insert method.
//
@@ -16,6 +10,13 @@ var PickyClient = function(config) {
// jQuery selectors are executed.
//
+ // The locale is by default extracted from the html attribute.
+ //
+ // TODO Remove.
+ //
+ PickyI18n.locale = $('html').attr('lang').split('-')[0] || 'en';
+ config['locale'] = config['locale'] || PickyI18n.locale;
+
// This is used to generate the correct query strings, localized.
//
// e.g with locale it:
8 client/test_project/javascripts/picky.data.js
View
@@ -11,9 +11,9 @@ function Allocation(type, weight, count, combination, ids, rendered) {
this.count = count; // 14
this.combination = combination; // [['title', 'Old', 'old'], ['title', 'Man', 'man']]
this.ids = ids || [];
- this.rendered = rendered;
+ this.rendered = rendered || [];
this.entries = this.rendered; // TODO Remove?
-
+
this.isType = function(name) {
return name == self.type;
};
@@ -25,7 +25,7 @@ function Allocation(type, weight, count, combination, ids, rendered) {
//
function Allocations(allocations) {
var self = this;
-
+
this.allocations = [];
// Wrap and save the allocations.
@@ -76,7 +76,7 @@ function PickyData(data) {
var renderedAmount = function() {
var sum = 0;
allocations.each(function(i, allocation) {
- sum += allocation.rendered.length;
+ sum += allocation.rendered.length;
});
return sum;
};
47 client/test_project/javascripts/picky.results_renderer.js
View
@@ -1,5 +1,7 @@
var PickyResultsRenderer = function(addination, config) {
+ var locale = config.locale;
+
var results = config['results'];
var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
@@ -7,9 +9,10 @@ var PickyResultsRenderer = function(addination, config) {
// Adds asterisks to the last token.
//
- var asteriskifyLastToken = function(combination) {
- var last_part = combination[combination.length-1];
- var parts = combination.slice(0, combination.length-1);
+ var asteriskifyLastToken = function(combinations) {
+ var last_part = combinations[combinations.length-1];
+ if (last_part === undefined) { return []; }
+ var parts = combinations.slice(0, combinations.length-1);
if (parts == []) { parts = [parts]; }
if (!noAsterisks.include(last_part[0])) {
// Replace with * unless there is already one or a tilde.
@@ -19,11 +22,12 @@ var PickyResultsRenderer = function(addination, config) {
parts.push(last_part);
return parts;
};
+ this.asteriskifyLastToken = asteriskifyLastToken; // Note: For tests.
// Replaces the category with an explanation of the category.
//
var explainCategory = function(combination) {
- var explanations = Localization.explanations && Localization.explanations[PickyI18n.locale] || {}; // TODO
+ var explanations = Localization.explanations && Localization.explanations[locale] || {}; // TODO
var parts = [];
var combo;
@@ -33,24 +37,33 @@ var PickyResultsRenderer = function(addination, config) {
explanation = explanations[explanation] || explanation;
parts.push([explanation, combo[1]]);
}
+
return parts;
};
+ this.explainCategory = explainCategory; // Note: Only exposed for testing.
- // Puts together an explanation.
//
- // Note: Accumulates same categories using a whitespace.
//
var strongify = function(category, joinedTokens) {
- return [category.replace(/([\w\sÄäÖöÜüéèà]+)/, "<strong>$1</strong>"), joinedTokens].join(' ');
+ return [category.replace(/([\w\sÄäÖöÜüéèà\,]+)/, "<strong>$1</strong>"), joinedTokens].join(' ');
};
- var explain = function(type, combination) {
- var explanation_delimiter = Localization.explanation_delimiters[PickyI18n.locale];
+ this.strongify = strongify; // Note: Only exposed for testing.
+
+ // Puts together an explanation.
+ //
+ // Note: Accumulates same categories using a whitespace.
+ //
+ var explain = function(type, combinations) {
+ var explanation_delimiter = Localization.explanation_delimiters[locale];
- var parts = explainCategory(asteriskifyLastToken(combination));
+ var parts = explainCategory(asteriskifyLastToken(combinations));
var lastCategory = '';
var tokenAccumulator = [];
var joinedTokens = '';
- var replaced = $.map(parts, function(part) {
+ var replaced = []
+
+ // Note: Was $.map
+ parts.each(function(i, part) {
var category = part[0];
var token = part[1];
@@ -63,7 +76,8 @@ var PickyResultsRenderer = function(addination, config) {
tokenAccumulator.push(token);
lastCategory = category;
- return undefined;
+ replaced.push(undefined);
+ return;
}
var result = strongify(lastCategory, tokenAccumulator.join(' '));
@@ -72,16 +86,19 @@ var PickyResultsRenderer = function(addination, config) {
tokenAccumulator.push(token);
lastCategory = category;
- return result;
+ replaced.push(result);
});
+
// there might be something in the accumulator
//
replaced.push(strongify(lastCategory, tokenAccumulator.join(' ')));
replaced = replaced.join(' ' + explanation_delimiter + ' ');
+ replaced = '<span class="explanation">' + type + ' ' + replaced + '</span>';
- return '<span class="explanation">' + type + ' ' + replaced + '</span>';
+ return replaced;
};
+ this.explain = explain; // Note: Only exposed for testing.
// TODO Make customizable.
//
@@ -91,6 +108,8 @@ var PickyResultsRenderer = function(addination, config) {
var header_html = '<div class="header">';
header_html += explain(allocation.type, allocation.combination);
if (data.offset > 0) {
+ // TODO Add the class to the link. Remove the div.
+ //
header_html += '<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>'; // searchEngine.focus();
}
3  client/test_project/javascripts/picky.translations.js
View
@@ -1,5 +1,7 @@
// Translations
//
+// TODO Still needed?
+//
var dictionary = {
common:{
@@ -39,5 +41,6 @@ var t = function(key) {
break;
}
};
+
return current;
};
39 generators/prototypes/client/sinatra/javascripts/picky.min.js
View
@@ -1,20 +1,19 @@
-Array.prototype.index=function(a){for(var b=0,h=this.length;b<h;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,h=this.length;b<h;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",h=a.split(".").concat(b),g=dictionary,e=0,n=h.length;e<n;e++){g=g[h[e]];if(g==undefined){g="Translation missing: "+a+"."+b;break}}return g};function Allocation(a,b,h,g,e,n){var p=this;this.type=a;this.weight=b;this.count=h;this.combination=g;this.ids=e||[];this.entries=this.rendered=n;this.isType=function(s){return s==p.type}}function Allocations(a){this.allocations=[];for(var b=0,h=a.length;b<h;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(e){this.allocations.splice(e,1)};this.each=function(e){this.allocations.each(e)}}
-function PickyData(a){var b=a.total,h=a.duration,g=a.offset,e=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=h;this.offset=g;this.allocations=e;this.renderedAmount=function(){var n=0;e.each(function(p,s){n+=s.rendered.length});return n};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var h=b.showResultsLimit||10,g=b.input,e=b.reset,n=b.button,p=b.counter,s=b.dashboard,w=b.moreSelector,x=b.results,y=b.noResults,j=new PickyAddination(this,x),r=new PickyAllocationsCloud(this,b),d=new PickyResultsRenderer(j,b),f=function(){e.fadeTo(166,1)},k=function(){r.hide();x.empty();y.hide()},o=function(i){g.val(i);e.fadeTo(166,0);q("empty");p.empty();k()},m=function(){return g.val()};this.text=m;var u=function(i){p.text(i);i>0&&i<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
-1)},c=function(i){if(i.isEmpty())return"none";if(i.total>h&&i.allocations.length>1)return"support";return"ok"},q=function(i){s.attr("class","dashboard "+i)};this.insert=function(i){g.val(i);g.select()};this.fullResultsCallback=function(i){q(c(i));if(i.isEmpty()){k();u(0);y.show();f()}else if(i.total>h&&i.allocations.length>1){k();f();r.show(i);u(i.total)}else if(i.offset==0){k();u(i.total);d.render(i);x.show();f();g.focus()}else{var v=$(w).position().top;j.remove();d.render(i);$("body").animate({scrollTop:v-
-12},500)}};this.liveResultsCallback=function(i){q(c(i));u(i.total)};this.allocationChosen=function(i){i=i.data.query;a.insert(i);a.allocationChosen(i)};this.addinationClicked=function(i){a.addinationClicked(m(),i)};(function(){g.keyup(function(i){if(m()==""){o();a.searchTextCleared()}else{a.searchTextEntered(m(),i);f()}});p.click(function(){m()==""||a.searchButtonClicked(m())});n.click(function(){m()==""||a.searchButtonClicked(m())});e.click(function(){o("");a.clearButtonClicked();g.focus()})})();
-g.focus()};var PickyBackend=function(a){var b=function(h,g,e){var n=e||{};n=$.extend({query:h},e);$.getJSON(a,n,function(p){g&&g(new PickyData(p))})};this.search=function(h,g,e,n){b(h,function(p){g&&g(n,p)},e)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),h=new PickyBackend(b);this.search=function(g,e,n,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;n=$.extend({ids:a.liveResults||0,offset:0},n);h.search(g,function(s,w){if(!s.live||s.live==latestRequestTimestamp)e&&
-e(w)},n,p)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),h=new PickyBackend(b);this.search=function(g,e,n,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;n=$.extend({ids:a.fullResults||20,offset:0},n);h.search(g,function(s,w){if(!s.full||s.full==latestRequestTimestamp)e&&e(w)},n,p)}};var PickyController=function(a){var b=new PickyView(this,a),h=a.backends,g=a.beforeInsert||function(){},e=a.before||function(){},n=a.success||function(){},p=a.after||function(){},s=a.liveRendered||false,w=a.liveSearchInterval||180,x,y=function(c){return(c=c&&c.match(/q=([^&]+)/))&&decodeURIComponent(c[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=y;var j=function(){var c=window.History&&window.History.getState();return y(c&&c.url)};this.lastFullQuery=j;var r=function(c,q,i,v){q=e(q,
-v)||q;x=[c,q,i,v];var z=q;if(z!=j()){z="?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}(c=h[c])&&c.search(q,i,v)};this.resend=function(){x&&r.apply(this,x)};var d=function(c,q){c=n(c,q)||c;b.fullResultsCallback(c);p(c,q)},f=function(c,q){clearInterval(o);r("full",c,d,q||{})};a=function(c,q){c=n(c,q)||c;b.liveResultsCallback(c);p(c,q)};var k=s?d:a,o,m=function(){var c=b.text();r("live",c,k,{});clearInterval(o)};
-o=setInterval(m,w);clearInterval(o);var u=function(c,q,i){c=g(c)||c;b.insert(c);i&&f(c,q)};this.insert=u;this.clearButtonClicked=function(){clearInterval(o)};this.searchTextCleared=function(){clearInterval(o)};this.searchTextEntered=function(c,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)f(c);else{clearInterval(o);o=setInterval(m,w)}};this.searchButtonClicked=function(c){f(c)};
-this.allocationChosen=function(c){f(c)};this.addinationClicked=function(c,q){f(c,{offset:q.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(x.length>1&&x[1])&&u(c,{},true)})};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
-var PickyClient=function(a){Localization.qualifiers=a.qualifiers||{};Localization.explanations=a.explanations||{};Localization.choices=a.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};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.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var h=a.controller&&new a.controller(a)||new PickyController(a);var g=this.insert=function(e,n,p){h.insert(e,n||{},p||true)};this.resend=h.resend;this.insertFromURL=function(e){if(e&&e!="")g(e);else(e=h.lastFullQuery())&&
-g(e)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(h){var g=h.total,e,n=h.renderedAmount();e=h.offset+n;n=e+n;h=h.total;if(h<n)n=h;e={offset:e,start:e+1,end:n};if(e.offset<g){g=$("<div class='addination'>"+t("results.addination.more")+"</div>");g.bind("click",{offset:e.offset},a.addinationClicked);return g}else return""}};var PickyResultsRenderer=function(a,b){var h=b.results,g=b.resultsDivider,e=b.wrapResults,n=b.noAsterisks,p=function(j){var r=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!n.include(r[0]))if(r[1].match(/[^\*~]$/))r[1]+="*";j.push(r);return j},s=function(j){for(var r=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},d=[],f,k=0,o=j.length;k<o;k++){f=j[k];var m=f[0];m=r[m]||m;d.push([m,f[1]])}return d},w=function(j,r){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),r].join(" ")},x=function(j,r){var d=Localization.explanation_delimiters[PickyI18n.locale],f=s(p(r)),k="",o=[];f=$.map(f,function(m){var u=m[0];m=m[1];if(k==""||u==k){m=m.replace(/[\w,]+:(.+)/,"$1");o.push(m);k=u}else{var c=w(k,o.join(" "));o=[];o.push(m);k=u;return c}});f.push(w(k,o.join(" ")));f=f.join(" "+d+" ");return'<span class="explanation">'+j+" "+f+"</span>"},y=function(j,r){var d='<div class="header">';d+=x(r.type,r.combination);if(j.offset>0)d+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return d};this.render=function(j){j.allocations.each(function(r,d){if(d.entries.length>0){h.append(y(j,d)).append(d.entries.join(g));h.children("li").wrapAll(e)}});h.append(a.render(j))}};function AllocationRenderer(a,b){function h(d){var f={},k={},o=[],m;m=0;for(l=d.length;m<l;m++){var u=d[m][0];if(u in f){f[u]=f[u]+" "+d[m][1];o.push(m)}else{f[u]=d[m][1];k[m]=u}}for(m in k)d[m][1]=f[k[m]];for(m=o.length-1;m>=0;m--)d.remove(o[m]);return d}function g(d){return $.map(d,function(f,k){return"%"+(k+1)+"$s"}).join(" ")}function e(d){if(d.length==0)return"";var f=d=h(d);f.sort(function(v,z){return v[0]<z[0]?-1:1});for(var k=[],o=0,m=f.length;o<m;o++)k.push(f[o][0]);var u=k.length==1,c=j[k]||
-(j[k]=g(k));if($.type(c)==="string"){j[k]={format:c};c=j[k]}var q=1,i=c.format;$.each(d,function(v,z){var A=z[0],B=z[2];if(c.filter)B=c.filter(B);A=x[A]||A;if(u&&!(c&&c.ignoreSingle))return i=B+"&nbsp;("+A+")";i=i.replace(RegExp("%"+q+"\\$s","g"),B);q+=1;return q});return i}function n(d){for(var f=[],k=0,o=y.length;k<o;k++)f.push([]);f.push([]);k=0;for(o=d.length;k<o;k++){for(var m=d[k],u=m[0],c=false,q=0,i=y.length;q<i;q++)if(y[q].include(u)){f[q].push(m);c=true;break}c||f[f.length-1].push(m)}var v;
-for(d=f.length-1;d>=0;d--){v=f[d];if(v.length>0)break}v=v[v.length-1];r.include(v[0])||(v[1]+="...");return $.map(f,function(z){return e(z)})}function p(d){var f=[],k,o;for(o in d){k=d[o][0];k=w[k]||k;f[o]=k+":"+d[o][2]}return f.join(" ")}var s=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[s]||{},x=Localization.explanations&&Localization.explanations[s]||{},y=b.groups||[],j=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var r=["street_number",
-"zipcode"];this.contract=h;this.rendered=e;this.groupify=n;this.querify=p;this.render=function(d){var f=d.combination,k=d.count;d=p(f);f=n(f).join(" ");f=$('<li><div class="text">'+f+'</div><div class="count">'+k+"</div></li>");f.bind("click",{query:d},a);return f}};var PickyAllocationsCloud=function(a,b){var h=b.allocations,g=b.shownAllocations,e=b.showMoreAllocations,n=b.hiddenAllocations,p=b.maxSuggestions,s=function(){h.hide()},w=new AllocationRenderer(function(j){s();a.allocationChosen(j)},b),x=function(j){var r=[];j.each(function(d,f){r.push(w.render(f))});return r},y=function(j){if(j.length==0)return h.hide();g.empty();e.hide();n.empty().hide();if(j.length>p){$.each(j.slice(0,p-1),function(r,d){g.append(d)});$.each(j.slice(p-1),function(r,d){n.append(d)});
-e.show()}else $.each(j,function(r,d){g.append(d)});return h.show()};e.click(function(){e.hide();n.show()});this.hide=s;this.show=function(j){y(x(j.allocations));h.show()}};
+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,g=0,m=i.length;g<m;g++){f=f[i[g]];if(f==undefined){f="Translation missing: "+a+"."+b;break}}return f};function Allocation(a,b,i,f,g,m){var q=this;this.type=a;this.weight=b;this.count=i;this.combination=f;this.ids=g||[];this.entries=this.rendered=m||[];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(g){this.allocations.splice(g,1)};this.each=function(g){this.allocations.each(g)}}
+function PickyData(a){var b=a.total,i=a.duration,f=a.offset,g=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=i;this.offset=f;this.allocations=g;this.renderedAmount=function(){var m=0;g.each(function(q,s){m+=s.rendered.length});return m};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var i=b.showResultsLimit||10,f=b.input,g=b.reset,m=b.button,q=b.counter,s=b.dashboard,x=b.moreSelector,w=b.results,y=b.noResults,r=new PickyAddination(this,w),n=new PickyAllocationsCloud(this,b),d=new PickyResultsRenderer(r,b),e=function(){g.fadeTo(166,1)},j=function(){n.hide();w.empty();y.hide()},p=function(h){f.val(h);g.fadeTo(166,0);o("empty");q.empty();j()},k=function(){return f.val()};this.text=k;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();e()}else if(h.total>i&&h.allocations.length>1){j();e();n.show(h);u(h.total)}else if(h.offset==0){j();u(h.total);d.render(h);w.show();e();f.focus()}else{var v=$(x).position().top;r.remove();d.render(h);$("body").animate({scrollTop:v-
+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(k(),h)};(function(){f.keyup(function(h){if(k()==""){p();a.searchTextCleared()}else{a.searchTextEntered(k(),h);e()}});q.click(function(){k()==""||a.searchButtonClicked(k())});m.click(function(){k()==""||a.searchButtonClicked(k())});g.click(function(){p("");a.clearButtonClicked();f.focus()})})();
+f.focus()};var PickyBackend=function(a){var b=function(i,f,g){var m=g||{};m=$.extend({query:i},g);$.getJSON(a,m,function(q){f&&f(new PickyData(q))})};this.search=function(i,f,g,m){b(i,function(q){f&&f(m,q)},g)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),i=new PickyBackend(b);this.search=function(f,g,m,q){q=q||{};latestRequestTimestamp=new Date;q.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);i.search(f,function(s,x){if(!s.live||s.live==latestRequestTimestamp)g&&
+g(x)},m,q)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),i=new PickyBackend(b);this.search=function(f,g,m,q){q=q||{};latestRequestTimestamp=new Date;q.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);i.search(f,function(s,x){if(!s.full||s.full==latestRequestTimestamp)g&&g(x)},m,q)}};var PickyController=function(a){var b=new PickyView(this,a),i=a.backends,f=a.beforeInsert||function(){},g=a.before||function(){},m=a.success||function(){},q=a.after||function(){},s=a.liveRendered||false,x=a.liveSearchInterval||180,w,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 n=function(c,o,h,v){o=g(o,
+v)||o;w=[c,o,h,v];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,v)};this.resend=function(){w&&n.apply(this,w)};var d=function(c,o){c=m(c,o)||c;b.fullResultsCallback(c);q(c,o)},e=function(c,o){clearInterval(p);n("full",c,d,o||{})};a=function(c,o){c=m(c,o)||c;b.liveResultsCallback(c);q(c,o)};var j=s?d:a,p,k=function(){var c=b.text();n("live",c,j,{});clearInterval(p)};
+p=setInterval(k,x);clearInterval(p);var u=function(c,o,h){c=f(c)||c;b.insert(c);h&&e(c,o)};this.insert=u;this.clearButtonClicked=function(){clearInterval(p)};this.searchTextCleared=function(){clearInterval(p)};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)e(c);else{clearInterval(p);p=setInterval(k,x)}};this.searchButtonClicked=function(c){e(c)};
+this.allocationChosen=function(c){e(c)};this.addinationClicked=function(c,o){e(c,{offset:o.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var c=window.History.getState();(c=y(c.url))&&c!=(w.length>1&&w[1])&&u(c,{},true)})};var Localization={},PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;Localization.qualifiers=a.qualifiers||{};Localization.explanations=a.explanations||{};Localization.choices=a.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};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.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var i=a.controller&&new a.controller(a)||new PickyController(a);var f=this.insert=function(g,m,q){i.insert(g,
+m||{},q||true)};this.resend=i.resend;this.insertFromURL=function(g){if(g&&g!="")f(g);else(g=i.lastFullQuery())&&f(g)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(i){var f=i.total,g,m=i.renderedAmount();g=i.offset+m;m=g+m;i=i.total;if(i<m)m=i;g={offset:g,start:g+1,end:m};if(g.offset<f){f=$("<div class='addination'>"+t("results.addination.more")+"</div>");f.bind("click",{offset:g.offset},a.addinationClicked);return f}else return""}};var PickyResultsRenderer=function(a,b){var i=b.locale,f=b.results,g=b.resultsDivider,m=b.wrapResults,q=b.noAsterisks,s=function(n){var d=n[n.length-1];if(d===undefined)return[];n=n.slice(0,n.length-1);if(n==[])n=[n];if(!q.include(d[0]))if(d[1].match(/[^\*~]$/))d[1]+="*";n.push(d);return n};this.asteriskifyLastToken=s;var x=function(n){for(var d=Localization.explanations&&Localization.explanations[i]||{},e=[],j,p=0,k=n.length;p<k;p++){j=n[p];var u=j[0];u=d[u]||u;e.push([u,j[1]])}return e};this.explainCategory=
+x;var w=function(n,d){return[n.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0\,]+)/,"<strong>$1</strong>"),d].join(" ")};this.strongify=w;var y=function(n,d){var e=Localization.explanation_delimiters[i],j="",p=[],k=[];x(s(d)).each(function(u,c){var o=c[0],h=c[1];if(j==""||o==j){h=h.replace(/[\w,]+:(.+)/,"$1");p.push(h);j=o;k.push(undefined)}else{var v=w(j,p.join(" "));p=[];p.push(h);j=o;k.push(v)}});k.push(w(j,p.join(" ")));k=k.join(" "+e+" ");return k='<span class="explanation">'+
+n+" "+k+"</span>"};this.explain=y;var r=function(n,d){var e='<div class="header">';e+=y(d.type,d.combination);if(n.offset>0)e+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';return e};this.render=function(n){n.allocations.each(function(d,e){if(e.entries.length>0){f.append(r(n,e)).append(e.entries.join(g));f.children("li").wrapAll(m)}});f.append(a.render(n))}};function AllocationRenderer(a,b){function i(d){var e={},j={},p=[],k;k=0;for(l=d.length;k<l;k++){var u=d[k][0];if(u in e){e[u]=e[u]+" "+d[k][1];p.push(k)}else{e[u]=d[k][1];j[k]=u}}for(k in j)d[k][1]=e[j[k]];for(k=p.length-1;k>=0;k--)d.remove(p[k]);return d}function f(d){return $.map(d,function(e,j){return"%"+(j+1)+"$s"}).join(" ")}function g(d){if(d.length==0)return"";var e=d=i(d);e.sort(function(v,z){return v[0]<z[0]?-1:1});for(var j=[],p=0,k=e.length;p<k;p++)j.push(e[p][0]);var u=j.length==1,c=r[j]||
+(r[j]=f(j));if($.type(c)==="string"){r[j]={format:c};c=r[j]}var o=1,h=c.format;$.each(d,function(v,z){var A=z[0],B=z[2];if(c.filter)B=c.filter(B);A=w[A]||A;if(u&&!(c&&c.ignoreSingle))return h=B+"&nbsp;("+A+")";h=h.replace(RegExp("%"+o+"\\$s","g"),B);o+=1;return o});return h}function m(d){for(var e=[],j=0,p=y.length;j<p;j++)e.push([]);e.push([]);j=0;for(p=d.length;j<p;j++){for(var k=d[j],u=k[0],c=false,o=0,h=y.length;o<h;o++)if(y[o].include(u)){e[o].push(k);c=true;break}c||e[e.length-1].push(k)}var v;
+for(d=e.length-1;d>=0;d--){v=e[d];if(v.length>0)break}v=v[v.length-1];n.include(v[0])||(v[1]+="...");return $.map(e,function(z){return g(z)})}function q(d){var e=[],j,p;for(p in d){j=d[p][0];j=x[j]||j;e[p]=j+":"+d[p][2]}return e.join(" ")}var s=b.locale,x=Localization.qualifiers&&Localization.qualifiers[s]||{},w=Localization.explanations&&Localization.explanations[s]||{},y=b.groups||[],r=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var n=["street_number",
+"zipcode"];this.contract=i;this.rendered=g;this.groupify=m;this.querify=q;this.render=function(d){var e=d.combination,j=d.count;d=q(e);e=m(e).join(" ");e=$('<li><div class="text">'+e+'</div><div class="count">'+j+"</div></li>");e.bind("click",{query:d},a);return e}};var PickyAllocationsCloud=function(a,b){var i=b.allocations,f=b.shownAllocations,g=b.showMoreAllocations,m=b.hiddenAllocations,q=b.maxSuggestions,s=function(){i.hide()},x=new AllocationRenderer(function(r){s();a.allocationChosen(r)},b),w=function(r){var n=[];r.each(function(d,e){n.push(x.render(e))});return n},y=function(r){if(r.length==0)return i.hide();f.empty();g.hide();m.empty().hide();if(r.length>q){$.each(r.slice(0,q-1),function(n,d){f.append(d)});$.each(r.slice(q-1),function(n,d){m.append(d)});
+g.show()}else $.each(r,function(n,d){f.append(d)});return i.show()};g.click(function(){g.hide();m.show()});this.hide=s;this.show=function(r){y(w(r.allocations));i.show()}};
Please sign in to comment.
Something went wrong with that request. Please try again.