Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

+ correctly handle query string when using + or #

  • Loading branch information...
commit 1dc88eaced850a955bf8ffb87be31340a9b56265 1 parent 86e8af2
@floere authored
View
7 client/javascripts/picky.min.js
@@ -3,9 +3,10 @@ Array.prototype.index=function(a){for(var c=0,g=this.length;c<g;c++)if(this[c]==
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"});
+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=([^&]+)/))&&decodeURIComponent(b[1]).replace(/\+/g," ").replace(/#/g,"")||""};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 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",
View
BIN  client/javascripts/picky.source.js.tar
Binary file not shown
View
24 client/javascripts/source/picky.controller.js
@@ -16,7 +16,7 @@ var PickyController = function(config) {
//
var extractQuery = function(url) {
var match = url && url.match(/q=([^&]+)/);
- return match && unescape(match[1] || "");
+ return match && decodeURIComponent(match[1]).replace(/\+/g, ' ').replace(/#/g, '') || "";
};
this.extractQuery = extractQuery;
@@ -99,16 +99,10 @@ var PickyController = function(config) {
if (full) { fullSearch(query, params); }
};
- var clearButtonClicked = function() {
- clearInterval(liveSearchTimerId);
- // liveSearchTimer.stop();
- };
+ var clearButtonClicked = function() { clearInterval(liveSearchTimerId); };
this.clearButtonClicked = clearButtonClicked;
- var searchTextCleared = function() {
- clearInterval(liveSearchTimerId);
- // liveSearchTimer.stop();
- };
+ var searchTextCleared = function() { clearInterval(liveSearchTimerId); };
this.searchTextCleared = searchTextCleared;
var shouldTriggerSearch = function(event) {
@@ -131,19 +125,13 @@ var PickyController = function(config) {
};
this.searchTextEntered = searchTextEntered;
- var searchButtonClicked = function(text) {
- fullSearch(text);
- };
+ var searchButtonClicked = function(text) { fullSearch(text); };
this.searchButtonClicked = searchButtonClicked;
- var allocationChosen = function(text) {
- fullSearch(text);
- };
+ var allocationChosen = function(text) { fullSearch(text); };
this.allocationChosen = allocationChosen;
// Move to a view object.
- var addinationClicked = function(text, event) {
- fullSearch(text, { offset: event.data.offset });
- };
+ var addinationClicked = function(text, event) { fullSearch(text, { offset: event.data.offset }); };
this.addinationClicked = addinationClicked;
};
View
24 client/test_project/javascripts/picky.controller.js
@@ -16,7 +16,7 @@ var PickyController = function(config) {
//
var extractQuery = function(url) {
var match = url && url.match(/q=([^&]+)/);
- return match && unescape(match[1] || "");
+ return match && decodeURIComponent(match[1]).replace(/\+/g, ' ').replace(/#/g, '') || "";
};
this.extractQuery = extractQuery;
@@ -99,16 +99,10 @@ var PickyController = function(config) {
if (full) { fullSearch(query, params); }
};
- var clearButtonClicked = function() {
- clearInterval(liveSearchTimerId);
- // liveSearchTimer.stop();
- };
+ var clearButtonClicked = function() { clearInterval(liveSearchTimerId); };
this.clearButtonClicked = clearButtonClicked;
- var searchTextCleared = function() {
- clearInterval(liveSearchTimerId);
- // liveSearchTimer.stop();
- };
+ var searchTextCleared = function() { clearInterval(liveSearchTimerId); };
this.searchTextCleared = searchTextCleared;
var shouldTriggerSearch = function(event) {
@@ -131,19 +125,13 @@ var PickyController = function(config) {
};
this.searchTextEntered = searchTextEntered;
- var searchButtonClicked = function(text) {
- fullSearch(text);
- };
+ var searchButtonClicked = function(text) { fullSearch(text); };
this.searchButtonClicked = searchButtonClicked;
- var allocationChosen = function(text) {
- fullSearch(text);
- };
+ var allocationChosen = function(text) { fullSearch(text); };
this.allocationChosen = allocationChosen;
// Move to a view object.
- var addinationClicked = function(text, event) {
- fullSearch(text, { offset: event.data.offset });
- };
+ var addinationClicked = function(text, event) { fullSearch(text, { offset: event.data.offset }); };
this.addinationClicked = addinationClicked;
};
View
7 generators/prototypes/client/sinatra/javascripts/picky.min.js
@@ -3,9 +3,10 @@ Array.prototype.index=function(a){for(var c=0,g=this.length;c<g;c++)if(this[c]==
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"});
+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=([^&]+)/))&&decodeURIComponent(b[1]).replace(/\+/g," ").replace(/#/g,"")||""};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 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",
Please sign in to comment.
Something went wrong with that request. Please try again.