comparison 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
comparison
equal deleted inserted replaced
4:fd988ee76408 5:96bb8d08e94a
50 onSearchComplete(controller); 50 onSearchComplete(controller);
51 }; 51 };
52 52
53 controller.startSearch(partialSearch); 53 controller.startSearch(partialSearch);
54 }, 54 },
55 suggestions: [], 55 _onSearchComplete: function(controller, callback) {
56 _onSearchComplete: function(controller) {
57 var suggs = [];
58 var max_suggs = 5; 56 var max_suggs = 5;
59 for (var i = 0; i < controller.matchCount && i <= max_suggs; i++) { 57 for (var i = 0; i < controller.matchCount && i <= max_suggs; i++) {
60 var result = { 58 var result = {
61 title: controller.getCommentAt(i), 59 title: controller.getCommentAt(i),
62 url: controller.getValueAt(i), 60 url: controller.getValueAt(i),
67 result.title = result.url; 65 result.title = result.url;
68 if (result.image.indexOf("moz-anno:favicon:") == 0) 66 if (result.image.indexOf("moz-anno:favicon:") == 0)
69 result.image = result.image.slice("moz-anno:favicon:".length); 67 result.image = result.image.slice("moz-anno:favicon:".length);
70 else 68 else
71 result.image = ""; 69 result.image = "";
72 suggs.push(CmdUtils.makeSugg(result.title, undefined, result)); 70 callback(CmdUtils.makeSugg(result.title, undefined, result));
73 } 71 }
74 noun_type_url.suggestions = suggs;
75 }, 72 },
76 suggest: function(fragment) { 73 suggest: function(fragment, html, callback) {
77 this._getHistoryLinks(fragment, this._onSearchComplete); 74 var self = this;
78 var regexp = /(ftp|http|https):\/\/(\w+:{01}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; 75 this._getHistoryLinks(
79 // Magic words "page" or "url" result in the URL of the current page 76 fragment,
80 if (fragment == "page" || fragment == "url") { 77 function(controller) {
81 var url = Application.activeWindow.activeTab.document.URL; 78 self._onSearchComplete(controller, callback);
82 this.suggestions.push(CmdUtils.makeSugg(url)); 79 });
83 } 80 return [CmdUtils.makeSugg(fragment)];
84 // If it's a valid URL, suggest it back
85 if (regexp.test(fragment)) {
86 this.suggestions.push(CmdUtils.makeSugg(fragment));
87 } else if (regexp.test("http://" + fragment)) {
88 this.suggestions.push(CmdUtils.makeSugg("http://" + fragment));
89 }
90 return this.suggestions;
91 } 81 }
92 }; 82 };
93 83
94 CmdUtils.CreateCommand( 84 CmdUtils.CreateCommand(
95 {name: "go", 85 {name: "go",