picky-client 3.1.6 → 3.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/javascripts/picky.min.js +5 -5
- metadata +1 -1
data/javascripts/picky.min.js
CHANGED
@@ -3,15 +3,15 @@ var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":
|
|
3
3
|
"en",g=b.split(".").concat(i),e=dictionary,d=0,j=g.length;d<j;d++){e=e[g[d]];if(e==undefined){e="Translation missing: "+b+"."+i;break}}return e};function Allocation(b,i,g,e,d,j){var n=this;this.type=b;this.weight=i;this.count=g;this.combination=e;this.ids=d||[];this.entries=this.rendered=j||[];this.isType=function(s){return s==n.type}}function Allocations(b){this.allocations=[];for(var i=0,g=b.length;i<g;i++){var e=b[i];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 $.each(this.allocations,d)}}
|
4
4
|
function PickyData(b){var i=b.total,g=b.duration,e=b.offset,d=new Allocations(b.allocations||[]);this.original_hash=b;this.total=i;this.duration=g;this.offset=e;this.allocations=d;this.renderedAmount=function(){var j=0;d.each(function(n,s){j+=s.rendered.length});return j};this.isEmpty=function(){return i==0}};var PickyView=function(b,i){var g=i.showResultsLimit||10,e=$("#picky input.query"),d=$("#picky div.reset"),j=$("#picky input.search_button"),n=$("#picky div.status"),s=$("#picky .dashboard"),u=$("#picky .results"),k=$("#picky .no_results"),m=new PickyAddination(this,u),r=new PickyAllocationsCloud(this,i),p=new PickyResultsRenderer(m,i),a=function(){d.fadeTo(166,1)},c=function(){r.hide();u.empty();k.hide()},f=function(h){e.val(h);d.fadeTo(166,0);v("empty");n.empty();c()},o=function(){return e.val()};
|
5
5
|
this.text=o;var q=function(h){n.text(h);h>0&&h<=5&&n.fadeTo("fast",0.5).fadeTo("fast",1)},w=function(h){if(h.isEmpty())return"none";if(h.total>g&&h.allocations.length>1)return"support";return"ok"},v=function(h){s.attr("class","dashboard "+h)};this.insert=function(h){e.val(h);e.select()};this.fullResultsCallback=function(h){v(w(h));if(h.isEmpty()){c();q(0);k.show();a()}else if(h.total>g&&h.allocations.length>1){c();a();r.show(h);q(h.total)}else if(h.offset==0){c();q(h.total);p.render(h);u.show();a();
|
6
|
-
e.focus()}else{m.remove();p.render(h);$("body").animate({scrollTop
|
7
|
-
""||b.searchButtonClicked(o())});d.click(function(){f("");b.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(b){var i=function(g,e,d){var j=d||{};j=$.extend({query:g},d);$.getJSON(b,j,function(n){e&&e(new PickyData(n))})};this.search=function(g,e,d,j){i(g,function(n){e&&e(j,n)},d)}},LiveBackend=function(b){var i=b.live||alert("A live backend path must be provided."),g=new PickyBackend(i);this.search=function(e,d,j,n){n=n||{};latestRequestTimestamp=new Date;n.live=latestRequestTimestamp;j=$.extend({ids:b.liveResults||0,offset:0},j);g.search(e,function(s,u){if(!s.live||s.live==latestRequestTimestamp)d&&
|
6
|
+
e.focus()}else{var y=$("#picky div.results div.addination:last").position().top;m.remove();p.render(h);$("body").animate({scrollTop:y-12},500)}};this.liveResultsCallback=function(h){v(w(h));q(h.total)};this.allocationChosen=function(h){h=h.data.query;e.val(h);b.allocationChosen(h)};this.addinationClicked=function(h){b.addinationClicked(o(),h)};(function(){e.keyup(function(h){if(o()==""){f();b.searchTextCleared()}else{b.searchTextEntered(o(),h);a()}});n.click(function(){o()==""||b.searchButtonClicked(o())});
|
7
|
+
j.click(function(){o()==""||b.searchButtonClicked(o())});d.click(function(){f("");b.clearButtonClicked();e.focus()})})();e.focus()};var PickyBackend=function(b){var i=function(g,e,d){var j=d||{};j=$.extend({query:g},d);$.getJSON(b,j,function(n){e&&e(new PickyData(n))})};this.search=function(g,e,d,j){i(g,function(n){e&&e(j,n)},d)}},LiveBackend=function(b){var i=b.live||alert("A live backend path must be provided."),g=new PickyBackend(i);this.search=function(e,d,j,n){n=n||{};latestRequestTimestamp=new Date;n.live=latestRequestTimestamp;j=$.extend({ids:b.liveResults||0,offset:0},j);g.search(e,function(s,u){if(!s.live||s.live==latestRequestTimestamp)d&&
|
8
8
|
d(u)},j,n)}},FullBackend=function(b){var i=b.full||alert("A full backend path must be provided."),g=new PickyBackend(i);this.search=function(e,d,j,n){n=n||{};latestRequestTimestamp=new Date;n.full=latestRequestTimestamp;j=$.extend({ids:b.fullResults||20,offset:0},j);g.search(e,function(s,u){if(!s.full||s.full==latestRequestTimestamp)d&&d(u)},j,n)}};var PickyController=function(b){var i=new PickyView(this,b),g=b.backends,e=b.before||function(){},d=b.success||function(){},j=b.after||function(){},n=function(a){return(a=a&&a.match(/q=([^&]+)/))&&unescape(a[1]||"")};this.extractQuery=n;var s=function(){var a=window.History&&window.History.getState();return n(a&&a.url)};this.lastQuery=s;var u=function(a,c){a=d(a,c)||a;i.liveResultsCallback(a);j(a,c)},k,m=function(){var a=i.text(),c={};a=e(a,c)||a;var f=g.live;f&&f.search(a,u,c);clearInterval(k)};
|
9
9
|
k=setInterval(m,180);clearInterval(k);var r=function(a,c){a=d(a,c)||a;i.fullResultsCallback(a);j(a,c)},p=function(a,c){var f=c||{};clearInterval(k);if(a!=s()){var o="?q="+escape(a).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,o)}a=e(a,f)||a;(o=g.full)&&o.search(a,r,f)};this.insert=function(a,c,f){i.insert(a);f&&p(a,c)};this.clearButtonClicked=function(){clearInterval(k)};this.searchTextCleared=function(){clearInterval(k)};
|
10
10
|
this.searchTextEntered=function(a,c){if($.inArray(c.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(c.keyCode==13)p(a);else{clearInterval(k);k=setInterval(m,180)}};this.searchButtonClicked=function(a){p(a)};this.allocationChosen=function(a){p(a)};this.addinationClicked=function(a,c){p(a,{offset:c.data.offset})}};var Localization={},PickyClient=function(b){Localization.qualifiers=b.qualifiers||{};Localization.explanations=b.explanations||{};Localization.choices=b.choices||{};Localization.explanation_delimiters={de:"und",fr:"et",it:"e",en:"and",ch:"und"};var i=b.backends;if(i){i.live||alert("Both a full and live backend must be provided.");i.full||alert("Both a full and live backend must be provided.")}else b.backends={live:new LiveBackend(b),full:new FullBackend(b)};var g=b.controller&&new b.controller(b)||
|
11
11
|
new PickyController(b);var e=this.insert=function(d,j,n){g.insert(d,j||{},n||true)};this.insertFromURL=function(d){if(d&&d!="")e(d);else(d=g.lastQuery())&&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(b,i){this.remove=function(){i.find(".addination").remove()};this.render=function(g){var e=g.total,d,j=g.renderedAmount();d=g.offset+j;j=d+j;g=g.total;if(g<j)j=g;d={offset:d,start:d+1,end:j};if(d.offset<e){e=$("<div class='addination'>"+t("results.addination.more")+"</div>");e.bind("click",{offset:d.offset},b.addinationClicked);return e}else return""}};var PickyResultsRenderer=function(b,i){var g=i.wrapResults||'<ol class="results"></ol>',e=["street_number","zipcode"],d=function(k){var m=k[k.length-1];k=k.slice(0,k.length-1);if(k==[])k=[k];if(!e.include(m[0]))if(m[1].match(/[^\*~]$/))m[1]+="*";k.push(m);return k},j=function(k){for(var m=Localization.explanations&&Localization.explanations[PickyI18n.locale]||{},r=[],p,a=0,c=k.length;a<c;a++){p=k[a];var f=p[0];f=m[f]||f;r.push([f,p[1]])}return r},n=function(k,m){return[k.replace(/([\w\s\u00c4\u00e4\u00d6\u00f6\u00dc\u00fc\u00e9\u00e8\u00e0]+)/,
|
12
12
|
"<strong>$1</strong>"),m].join(" ")},s=function(k,m){var r=Localization.explanation_delimiters[PickyI18n.locale],p=j(d(m)),a="",c=[];p=$.map(p,function(f){var o=f[0];f=f[1];if(a==""||o==a){c.push(f);a=o}else{var q=n(a,c.join(" "));c=[];c.push(f);a=o;return q}});p.push(n(a,c.join(" ")));p=p.join(" "+r+" ");return'<span class="explanation">'+k+" "+p+"</span>"},u=function(k,m){var r='<div class="header">';r+=s(m.type,m.combination);if(k.offset>0)r+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">↑</a></div>';
|
13
|
-
return r};this.render=function(k){var m=$("#picky div.results");k.allocations.each(function(r,p){if(p.entries.length>0){m.append(u(k,p)).append(p.entries.join(""));m.children("li").wrapAll(g)}});m.append(b.render(k))}};function AllocationRenderer(b,i){function g(a){var c={},f={},o=[],q;q=0;for(l=a.length;q<l;q++){var w=a[q][0];if(w in c){c[w]=c[w]+" "+a[q][1];o.push(q)}else{c[w]=a[q][1];f[q]=w}}for(q in f)a[q][1]=c[f[q]];for(q=o.length-1;q>=0;q--)a.remove(o[q]);return a}function e(a){return $.map(a,function(c,f){return"%"+(f+1)+"$s"}).join(" ")}function d(a){if(a.length==0)return"";var c=a=g(a);c.sort(function(x,
|
14
|
-
(r[f]=e(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,
|
15
|
-
for(a=c.length-1;a>=0;a--){x=c[a];if(x.length>0)break}x=x[x.length-1];p.include(x[0])||(x[1]+="...");return $.map(c,function(
|
13
|
+
return r};this.render=function(k){var m=$("#picky div.results");k.allocations.each(function(r,p){if(p.entries.length>0){m.append(u(k,p)).append(p.entries.join(""));m.children("li").wrapAll(g)}});m.append(b.render(k))}};function AllocationRenderer(b,i){function g(a){var c={},f={},o=[],q;q=0;for(l=a.length;q<l;q++){var w=a[q][0];if(w in c){c[w]=c[w]+" "+a[q][1];o.push(q)}else{c[w]=a[q][1];f[q]=w}}for(q in f)a[q][1]=c[f[q]];for(q=o.length-1;q>=0;q--)a.remove(o[q]);return a}function e(a){return $.map(a,function(c,f){return"%"+(f+1)+"$s"}).join(" ")}function d(a){if(a.length==0)return"";var c=a=g(a);c.sort(function(x,z){return x[0]<z[0]?-1:1});for(var f=[],o=0,q=c.length;o<q;o++)f.push(c[o][0]);var w=f.length==1,v=r[f]||
|
14
|
+
(r[f]=e(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,y=v.format;$.each(a,function(x,z){var A=z[0],B=z[1];if(v.filter)B=v.filter(B);A=k[A]||A;if(w&&!(v&&v.ignoreSingle))return y=B+" ("+A+")";y=y.replace(RegExp("%"+h+"\\$s","g"),B);h+=1;return h});return y}function j(a){for(var c=[],f=0,o=m.length;f<o;f++)c.push([]);c.push([]);f=0;for(o=a.length;f<o;f++){for(var q=a[f],w=q[0],v=false,h=0,y=m.length;h<y;h++)if(m[h].include(w)){c[h].push(q);v=true;break}v||c[c.length-1].push(q)}var x;
|
15
|
+
for(a=c.length-1;a>=0;a--){x=c[a];if(x.length>0)break}x=x[x.length-1];p.include(x[0])||(x[1]+="...");return $.map(c,function(z){return d(z)})}function n(a){var c=[],f,o;for(o in a){f=a[o][0];f=u[f]||f;c[o]=f+":"+a[o][1]}return c.join(" ")}var s=PickyI18n.locale,u=Localization.qualifiers&&Localization.qualifiers[s]||{},k=Localization.explanations&&Localization.explanations[s]||{},m=i.groups||[],r=Localization.choices&&Localization.choices[s]||{};this.explanation=this.query=this.text="";var p=["street_number",
|
16
16
|
"zipcode"];this.contract=g;this.rendered=d;this.groupify=j;this.querify=n;this.render=function(a){var c=a.combination,f=a.count;a=n(c);c=j(c).join(" ");c=$('<li><div class="text">'+c+'</div><div class="count">'+f+"</div></li>");c.bind("click",{query:a},b);return c}};var PickyAllocationsCloud=function(b,i){var g=$("#picky .allocations"),e=g.find(".shown"),d=g.find(".more"),j=g.find(".hidden"),n=function(){g.hide()},s=new AllocationRenderer(function(m){n();b.allocationChosen(m)},i),u=function(m){var r=[];m.each(function(p,a){r.push(s.render(a))});return r},k=function(m){if(m.length==0)return $("#search .allocations").hide();e.empty();d.hide();j.empty().hide();if(m.length>3){$.each(m.slice(0,2),function(r,p){e.append(p)});$.each(m.slice(2),function(r,p){j.append(p)});
|
17
17
|
d.show()}else $.each(m,function(r,p){e.append(p)});return $("#search .allocations").show()};d.click(function(){d.hide();j.show()});this.hide=n;this.show=function(m){k(u(m.allocations));g.show()}};
|