Permalink
Browse files

+ URL history now also saves live query, + URL history saves query af…

…ter it has been tampered with in before filter
  • Loading branch information...
1 parent 1dc88ea commit 6bab4b23cc3ee9056c3465c24a75b4241743a11c @floere committed Feb 6, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
Binary file not shown.
@@ -4,6 +4,7 @@ var PickyAllocationsCloud = function(view, config) {
var shownAllocations = config['shownAllocations'];
var showMoreAllocations = config['showMoreAllocations'];
var hiddenAllocations = config['hiddenAllocations'];
+ var maxSuggestions = config['maxSuggestions'];
// Show the cloud.
//
@@ -50,7 +51,6 @@ var PickyAllocationsCloud = function(view, config) {
if (list.length == 0) {
return allocations.hide();
}
- var maxSuggestions = 3;
clearAllocationCloud();
if (list.length > maxSuggestions) {
@@ -79,12 +79,14 @@ var PickyClient = function(config) {
config['shownAllocations'] = config['allocations'].find('.shown');
config['showMoreAllocations'] = config['allocations'].find('.more');
config['hiddenAllocations'] = config['allocations'].find('.hidden');
+ config['maxSuggestions'] = config['maxSuggestions'] || 3; // How many are shown directly?
// Results rendering.
//
- config['results'] = $(config['resultsSelector'] || (enclosingSelector + ' div.results'));
- config['noAsterisks'] = config['noAsterisks'] || []; // e.g. ['category1', 'category2']
- config['wrapResults'] = config['wrapResults'] || '<ol class="results"></ol>';
+ config['results'] = $(config['resultsSelector'] || (enclosingSelector + ' div.results'));
+ config['resultsDivider'] = config['resultsDivider'] || '';
+ config['noAsterisks'] = config['noAsterisks'] || []; // e.g. ['category1', 'category2']
+ config['wrapResults'] = config['wrapResults'] || '<ol class="results"></ol>';
// The central Picky controller.
//
@@ -118,14 +120,5 @@ var PickyClient = function(config) {
lastFullQuery && insert(lastFullQuery);
}
};
-
- // Bind adapter to let the back/forward button start queries.
- //
- if (window.History) {
- window.History.Adapter.bind(window, 'statechange', function() {
- var state = window.History.getState();
- var query = controller.extractQuery(state.url);
- query && insert(query);
- });
- };
+
};
@@ -3,9 +3,9 @@ var PickyController = function(config) {
var view = new PickyView(this, config);
var backends = config.backends;
- var beforeCallback = config.before || function(query, params) { };
+ var beforeCallback = config.before || function(query, params) { };
var successCallback = config.success || function(data, query) { };
- var afterCallback = config.after || function(data, query) { };
+ var afterCallback = config.after || function(data, query) { };
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
@@ -20,6 +20,13 @@ var PickyController = function(config) {
};
this.extractQuery = extractQuery;
+ // Returns the last saved query from
+ // the saved params.
+ //
+ var lastQuery = function() {
+ return lastQueryParams.length > 1 && lastQueryParams[1];
+ }
+
// Failsafe extraction of the last made query.
//
var lastFullQuery = function() {
@@ -29,13 +36,27 @@ var PickyController = function(config) {
};
this.lastFullQuery = lastFullQuery;
+ // Saves the last query in history.
+ //
+ var saveInHistory = function(query) {
+ // 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 != lastFullQuery()) { // TODO Not full.
+ var url = "?q=" + escape(query).replace(/\*/g,'%2A');
+ window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
+ }
+ }
+
// 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;
+ lastQueryParams = [type, query, callback, specificParams];
+ saveInHistory(query);
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
@@ -56,15 +77,6 @@ var PickyController = function(config) {
};
var fullSearch = function(query, 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 != lastFullQuery()) {
- var url = "?q=" + escape(query).replace(/\*/g,'%2A');
- window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
- }
search('full', query, fullSearchCallback, possibleParams || {});
};
@@ -93,11 +105,12 @@ var PickyController = function(config) {
//
//
- this.insert = function(query, params, full) {
+ var insert = function(query, params, full) {
view.insert(query);
if (full) { fullSearch(query, params); }
};
+ this.insert = insert;
var clearButtonClicked = function() { clearInterval(liveSearchTimerId); };
this.clearButtonClicked = clearButtonClicked;
@@ -134,4 +147,15 @@ var PickyController = function(config) {
// Move to a view object.
var addinationClicked = function(text, event) { fullSearch(text, { offset: event.data.offset }); };
this.addinationClicked = addinationClicked;
+
+ // Bind adapter to let the back/forward button start queries.
+ //
+ if (window.History) {
+ window.History.Adapter.bind(window, 'statechange', function() {
+ var state = window.History.getState();
+ var query = extractQuery(state.url);
+ if (query && query != lastQuery()) { insert(query); }
+ });
+ };
+
};
@@ -1,6 +1,7 @@
var PickyResultsRenderer = function(addination, config) {
var results = config['results'];
+ var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
var noAsterisks = config['noAsterisks'];
@@ -107,7 +108,7 @@ var PickyResultsRenderer = function(addination, config) {
// TODO header.render(data);
//
results.append(renderHeader(data, allocation))
- .append(allocation.entries.join(''));
+ .append(allocation.entries.join(resultsDivider));
results.children('li').wrapAll(allocationWrapper);
}
});
@@ -4,6 +4,7 @@ var PickyAllocationsCloud = function(view, config) {
var shownAllocations = config['shownAllocations'];
var showMoreAllocations = config['showMoreAllocations'];
var hiddenAllocations = config['hiddenAllocations'];
+ var maxSuggestions = config['maxSuggestions'];
// Show the cloud.
//
@@ -50,7 +51,6 @@ var PickyAllocationsCloud = function(view, config) {
if (list.length == 0) {
return allocations.hide();
}
- var maxSuggestions = 3;
clearAllocationCloud();
if (list.length > maxSuggestions) {
@@ -79,12 +79,14 @@ var PickyClient = function(config) {
config['shownAllocations'] = config['allocations'].find('.shown');
config['showMoreAllocations'] = config['allocations'].find('.more');
config['hiddenAllocations'] = config['allocations'].find('.hidden');
+ config['maxSuggestions'] = config['maxSuggestions'] || 3; // How many are shown directly?
// Results rendering.
//
- config['results'] = $(config['resultsSelector'] || (enclosingSelector + ' div.results'));
- config['noAsterisks'] = config['noAsterisks'] || []; // e.g. ['category1', 'category2']
- config['wrapResults'] = config['wrapResults'] || '<ol class="results"></ol>';
+ config['results'] = $(config['resultsSelector'] || (enclosingSelector + ' div.results'));
+ config['resultsDivider'] = config['resultsDivider'] || '';
+ config['noAsterisks'] = config['noAsterisks'] || []; // e.g. ['category1', 'category2']
+ config['wrapResults'] = config['wrapResults'] || '<ol class="results"></ol>';
// The central Picky controller.
//
@@ -118,14 +120,5 @@ var PickyClient = function(config) {
lastFullQuery && insert(lastFullQuery);
}
};
-
- // Bind adapter to let the back/forward button start queries.
- //
- if (window.History) {
- window.History.Adapter.bind(window, 'statechange', function() {
- var state = window.History.getState();
- var query = controller.extractQuery(state.url);
- query && insert(query);
- });
- };
+
};
@@ -3,9 +3,9 @@ var PickyController = function(config) {
var view = new PickyView(this, config);
var backends = config.backends;
- var beforeCallback = config.before || function(query, params) { };
+ var beforeCallback = config.before || function(query, params) { };
var successCallback = config.success || function(data, query) { };
- var afterCallback = config.after || function(data, query) { };
+ var afterCallback = config.after || function(data, query) { };
var liveRendered = config.liveRendered || false;
var liveSearchTimerInterval = config.liveSearchInterval || 180;
@@ -20,6 +20,13 @@ var PickyController = function(config) {
};
this.extractQuery = extractQuery;
+ // Returns the last saved query from
+ // the saved params.
+ //
+ var lastQuery = function() {
+ return lastQueryParams.length > 1 && lastQueryParams[1];
+ }
+
// Failsafe extraction of the last made query.
//
var lastFullQuery = function() {
@@ -29,13 +36,27 @@ var PickyController = function(config) {
};
this.lastFullQuery = lastFullQuery;
+ // Saves the last query in history.
+ //
+ var saveInHistory = function(query) {
+ // 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 != lastFullQuery()) { // TODO Not full.
+ var url = "?q=" + escape(query).replace(/\*/g,'%2A');
+ window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
+ }
+ }
+
// 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;
+ lastQueryParams = [type, query, callback, specificParams];
+ saveInHistory(query);
+
var currentBackend = backends[type];
if (currentBackend) { currentBackend.search(query, callback, specificParams); };
};
@@ -56,15 +77,6 @@ var PickyController = function(config) {
};
var fullSearch = function(query, 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 != lastFullQuery()) {
- var url = "?q=" + escape(query).replace(/\*/g,'%2A');
- window.History && window.History.getState() && window.History.pushState && window.History.pushState(null, null, url);
- }
search('full', query, fullSearchCallback, possibleParams || {});
};
@@ -93,11 +105,12 @@ var PickyController = function(config) {
//
//
- this.insert = function(query, params, full) {
+ var insert = function(query, params, full) {
view.insert(query);
if (full) { fullSearch(query, params); }
};
+ this.insert = insert;
var clearButtonClicked = function() { clearInterval(liveSearchTimerId); };
this.clearButtonClicked = clearButtonClicked;
@@ -134,4 +147,15 @@ var PickyController = function(config) {
// Move to a view object.
var addinationClicked = function(text, event) { fullSearch(text, { offset: event.data.offset }); };
this.addinationClicked = addinationClicked;
+
+ // Bind adapter to let the back/forward button start queries.
+ //
+ if (window.History) {
+ window.History.Adapter.bind(window, 'statechange', function() {
+ var state = window.History.getState();
+ var query = extractQuery(state.url);
+ if (query && query != lastQuery()) { insert(query); }
+ });
+ };
+
};
@@ -1,6 +1,7 @@
var PickyResultsRenderer = function(addination, config) {
var results = config['results'];
+ var resultsDivider = config['resultsDivider'];
var allocationWrapper = config['wrapResults'];
var noAsterisks = config['noAsterisks'];
@@ -107,7 +108,7 @@ var PickyResultsRenderer = function(addination, config) {
// TODO header.render(data);
//
results.append(renderHeader(data, allocation))
- .append(allocation.entries.join(''));
+ .append(allocation.entries.join(resultsDivider));
results.children('li').wrapAll(allocationWrapper);
}
});
Oops, something went wrong.

0 comments on commit 6bab4b2

Please sign in to comment.