Permalink
Browse files

+ PickyClient.resend function which resends the last query (still run…

…s before etc. filters)
  • Loading branch information...
1 parent f615463 commit 86e8af2a93b41912b56a2c2c00d44e01c76644e8 @floere committed Feb 3, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -98,16 +98,12 @@ var PickyClient = function(config) {
};
var insert = this.insert;
- // Resends the last query text.
+ // Resends the last query text, full/live.
//
// Note: Other variables apart from the text
// could have changed.
//
- var resend = function() {
- var lastQuery = controller.lastQuery();
- lastQuery && insert(lastQuery);
- };
- this.resend = resend;
+ this.resend = controller.resend;
// Takes a query or nothing as parameter.
//
@@ -118,7 +114,8 @@ var PickyClient = function(config) {
if (override && override != '') {
insert(override);
} else {
- resend();
+ var lastFullQuery = controller.lastFullQuery();
+ lastFullQuery && insert(lastFullQuery);
}
};
@@ -10,6 +10,8 @@ var PickyController = function(config) {
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
+ var lastQueryParams;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -20,20 +22,31 @@ var PickyController = function(config) {
// Failsafe extraction of the last made query.
//
- var lastQuery = function() {
+ var lastFullQuery = function() {
var state = window.History && window.History.getState();
var url = state && state.url;
return extractQuery(url);
};
- this.lastQuery = lastQuery;
+ this.lastFullQuery = lastFullQuery;
// If the given backend cannot be found, ignore the search request.
//
var search = function(type, query, callback, specificParams) {
+ lastQueryParams = [type, query, callback, specificParams];
+
+ query = beforeCallback(query, specificParams) || query;
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
+ // Resend the last query as it was.
+ //
+ var resend = function() {
+ if (lastQueryParams) { search.apply(this, lastQueryParams); }
+ };
+ this.resend = resend;
+
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -42,21 +55,18 @@ var PickyController = function(config) {
afterCallback(data, query);
};
var fullSearch = function(query, possibleParams) {
- var params = possibleParams || {};
clearInterval(liveSearchTimerId);
// Be extra cautious since not all browsers/histories offer pushState.
//
// Note: If this query is the same as the last, we do not save it in the history.
//
- if (query != lastQuery()) {
+ if (query != lastFullQuery()) {
var url = "?q=" + escape(query).replace(/\*/g,'%2A');
window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
}
- query = beforeCallback(query, params) || query;
-
- search('full', query, fullSearchCallback, params);
+ search('full', query, fullSearchCallback, possibleParams || {});
};
var liveSearchCallback = function(data, query) {
@@ -68,11 +78,7 @@ var PickyController = function(config) {
};
var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveCallbackUsed, params);
+ search('live', query, liveCallbackUsed, possibleParams || {});
};
// The timer is initially instantly stopped.
@@ -98,16 +98,12 @@ var PickyClient = function(config) {
};
var insert = this.insert;
- // Resends the last query text.
+ // Resends the last query text, full/live.
//
// Note: Other variables apart from the text
// could have changed.
//
- var resend = function() {
- var lastQuery = controller.lastQuery();
- lastQuery && insert(lastQuery);
- };
- this.resend = resend;
+ this.resend = controller.resend;
// Takes a query or nothing as parameter.
//
@@ -118,7 +114,8 @@ var PickyClient = function(config) {
if (override && override != '') {
insert(override);
} else {
- resend();
+ var lastFullQuery = controller.lastFullQuery();
+ lastFullQuery && insert(lastFullQuery);
}
};
@@ -10,6 +10,8 @@ var PickyController = function(config) {
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
+ var lastQueryParams;
+
// Extracts the query part from an URL.
//
var extractQuery = function(url) {
@@ -20,20 +22,31 @@ var PickyController = function(config) {
// Failsafe extraction of the last made query.
//
- var lastQuery = function() {
+ var lastFullQuery = function() {
var state = window.History && window.History.getState();
var url = state && state.url;
return extractQuery(url);
};
- this.lastQuery = lastQuery;
+ this.lastFullQuery = lastFullQuery;
// If the given backend cannot be found, ignore the search request.
//
var search = function(type, query, callback, specificParams) {
+ lastQueryParams = [type, query, callback, specificParams];
+
+ query = beforeCallback(query, specificParams) || query;
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
+ // Resend the last query as it was.
+ //
+ var resend = function() {
+ if (lastQueryParams) { search.apply(this, lastQueryParams); }
+ };
+ this.resend = resend;
+
var fullSearchCallback = function(data, query) {
data = successCallback(data, query) || data;
@@ -42,21 +55,18 @@ var PickyController = function(config) {
afterCallback(data, query);
};
var fullSearch = function(query, possibleParams) {
- var params = possibleParams || {};
clearInterval(liveSearchTimerId);
// Be extra cautious since not all browsers/histories offer pushState.
//
// Note: If this query is the same as the last, we do not save it in the history.
//
- if (query != lastQuery()) {
+ if (query != lastFullQuery()) {
var url = "?q=" + escape(query).replace(/\*/g,'%2A');
window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
}
- query = beforeCallback(query, params) || query;
-
- search('full', query, fullSearchCallback, params);
+ search('full', query, fullSearchCallback, possibleParams || {});
};
var liveSearchCallback = function(data, query) {
@@ -68,11 +78,7 @@ var PickyController = function(config) {
};
var liveCallbackUsed = liveRendered ? fullSearchCallback : liveSearchCallback;
var liveSearch = function(query, possibleParams) {
- var params = possibleParams || {};
-
- query = beforeCallback(query, params) || query;
-
- search('live', query, liveCallbackUsed, params);
+ search('live', query, liveCallbackUsed, possibleParams || {});
};
// The timer is initially instantly stopped.
Oops, something went wrong.

0 comments on commit 86e8af2

Please sign in to comment.