picky-client 4.19.2 → 4.19.3
Sign up to get free protection for your applications and to get access to all the features.
- data/javascripts/picky.min.js +19 -19
- data/spec/picky-client/spec/test_client_spec.rb +10 -0
- metadata +2 -2
data/javascripts/picky.min.js
CHANGED
@@ -1,19 +1,19 @@
|
|
1
|
-
Array.prototype.index=function(a){for(var
|
2
|
-
"en",
|
3
|
-
function PickyData(a){var
|
4
|
-
0.5).fadeTo("fast",1)},
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
function(
|
9
|
-
|
10
|
-
13)m(
|
11
|
-
|
12
|
-
a.shownAllocations
|
13
|
-
function(
|
14
|
-
|
15
|
-
0)m+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">↑</a></div>';m+="</div>";return m};this.renderHeader=
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
Array.prototype.index=function(a){for(var b=0,j=this.length;b<j;b++)if(this[b]==a)return b;return null};Array.prototype.include=function(a){return this.index(a)!==null};Array.prototype.remove=function(a){this.splice(a,1);return this};Array.prototype.compare=function(a){return this.join("")==a.join("")};Array.prototype.each=function(a){for(var b=0,j=this.length;b<j;b++)a(b,this[b]);return this};Array.prototype.map=function(a){for(var b=0,j=this.length;b<j;b++)this[b]=a(b,this[b]);return this};var dictionary={common:{join:{de:"und",fr:"et",it:"e",en:"and",ch:"und"},"with":{de:"mit",fr:"avec",it:"con",en:"with",ch:"mit"},of:{de:"von",fr:"de",it:"di",en:"of",ch:"vo"},to:{de:"bis",fr:"\u00e0",it:"alla",en:"to",ch:"bis"}},results:{addination:{more:{de:"Weitere Resultate",fr:"Autres r\u00e9sultats",it:"Altri risultati",en:"More results",ch:"Mee Resultaat"}},header:{de:"Ergebnisse",fr:"R\u00e9sultats",it:"Risultati",en:"Results",ch:"Erg\u00e4bnis"}}},t=function(a){for(var b=PickyI18n.locale||
|
2
|
+
"en",j=a.split(".").concat(b),k=dictionary,l=0,i=j.length;l<i;l++){k=k[j[l]];if(k==undefined){k="Translation missing: "+a+"."+b;break}}return k};function Allocation(a,b,j,k,l,i){var o=this;this.type=a;this.weight=b;this.count=j;this.combination=k;this.ids=l||[];this.entries=this.rendered=i||[];this.isType=function(r){return r==o.type}}function Allocations(a){this.allocations=[];for(var b=0,j=a.length;b<j;b++){var k=a[b];this.allocations.push(new Allocation(k[0],k[1],k[2],k[3],k[4],k[5]))}this.length=this.allocations.length;this.remove=function(l){this.allocations.splice(l,1)};this.each=function(l){this.allocations.each(l)}}
|
3
|
+
function PickyData(a){var b=a.total,j=a.duration,k=a.offset,l=new Allocations(a.allocations||[]);this.original_hash=a;this.total=b;this.duration=j;this.offset=k;this.allocations=l;this.renderedAmount=function(){var i=0;l.each(function(o,r){i+=r.rendered.length});return i};this.isEmpty=function(){return b==0}};var PickyView=function(a,b){var j=b.showResultsLimit||10,k=b.alwaysShowResults||false,l=b.alwaysShowSelection||false,i=b.input,o=b.reset,r=b.button,v=b.counter,x=b.form,u=b.moreSelector,w=b.results,g=b.noResults,d=new PickyAddination(this,w),h=new PickyAllocationsCloud(this,b),m=new PickyResultsRenderer(d,b),n=function(c){i.val(c);o.fadeTo(166,0);x.attr("class","empty");v.empty();h.hide();g.hide()};this.reset=n;var f=function(){return i.val()};this.text=f;var p=function(c){if(c.offset==0){w.empty();
|
4
|
+
m.render(w,c);w.show();i.focus()}else{var s=$(u).position().top;d.remove();m.render(w,c);$("body").animate({scrollTop:s-12},500)}},q=function(c){c>0&&c<=5&&v.fadeTo("fast",0.5).fadeTo("fast",1)},e=function(c){if(c.isEmpty())return"none";if(c.total>j&&c.allocations.length>1)return"support";return"ok"};this.insert=function(c){i.val(c);i.select()};this.fullResultsCallback=function(c){var s=e(c);x.attr("class",s);h.hide();g.hide();o.fadeTo(166,1);s=c.total;v.text(s);q(s);if(c.isEmpty()){w.empty();g.show()}else if(c.total>
|
5
|
+
j&&c.allocations.length>1){k&&p(c);h.show(c)}else{p(c);l&&h.show(c)}};this.liveResultsCallback=function(c){var s=e(c);x.attr("class",s);c=c.total;v.text(c);q(c)};this.allocationChosen=function(c){c=c.data.query;a.insert(c);a.allocationChosen(c)};this.addinationClicked=function(c){a.addinationClicked(f(),c)};(function(){i.keyup(function(c){if(f()==""){n();a.searchTextCleared()}else o.fadeTo(166,1);a.searchTextEntered(f(),c)});v.click(function(){a.searchButtonClicked(f())});r.click(function(){a.searchButtonClicked(f())});
|
6
|
+
o.click(function(){n();a.clearButtonClicked();i.focus()})})();i.focus()};var PickyBackend=function(a){var b=function(j,k,l){var i=l||{};i=$.extend({query:j},l);$.getJSON(a,i,function(o){k&&k(new PickyData(o))})};this.search=function(j,k,l,i){b(j,function(o){k&&k(i,o)},l)}},LiveBackend=function(a){var b=a.live||alert("A live backend path must be provided."),j=new PickyBackend(b);this.search=function(k,l,i,o){o=o||{};latestRequestTimestamp=new Date;o.live=latestRequestTimestamp;i=$.extend({ids:a.liveResults||0,offset:0},i);j.search(k,function(r,v){if(!r.live||r.live==latestRequestTimestamp)l&&
|
7
|
+
l(v,k)},i,o)}},FullBackend=function(a){var b=a.full||alert("A full backend path must be provided."),j=new PickyBackend(b);this.search=function(k,l,i,o){o=o||{};latestRequestTimestamp=new Date;o.full=latestRequestTimestamp;i=$.extend({ids:a.fullResults||20,offset:0},i);j.search(k,function(r,v){if(!r.full||r.full==latestRequestTimestamp)l&&l(v,k)},i,o)}};var PickyController=function(a){var b=new PickyView(this,a),j=a.backends,k=a.beforeInsert||function(e){return e},l=a.before||function(e){return e},i=a.success||function(e){return e},o=a.after||function(e){return e},r=a.searchOnEmpty||false,v=a.liveRendered||false,x=a.liveSearchInterval||180,u,w=function(e){return(e=e&&e.match(/q=([^&]+)/))&&decodeURIComponent(e[1]).replace(/\+/g," ").replace(/#/g,"")||""};this.extractQuery=w;var g=function(){var e=window.History&&window.History.getState();return w(e&&
|
8
|
+
e.url)};this.lastFullQuery=g;var d=function(e,c,s,y){var z=l(c,y);if(z!=undefined)c=z;u=[e,c,s,y];z=c;if(z!=g()){z=!r&&z==""?"":"?q="+escape(z).replace(/\*/g,"%2A");window.History&&window.History.getState()&&window.History.pushState&&window.History.pushState(null,null,z)}if(!r&&c=="")b.reset();else(e=j[e])&&e.search(c,s,y)};this.resend=function(){u&&d.apply(this,u)};var h=function(e,c){(e=i(e,c))&&b.fullResultsCallback(e);o(e,c)},m=function(e,c){clearInterval(f);d("full",e,h,c||{})};a=function(e,
|
9
|
+
c){(e=i(e,c))&&b.liveResultsCallback(e);o(e,c)};var n=v?h:a,f,p=function(){var e=b.text();d("live",e,n,{});clearInterval(f)};f=setInterval(p,x);clearInterval(f);var q=function(e,c,s){var y=k(e);if(y!=undefined)e=y;b.insert(e);s&&m(e,c)};this.insert=q;this.clearButtonClicked=function(){clearInterval(f)};this.searchTextCleared=function(){clearInterval(f)};this.searchTextEntered=function(e,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,
|
10
|
+
79,80,81,82,83,84,85,86,87,88,89,90])>-1)if(c.keyCode==13)m(e);else{clearInterval(f);f=setInterval(p,x)}};this.searchButtonClicked=function(e){m(e)};this.allocationChosen=function(e){m(e)};this.addinationClicked=function(e,c){m(e,{offset:c.data.offset})};window.History&&window.History.Adapter.bind(window,"statechange",function(){var e=window.History.getState();e=w(e.url);e!=undefined&&e!=(u&&u.length>1&&u[1])&&q(e,{},true)})};var PickyI18n={},PickyClient=function(a){PickyI18n.locale=$("html").attr("lang").split("-")[0]||"en";a.locale=a.locale||PickyI18n.locale;a.qualifiers=a.qualifiers||{};a.explanations=a.explanations||{};a.choices=a.choices||{};a.explanation_delimiters={ch:"und",de:"und",en:"and",fr:"et",it:"e"};var b=a.backends;if(b){b.live||alert("Both a full and live backend must be provided.");b.full||alert("Both a full and live backend must be provided.")}else a.backends={live:new LiveBackend(a),full:new FullBackend(a)};
|
11
|
+
b=a.enclosingSelector||".picky";var j=a.formSelector||b+" form";a.form=$(j);a.input=$(a.inputSelector||j+" input[type=search]");a.reset=$(a.resetSelector||j+" div.reset");a.button=$(a.buttonSelector||j+" input[type=button]");a.counter=$(a.counterSelector||j+" div.status");a.results=$(a.resultsSelector||b+" div.results");a.noResults=$(a.noResultsSelector||b+" div.no_results");a.moreSelector=a.moreSelector||b+" div.results div.addination:last";a.allocations=$(a.allocationsSelector||b+" .allocations");
|
12
|
+
a.shownAllocations=$(a.shownAllocations||a.allocations.find(".shown"));a.showMoreAllocations=$(a.showMoreAllocations||a.allocations.find(".more"));a.hiddenAllocations=$(a.hiddenAllocations||a.allocations.find(".hidden"));a.maxSuggestions=a.maxSuggestions||3;a.results=$(a.resultsSelector||b+" div.results");a.resultsDivider=a.resultsDivider||"";a.nonPartial=a.nonPartial||[];a.wrapResults=a.wrapResults||"<ol></ol>";var k=a.controller&&new a.controller(a)||new PickyController(a);var l=this.insert=function(i,
|
13
|
+
o,r){k.insert(i,o||{},r||true)};this.resend=k.resend;this.insertFromURL=function(i){if(i)l(i);else(i=k.lastFullQuery())&&l(i)}};var PickyAddination=function(a,b){this.remove=function(){b.find(".addination").remove()};this.render=function(j){var k=j.total,l,i=j.renderedAmount();l=j.offset+i;i=l+i;j=j.total;if(j<i)i=j;l={offset:l,start:l+1,end:i};if(l.offset<k){k=$("<div class='addination'>"+t("results.addination.more")+"</div>");k.bind("click",{offset:l.offset},a.addinationClicked);return k}else return""}};var PickyResultsRenderer=function(a,b){var j=b.locale,k=b.explanations||{},l=b.explanation_delimiters||{},i=b.resultsDivider,o=b.wrapResults,r=b.nonPartial,v=function(d){var h=d[d.length-1];if(h===undefined)return[];d=d.slice(0,d.length-1);if(d==[])d=[d];if(!r.include(h[0]))if(h[1].match(/[^\*~]$/))h[1]+="*";d.push(h);return d};this.asteriskifyLastToken=v;var x=function(d){for(var h=k[j]||{},m=[],n,f=0,p=d.length;f<p;f++){n=d[f];var q=n[0];q=h[q]||q;m.push([q,n[1]])}return m};this.explainCategory=
|
14
|
+
x;var u=function(d,h){return["<strong>"+d+"</strong>",h].join(" ")};this.strongify=u;var w=function(d,h){var m=l[j],n="",f=[],p=[];x(v(h)).each(function(q,e){var c=e[0],s=e[1];s=s.replace(/[\w,]+:(.+)/,"$1");if(n==""||c==n){f.push(s);n=c}else{var y=u(n,f.join(" "));f=[];f.push(s);n=c;p.push(y)}});p.push(u(n,f.join(" ")));p=p.join(" "+m+" ");return p='<span class="explanation">'+d+" "+p+"</span>"};this.explain=w;var g=function(d,h){var m='<div class="header">';m+=w(h.type,h.combination);if(d.offset>
|
15
|
+
0)m+='<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">↑</a></div>';m+="</div>";return m};this.renderHeader=g;this.render=function(d,h){h.allocations.each(function(m,n){if(n.entries.length>0){d.append(g(h,n)).append(n.entries.join(i));d.children("li").wrapAll(o)}});d.append(a.render(h))}};function AllocationRenderer(a){function b(g){var d={},h={},m={},n=[],f,p;f=0;for(p=g.length;f<p;f++){var q=g[f][0];if(q in d){d[q].push(g[f][1]);h[q].push(g[f][2]);n.push(f)}else{d[q]=[g[f][1]];h[q]=[g[f][2]];m[f]=q}}for(f in m){g[f][1]=d[m[f]];g[f][2]=h[m[f]]}for(f=n.length-1;f>=0;f--)g.remove(n[f]);return g}function j(g){g.map(function(d){return"%"+(d+1)+"$s"});return g.join(" ")}function k(g){if(g.length==0)return"";g=b(g);for(var d=[],h=0,m=g.length;h<m;h++)d.push(g[h][0]);var n=d.length==1,f=
|
16
|
+
u[d.join(",")];if(f===undefined)f=u[d]=j(d);if(typeof f==="string"){u[d]={format:f,ignoreSingle:true};f=u[d]}var p=f.format;g.each(function(q,e){var c=e[0],s=e[1],y=e[2];y.map(function(z,A){var B=s[z];if(B.charAt(B.length-1)=="*")A+="...";return A});f.filter&&y.map(function(z,A){return f.filter(A)});if(n&&!(f&&f.ignoreSingle)){c=v[c]||c;return p=y.join(" ")+" ("+c+")"}y.map(function(z,A){return A.replace(/[\w,]+:(.+)/,"$1")});p=p.replace(RegExp("%"+(q+1)+"\\$s","g"),y.join(" "))});
|
17
|
+
return p}function l(g){for(var d=[],h=0,m=x.length;h<m;h++)d.push([]);d.push([]);h=0;for(m=g.length;h<m;h++){for(var n=g[h],f=n[0],p=false,q=0,e=x.length;q<e;q++)if(x[q].include(f)){d[q].push(n);p=true;break}p||d[d.length-1].push(n)}var c;for(g=d.length-1;g>=0;g--){c=d[g];if(c.length>0)break}c=c[c.length-1];w.include(c[0])||(c[1]=c[1].valueOf()+"*");return d}function i(g){var d=[];l(g).each(function(h,m){var n=k(m);n&&d.push(n)});return d.join(" ")}var o=a.locale,r=a.qualifiers&&a.qualifiers[o]||
|
18
|
+
{},v=a.explanations&&a.explanations[o]||{},x=a.groups||[],u=a.choices&&a.choices[o]||{},w=a.nonPartial||[];this.explanation=this.query=this.text="";this.contract=b;this.makeUpMissingFormat=j;this.rendered=k;this.groupify=l;this.querify=function(g){var d=[],h,m,n;for(n in g){h=g[n][0];h=r[h]||h;m=(m=g[n][1])||"";m=m.charAt(m.length-1)=="*"?"*":"";d[n]=h+":"+g[n][2]+m}return d.join(" ")};this.suggestify=i;this.render=function(g){return i(g.combination)}};var PickyAllocationsCloud=function(a,b){var j=b.allocations,k=b.shownAllocations,l=b.showMoreAllocations,i=b.hiddenAllocations,o=b.maxSuggestions,r=function(){j.hide()},v=function(g){r();a.allocationChosen(g)},x=new AllocationRenderer(b),u=function(g){var d=[];g.each(function(h,m){var n=x.querify(m.combination),f=x.render(m);f=$('<li><div class="text">'+f+'</div><div class="count">'+m.count+"</div></li>");f.bind("click",{query:n},v);d.push(f)});return d},w=function(g){if(g.length==0)return j.hide();
|
19
|
+
k.empty();l.hide();i.empty().hide();if(g.length>o){$.each(g.slice(0,o-1),function(d,h){k.append(h)});$.each(g.slice(o-1),function(d,h){i.append(h)});l.show()}else $.each(g,function(d,h){k.append(h)});return j.show()};l.click(function(){l.hide();i.show()});this.hide=r;this.show=function(g){w(u(g.allocations));j.show()}};
|
@@ -20,6 +20,16 @@ describe Picky::TestClient do
|
|
20
20
|
|
21
21
|
client.search('test').total.should == 1
|
22
22
|
end
|
23
|
+
it 'sends correctly' do
|
24
|
+
response = stub :response
|
25
|
+
request = stub :request
|
26
|
+
client.stub! :request => request
|
27
|
+
|
28
|
+
request.should_receive(:get).once.with('/some/path?ids=100&query=some_query').and_return response
|
29
|
+
response.should_receive(:body).once.and_return '"some_body"'
|
30
|
+
|
31
|
+
client.search('some_query', :ids => 100).should == 'some_body'
|
32
|
+
end
|
23
33
|
end
|
24
34
|
|
25
35
|
context 'send_search' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: picky-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.19.
|
4
|
+
version: 4.19.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yajl-ruby
|