diff chromeless-browsing/chromeless.js @ 5:96bb8d08e94a

The 'go' command now uses proper asynchronous suggestions.
author Atul Varma <varmaa@toolness.com>
date Fri, 27 Mar 2009 13:34:14 -0700
parents fd988ee76408
children c89423660272
line wrap: on
line diff
--- a/chromeless-browsing/chromeless.js	Fri Mar 27 13:16:11 2009 -0700
+++ b/chromeless-browsing/chromeless.js	Fri Mar 27 13:34:14 2009 -0700
@@ -52,9 +52,7 @@
 
     controller.startSearch(partialSearch);
   },
-  suggestions: [],
-  _onSearchComplete: function(controller) {
-    var suggs = [];
+  _onSearchComplete: function(controller, callback) {
     var max_suggs = 5;
     for (var i = 0; i < controller.matchCount && i <= max_suggs; i++) {
       var result = {
@@ -69,25 +67,17 @@
         result.image = result.image.slice("moz-anno:favicon:".length);
       else
         result.image = "";
-      suggs.push(CmdUtils.makeSugg(result.title, undefined, result));
+      callback(CmdUtils.makeSugg(result.title, undefined, result));
     }
-    noun_type_url.suggestions = suggs;
   },
-  suggest: function(fragment) {
-    this._getHistoryLinks(fragment, this._onSearchComplete);
-    var regexp = /(ftp|http|https):\/\/(\w+:{01}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
-    // Magic words "page" or "url" result in the URL of the current page
-    if (fragment == "page" || fragment == "url") {
-      var url = Application.activeWindow.activeTab.document.URL;
-      this.suggestions.push(CmdUtils.makeSugg(url));
-    }
-    // If it's a valid URL, suggest it back
-    if (regexp.test(fragment)) {
-      this.suggestions.push(CmdUtils.makeSugg(fragment));
-    } else if (regexp.test("http://" + fragment)) {
-      this.suggestions.push(CmdUtils.makeSugg("http://" + fragment));
-    }
-    return this.suggestions;
+  suggest: function(fragment, html, callback) {
+    var self = this;
+    this._getHistoryLinks(
+      fragment,
+      function(controller) {
+        self._onSearchComplete(controller, callback);
+      });
+    return [CmdUtils.makeSugg(fragment)];
   }
 };