Browse files

+ Added liveRendered option that can be used to make the live results…

… render like the full ones
  • Loading branch information...
1 parent 1822a0f commit 3561fb3e0d9f4222788b1b31c4908d7a986c16b7 @floere committed Feb 3, 2012
View
30 client/javascripts/picky.min.js
@@ -1,18 +1,18 @@
Array.prototype.index=function(a){for(var c=0,g=this.length;c<g;c++)if(this[c]==a)return c;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 c=0,g=this.length;c<g;c++)a(c,this[c]);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 c=PickyI18n.locale||
-"en",g=a.split(".").concat(c),e=dictionary,h=0,f=g.length;h<f;h++){e=e[g[h]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,h,f){var n=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=h||[];this.entries=this.rendered=f||[];this.isType=function(r){return r==n.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var e=a[c];this.allocations.push(new Allocation(e[0],e[1],e[2],e[3],e[4],e[5]))}this.length=this.allocations.length;this.each=function(h){return this.allocations.each(h)}}
-function PickyData(a){var c=a.total,g=a.duration,e=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=h;this.renderedAmount=function(){var f=0;h.each(function(n,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,h=c.reset,f=c.button,n=c.counter,r=c.dashboard,w=c.moreSelector,s=c.results,j=c.noResults,p=new PickyAddination(this,s),q=new PickyAllocationsCloud(this,c),b=new PickyResultsRenderer(p,c),d=function(){h.fadeTo(166,1)},i=function(){q.hide();s.empty();j.hide()},m=function(k){e.val(k);h.fadeTo(166,0);x("empty");n.empty();i()},o=function(){return e.val()};this.text=o;var u=function(k){n.text(k);k>0&&k<=5&&n.fadeTo("fast",0.5).fadeTo("fast",
-1)},v=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},x=function(k){r.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){x(v(k));if(k.isEmpty()){i();u(0);j.show();d()}else if(k.total>g&&k.allocations.length>1){i();d();q.show(k);u(k.total)}else if(k.offset==0){i();u(k.total);b.render(k);s.show();d();e.focus()}else{var y=$(w).position().top;p.remove();b.render(k);$("body").animate({scrollTop:y-
-12},500)}};this.liveResultsCallback=function(k){x(v(k));u(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(o(),k)};(function(){e.keyup(function(k){if(o()==""){m();a.searchTextCleared()}else{a.searchTextEntered(o(),k);d()}});n.click(function(){o()==""||a.searchButtonClicked(o())});f.click(function(){o()==""||a.searchButtonClicked(o())});h.click(function(){m("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,h){var f=h||{};f=$.extend({query:g},h);$.getJSON(a,f,function(n){e&&e(new PickyData(n))})};this.search=function(g,e,h,f){c(g,function(n){e&&e(f,n)},h)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,n){n=n||{};latestRequestTimestamp=new Date;n.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(e,function(r,w){if(!r.live||r.live==latestRequestTimestamp)h&&
-h(w)},f,n)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,n){n=n||{};latestRequestTimestamp=new Date;n.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(e,function(r,w){if(!r.full||r.full==latestRequestTimestamp)h&&h(w)},f,n)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},h=a.success||function(){},f=a.after||function(){},n=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=n;var r=function(){var b=window.History&&window.History.getState();return n(b&&b.url)};this.lastQuery=r;var w=function(b,d){b=h(b,d)||b;console.log(b.renderedAmount());b.renderedAmount()>0?c.fullResultsCallback(b):c.liveResultsCallback(b);f(b,d)},s,j=function(){var b=
-c.text(),d={};b=e(b,d)||b;var i=g.live;i&&i.search(b,w,d);clearInterval(s)};s=setInterval(j,180);clearInterval(s);var p=function(b,d){b=h(b,d)||b;c.fullResultsCallback(b);f(b,d)},q=function(b,d){var i=d||{};clearInterval(s);if(b!=r()){var m="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,m)}b=e(b,i)||b;(m=g.full)&&m.search(b,p,i)};this.insert=function(b,d,i){c.insert(b);i&&q(b,d)};this.clearButtonClicked=
-function(){clearInterval(s)};this.searchTextCleared=function(){clearInterval(s)};this.searchTextEntered=function(b,d){if($.inArray(d.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(d.keyCode==13)q(b);else{clearInterval(s);s=setInterval(j,180)}};this.searchButtonClicked=function(b){q(b)};this.allocationChosen=function(b){q(b)};this.addinationClicked=function(b,d){q(b,{offset:d.data.offset})}};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
+"en",g=a.split(".").concat(c),e=dictionary,h=0,f=g.length;h<f;h++){e=e[g[h]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,h,f){var o=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=h||[];this.entries=this.rendered=f;this.isType=function(r){return r==o.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var e=a[c];this.allocations.push(new Allocation(e[0],e[1],e[2],e[3],e[4],e[5]))}this.length=this.allocations.length;this.each=function(h){return this.allocations.each(h)}}
+function PickyData(a){var c=a.total,g=a.duration,e=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=h;this.renderedAmount=function(){var f=0;h.each(function(o,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,h=c.reset,f=c.button,o=c.counter,r=c.dashboard,v=c.moreSelector,u=c.results,j=c.noResults,q=new PickyAddination(this,u),p=new PickyAllocationsCloud(this,c),i=new PickyResultsRenderer(q,c),b=function(){h.fadeTo(166,1)},d=function(){p.hide();u.empty();j.hide()},m=function(k){e.val(k);h.fadeTo(166,0);x("empty");o.empty();d()},n=function(){return e.val()};this.text=n;var s=function(k){o.text(k);k>0&&k<=5&&o.fadeTo("fast",0.5).fadeTo("fast",
+1)},w=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},x=function(k){r.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){x(w(k));if(k.isEmpty()){d();s(0);j.show();b()}else if(k.total>g&&k.allocations.length>1){d();b();p.show(k);s(k.total)}else if(k.offset==0){d();s(k.total);i.render(k);u.show();b();e.focus()}else{var y=$(v).position().top;q.remove();i.render(k);$("body").animate({scrollTop:y-
+12},500)}};this.liveResultsCallback=function(k){x(w(k));s(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(n(),k)};(function(){e.keyup(function(k){if(n()==""){m();a.searchTextCleared()}else{a.searchTextEntered(n(),k);b()}});o.click(function(){n()==""||a.searchButtonClicked(n())});f.click(function(){n()==""||a.searchButtonClicked(n())});h.click(function(){m("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,h){var f=h||{};f=$.extend({query:g},h);$.getJSON(a,f,function(o){e&&e(new PickyData(o))})};this.search=function(g,e,h,f){c(g,function(o){e&&e(f,o)},h)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(e,function(r,v){if(!r.live||r.live==latestRequestTimestamp)h&&
+h(v)},f,o)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(e,function(r,v){if(!r.full||r.full==latestRequestTimestamp)h&&h(v)},f,o)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},h=a.success||function(){},f=a.after||function(){};a=a.liveRendered||false;var o=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=o;var r=function(){var b=window.History&&window.History.getState();return o(b&&b.url)};this.lastQuery=r;var v=function(b,d){b=h(b,d)||b;c.fullResultsCallback(b);f(b,d)},u=function(b,d){var m=d||{};clearInterval(p);if(b!=r()){var n="?q="+escape(b).replace(/\*/g,
+"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,n)}b=e(b,m)||b;(n=g.full)&&n.search(b,v,m)},j=function(b,d){b=h(b,d)||b;c.liveResultsCallback(b);f(b,d)},q=a?v:j,p,i=function(){var b=c.text(),d={};b=e(b,d)||b;var m=g.live;m&&m.search(b,q,d);clearInterval(p)};p=setInterval(i,180);clearInterval(p);this.insert=function(b,d,m){c.insert(b);m&&u(b,d)};this.clearButtonClicked=function(){clearInterval(p)};this.searchTextCleared=function(){clearInterval(p)};
+this.searchTextEntered=function(b,d){if($.inArray(d.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(d.keyCode==13)u(b);else{clearInterval(p);p=setInterval(i,180)}};this.searchButtonClicked=function(b){u(b)};this.allocationChosen=function(b){u(b)};this.addinationClicked=function(b,d){u(b,{offset:d.data.offset})}};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 c=a.backends;if(c){c.live||alert("Both a full and live backend must be provided.");c.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};c=a.enclosingSelector||"#picky";a.input=$(a.inputSelector||
c+" input.query");a.reset=$(a.resetSelector||c+" div.reset");a.button=$(a.buttonSelector||c+" input.search_button");a.counter=$(a.counterSelector||c+" div.status");a.dashboard=$(a.dashboardSelector||c+" .dashboard");a.results=$(a.resultsSelector||c+" div.results");a.noResults=$(a.noResultsSelector||c+" .no_results");a.moreSelector=a.moreSelector||c+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||c+" .allocations");a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=
-a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.results=$(a.resultsSelector||c+" div.results");a.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var g=a.controller&&new a.controller(a)||new PickyController(a);var e=this.insert=function(f,n,r){g.insert(f,n||{},r||true)},h=function(){var f=g.lastQuery();f&&e(f)};this.resend=h;this.insertFromURL=function(f){f&&f!=""?e(f):h()};window.History&&window.History.Adapter.bind(window,"statechange",
-function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&e(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,h,f=g.renderedAmount();h=g.offset+f;f=h+f;g=g.total;if(g<f)f=g;h={offset:h,start:h+1,end:f};if(h.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:h.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,h=c.noAsterisks,f=function(j){var p=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!h.include(p[0]))if(p[1].match(/[^\*~]$/))p[1]+="*";j.push(p);return j},n=function(j){for(var p=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},q=[],b,d=0,i=j.length;d<i;d++){b=j[d];var m=b[0];m=p[m]||m;q.push([m,b[1]])}return q},r=function(j,p){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),p].join(" ")},w=function(j,p){var q=Localization.explanation_delimiters[PickyI18n.locale],b=n(f(p)),d="",i=[];b=$.map(b,function(m){var o=m[0];m=m[1];if(d==""||o==d){m=m.replace(/[\w,]+:(.+)/,"$1");i.push(m);d=o}else{var u=r(d,i.join(" "));i=[];i.push(m);d=o;return u}});b.push(r(d,i.join(" ")));b=b.join(" "+q+" ");return'<span class="explanation">'+j+" "+b+"</span>"},s=function(j,p){var q='<div class="header">';q+=w(p.type,p.combination);if(j.offset>0)q+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return q};this.render=function(j){j.allocations.each(function(p,q){if(q.entries.length>0){g.append(s(j,q)).append(q.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(b){var d={},i={},m=[],o;o=0;for(l=b.length;o<l;o++){var u=b[o][0];if(u in d){d[u]=d[u]+" "+b[o][1];m.push(o)}else{d[u]=b[o][1];i[o]=u}}for(o in i)b[o][1]=d[i[o]];for(o=m.length-1;o>=0;o--)b.remove(m[o]);return b}function e(b){return $.map(b,function(d,i){return"%"+(i+1)+"$s"}).join(" ")}function h(b){if(b.length==0)return"";var d=b=g(b);d.sort(function(y,z){return y[0]<z[0]?-1:1});for(var i=[],m=0,o=d.length;m<o;m++)i.push(d[m][0]);var u=i.length==1,v=p[i]||
-(p[i]=e(i));if($.type(v)==="string"){p[i]={format:v};v=p[i]}var x=1,k=v.format;$.each(b,function(y,z){var A=z[0],B=z[2];if(v.filter)B=v.filter(B);A=s[A]||A;if(u&&!(v&&v.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return k}function f(b){for(var d=[],i=0,m=j.length;i<m;i++)d.push([]);d.push([]);i=0;for(m=b.length;i<m;i++){for(var o=b[i],u=o[0],v=false,x=0,k=j.length;x<k;x++)if(j[x].include(u)){d[x].push(o);v=true;break}v||d[d.length-1].push(o)}var y;
-for(b=d.length-1;b>=0;b--){y=d[b];if(y.length>0)break}y=y[y.length-1];q.include(y[0])||(y[1]+="...");return $.map(d,function(z){return h(z)})}function n(b){var d=[],i,m;for(m in b){i=b[m][0];i=w[i]||i;d[m]=i+":"+b[m][2]}return d.join(" ")}var r=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[r]||{},s=Localization.explanations&&Localization.explanations[r]||{},j=c.groups||[],p=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var q=["street_number",
-"zipcode"];this.contract=g;this.rendered=h;this.groupify=f;this.querify=n;this.render=function(b){var d=b.combination,i=b.count;b=n(d);d=f(d).join(" ");d=$('<li><div class="text">'+d+'</div><div class="count">'+i+"</div></li>");d.bind("click",{query:b},a);return d}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,h=c.showMoreAllocations,f=c.hiddenAllocations,n=function(){g.hide()},r=new AllocationRenderer(function(j){n();a.allocationChosen(j)},c),w=function(j){var p=[];j.each(function(q,b){p.push(r.render(b))});return p},s=function(j){if(j.length==0)return g.hide();e.empty();h.hide();f.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(p,q){e.append(q)});$.each(j.slice(2),function(p,q){f.append(q)});h.show()}else $.each(j,
-function(p,q){e.append(q)});return g.show()};h.click(function(){h.hide();f.show()});this.hide=n;this.show=function(j){s(w(j.allocations));g.show()}};
+a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.results=$(a.resultsSelector||c+" div.results");a.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var g=a.controller&&new a.controller(a)||new PickyController(a);var e=this.insert=function(f,o,r){g.insert(f,o||{},r||true)},h=function(){var f=g.lastQuery();f&&e(f)};this.resend=h;this.insertFromURL=function(f){f&&f!=""?e(f):h()};window.History&&window.History.Adapter.bind(window,"statechange",
+function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&e(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,h,f=g.renderedAmount();h=g.offset+f;f=h+f;g=g.total;if(g<f)f=g;h={offset:h,start:h+1,end:f};if(h.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:h.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,h=c.noAsterisks,f=function(j){var q=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!h.include(q[0]))if(q[1].match(/[^\*~]$/))q[1]+="*";j.push(q);return j},o=function(j){for(var q=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},p=[],i,b=0,d=j.length;b<d;b++){i=j[b];var m=i[0];m=q[m]||m;p.push([m,i[1]])}return p},r=function(j,q){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
+"<strong>$1</strong>"),q].join(" ")},v=function(j,q){var p=Localization.explanation_delimiters[PickyI18n.locale],i=o(f(q)),b="",d=[];i=$.map(i,function(m){var n=m[0];m=m[1];if(b==""||n==b){m=m.replace(/[\w,]+:(.+)/,"$1");d.push(m);b=n}else{var s=r(b,d.join(" "));d=[];d.push(m);b=n;return s}});i.push(r(b,d.join(" ")));i=i.join(" "+p+" ");return'<span class="explanation">'+j+" "+i+"</span>"},u=function(j,q){var p='<div class="header">';p+=v(q.type,q.combination);if(j.offset>0)p+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
+return p};this.render=function(j){j.allocations.each(function(q,p){if(p.entries.length>0){g.append(u(j,p)).append(p.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(i){var b={},d={},m=[],n;n=0;for(l=i.length;n<l;n++){var s=i[n][0];if(s in b){b[s]=b[s]+" "+i[n][1];m.push(n)}else{b[s]=i[n][1];d[n]=s}}for(n in d)i[n][1]=b[d[n]];for(n=m.length-1;n>=0;n--)i.remove(m[n]);return i}function e(i){return $.map(i,function(b,d){return"%"+(d+1)+"$s"}).join(" ")}function h(i){if(i.length==0)return"";var b=i=g(i);b.sort(function(y,z){return y[0]<z[0]?-1:1});for(var d=[],m=0,n=b.length;m<n;m++)d.push(b[m][0]);var s=d.length==1,w=q[d]||
+(q[d]=e(d));if($.type(w)==="string"){q[d]={format:w};w=q[d]}var x=1,k=w.format;$.each(i,function(y,z){var A=z[0],B=z[2];if(w.filter)B=w.filter(B);A=u[A]||A;if(s&&!(w&&w.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return k}function f(i){for(var b=[],d=0,m=j.length;d<m;d++)b.push([]);b.push([]);d=0;for(m=i.length;d<m;d++){for(var n=i[d],s=n[0],w=false,x=0,k=j.length;x<k;x++)if(j[x].include(s)){b[x].push(n);w=true;break}w||b[b.length-1].push(n)}var y;
+for(i=b.length-1;i>=0;i--){y=b[i];if(y.length>0)break}y=y[y.length-1];p.include(y[0])||(y[1]+="...");return $.map(b,function(z){return h(z)})}function o(i){var b=[],d,m;for(m in i){d=i[m][0];d=v[d]||d;b[m]=d+":"+i[m][2]}return b.join(" ")}var r=PickyI18n.locale,v=Localization.qualifiers&&Localization.qualifiers[r]||{},u=Localization.explanations&&Localization.explanations[r]||{},j=c.groups||[],q=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var p=["street_number",
+"zipcode"];this.contract=g;this.rendered=h;this.groupify=f;this.querify=o;this.render=function(i){var b=i.combination,d=i.count;i=o(b);b=f(b).join(" ");b=$('<li><div class="text">'+b+'</div><div class="count">'+d+"</div></li>");b.bind("click",{query:i},a);return b}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,h=c.showMoreAllocations,f=c.hiddenAllocations,o=function(){g.hide()},r=new AllocationRenderer(function(j){o();a.allocationChosen(j)},c),v=function(j){var q=[];j.each(function(p,i){q.push(r.render(i))});return q},u=function(j){if(j.length==0)return g.hide();e.empty();h.hide();f.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(q,p){e.append(p)});$.each(j.slice(2),function(q,p){f.append(p)});h.show()}else $.each(j,
+function(q,p){e.append(p)});return g.show()};h.click(function(){h.hide();f.show()});this.hide=o;this.show=function(j){u(v(j.allocations));g.show()}};
View
BIN client/javascripts/picky.source.js.tar
Binary file not shown.
View
57 client/javascripts/source/picky.controller.js
@@ -7,6 +7,8 @@ var PickyController = function(config) {
var successCallback = config.success || function(data, query) { };
var afterCallback = config.after || function(data, query) { };
+ var liveRendered = config.liveRendered || false;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -31,32 +33,6 @@ var PickyController = function(config) {
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
- var liveSearchCallback = function(data, query) {
- data = successCallback(data, query) || data;
-
- view.liveResultsCallback(data);
-
- afterCallback(data, query);
- };
- var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveSearchCallback, params);
- };
-
- // The timer is initially instantly stopped.
- //
- var liveSearchTimerInterval = 180;
- var liveSearchTimerId;
- var liveSearchTimerCallback = function() {
- liveSearch(view.text());
- clearInterval(liveSearchTimerId);
- };
- liveSearchTimerId = setInterval(liveSearchTimerCallback, liveSearchTimerInterval);
- clearInterval(liveSearchTimerId);
-
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -82,6 +58,35 @@ var PickyController = function(config) {
search('full', query, fullSearchCallback, params);
};
+ var liveSearchCallback = function(data, query) {
+ data = successCallback(data, query) || data;
+
+ view.liveResultsCallback(data);
+
+ afterCallback(data, query);
+ };
+ var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
+ var liveSearch = function(query, possibleParams) {
+ var params = possibleParams || {};
+
+ query = beforeCallback(query, params) || query;
+
+ search('live', query, liveCallbackUsed, params);
+ };
+
+ // The timer is initially instantly stopped.
+ //
+ var liveSearchTimerInterval = 180;
+ var liveSearchTimerId;
+ var liveSearchTimerCallback = function() {
+ liveSearch(view.text());
+ clearInterval(liveSearchTimerId);
+ };
+ liveSearchTimerId = setInterval(liveSearchTimerCallback, liveSearchTimerInterval);
+ clearInterval(liveSearchTimerId);
+
+ //
+ //
this.insert = function(query, params, full) {
view.insert(query);
View
6 client/javascripts/source/picky.data.js
@@ -11,8 +11,8 @@ 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.entries = this.rendered;
+ this.rendered = rendered;
+ this.entries = this.rendered; // TODO Remove?
this.isType = function(name) {
return name == self.type;
@@ -74,7 +74,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;
};
View
57 client/test_project/javascripts/picky.controller.js
@@ -7,6 +7,8 @@ var PickyController = function(config) {
var successCallback = config.success || function(data, query) { };
var afterCallback = config.after || function(data, query) { };
+ var liveRendered = config.liveRendered || false;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -31,32 +33,6 @@ var PickyController = function(config) {
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
- var liveSearchCallback = function(data, query) {
- data = successCallback(data, query) || data;
-
- view.liveResultsCallback(data);
-
- afterCallback(data, query);
- };
- var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveSearchCallback, params);
- };
-
- // The timer is initially instantly stopped.
- //
- var liveSearchTimerInterval = 180;
- var liveSearchTimerId;
- var liveSearchTimerCallback = function() {
- liveSearch(view.text());
- clearInterval(liveSearchTimerId);
- };
- liveSearchTimerId = setInterval(liveSearchTimerCallback, liveSearchTimerInterval);
- clearInterval(liveSearchTimerId);
-
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -82,6 +58,35 @@ var PickyController = function(config) {
search('full', query, fullSearchCallback, params);
};
+ var liveSearchCallback = function(data, query) {
+ data = successCallback(data, query) || data;
+
+ view.liveResultsCallback(data);
+
+ afterCallback(data, query);
+ };
+ var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
+ var liveSearch = function(query, possibleParams) {
+ var params = possibleParams || {};
+
+ query = beforeCallback(query, params) || query;
+
+ search('live', query, liveCallbackUsed, params);
+ };
+
+ // The timer is initially instantly stopped.
+ //
+ var liveSearchTimerInterval = 180;
+ var liveSearchTimerId;
+ var liveSearchTimerCallback = function() {
+ liveSearch(view.text());
+ clearInterval(liveSearchTimerId);
+ };
+ liveSearchTimerId = setInterval(liveSearchTimerCallback, liveSearchTimerInterval);
+ clearInterval(liveSearchTimerId);
+
+ //
+ //
this.insert = function(query, params, full) {
view.insert(query);
View
6 client/test_project/javascripts/picky.data.js
@@ -11,8 +11,8 @@ 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.entries = this.rendered;
+ this.rendered = rendered;
+ this.entries = this.rendered; // TODO Remove?
this.isType = function(name) {
return name == self.type;
@@ -74,7 +74,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;
};
View
30 generators/prototypes/client/sinatra/javascripts/picky.min.js
@@ -1,18 +1,18 @@
Array.prototype.index=function(a){for(var c=0,g=this.length;c<g;c++)if(this[c]==a)return c;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 c=0,g=this.length;c<g;c++)a(c,this[c]);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 c=PickyI18n.locale||
-"en",g=a.split(".").concat(c),e=dictionary,h=0,f=g.length;h<f;h++){e=e[g[h]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,h,f){var n=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=h||[];this.entries=this.rendered=f||[];this.isType=function(r){return r==n.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var e=a[c];this.allocations.push(new Allocation(e[0],e[1],e[2],e[3],e[4],e[5]))}this.length=this.allocations.length;this.each=function(h){return this.allocations.each(h)}}
-function PickyData(a){var c=a.total,g=a.duration,e=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=h;this.renderedAmount=function(){var f=0;h.each(function(n,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,h=c.reset,f=c.button,n=c.counter,r=c.dashboard,w=c.moreSelector,s=c.results,j=c.noResults,p=new PickyAddination(this,s),q=new PickyAllocationsCloud(this,c),b=new PickyResultsRenderer(p,c),d=function(){h.fadeTo(166,1)},i=function(){q.hide();s.empty();j.hide()},m=function(k){e.val(k);h.fadeTo(166,0);x("empty");n.empty();i()},o=function(){return e.val()};this.text=o;var u=function(k){n.text(k);k>0&&k<=5&&n.fadeTo("fast",0.5).fadeTo("fast",
-1)},v=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},x=function(k){r.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){x(v(k));if(k.isEmpty()){i();u(0);j.show();d()}else if(k.total>g&&k.allocations.length>1){i();d();q.show(k);u(k.total)}else if(k.offset==0){i();u(k.total);b.render(k);s.show();d();e.focus()}else{var y=$(w).position().top;p.remove();b.render(k);$("body").animate({scrollTop:y-
-12},500)}};this.liveResultsCallback=function(k){x(v(k));u(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(o(),k)};(function(){e.keyup(function(k){if(o()==""){m();a.searchTextCleared()}else{a.searchTextEntered(o(),k);d()}});n.click(function(){o()==""||a.searchButtonClicked(o())});f.click(function(){o()==""||a.searchButtonClicked(o())});h.click(function(){m("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,h){var f=h||{};f=$.extend({query:g},h);$.getJSON(a,f,function(n){e&&e(new PickyData(n))})};this.search=function(g,e,h,f){c(g,function(n){e&&e(f,n)},h)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,n){n=n||{};latestRequestTimestamp=new Date;n.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(e,function(r,w){if(!r.live||r.live==latestRequestTimestamp)h&&
-h(w)},f,n)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,n){n=n||{};latestRequestTimestamp=new Date;n.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(e,function(r,w){if(!r.full||r.full==latestRequestTimestamp)h&&h(w)},f,n)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},h=a.success||function(){},f=a.after||function(){},n=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=n;var r=function(){var b=window.History&&window.History.getState();return n(b&&b.url)};this.lastQuery=r;var w=function(b,d){b=h(b,d)||b;console.log(b.renderedAmount());b.renderedAmount()>0?c.fullResultsCallback(b):c.liveResultsCallback(b);f(b,d)},s,j=function(){var b=
-c.text(),d={};b=e(b,d)||b;var i=g.live;i&&i.search(b,w,d);clearInterval(s)};s=setInterval(j,180);clearInterval(s);var p=function(b,d){b=h(b,d)||b;c.fullResultsCallback(b);f(b,d)},q=function(b,d){var i=d||{};clearInterval(s);if(b!=r()){var m="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,m)}b=e(b,i)||b;(m=g.full)&&m.search(b,p,i)};this.insert=function(b,d,i){c.insert(b);i&&q(b,d)};this.clearButtonClicked=
-function(){clearInterval(s)};this.searchTextCleared=function(){clearInterval(s)};this.searchTextEntered=function(b,d){if($.inArray(d.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(d.keyCode==13)q(b);else{clearInterval(s);s=setInterval(j,180)}};this.searchButtonClicked=function(b){q(b)};this.allocationChosen=function(b){q(b)};this.addinationClicked=function(b,d){q(b,{offset:d.data.offset})}};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
+"en",g=a.split(".").concat(c),e=dictionary,h=0,f=g.length;h<f;h++){e=e[g[h]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,h,f){var o=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=h||[];this.entries=this.rendered=f;this.isType=function(r){return r==o.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var e=a[c];this.allocations.push(new Allocation(e[0],e[1],e[2],e[3],e[4],e[5]))}this.length=this.allocations.length;this.each=function(h){return this.allocations.each(h)}}
+function PickyData(a){var c=a.total,g=a.duration,e=a.offset,h=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=h;this.renderedAmount=function(){var f=0;h.each(function(o,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,h=c.reset,f=c.button,o=c.counter,r=c.dashboard,v=c.moreSelector,u=c.results,j=c.noResults,q=new PickyAddination(this,u),p=new PickyAllocationsCloud(this,c),i=new PickyResultsRenderer(q,c),b=function(){h.fadeTo(166,1)},d=function(){p.hide();u.empty();j.hide()},m=function(k){e.val(k);h.fadeTo(166,0);x("empty");o.empty();d()},n=function(){return e.val()};this.text=n;var s=function(k){o.text(k);k>0&&k<=5&&o.fadeTo("fast",0.5).fadeTo("fast",
+1)},w=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},x=function(k){r.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){x(w(k));if(k.isEmpty()){d();s(0);j.show();b()}else if(k.total>g&&k.allocations.length>1){d();b();p.show(k);s(k.total)}else if(k.offset==0){d();s(k.total);i.render(k);u.show();b();e.focus()}else{var y=$(v).position().top;q.remove();i.render(k);$("body").animate({scrollTop:y-
+12},500)}};this.liveResultsCallback=function(k){x(w(k));s(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(n(),k)};(function(){e.keyup(function(k){if(n()==""){m();a.searchTextCleared()}else{a.searchTextEntered(n(),k);b()}});o.click(function(){n()==""||a.searchButtonClicked(n())});f.click(function(){n()==""||a.searchButtonClicked(n())});h.click(function(){m("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,h){var f=h||{};f=$.extend({query:g},h);$.getJSON(a,f,function(o){e&&e(new PickyData(o))})};this.search=function(g,e,h,f){c(g,function(o){e&&e(f,o)},h)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(e,function(r,v){if(!r.live||r.live==latestRequestTimestamp)h&&
+h(v)},f,o)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,h,f,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(e,function(r,v){if(!r.full||r.full==latestRequestTimestamp)h&&h(v)},f,o)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},h=a.success||function(){},f=a.after||function(){};a=a.liveRendered||false;var o=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=o;var r=function(){var b=window.History&&window.History.getState();return o(b&&b.url)};this.lastQuery=r;var v=function(b,d){b=h(b,d)||b;c.fullResultsCallback(b);f(b,d)},u=function(b,d){var m=d||{};clearInterval(p);if(b!=r()){var n="?q="+escape(b).replace(/\*/g,
+"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,n)}b=e(b,m)||b;(n=g.full)&&n.search(b,v,m)},j=function(b,d){b=h(b,d)||b;c.liveResultsCallback(b);f(b,d)},q=a?v:j,p,i=function(){var b=c.text(),d={};b=e(b,d)||b;var m=g.live;m&&m.search(b,q,d);clearInterval(p)};p=setInterval(i,180);clearInterval(p);this.insert=function(b,d,m){c.insert(b);m&&u(b,d)};this.clearButtonClicked=function(){clearInterval(p)};this.searchTextCleared=function(){clearInterval(p)};
+this.searchTextEntered=function(b,d){if($.inArray(d.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(d.keyCode==13)u(b);else{clearInterval(p);p=setInterval(i,180)}};this.searchButtonClicked=function(b){u(b)};this.allocationChosen=function(b){u(b)};this.addinationClicked=function(b,d){u(b,{offset:d.data.offset})}};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 c=a.backends;if(c){c.live||alert("Both a full and live backend must be provided.");c.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};c=a.enclosingSelector||"#picky";a.input=$(a.inputSelector||
c+" input.query");a.reset=$(a.resetSelector||c+" div.reset");a.button=$(a.buttonSelector||c+" input.search_button");a.counter=$(a.counterSelector||c+" div.status");a.dashboard=$(a.dashboardSelector||c+" .dashboard");a.results=$(a.resultsSelector||c+" div.results");a.noResults=$(a.noResultsSelector||c+" .no_results");a.moreSelector=a.moreSelector||c+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||c+" .allocations");a.shownAllocations=a.allocations.find(".shown");a.showMoreAllocations=
-a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.results=$(a.resultsSelector||c+" div.results");a.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var g=a.controller&&new a.controller(a)||new PickyController(a);var e=this.insert=function(f,n,r){g.insert(f,n||{},r||true)},h=function(){var f=g.lastQuery();f&&e(f)};this.resend=h;this.insertFromURL=function(f){f&&f!=""?e(f):h()};window.History&&window.History.Adapter.bind(window,"statechange",
-function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&e(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,h,f=g.renderedAmount();h=g.offset+f;f=h+f;g=g.total;if(g<f)f=g;h={offset:h,start:h+1,end:f};if(h.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:h.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,h=c.noAsterisks,f=function(j){var p=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!h.include(p[0]))if(p[1].match(/[^\*~]$/))p[1]+="*";j.push(p);return j},n=function(j){for(var p=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},q=[],b,d=0,i=j.length;d<i;d++){b=j[d];var m=b[0];m=p[m]||m;q.push([m,b[1]])}return q},r=function(j,p){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),p].join(" ")},w=function(j,p){var q=Localization.explanation_delimiters[PickyI18n.locale],b=n(f(p)),d="",i=[];b=$.map(b,function(m){var o=m[0];m=m[1];if(d==""||o==d){m=m.replace(/[\w,]+:(.+)/,"$1");i.push(m);d=o}else{var u=r(d,i.join(" "));i=[];i.push(m);d=o;return u}});b.push(r(d,i.join(" ")));b=b.join(" "+q+" ");return'<span class="explanation">'+j+" "+b+"</span>"},s=function(j,p){var q='<div class="header">';q+=w(p.type,p.combination);if(j.offset>0)q+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return q};this.render=function(j){j.allocations.each(function(p,q){if(q.entries.length>0){g.append(s(j,q)).append(q.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(b){var d={},i={},m=[],o;o=0;for(l=b.length;o<l;o++){var u=b[o][0];if(u in d){d[u]=d[u]+" "+b[o][1];m.push(o)}else{d[u]=b[o][1];i[o]=u}}for(o in i)b[o][1]=d[i[o]];for(o=m.length-1;o>=0;o--)b.remove(m[o]);return b}function e(b){return $.map(b,function(d,i){return"%"+(i+1)+"$s"}).join(" ")}function h(b){if(b.length==0)return"";var d=b=g(b);d.sort(function(y,z){return y[0]<z[0]?-1:1});for(var i=[],m=0,o=d.length;m<o;m++)i.push(d[m][0]);var u=i.length==1,v=p[i]||
-(p[i]=e(i));if($.type(v)==="string"){p[i]={format:v};v=p[i]}var x=1,k=v.format;$.each(b,function(y,z){var A=z[0],B=z[2];if(v.filter)B=v.filter(B);A=s[A]||A;if(u&&!(v&&v.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return k}function f(b){for(var d=[],i=0,m=j.length;i<m;i++)d.push([]);d.push([]);i=0;for(m=b.length;i<m;i++){for(var o=b[i],u=o[0],v=false,x=0,k=j.length;x<k;x++)if(j[x].include(u)){d[x].push(o);v=true;break}v||d[d.length-1].push(o)}var y;
-for(b=d.length-1;b>=0;b--){y=d[b];if(y.length>0)break}y=y[y.length-1];q.include(y[0])||(y[1]+="...");return $.map(d,function(z){return h(z)})}function n(b){var d=[],i,m;for(m in b){i=b[m][0];i=w[i]||i;d[m]=i+":"+b[m][2]}return d.join(" ")}var r=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[r]||{},s=Localization.explanations&&Localization.explanations[r]||{},j=c.groups||[],p=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var q=["street_number",
-"zipcode"];this.contract=g;this.rendered=h;this.groupify=f;this.querify=n;this.render=function(b){var d=b.combination,i=b.count;b=n(d);d=f(d).join(" ");d=$('<li><div class="text">'+d+'</div><div class="count">'+i+"</div></li>");d.bind("click",{query:b},a);return d}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,h=c.showMoreAllocations,f=c.hiddenAllocations,n=function(){g.hide()},r=new AllocationRenderer(function(j){n();a.allocationChosen(j)},c),w=function(j){var p=[];j.each(function(q,b){p.push(r.render(b))});return p},s=function(j){if(j.length==0)return g.hide();e.empty();h.hide();f.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(p,q){e.append(q)});$.each(j.slice(2),function(p,q){f.append(q)});h.show()}else $.each(j,
-function(p,q){e.append(q)});return g.show()};h.click(function(){h.hide();f.show()});this.hide=n;this.show=function(j){s(w(j.allocations));g.show()}};
+a.allocations.find(".more");a.hiddenAllocations=a.allocations.find(".hidden");a.results=$(a.resultsSelector||c+" div.results");a.noAsterisks=a.noAsterisks||[];a.wrapResults=a.wrapResults||'<ol class="results"></ol>';var g=a.controller&&new a.controller(a)||new PickyController(a);var e=this.insert=function(f,o,r){g.insert(f,o||{},r||true)},h=function(){var f=g.lastQuery();f&&e(f)};this.resend=h;this.insertFromURL=function(f){f&&f!=""?e(f):h()};window.History&&window.History.Adapter.bind(window,"statechange",
+function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&e(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,h,f=g.renderedAmount();h=g.offset+f;f=h+f;g=g.total;if(g<f)f=g;h={offset:h,start:h+1,end:f};if(h.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:h.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,h=c.noAsterisks,f=function(j){var q=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!h.include(q[0]))if(q[1].match(/[^\*~]$/))q[1]+="*";j.push(q);return j},o=function(j){for(var q=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},p=[],i,b=0,d=j.length;b<d;b++){i=j[b];var m=i[0];m=q[m]||m;p.push([m,i[1]])}return p},r=function(j,q){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
+"<strong>$1</strong>"),q].join(" ")},v=function(j,q){var p=Localization.explanation_delimiters[PickyI18n.locale],i=o(f(q)),b="",d=[];i=$.map(i,function(m){var n=m[0];m=m[1];if(b==""||n==b){m=m.replace(/[\w,]+:(.+)/,"$1");d.push(m);b=n}else{var s=r(b,d.join(" "));d=[];d.push(m);b=n;return s}});i.push(r(b,d.join(" ")));i=i.join(" "+p+" ");return'<span class="explanation">'+j+" "+i+"</span>"},u=function(j,q){var p='<div class="header">';p+=v(q.type,q.combination);if(j.offset>0)p+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
+return p};this.render=function(j){j.allocations.each(function(q,p){if(p.entries.length>0){g.append(u(j,p)).append(p.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(i){var b={},d={},m=[],n;n=0;for(l=i.length;n<l;n++){var s=i[n][0];if(s in b){b[s]=b[s]+" "+i[n][1];m.push(n)}else{b[s]=i[n][1];d[n]=s}}for(n in d)i[n][1]=b[d[n]];for(n=m.length-1;n>=0;n--)i.remove(m[n]);return i}function e(i){return $.map(i,function(b,d){return"%"+(d+1)+"$s"}).join(" ")}function h(i){if(i.length==0)return"";var b=i=g(i);b.sort(function(y,z){return y[0]<z[0]?-1:1});for(var d=[],m=0,n=b.length;m<n;m++)d.push(b[m][0]);var s=d.length==1,w=q[d]||
+(q[d]=e(d));if($.type(w)==="string"){q[d]={format:w};w=q[d]}var x=1,k=w.format;$.each(i,function(y,z){var A=z[0],B=z[2];if(w.filter)B=w.filter(B);A=u[A]||A;if(s&&!(w&&w.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return k}function f(i){for(var b=[],d=0,m=j.length;d<m;d++)b.push([]);b.push([]);d=0;for(m=i.length;d<m;d++){for(var n=i[d],s=n[0],w=false,x=0,k=j.length;x<k;x++)if(j[x].include(s)){b[x].push(n);w=true;break}w||b[b.length-1].push(n)}var y;
+for(i=b.length-1;i>=0;i--){y=b[i];if(y.length>0)break}y=y[y.length-1];p.include(y[0])||(y[1]+="...");return $.map(b,function(z){return h(z)})}function o(i){var b=[],d,m;for(m in i){d=i[m][0];d=v[d]||d;b[m]=d+":"+i[m][2]}return b.join(" ")}var r=PickyI18n.locale,v=Localization.qualifiers&&Localization.qualifiers[r]||{},u=Localization.explanations&&Localization.explanations[r]||{},j=c.groups||[],q=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var p=["street_number",
+"zipcode"];this.contract=g;this.rendered=h;this.groupify=f;this.querify=o;this.render=function(i){var b=i.combination,d=i.count;i=o(b);b=f(b).join(" ");b=$('<li><div class="text">'+b+'</div><div class="count">'+d+"</div></li>");b.bind("click",{query:i},a);return b}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,h=c.showMoreAllocations,f=c.hiddenAllocations,o=function(){g.hide()},r=new AllocationRenderer(function(j){o();a.allocationChosen(j)},c),v=function(j){var q=[];j.each(function(p,i){q.push(r.render(i))});return q},u=function(j){if(j.length==0)return g.hide();e.empty();h.hide();f.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(q,p){e.append(p)});$.each(j.slice(2),function(q,p){f.append(p)});h.show()}else $.each(j,
+function(q,p){e.append(p)});return g.show()};h.click(function(){h.hide();f.show()});this.hide=o;this.show=function(j){u(v(j.allocations));g.show()}};

0 comments on commit 3561fb3

Please sign in to comment.