Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: lib/main.js

Issue 8402021: Crawler frontend (Closed)
Patch Set: Created Sept. 26, 2012, 8:25 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/crawler.js ('k') | lib/storage.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This Source Code is subject to the terms of the Mozilla Public License
3 * version 2.0 (the "License"). You can obtain a copy of the License at
4 * http://mozilla.org/MPL/2.0/.
5 */
6
7 Cu.import("resource://gre/modules/Services.jsm");
8
9 let {WindowObserver} = require("windowObserver");
10
11 let knownWindowTypes =
12 {
13 "navigator:browser": true,
14 __proto__: null
15 };
16
17 new WindowObserver({
18 applyToWindow: function(window)
19 {
20 let type = window.document.documentElement.getAttribute("windowtype");
21 if (!(type in knownWindowTypes))
22 return;
23
24 window.addEventListener("popupshowing", popupShowingHandler, false);
25 window.addEventListener("popuphidden", popupHiddenHandler, false);
26 },
27
28 removeFromWindow: function(window)
29 {
30 let type = window.document.documentElement.getAttribute("windowtype");
31 if (!(type in knownWindowTypes))
32 return;
33
34 window.removeEventListener("popupshowing", popupShowingHandler, false);
35 window.removeEventListener("popuphidden", popupHiddenHandler, false);
36 }
37 });
38
39 function getMenuItem()
40 {
41 // Randomize URI to work around bug 719376
42 let stringBundle = Services.strings.createBundle("chrome://abpcrawler/locale/g lobal.properties?" + Math.random());
43 let result = [stringBundle.GetStringFromName("crawler.label")];
44
45 getMenuItem = function() result;
46 return getMenuItem();
47 }
48
49 function popupShowingHandler(event)
50 {
51 let popup = event.target;
52 if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id))
53 return;
54
55 popupHiddenHandler(event);
56
57 let [label] = getMenuItem();
58 let item = popup.ownerDocument.createElement("menuitem");
59 item.setAttribute("label", label);
60 item.setAttribute("class", "abpcrawler-item");
61
62 item.addEventListener("command", popupCommandHandler, false);
63
64 let insertBefore = null;
65 for (let child = popup.firstChild; child; child = child.nextSibling)
66 if (/-options$/.test(child.id))
67 insertBefore = child;
68 popup.insertBefore(item, insertBefore);
69 }
70
71 function popupHiddenHandler(event)
72 {
73 let popup = event.target;
74 if (!/^(abp-(?:toolbar|status|menuitem)-)popup$/.test(popup.id))
75 return;
76
77 let items = popup.getElementsByClassName("abpcrawler-item");
78 while (items.length)
79 items[0].parentNode.removeChild(items[0]);
80 }
81
82 function popupCommandHandler(event)
83 {
84 if (!("@adblockplus.org/abp/public;1" in Cc))
85 return;
86
87 let crawlerWnd = Services.wm.getMostRecentWindow("abpcrawler:crawl");
88 if (crawlerWnd)
89 crawlerWnd.focus();
90 else
91 event.target.ownerDocument.defaultView.openDialog("chrome://abpcrawler/conte nt/crawler.xul", "_blank", "chrome,centerscreen,resizable,dialog=no");
92 }
OLDNEW
« no previous file with comments | « lib/crawler.js ('k') | lib/storage.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld