annotate chromeless-browsing/chromeless.js @ 11:8e00d50976d9

Added a 'where-am-i' command to the chromeless browsing feed.
author Atul Varma <varmaa@toolness.com>
date Fri, 27 Mar 2009 20:27:36 -0700
parents 6b955e36a9e9
children 426e9c04c6f9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 CmdUtils.CreateCommand(
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2 {name: "go",
8
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
3 takes: {"search terms": /.*/},
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
4 preview: function(pblock, dobj) {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
5 if (dobj.text.length == 0) {
9
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
6 pblock.innerHTML = "<b>Please enter a search term.</b>";
4
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7 return;
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 }
8
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
9
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
10 var history = Cc["@mozilla.org/autocomplete/search;1?name=history"]
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
11 .createInstance(Ci.nsIAutoCompleteSearch);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
12
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
13 var observer = {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
14 onSearchResult: function onSearchResult(search, result) {
9
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
15 if (result.searchResult == result.RESULT_NOMATCH) {
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
16 pblock.innerHTML = "<b>No matches were found.</b>";
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
17 } else if (result.searchResult == result.RESULT_NOMATCH_ONGOING) {
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
18 pblock.innerHTML = "<b>Please wait...</b>";
6b955e36a9e9 The 'go' command now reports if there are no search results.
Atul Varma <varmaa@toolness.com>
parents: 8
diff changeset
19 } else if (result.searchResult == result.RESULT_SUCCESS ||
8
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
20 result.searchResult == result.RESULT_SUCCESS_ONGOING) {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
21 var html = "";
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
22 for (var i = 0; i < result.matchCount; i++) {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
23 var image = result.getImageAt(i);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
24 var title = result.getCommentAt(i);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
25 var url = result.getValueAt(i);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
26
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
27 if (!title)
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
28 title = url;
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
29
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
30 if (image.indexOf("moz-anno:favicon:") == 0)
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
31 image = image.slice("moz-anno:favicon:".length);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
32 else
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
33 image = "";
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
34
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
35 html += '<div class="gresult">';
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
36 if (image)
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
37 html += ('<img src="' +
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
38 Utils.escapeHtml(image) +
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
39 '"/> ');
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
40 html += ('<a href="' + Utils.escapeHtml(url) + '">' +
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
41 Utils.escapeHtml(title) +
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
42 "</a>");
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
43 html += ('<div class="gresult-url">' + Utils.escapeHtml(url) +
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
44 '</div');
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
45 html += "</div>";
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
46 }
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
47 pblock.innerHTML = html;
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
48 }
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
49 }
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
50 };
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
51
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
52 history.startSearch(
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
53 dobj.text,
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
54 "",
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
55 null,
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
56 observer
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
57 );
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
58
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
59 pblock.addEventListener(
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
60 "preview-change",
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
61 function onPreviewChange() {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
62 pblock.removeEventListener("preview-change", onPreviewChange, false);
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
63 history.stopSearch();
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
64 },
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
65 false);
4
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
66 },
8
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
67 execute: function(dobj) {
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
68 if (dobj.text)
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
69 Utils.openUrlInBrowser(dobj.text);
7
c89423660272 Fixed execute of 'go' cmd to work in all cases.
Atul Varma <varmaa@toolness.com>
parents: 5
diff changeset
70 else
8
abe54fcda16c Suggestions for the 'go' command now show up in the preview area rather than as noun suggestions, since async noun suggestions aren't very mature and suggestions don't have much display room.
Atul Varma <varmaa@toolness.com>
parents: 7
diff changeset
71 displayMessage("No URL was provided.");
4
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
72 }}
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
73 );
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
74
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
75 function cmd_show_tabs() {
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
76 var content = context.chromeWindow.document.getElementById("appcontent");
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
77 var browser = content.firstChild;
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
78 var tabs = browser.tabContainer;
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
79 tabs.style.height = "25px";
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
80 tabs.style.marginTop = "0px";
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
81 }
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
82
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
83 function cmd_hide_tabs() {
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
84 var content = context.chromeWindow.document.getElementById("appcontent");
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
85 var browser = content.firstChild;
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
86 var tabs = browser.tabContainer;
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
87 tabs.style.height = "0px";
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
88 tabs.style.marginTop = "-500px";
fd988ee76408 Added chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
89 }
11
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
90
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
91 CmdUtils.CreateCommand({
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
92 name: "where-am-i",
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
93 preview: function(pblock, dobj) {
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
94 var loc = CmdUtils.getWindow().location;
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
95 pblock.innerHTML = ("Your current URL is <tt>" +
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
96 Utils.escapeHtml(loc.href) + "</tt>.");
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
97 }
8e00d50976d9 Added a 'where-am-i' command to the chromeless browsing feed.
Atul Varma <varmaa@toolness.com>
parents: 9
diff changeset
98 });