Permalink
Browse files

! javascript addination and header rendering, + 3.1.6

  • Loading branch information...
1 parent 1355731 commit c7ffbd46ad6fb28e5a96ff2b019387f504664edc @floere committed Sep 16, 2011
View
2 client/javascripts/picky.min.js
@@ -10,7 +10,7 @@ k=setInterval(m,180);clearInterval(k);var r=function(a,c){a=d(a,c)||a;i.fullResu
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)||
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]+)/,
"<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);">&uarr;</a></div>';
-return r};this.render=function(k){var m=$("#picky div.results");k.allocations.each(function(r,p){m.append(u(k,p)).append(p.entries.join("")).append(b.render(k));m.children("li").wrapAll(g)})}};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,y){return x[0]<y[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]||
+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,y){return x[0]<y[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]||
(r[f]=e(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,z=v.format;$.each(a,function(x,y){var A=y[0],B=y[1];if(v.filter)B=v.filter(B);A=k[A]||A;if(w&&!(v&&v.ignoreSingle))return z=B+"&nbsp;("+A+")";z=z.replace(RegExp("%"+h+"\\$s","g"),B);h+=1;return h});return z}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,z=m.length;h<z;h++)if(m[h].include(w)){c[h].push(q);v=true;break}v||c[c.length-1].push(q)}var x;
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(y){return d(y)})}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",
"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)});
View
BIN client/javascripts/picky.source.js.tar
Binary file not shown.
View
47 client/javascripts/source/picky.results_renderer.js
@@ -87,46 +87,27 @@ var PickyResultsRenderer = function(addination, config) {
header_html += '<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>'; // searchEngine.focus();
}
- // TODO Parametrize!
- // var names = '';
- // var firstEntryName = $(allocation.entries[0]).find('.name').html();
- // var lastEntryName = $(allocation.entries[allocation.entries.length-1]).find('.name').html();
- // if(firstEntryName == lastEntryName) {
- // var firstEntryFirstName = $(allocation.entries[0]).find('.first_name').html();
- // var lastEntryFirstName = $(allocation.entries[allocation.entries.length-1]).find('.first_name').html();
- // names = '<div class="names">' + firstEntryName + ', ' + firstEntryFirstName + ' ' + t('common.to') + ' ' + lastEntryFirstName + '</div>';
- // }
- // else {
- // names = '<div class="names">' + firstEntryName + ' ' + t('common.to') + ' ' + lastEntryName + '</div>';
- // }
-
- // var rangeStart = data.offset + 1;
- // var rangeEnd = data.offset + allocation.entries.length;
- // var rangeText = (rangeStart == rangeEnd) ? rangeStart : rangeStart + '-' + rangeEnd;
- // var range = '<div class="range">' + rangeText + ' ' + t('common.of') + ' ' + data.total + '</div>';
-
- // if (data.total > 20) { // TODO Make settable.
- // // header_html += '<div class="clear"></div>'; // TODO
- // // header_html += names; // TODO
- // // header_html += range; // TODO
- // }
-
- // // For smooth addination scrolling. Don't ask.
- //
- // header_html += '<div class="clear"></div></div>';
-
return header_html;
};
// Render results with the data.
//
this.render = function(data) {
- var results = $('#picky div.results'); // TODO Extract, also from view.
+ // TODO Extract, also from view.
+ //
+ var results = $('#picky div.results');
data.allocations.each(function(i, allocation) {
- results.append(renderHeader(data, allocation)) // TODO header.render(data);
- .append(allocation.entries.join(''))
- .append(addination.render(data));
- results.children('li').wrapAll(allocationWrapper);
+ // Only render if there is something to render.
+ // TODO Move into methods.
+ //
+ if (allocation.entries.length > 0) {
+ // TODO header.render(data);
+ //
+ results.append(renderHeader(data, allocation))
+ .append(allocation.entries.join(''));
+ results.children('li').wrapAll(allocationWrapper);
+ }
});
+ results.append(addination.render(data));
};
};
View
47 client/test_project/javascripts/picky.results_renderer.js
@@ -87,46 +87,27 @@ var PickyResultsRenderer = function(addination, config) {
header_html += '<div class="tothetop"><a href="#" onclick="javascript:$(\'body\').animate({scrollTop: 0}, 500);">&uarr;</a></div>'; // searchEngine.focus();
}
- // TODO Parametrize!
- // var names = '';
- // var firstEntryName = $(allocation.entries[0]).find('.name').html();
- // var lastEntryName = $(allocation.entries[allocation.entries.length-1]).find('.name').html();
- // if(firstEntryName == lastEntryName) {
- // var firstEntryFirstName = $(allocation.entries[0]).find('.first_name').html();
- // var lastEntryFirstName = $(allocation.entries[allocation.entries.length-1]).find('.first_name').html();
- // names = '<div class="names">' + firstEntryName + ', ' + firstEntryFirstName + ' ' + t('common.to') + ' ' + lastEntryFirstName + '</div>';
- // }
- // else {
- // names = '<div class="names">' + firstEntryName + ' ' + t('common.to') + ' ' + lastEntryName + '</div>';
- // }
-
- // var rangeStart = data.offset + 1;
- // var rangeEnd = data.offset + allocation.entries.length;
- // var rangeText = (rangeStart == rangeEnd) ? rangeStart : rangeStart + '-' + rangeEnd;
- // var range = '<div class="range">' + rangeText + ' ' + t('common.of') + ' ' + data.total + '</div>';
-
- // if (data.total > 20) { // TODO Make settable.
- // // header_html += '<div class="clear"></div>'; // TODO
- // // header_html += names; // TODO
- // // header_html += range; // TODO
- // }
-
- // // For smooth addination scrolling. Don't ask.
- //
- // header_html += '<div class="clear"></div></div>';
-
return header_html;
};
// Render results with the data.
//
this.render = function(data) {
- var results = $('#picky div.results'); // TODO Extract, also from view.
+ // TODO Extract, also from view.
+ //
+ var results = $('#picky div.results');
data.allocations.each(function(i, allocation) {
- results.append(renderHeader(data, allocation)) // TODO header.render(data);
- .append(allocation.entries.join(''))
- .append(addination.render(data));
- results.children('li').wrapAll(allocationWrapper);
+ // Only render if there is something to render.
+ // TODO Move into methods.
+ //
+ if (allocation.entries.length > 0) {
+ // TODO header.render(data);
+ //
+ results.append(renderHeader(data, allocation))
+ .append(allocation.entries.join(''));
+ results.children('li').wrapAll(allocationWrapper);
+ }
});
+ results.append(addination.render(data));
};
};
View
2 client/test_project/views/search.haml
@@ -78,7 +78,7 @@
live: '/search/live',
// liveResults: 0, // Optional. Amount of ids to search for, default 0.
- // showResultsLimit: 10, // Optional. Default is 10.
+ showResultsLimit: 100, // Optional. Default is 10.
// Wrap each li group (like author-title, or title-isbn etc.) of results
// in this element.
View
2 generators/prototypes/client/sinatra/javascripts/picky.min.js
@@ -10,7 +10,7 @@ k=setInterval(m,180);clearInterval(k);var r=function(a,c){a=d(a,c)||a;i.fullResu
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)||
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]+)/,
"<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);">&uarr;</a></div>';
-return r};this.render=function(k){var m=$("#picky div.results");k.allocations.each(function(r,p){m.append(u(k,p)).append(p.entries.join("")).append(b.render(k));m.children("li").wrapAll(g)})}};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,y){return x[0]<y[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]||
+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,y){return x[0]<y[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]||
(r[f]=e(f));if($.type(v)==="string"){r[f]={format:v};v=r[f]}var h=1,z=v.format;$.each(a,function(x,y){var A=y[0],B=y[1];if(v.filter)B=v.filter(B);A=k[A]||A;if(w&&!(v&&v.ignoreSingle))return z=B+"&nbsp;("+A+")";z=z.replace(RegExp("%"+h+"\\$s","g"),B);h+=1;return h});return z}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,z=m.length;h<z;h++)if(m[h].include(w)){c[h].push(q);v=true;break}v||c[c.length-1].push(q)}var x;
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(y){return d(y)})}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",
"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)});
View
3 history.textile
@@ -1,5 +1,8 @@
h2. Upcoming Version
+h2. Version 3.1.6
+
+* hanke: (client) Javascripts fixed. Get the new minified version here: "https://github.com/floere/picky/tree/master/client/javascripts":https://github.com/floere/picky/tree/master/client/javascripts.
* hanke: (server) Number of cores for OS Lion correctly reported.
h2. Version 3.1.5
View
2 version.rb
@@ -1,3 +1,3 @@
module Picky
- VERSION = '3.1.5'
+ VERSION = '3.1.6'
end

0 comments on commit c7ffbd4

Please sign in to comment.