Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

+ PickyClient.resend function which resends the last query (still run…

…s before etc. filters)
  • Loading branch information...
commit 86e8af2a93b41912b56a2c2c00d44e01c76644e8 1 parent f615463
@floere authored
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),d=dictionary,i=0,f=g.length;i<f;i++){d=d[g[i]];if(d==undefined){d="Translation missing: "+a+"."+c;break}}return d};function Allocation(a,c,g,d,i,f){var p=this;this.type=a;this.weight=c;this.count=g;this.combination=d;this.ids=i||[];this.entries=this.rendered=f;this.isType=function(r){return r==p.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var d=a[c];this.allocations.push(new Allocation(d[0],d[1],d[2],d[3],d[4],d[5]))}this.length=this.allocations.length;this.each=function(i){return this.allocations.each(i)}}
-function PickyData(a){var c=a.total,g=a.duration,d=a.offset,i=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=d;this.allocations=i;this.renderedAmount=function(){var f=0;i.each(function(p,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,d=c.input,i=c.reset,f=c.button,p=c.counter,r=c.dashboard,u=c.moreSelector,w=c.results,k=c.noResults,o=new PickyAddination(this,w),q=new PickyAllocationsCloud(this,c),e=new PickyResultsRenderer(o,c),j=function(){i.fadeTo(166,1)},b=function(){q.hide();w.empty();k.hide()},h=function(m){d.val(m);i.fadeTo(166,0);x("empty");p.empty();b()},n=function(){return d.val()};this.text=n;var s=function(m){p.text(m);m>0&&m<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
-1)},v=function(m){if(m.isEmpty())return"none";if(m.total>g&&m.allocations.length>1)return"support";return"ok"},x=function(m){r.attr("class","dashboard "+m)};this.insert=function(m){d.val(m);d.select()};this.fullResultsCallback=function(m){x(v(m));if(m.isEmpty()){b();s(0);k.show();j()}else if(m.total>g&&m.allocations.length>1){b();j();q.show(m);s(m.total)}else if(m.offset==0){b();s(m.total);e.render(m);w.show();j();d.focus()}else{var y=$(u).position().top;o.remove();e.render(m);$("body").animate({scrollTop:y-
-12},500)}};this.liveResultsCallback=function(m){x(v(m));s(m.total)};this.allocationChosen=function(m){m=m.data.query;d.val(m);a.allocationChosen(m)};this.addinationClicked=function(m){a.addinationClicked(n(),m)};(function(){d.keyup(function(m){if(n()==""){h();a.searchTextCleared()}else{a.searchTextEntered(n(),m);j()}});p.click(function(){n()==""||a.searchButtonClicked(n())});f.click(function(){n()==""||a.searchButtonClicked(n())});i.click(function(){h("");a.clearButtonClicked();d.focus()})})();d.focus()};var PickyBackend=function(a){var c=function(g,d,i){var f=i||{};f=$.extend({query:g},i);$.getJSON(a,f,function(p){d&&d(new PickyData(p))})};this.search=function(g,d,i,f){c(g,function(p){d&&d(f,p)},i)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(d,i,f,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(d,function(r,u){if(!r.live||r.live==latestRequestTimestamp)i&&
-i(u)},f,p)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(d,i,f,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(d,function(r,u){if(!r.full||r.full==latestRequestTimestamp)i&&i(u)},f,p)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,d=a.before||function(){},i=a.success||function(){},f=a.after||function(){},p=a.liveRendered||false,r=a.liveSearchInterval||180,u=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=u;var w=function(){var b=window.History&&window.History.getState();return u(b&&b.url)};this.lastQuery=w;var k=function(b,h){b=i(b,h)||b;c.fullResultsCallback(b);f(b,h)},o=function(b,h){var n=h||{};clearInterval(e);
-if(b!=w()){var s="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,s)}b=d(b,n)||b;(s=g.full)&&s.search(b,k,n)};a=function(b,h){b=i(b,h)||b;c.liveResultsCallback(b);f(b,h)};var q=p?k:a,e,j=function(){var b=c.text(),h={};b=d(b,h)||b;var n=g.live;n&&n.search(b,q,h);clearInterval(e)};e=setInterval(j,r);clearInterval(e);this.insert=function(b,h,n){c.insert(b);n&&o(b,h)};this.clearButtonClicked=function(){clearInterval(e)};
-this.searchTextCleared=function(){clearInterval(e)};this.searchTextEntered=function(b,h){if($.inArray(h.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(h.keyCode==13)o(b);else{clearInterval(e);e=setInterval(j,r)}};this.searchButtonClicked=function(b){o(b)};this.allocationChosen=function(b){o(b)};this.addinationClicked=function(b,h){o(b,{offset:h.data.offset})}};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
+"en",g=a.split(".").concat(c),e=dictionary,d=0,m=g.length;d<m;d++){e=e[g[d]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,d,m){var p=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=d||[];this.entries=this.rendered=m;this.isType=function(s){return s==p.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(d){return this.allocations.each(d)}}
+function PickyData(a){var c=a.total,g=a.duration,e=a.offset,d=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=d;this.renderedAmount=function(){var m=0;d.each(function(p,s){m+=s.rendered.length});return m};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,d=c.reset,m=c.button,p=c.counter,s=c.dashboard,w=c.moreSelector,x=c.results,j=c.noResults,q=new PickyAddination(this,x),r=new PickyAllocationsCloud(this,c),f=new PickyResultsRenderer(q,c),i=function(){d.fadeTo(166,1)},h=function(){r.hide();x.empty();j.hide()},o=function(k){e.val(k);d.fadeTo(166,0);v("empty");p.empty();h()},b=function(){return e.val()};this.text=b;var n=function(k){p.text(k);k>0&&k<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
+1)},u=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},v=function(k){s.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){v(u(k));if(k.isEmpty()){h();n(0);j.show();i()}else if(k.total>g&&k.allocations.length>1){h();i();r.show(k);n(k.total)}else if(k.offset==0){h();n(k.total);f.render(k);x.show();i();e.focus()}else{var y=$(w).position().top;q.remove();f.render(k);$("body").animate({scrollTop:y-
+12},500)}};this.liveResultsCallback=function(k){v(u(k));n(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(b(),k)};(function(){e.keyup(function(k){if(b()==""){o();a.searchTextCleared()}else{a.searchTextEntered(b(),k);i()}});p.click(function(){b()==""||a.searchButtonClicked(b())});m.click(function(){b()==""||a.searchButtonClicked(b())});d.click(function(){o("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,d){var m=d||{};m=$.extend({query:g},d);$.getJSON(a,m,function(p){e&&e(new PickyData(p))})};this.search=function(g,e,d,m){c(g,function(p){e&&e(m,p)},d)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,d,m,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);g.search(e,function(s,w){if(!s.live||s.live==latestRequestTimestamp)d&&
+d(w)},m,p)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,d,m,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);g.search(e,function(s,w){if(!s.full||s.full==latestRequestTimestamp)d&&d(w)},m,p)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},d=a.success||function(){},m=a.after||function(){},p=a.liveRendered||false,s=a.liveSearchInterval||180,w,x=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=x;var j=function(){var b=window.History&&window.History.getState();return x(b&&b.url)};this.lastFullQuery=j;var q=function(b,n,u,v){w=[b,n,u,v];n=e(n,v)||n;(b=g[b])&&b.search(n,u,v)};this.resend=function(){w&&q.apply(this,
+w)};var r=function(b,n){b=d(b,n)||b;c.fullResultsCallback(b);m(b,n)},f=function(b,n){clearInterval(h);if(b!=j()){var u="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,u)}q("full",b,r,n||{})};a=function(b,n){b=d(b,n)||b;c.liveResultsCallback(b);m(b,n)};var i=p?r:a,h,o=function(){var b=c.text();q("live",b,i,{});clearInterval(h)};h=setInterval(o,s);clearInterval(h);this.insert=function(b,n,u){c.insert(b);u&&
+f(b,n)};this.clearButtonClicked=function(){clearInterval(h)};this.searchTextCleared=function(){clearInterval(h)};this.searchTextEntered=function(b,n){if($.inArray(n.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(n.keyCode==13)f(b);else{clearInterval(h);h=setInterval(o,s)}};this.searchButtonClicked=function(b){f(b)};this.allocationChosen=function(b){f(b)};this.addinationClicked=function(b,n){f(b,{offset:n.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 d=this.insert=function(f,p,r){g.insert(f,p||{},r||true)},i=function(){var f=g.lastQuery();f&&d(f)};this.resend=i;this.insertFromURL=function(f){f&&f!=""?d(f):i()};window.History&&window.History.Adapter.bind(window,"statechange",
-function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&d(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var d=g.total,i,f=g.renderedAmount();i=g.offset+f;f=i+f;g=g.total;if(g<f)f=g;i={offset:i,start:i+1,end:f};if(i.offset<d){d=$("<div class='addination'>"+t("results.addination.more")+"</div>");d.bind("click",{offset:i.offset},a.addinationClicked);return d}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,d=c.wrapResults,i=c.noAsterisks,f=function(k){var o=k[k.length-1];k=k.slice(0,k.length-1);if(k==[])k=[k];if(!i.include(o[0]))if(o[1].match(/[^\*~]$/))o[1]+="*";k.push(o);return k},p=function(k){for(var o=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},q=[],e,j=0,b=k.length;j<b;j++){e=k[j];var h=e[0];h=o[h]||h;q.push([h,e[1]])}return q},r=function(k,o){return[k.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),o].join(" ")},u=function(k,o){var q=Localization.explanation_delimiters[PickyI18n.locale],e=p(f(o)),j="",b=[];e=$.map(e,function(h){var n=h[0];h=h[1];if(j==""||n==j){h=h.replace(/[\w,]+:(.+)/,"$1");b.push(h);j=n}else{var s=r(j,b.join(" "));b=[];b.push(h);j=n;return s}});e.push(r(j,b.join(" ")));e=e.join(" "+q+" ");return'<span class="explanation">'+k+" "+e+"</span>"},w=function(k,o){var q='<div class="header">';q+=u(o.type,o.combination);if(k.offset>0)q+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return q};this.render=function(k){k.allocations.each(function(o,q){if(q.entries.length>0){g.append(w(k,q)).append(q.entries.join(""));g.children("li").wrapAll(d)}});g.append(a.render(k))}};function AllocationRenderer(a,c){function g(e){var j={},b={},h=[],n;n=0;for(l=e.length;n<l;n++){var s=e[n][0];if(s in j){j[s]=j[s]+" "+e[n][1];h.push(n)}else{j[s]=e[n][1];b[n]=s}}for(n in b)e[n][1]=j[b[n]];for(n=h.length-1;n>=0;n--)e.remove(h[n]);return e}function d(e){return $.map(e,function(j,b){return"%"+(b+1)+"$s"}).join(" ")}function i(e){if(e.length==0)return"";var j=e=g(e);j.sort(function(y,z){return y[0]<z[0]?-1:1});for(var b=[],h=0,n=j.length;h<n;h++)b.push(j[h][0]);var s=b.length==1,v=o[b]||
-(o[b]=d(b));if($.type(v)==="string"){o[b]={format:v};v=o[b]}var x=1,m=v.format;$.each(e,function(y,z){var A=z[0],B=z[2];if(v.filter)B=v.filter(B);A=w[A]||A;if(s&&!(v&&v.ignoreSingle))return m=B+"&nbsp;("+A+")";m=m.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return m}function f(e){for(var j=[],b=0,h=k.length;b<h;b++)j.push([]);j.push([]);b=0;for(h=e.length;b<h;b++){for(var n=e[b],s=n[0],v=false,x=0,m=k.length;x<m;x++)if(k[x].include(s)){j[x].push(n);v=true;break}v||j[j.length-1].push(n)}var y;
-for(e=j.length-1;e>=0;e--){y=j[e];if(y.length>0)break}y=y[y.length-1];q.include(y[0])||(y[1]+="...");return $.map(j,function(z){return i(z)})}function p(e){var j=[],b,h;for(h in e){b=e[h][0];b=u[b]||b;j[h]=b+":"+e[h][2]}return j.join(" ")}var r=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[r]||{},w=Localization.explanations&&Localization.explanations[r]||{},k=c.groups||[],o=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var q=["street_number",
-"zipcode"];this.contract=g;this.rendered=i;this.groupify=f;this.querify=p;this.render=function(e){var j=e.combination,b=e.count;e=p(j);j=f(j).join(" ");j=$('<li><div class="text">'+j+'</div><div class="count">'+b+"</div></li>");j.bind("click",{query:e},a);return j}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,d=c.shownAllocations,i=c.showMoreAllocations,f=c.hiddenAllocations,p=function(){g.hide()},r=new AllocationRenderer(function(k){p();a.allocationChosen(k)},c),u=function(k){var o=[];k.each(function(q,e){o.push(r.render(e))});return o},w=function(k){if(k.length==0)return g.hide();d.empty();i.hide();f.empty().hide();if(k.length>3){$.each(k.slice(0,2),function(o,q){d.append(q)});$.each(k.slice(2),function(o,q){f.append(q)});i.show()}else $.each(k,
-function(o,q){d.append(q)});return g.show()};i.click(function(){i.hide();f.show()});this.hide=p;this.show=function(k){w(u(k.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(d,m,p){g.insert(d,m||{},p||true)};this.resend=g.resend;this.insertFromURL=function(d){if(d&&d!="")e(d);else(d=g.lastFullQuery())&&e(d)};window.History&&window.History.Adapter.bind(window,"statechange",
+function(){var d=window.History.getState();(d=g.extractQuery(d.url))&&e(d)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,d,m=g.renderedAmount();d=g.offset+m;m=d+m;g=g.total;if(g<m)m=g;d={offset:d,start:d+1,end:m};if(d.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:d.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,d=c.noAsterisks,m=function(j){var q=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!d.include(q[0]))if(q[1].match(/[^\*~]$/))q[1]+="*";j.push(q);return j},p=function(j){for(var q=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},r=[],f,i=0,h=j.length;i<h;i++){f=j[i];var o=f[0];o=q[o]||o;r.push([o,f[1]])}return r},s=function(j,q){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
+"<strong>$1</strong>"),q].join(" ")},w=function(j,q){var r=Localization.explanation_delimiters[PickyI18n.locale],f=p(m(q)),i="",h=[];f=$.map(f,function(o){var b=o[0];o=o[1];if(i==""||b==i){o=o.replace(/[\w,]+:(.+)/,"$1");h.push(o);i=b}else{var n=s(i,h.join(" "));h=[];h.push(o);i=b;return n}});f.push(s(i,h.join(" ")));f=f.join(" "+r+" ");return'<span class="explanation">'+j+" "+f+"</span>"},x=function(j,q){var r='<div class="header">';r+=w(q.type,q.combination);if(j.offset>0)r+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
+return r};this.render=function(j){j.allocations.each(function(q,r){if(r.entries.length>0){g.append(x(j,r)).append(r.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(f){var i={},h={},o=[],b;b=0;for(l=f.length;b<l;b++){var n=f[b][0];if(n in i){i[n]=i[n]+" "+f[b][1];o.push(b)}else{i[n]=f[b][1];h[b]=n}}for(b in h)f[b][1]=i[h[b]];for(b=o.length-1;b>=0;b--)f.remove(o[b]);return f}function e(f){return $.map(f,function(i,h){return"%"+(h+1)+"$s"}).join(" ")}function d(f){if(f.length==0)return"";var i=f=g(f);i.sort(function(y,z){return y[0]<z[0]?-1:1});for(var h=[],o=0,b=i.length;o<b;o++)h.push(i[o][0]);var n=h.length==1,u=q[h]||
+(q[h]=e(h));if($.type(u)==="string"){q[h]={format:u};u=q[h]}var v=1,k=u.format;$.each(f,function(y,z){var A=z[0],B=z[2];if(u.filter)B=u.filter(B);A=x[A]||A;if(n&&!(u&&u.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+v+"\\$s","g"),B);v+=1;return v});return k}function m(f){for(var i=[],h=0,o=j.length;h<o;h++)i.push([]);i.push([]);h=0;for(o=f.length;h<o;h++){for(var b=f[h],n=b[0],u=false,v=0,k=j.length;v<k;v++)if(j[v].include(n)){i[v].push(b);u=true;break}u||i[i.length-1].push(b)}var y;
+for(f=i.length-1;f>=0;f--){y=i[f];if(y.length>0)break}y=y[y.length-1];r.include(y[0])||(y[1]+="...");return $.map(i,function(z){return d(z)})}function p(f){var i=[],h,o;for(o in f){h=f[o][0];h=w[h]||h;i[o]=h+":"+f[o][2]}return i.join(" ")}var s=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[s]||{},x=Localization.explanations&&Localization.explanations[s]||{},j=c.groups||[],q=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var r=["street_number",
+"zipcode"];this.contract=g;this.rendered=d;this.groupify=m;this.querify=p;this.render=function(f){var i=f.combination,h=f.count;f=p(i);i=m(i).join(" ");i=$('<li><div class="text">'+i+'</div><div class="count">'+h+"</div></li>");i.bind("click",{query:f},a);return i}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,d=c.showMoreAllocations,m=c.hiddenAllocations,p=function(){g.hide()},s=new AllocationRenderer(function(j){p();a.allocationChosen(j)},c),w=function(j){var q=[];j.each(function(r,f){q.push(s.render(f))});return q},x=function(j){if(j.length==0)return g.hide();e.empty();d.hide();m.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(q,r){e.append(r)});$.each(j.slice(2),function(q,r){m.append(r)});d.show()}else $.each(j,
+function(q,r){e.append(r)});return g.show()};d.click(function(){d.hide();m.show()});this.hide=p;this.show=function(j){x(w(j.allocations));g.show()}};
View
BIN  client/javascripts/picky.source.js.tar
Binary file not shown
View
11 client/javascripts/source/picky.client.js
@@ -98,16 +98,12 @@ var PickyClient = function(config) {
};
var insert = this.insert;
- // Resends the last query text.
+ // Resends the last query text, full/live.
//
// Note: Other variables apart from the text
// could have changed.
//
- var resend = function() {
- var lastQuery = controller.lastQuery();
- lastQuery && insert(lastQuery);
- };
- this.resend = resend;
+ this.resend = controller.resend;
// Takes a query or nothing as parameter.
//
@@ -118,7 +114,8 @@ var PickyClient = function(config) {
if (override && override != '') {
insert(override);
} else {
- resend();
+ var lastFullQuery = controller.lastFullQuery();
+ lastFullQuery && insert(lastFullQuery);
}
};
View
30 client/javascripts/source/picky.controller.js
@@ -10,6 +10,8 @@ var PickyController = function(config) {
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
+ var lastQueryParams;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -20,20 +22,31 @@ var PickyController = function(config) {
// Failsafe extraction of the last made query.
//
- var lastQuery = function() {
+ var lastFullQuery = function() {
var state = window.History && window.History.getState();
var url = state && state.url;
return extractQuery(url);
};
- this.lastQuery = lastQuery;
+ this.lastFullQuery = lastFullQuery;
// If the given backend cannot be found, ignore the search request.
//
var search = function(type, query, callback, specificParams) {
+ lastQueryParams = [type, query, callback, specificParams];
+
+ query = beforeCallback(query, specificParams) || query;
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
+ // Resend the last query as it was.
+ //
+ var resend = function() {
+ if (lastQueryParams) { search.apply(this, lastQueryParams); }
+ };
+ this.resend = resend;
+
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -42,21 +55,18 @@ var PickyController = function(config) {
afterCallback(data, query);
};
var fullSearch = function(query, possibleParams) {
- var params = possibleParams || {};
clearInterval(liveSearchTimerId);
// Be extra cautious since not all browsers/histories offer pushState.
//
// Note: If this query is the same as the last, we do not save it in the history.
//
- if (query != lastQuery()) {
+ if (query != lastFullQuery()) {
var url = "?q=" + escape(query).replace(/\*/g,'%2A');
window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
}
- query = beforeCallback(query, params) || query;
-
- search('full', query, fullSearchCallback, params);
+ search('full', query, fullSearchCallback, possibleParams || {});
};
var liveSearchCallback = function(data, query) {
@@ -68,11 +78,7 @@ var PickyController = function(config) {
};
var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveCallbackUsed, params);
+ search('live', query, liveCallbackUsed, possibleParams || {});
};
// The timer is initially instantly stopped.
View
11 client/test_project/javascripts/picky.client.js
@@ -98,16 +98,12 @@ var PickyClient = function(config) {
};
var insert = this.insert;
- // Resends the last query text.
+ // Resends the last query text, full/live.
//
// Note: Other variables apart from the text
// could have changed.
//
- var resend = function() {
- var lastQuery = controller.lastQuery();
- lastQuery && insert(lastQuery);
- };
- this.resend = resend;
+ this.resend = controller.resend;
// Takes a query or nothing as parameter.
//
@@ -118,7 +114,8 @@ var PickyClient = function(config) {
if (override && override != '') {
insert(override);
} else {
- resend();
+ var lastFullQuery = controller.lastFullQuery();
+ lastFullQuery && insert(lastFullQuery);
}
};
View
30 client/test_project/javascripts/picky.controller.js
@@ -10,6 +10,8 @@ var PickyController = function(config) {
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
+ var lastQueryParams;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -20,20 +22,31 @@ var PickyController = function(config) {
// Failsafe extraction of the last made query.
//
- var lastQuery = function() {
+ var lastFullQuery = function() {
var state = window.History && window.History.getState();
var url = state && state.url;
return extractQuery(url);
};
- this.lastQuery = lastQuery;
+ this.lastFullQuery = lastFullQuery;
// If the given backend cannot be found, ignore the search request.
//
var search = function(type, query, callback, specificParams) {
+ lastQueryParams = [type, query, callback, specificParams];
+
+ query = beforeCallback(query, specificParams) || query;
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
+ // Resend the last query as it was.
+ //
+ var resend = function() {
+ if (lastQueryParams) { search.apply(this, lastQueryParams); }
+ };
+ this.resend = resend;
+
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -42,21 +55,18 @@ var PickyController = function(config) {
afterCallback(data, query);
};
var fullSearch = function(query, possibleParams) {
- var params = possibleParams || {};
clearInterval(liveSearchTimerId);
// Be extra cautious since not all browsers/histories offer pushState.
//
// Note: If this query is the same as the last, we do not save it in the history.
//
- if (query != lastQuery()) {
+ if (query != lastFullQuery()) {
var url = "?q=" + escape(query).replace(/\*/g,'%2A');
window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
}
- query = beforeCallback(query, params) || query;
-
- search('full', query, fullSearchCallback, params);
+ search('full', query, fullSearchCallback, possibleParams || {});
};
var liveSearchCallback = function(data, query) {
@@ -68,11 +78,7 @@ var PickyController = function(config) {
};
var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveCallbackUsed, params);
+ search('live', query, liveCallbackUsed, possibleParams || {});
};
// The timer is initially instantly stopped.
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),d=dictionary,i=0,f=g.length;i<f;i++){d=d[g[i]];if(d==undefined){d="Translation missing: "+a+"."+c;break}}return d};function Allocation(a,c,g,d,i,f){var p=this;this.type=a;this.weight=c;this.count=g;this.combination=d;this.ids=i||[];this.entries=this.rendered=f;this.isType=function(r){return r==p.type}}function Allocations(a){this.allocations=[];for(var c=0,g=a.length;c<g;c++){var d=a[c];this.allocations.push(new Allocation(d[0],d[1],d[2],d[3],d[4],d[5]))}this.length=this.allocations.length;this.each=function(i){return this.allocations.each(i)}}
-function PickyData(a){var c=a.total,g=a.duration,d=a.offset,i=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=d;this.allocations=i;this.renderedAmount=function(){var f=0;i.each(function(p,r){f+=r.rendered.length});return f};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,d=c.input,i=c.reset,f=c.button,p=c.counter,r=c.dashboard,u=c.moreSelector,w=c.results,k=c.noResults,o=new PickyAddination(this,w),q=new PickyAllocationsCloud(this,c),e=new PickyResultsRenderer(o,c),j=function(){i.fadeTo(166,1)},b=function(){q.hide();w.empty();k.hide()},h=function(m){d.val(m);i.fadeTo(166,0);x("empty");p.empty();b()},n=function(){return d.val()};this.text=n;var s=function(m){p.text(m);m>0&&m<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
-1)},v=function(m){if(m.isEmpty())return"none";if(m.total>g&&m.allocations.length>1)return"support";return"ok"},x=function(m){r.attr("class","dashboard "+m)};this.insert=function(m){d.val(m);d.select()};this.fullResultsCallback=function(m){x(v(m));if(m.isEmpty()){b();s(0);k.show();j()}else if(m.total>g&&m.allocations.length>1){b();j();q.show(m);s(m.total)}else if(m.offset==0){b();s(m.total);e.render(m);w.show();j();d.focus()}else{var y=$(u).position().top;o.remove();e.render(m);$("body").animate({scrollTop:y-
-12},500)}};this.liveResultsCallback=function(m){x(v(m));s(m.total)};this.allocationChosen=function(m){m=m.data.query;d.val(m);a.allocationChosen(m)};this.addinationClicked=function(m){a.addinationClicked(n(),m)};(function(){d.keyup(function(m){if(n()==""){h();a.searchTextCleared()}else{a.searchTextEntered(n(),m);j()}});p.click(function(){n()==""||a.searchButtonClicked(n())});f.click(function(){n()==""||a.searchButtonClicked(n())});i.click(function(){h("");a.clearButtonClicked();d.focus()})})();d.focus()};var PickyBackend=function(a){var c=function(g,d,i){var f=i||{};f=$.extend({query:g},i);$.getJSON(a,f,function(p){d&&d(new PickyData(p))})};this.search=function(g,d,i,f){c(g,function(p){d&&d(f,p)},i)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(d,i,f,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;f=$.extend({ids:a.liveResults||0,offset:0},f);g.search(d,function(r,u){if(!r.live||r.live==latestRequestTimestamp)i&&
-i(u)},f,p)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(d,i,f,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;f=$.extend({ids:a.fullResults||20,offset:0},f);g.search(d,function(r,u){if(!r.full||r.full==latestRequestTimestamp)i&&i(u)},f,p)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,d=a.before||function(){},i=a.success||function(){},f=a.after||function(){},p=a.liveRendered||false,r=a.liveSearchInterval||180,u=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=u;var w=function(){var b=window.History&&window.History.getState();return u(b&&b.url)};this.lastQuery=w;var k=function(b,h){b=i(b,h)||b;c.fullResultsCallback(b);f(b,h)},o=function(b,h){var n=h||{};clearInterval(e);
-if(b!=w()){var s="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,s)}b=d(b,n)||b;(s=g.full)&&s.search(b,k,n)};a=function(b,h){b=i(b,h)||b;c.liveResultsCallback(b);f(b,h)};var q=p?k:a,e,j=function(){var b=c.text(),h={};b=d(b,h)||b;var n=g.live;n&&n.search(b,q,h);clearInterval(e)};e=setInterval(j,r);clearInterval(e);this.insert=function(b,h,n){c.insert(b);n&&o(b,h)};this.clearButtonClicked=function(){clearInterval(e)};
-this.searchTextCleared=function(){clearInterval(e)};this.searchTextEntered=function(b,h){if($.inArray(h.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(h.keyCode==13)o(b);else{clearInterval(e);e=setInterval(j,r)}};this.searchButtonClicked=function(b){o(b)};this.allocationChosen=function(b){o(b)};this.addinationClicked=function(b,h){o(b,{offset:h.data.offset})}};var Localization={},PickyI18n={};$(function(){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en"});
+"en",g=a.split(".").concat(c),e=dictionary,d=0,m=g.length;d<m;d++){e=e[g[d]];if(e==undefined){e="Translation missing: "+a+"."+c;break}}return e};function Allocation(a,c,g,e,d,m){var p=this;this.type=a;this.weight=c;this.count=g;this.combination=e;this.ids=d||[];this.entries=this.rendered=m;this.isType=function(s){return s==p.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(d){return this.allocations.each(d)}}
+function PickyData(a){var c=a.total,g=a.duration,e=a.offset,d=new Allocations(a.allocations||[]);this.original_hash=a;this.total=c;this.duration=g;this.offset=e;this.allocations=d;this.renderedAmount=function(){var m=0;d.each(function(p,s){m+=s.rendered.length});return m};this.isEmpty=function(){return c==0}};var PickyView=function(a,c){var g=c.showResultsLimit||10,e=c.input,d=c.reset,m=c.button,p=c.counter,s=c.dashboard,w=c.moreSelector,x=c.results,j=c.noResults,q=new PickyAddination(this,x),r=new PickyAllocationsCloud(this,c),f=new PickyResultsRenderer(q,c),i=function(){d.fadeTo(166,1)},h=function(){r.hide();x.empty();j.hide()},o=function(k){e.val(k);d.fadeTo(166,0);v("empty");p.empty();h()},b=function(){return e.val()};this.text=b;var n=function(k){p.text(k);k>0&&k<=5&&p.fadeTo("fast",0.5).fadeTo("fast",
+1)},u=function(k){if(k.isEmpty())return"none";if(k.total>g&&k.allocations.length>1)return"support";return"ok"},v=function(k){s.attr("class","dashboard "+k)};this.insert=function(k){e.val(k);e.select()};this.fullResultsCallback=function(k){v(u(k));if(k.isEmpty()){h();n(0);j.show();i()}else if(k.total>g&&k.allocations.length>1){h();i();r.show(k);n(k.total)}else if(k.offset==0){h();n(k.total);f.render(k);x.show();i();e.focus()}else{var y=$(w).position().top;q.remove();f.render(k);$("body").animate({scrollTop:y-
+12},500)}};this.liveResultsCallback=function(k){v(u(k));n(k.total)};this.allocationChosen=function(k){k=k.data.query;e.val(k);a.allocationChosen(k)};this.addinationClicked=function(k){a.addinationClicked(b(),k)};(function(){e.keyup(function(k){if(b()==""){o();a.searchTextCleared()}else{a.searchTextEntered(b(),k);i()}});p.click(function(){b()==""||a.searchButtonClicked(b())});m.click(function(){b()==""||a.searchButtonClicked(b())});d.click(function(){o("");a.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(a){var c=function(g,e,d){var m=d||{};m=$.extend({query:g},d);$.getJSON(a,m,function(p){e&&e(new PickyData(p))})};this.search=function(g,e,d,m){c(g,function(p){e&&e(m,p)},d)}},LiveBackend=function(a){var c=a.live||alert("A live backend path must be provided."),g=new PickyBackend(c);this.search=function(e,d,m,p){p=p||{};latestRequestTimestamp=new Date;p.live=latestRequestTimestamp;m=$.extend({ids:a.liveResults||0,offset:0},m);g.search(e,function(s,w){if(!s.live||s.live==latestRequestTimestamp)d&&
+d(w)},m,p)}},FullBackend=function(a){var c=a.full||alert("A full backend path must be provided."),g=new PickyBackend(c);this.search=function(e,d,m,p){p=p||{};latestRequestTimestamp=new Date;p.full=latestRequestTimestamp;m=$.extend({ids:a.fullResults||20,offset:0},m);g.search(e,function(s,w){if(!s.full||s.full==latestRequestTimestamp)d&&d(w)},m,p)}};var PickyController=function(a){var c=new PickyView(this,a),g=a.backends,e=a.before||function(){},d=a.success||function(){},m=a.after||function(){},p=a.liveRendered||false,s=a.liveSearchInterval||180,w,x=function(b){return(b=b&&b.match(/q=([^&]+)/))&&unescape(b[1]||"")};this.extractQuery=x;var j=function(){var b=window.History&&window.History.getState();return x(b&&b.url)};this.lastFullQuery=j;var q=function(b,n,u,v){w=[b,n,u,v];n=e(n,v)||n;(b=g[b])&&b.search(n,u,v)};this.resend=function(){w&&q.apply(this,
+w)};var r=function(b,n){b=d(b,n)||b;c.fullResultsCallback(b);m(b,n)},f=function(b,n){clearInterval(h);if(b!=j()){var u="?q="+escape(b).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,u)}q("full",b,r,n||{})};a=function(b,n){b=d(b,n)||b;c.liveResultsCallback(b);m(b,n)};var i=p?r:a,h,o=function(){var b=c.text();q("live",b,i,{});clearInterval(h)};h=setInterval(o,s);clearInterval(h);this.insert=function(b,n,u){c.insert(b);u&&
+f(b,n)};this.clearButtonClicked=function(){clearInterval(h)};this.searchTextCleared=function(){clearInterval(h)};this.searchTextEntered=function(b,n){if($.inArray(n.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(n.keyCode==13)f(b);else{clearInterval(h);h=setInterval(o,s)}};this.searchButtonClicked=function(b){f(b)};this.allocationChosen=function(b){f(b)};this.addinationClicked=function(b,n){f(b,{offset:n.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 d=this.insert=function(f,p,r){g.insert(f,p||{},r||true)},i=function(){var f=g.lastQuery();f&&d(f)};this.resend=i;this.insertFromURL=function(f){f&&f!=""?d(f):i()};window.History&&window.History.Adapter.bind(window,"statechange",
-function(){var f=window.History.getState();(f=g.extractQuery(f.url))&&d(f)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var d=g.total,i,f=g.renderedAmount();i=g.offset+f;f=i+f;g=g.total;if(g<f)f=g;i={offset:i,start:i+1,end:f};if(i.offset<d){d=$("<div class='addination'>"+t("results.addination.more")+"</div>");d.bind("click",{offset:i.offset},a.addinationClicked);return d}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,d=c.wrapResults,i=c.noAsterisks,f=function(k){var o=k[k.length-1];k=k.slice(0,k.length-1);if(k==[])k=[k];if(!i.include(o[0]))if(o[1].match(/[^\*~]$/))o[1]+="*";k.push(o);return k},p=function(k){for(var o=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},q=[],e,j=0,b=k.length;j<b;j++){e=k[j];var h=e[0];h=o[h]||h;q.push([h,e[1]])}return q},r=function(k,o){return[k.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
-"<strong>$1</strong>"),o].join(" ")},u=function(k,o){var q=Localization.explanation_delimiters[PickyI18n.locale],e=p(f(o)),j="",b=[];e=$.map(e,function(h){var n=h[0];h=h[1];if(j==""||n==j){h=h.replace(/[\w,]+:(.+)/,"$1");b.push(h);j=n}else{var s=r(j,b.join(" "));b=[];b.push(h);j=n;return s}});e.push(r(j,b.join(" ")));e=e.join(" "+q+" ");return'<span class="explanation">'+k+" "+e+"</span>"},w=function(k,o){var q='<div class="header">';q+=u(o.type,o.combination);if(k.offset>0)q+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
-return q};this.render=function(k){k.allocations.each(function(o,q){if(q.entries.length>0){g.append(w(k,q)).append(q.entries.join(""));g.children("li").wrapAll(d)}});g.append(a.render(k))}};function AllocationRenderer(a,c){function g(e){var j={},b={},h=[],n;n=0;for(l=e.length;n<l;n++){var s=e[n][0];if(s in j){j[s]=j[s]+" "+e[n][1];h.push(n)}else{j[s]=e[n][1];b[n]=s}}for(n in b)e[n][1]=j[b[n]];for(n=h.length-1;n>=0;n--)e.remove(h[n]);return e}function d(e){return $.map(e,function(j,b){return"%"+(b+1)+"$s"}).join(" ")}function i(e){if(e.length==0)return"";var j=e=g(e);j.sort(function(y,z){return y[0]<z[0]?-1:1});for(var b=[],h=0,n=j.length;h<n;h++)b.push(j[h][0]);var s=b.length==1,v=o[b]||
-(o[b]=d(b));if($.type(v)==="string"){o[b]={format:v};v=o[b]}var x=1,m=v.format;$.each(e,function(y,z){var A=z[0],B=z[2];if(v.filter)B=v.filter(B);A=w[A]||A;if(s&&!(v&&v.ignoreSingle))return m=B+"&nbsp;("+A+")";m=m.replace(RegExp("%"+x+"\\$s","g"),B);x+=1;return x});return m}function f(e){for(var j=[],b=0,h=k.length;b<h;b++)j.push([]);j.push([]);b=0;for(h=e.length;b<h;b++){for(var n=e[b],s=n[0],v=false,x=0,m=k.length;x<m;x++)if(k[x].include(s)){j[x].push(n);v=true;break}v||j[j.length-1].push(n)}var y;
-for(e=j.length-1;e>=0;e--){y=j[e];if(y.length>0)break}y=y[y.length-1];q.include(y[0])||(y[1]+="...");return $.map(j,function(z){return i(z)})}function p(e){var j=[],b,h;for(h in e){b=e[h][0];b=u[b]||b;j[h]=b+":"+e[h][2]}return j.join(" ")}var r=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[r]||{},w=Localization.explanations&&Localization.explanations[r]||{},k=c.groups||[],o=Localization.choices&&Localization.choices[r]||{};this.explanation=this.query=this.text="";var q=["street_number",
-"zipcode"];this.contract=g;this.rendered=i;this.groupify=f;this.querify=p;this.render=function(e){var j=e.combination,b=e.count;e=p(j);j=f(j).join(" ");j=$('<li><div class="text">'+j+'</div><div class="count">'+b+"</div></li>");j.bind("click",{query:e},a);return j}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,d=c.shownAllocations,i=c.showMoreAllocations,f=c.hiddenAllocations,p=function(){g.hide()},r=new AllocationRenderer(function(k){p();a.allocationChosen(k)},c),u=function(k){var o=[];k.each(function(q,e){o.push(r.render(e))});return o},w=function(k){if(k.length==0)return g.hide();d.empty();i.hide();f.empty().hide();if(k.length>3){$.each(k.slice(0,2),function(o,q){d.append(q)});$.each(k.slice(2),function(o,q){f.append(q)});i.show()}else $.each(k,
-function(o,q){d.append(q)});return g.show()};i.click(function(){i.hide();f.show()});this.hide=p;this.show=function(k){w(u(k.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(d,m,p){g.insert(d,m||{},p||true)};this.resend=g.resend;this.insertFromURL=function(d){if(d&&d!="")e(d);else(d=g.lastFullQuery())&&e(d)};window.History&&window.History.Adapter.bind(window,"statechange",
+function(){var d=window.History.getState();(d=g.extractQuery(d.url))&&e(d)})};var PickyAddination=function(a,c){this.remove=function(){c.find(".addination").remove()};this.render=function(g){var e=g.total,d,m=g.renderedAmount();d=g.offset+m;m=d+m;g=g.total;if(g<m)m=g;d={offset:d,start:d+1,end:m};if(d.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:d.offset},a.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(a,c){var g=c.results,e=c.wrapResults,d=c.noAsterisks,m=function(j){var q=j[j.length-1];j=j.slice(0,j.length-1);if(j==[])j=[j];if(!d.include(q[0]))if(q[1].match(/[^\*~]$/))q[1]+="*";j.push(q);return j},p=function(j){for(var q=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},r=[],f,i=0,h=j.length;i<h;i++){f=j[i];var o=f[0];o=q[o]||o;r.push([o,f[1]])}return r},s=function(j,q){return[j.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
+"<strong>$1</strong>"),q].join(" ")},w=function(j,q){var r=Localization.explanation_delimiters[PickyI18n.locale],f=p(m(q)),i="",h=[];f=$.map(f,function(o){var b=o[0];o=o[1];if(i==""||b==i){o=o.replace(/[\w,]+:(.+)/,"$1");h.push(o);i=b}else{var n=s(i,h.join(" "));h=[];h.push(o);i=b;return n}});f.push(s(i,h.join(" ")));f=f.join(" "+r+" ");return'<span class="explanation">'+j+" "+f+"</span>"},x=function(j,q){var r='<div class="header">';r+=w(q.type,q.combination);if(j.offset>0)r+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>';
+return r};this.render=function(j){j.allocations.each(function(q,r){if(r.entries.length>0){g.append(x(j,r)).append(r.entries.join(""));g.children("li").wrapAll(e)}});g.append(a.render(j))}};function AllocationRenderer(a,c){function g(f){var i={},h={},o=[],b;b=0;for(l=f.length;b<l;b++){var n=f[b][0];if(n in i){i[n]=i[n]+" "+f[b][1];o.push(b)}else{i[n]=f[b][1];h[b]=n}}for(b in h)f[b][1]=i[h[b]];for(b=o.length-1;b>=0;b--)f.remove(o[b]);return f}function e(f){return $.map(f,function(i,h){return"%"+(h+1)+"$s"}).join(" ")}function d(f){if(f.length==0)return"";var i=f=g(f);i.sort(function(y,z){return y[0]<z[0]?-1:1});for(var h=[],o=0,b=i.length;o<b;o++)h.push(i[o][0]);var n=h.length==1,u=q[h]||
+(q[h]=e(h));if($.type(u)==="string"){q[h]={format:u};u=q[h]}var v=1,k=u.format;$.each(f,function(y,z){var A=z[0],B=z[2];if(u.filter)B=u.filter(B);A=x[A]||A;if(n&&!(u&&u.ignoreSingle))return k=B+"&nbsp;("+A+")";k=k.replace(RegExp("%"+v+"\\$s","g"),B);v+=1;return v});return k}function m(f){for(var i=[],h=0,o=j.length;h<o;h++)i.push([]);i.push([]);h=0;for(o=f.length;h<o;h++){for(var b=f[h],n=b[0],u=false,v=0,k=j.length;v<k;v++)if(j[v].include(n)){i[v].push(b);u=true;break}u||i[i.length-1].push(b)}var y;
+for(f=i.length-1;f>=0;f--){y=i[f];if(y.length>0)break}y=y[y.length-1];r.include(y[0])||(y[1]+="...");return $.map(i,function(z){return d(z)})}function p(f){var i=[],h,o;for(o in f){h=f[o][0];h=w[h]||h;i[o]=h+":"+f[o][2]}return i.join(" ")}var s=PickyI18n.locale,w=Localization.qualifiers&&Localization.qualifiers[s]||{},x=Localization.explanations&&Localization.explanations[s]||{},j=c.groups||[],q=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var r=["street_number",
+"zipcode"];this.contract=g;this.rendered=d;this.groupify=m;this.querify=p;this.render=function(f){var i=f.combination,h=f.count;f=p(i);i=m(i).join(" ");i=$('<li><div class="text">'+i+'</div><div class="count">'+h+"</div></li>");i.bind("click",{query:f},a);return i}};var PickyAllocationsCloud=function(a,c){var g=c.allocations,e=c.shownAllocations,d=c.showMoreAllocations,m=c.hiddenAllocations,p=function(){g.hide()},s=new AllocationRenderer(function(j){p();a.allocationChosen(j)},c),w=function(j){var q=[];j.each(function(r,f){q.push(s.render(f))});return q},x=function(j){if(j.length==0)return g.hide();e.empty();d.hide();m.empty().hide();if(j.length>3){$.each(j.slice(0,2),function(q,r){e.append(r)});$.each(j.slice(2),function(q,r){m.append(r)});d.show()}else $.each(j,
+function(q,r){e.append(r)});return g.show()};d.click(function(){d.hide();m.show()});this.hide=p;this.show=function(j){x(w(j.allocations));g.show()}};
Please sign in to comment.
Something went wrong with that request. Please try again.