Loading template/app/GuideSearch.js +23 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,29 @@ Ext.define("Docs.GuideSearch", { return !!Docs.data.guideSearch.url; }, /** * Invokes #search after a specified delay. * * @param {String} term The query string to search for * @param {Function} callback Function to call with an array of search results. * @param {Object} scope Scope for the function. * @param {Number} delay Milliseconds to wait before starting. */ deferredSearch: function(term, callback, scope, delay) { // When new search term comes in, cancel the previous delayed search. clearTimeout(this.timeout); var timeout = this.timeout = Ext.Function.defer(function() { this.search(term, function(results) { // When new search is already started, don't show the // results of old search. if (timeout === this.timeout) { callback.call(scope, results); } }, this); }, delay, this); }, /** * Peforms the search remotely, then calls the given function. * Loading template/app/controller/Search.js +3 −12 Original line number Diff line number Diff line Loading @@ -151,19 +151,10 @@ Ext.define('Docs.controller.Search', { } }, // Wait a bit before launching guides search. // When new search term comes in, cancel the previous delayed search. // When the search had already started, don't show the results when it finishes. guideSearch: function(term) { clearTimeout(this.guideSearchTimeout); var timeout = this.guideSearchTimeout = Ext.Function.defer(function() { Docs.GuideSearch.search(term, function(guideResults) { if (timeout === this.guideSearchTimeout) { Docs.GuideSearch.deferredSearch(term, function(guideResults) { this.basicSearch(term, guideResults); } }, this); }, this.guideSearchDelay, this); }, this, this.guideSearchDelay); }, basicSearch: function(term, guideResults) { Loading Loading
template/app/GuideSearch.js +23 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,29 @@ Ext.define("Docs.GuideSearch", { return !!Docs.data.guideSearch.url; }, /** * Invokes #search after a specified delay. * * @param {String} term The query string to search for * @param {Function} callback Function to call with an array of search results. * @param {Object} scope Scope for the function. * @param {Number} delay Milliseconds to wait before starting. */ deferredSearch: function(term, callback, scope, delay) { // When new search term comes in, cancel the previous delayed search. clearTimeout(this.timeout); var timeout = this.timeout = Ext.Function.defer(function() { this.search(term, function(results) { // When new search is already started, don't show the // results of old search. if (timeout === this.timeout) { callback.call(scope, results); } }, this); }, delay, this); }, /** * Peforms the search remotely, then calls the given function. * Loading
template/app/controller/Search.js +3 −12 Original line number Diff line number Diff line Loading @@ -151,19 +151,10 @@ Ext.define('Docs.controller.Search', { } }, // Wait a bit before launching guides search. // When new search term comes in, cancel the previous delayed search. // When the search had already started, don't show the results when it finishes. guideSearch: function(term) { clearTimeout(this.guideSearchTimeout); var timeout = this.guideSearchTimeout = Ext.Function.defer(function() { Docs.GuideSearch.search(term, function(guideResults) { if (timeout === this.guideSearchTimeout) { Docs.GuideSearch.deferredSearch(term, function(guideResults) { this.basicSearch(term, guideResults); } }, this); }, this.guideSearchDelay, this); }, this, this.guideSearchDelay); }, basicSearch: function(term, guideResults) { Loading