Skip to content
This repository
Browse code

+ live search timer interval customizable

  • Loading branch information...
commit f61546304e3e5b24717491aae207775d2a2aaf76 1 parent 3561fb3
Florian R. Hanke authored
30 client/javascripts/picky.min.js
... ... @@ -1,18 +1,18 @@
1 1 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||
2   -"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)}}
3   -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",
4   -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-
5   -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&&
6   -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,
7   -"%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)};
8   -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"});
  2 +"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)}}
  3 +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",
  4 +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-
  5 +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&&
  6 +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);
  7 +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)};
  8 +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"});
9 9 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||
10 10 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=
11   -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",
12   -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]+)/,
13   -"<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>';
14   -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]||
15   -(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;
16   -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",
17   -"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,
18   -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()}};
  11 +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",
  12 +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]+)/,
  13 +"<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>';
  14 +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]||
  15 +(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;
  16 +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",
  17 +"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,
  18 +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()}};
BIN  client/javascripts/picky.source.js.tar
Binary file not shown
4 client/javascripts/source/picky.controller.js
@@ -7,7 +7,8 @@ var PickyController = function(config) {
7 7 var successCallback = config.success || function(data, query) { };
8 8 var afterCallback = config.after || function(data, query) { };
9 9
10   - var liveRendered = config.liveRendered || false;
  10 + var liveRendered = config.liveRendered || false;
  11 + var liveSearchTimerInterval = config.liveSearchInterval || 180;
11 12
12 13 // Extracts the query part from an URL.
13 14 //
@@ -76,7 +77,6 @@ var PickyController = function(config) {
76 77
77 78 // The timer is initially instantly stopped.
78 79 //
79   - var liveSearchTimerInterval = 180;
80 80 var liveSearchTimerId;
81 81 var liveSearchTimerCallback = function() {
82 82 liveSearch(view.text());
4 client/test_project/javascripts/picky.controller.js
@@ -7,7 +7,8 @@ var PickyController = function(config) {
7 7 var successCallback = config.success || function(data, query) { };
8 8 var afterCallback = config.after || function(data, query) { };
9 9
10   - var liveRendered = config.liveRendered || false;
  10 + var liveRendered = config.liveRendered || false;
  11 + var liveSearchTimerInterval = config.liveSearchInterval || 180;
11 12
12 13 // Extracts the query part from an URL.
13 14 //
@@ -76,7 +77,6 @@ var PickyController = function(config) {
76 77
77 78 // The timer is initially instantly stopped.
78 79 //
79   - var liveSearchTimerInterval = 180;
80 80 var liveSearchTimerId;
81 81 var liveSearchTimerCallback = function() {
82 82 liveSearch(view.text());
30 generators/prototypes/client/sinatra/javascripts/picky.min.js
... ... @@ -1,18 +1,18 @@
1 1 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||
2   -"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)}}
3   -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",
4   -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-
5   -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&&
6   -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,
7   -"%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)};
8   -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"});
  2 +"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)}}
  3 +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",
  4 +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-
  5 +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&&
  6 +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);
  7 +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)};
  8 +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"});
9 9 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||
10 10 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=
11   -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",
12   -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]+)/,
13   -"<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>';
14   -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]||
15   -(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;
16   -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",
17   -"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,
18   -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()}};
  11 +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",
  12 +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]+)/,
  13 +"<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>';
  14 +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]||
  15 +(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;
  16 +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",
  17 +"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,
  18 +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()}};

0 comments on commit f615463

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