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

Side by Side Diff: lib/ui.js

Issue 5294633391226880: issue 1435 - Port popup.html from Chrome/Safari/Opera to Firefox (Closed)
Patch Set: Created Sept. 26, 2014, 12:48 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« chrome/skin/popup.css ('K') | « chrome/skin/popup.png ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 16 matching lines...) Expand all
27 let {Filter} = require("filterClasses"); 27 let {Filter} = require("filterClasses");
28 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses"); 28 let {Subscription, SpecialSubscription, DownloadableSubscription} = require("sub scriptionClasses");
29 let {Synchronizer} = require("synchronizer"); 29 let {Synchronizer} = require("synchronizer");
30 let {KeySelector} = require("keySelector"); 30 let {KeySelector} = require("keySelector");
31 let {Notification} = require("notification"); 31 let {Notification} = require("notification");
32 let {initAntiAdblockNotification} = require("antiadblockInit"); 32 let {initAntiAdblockNotification} = require("antiadblockInit");
33 33
34 let CustomizableUI = null; 34 let CustomizableUI = null;
35 35
36 /** 36 /**
37 * Filter corresponding with "disable on site" menu item (set in fillIconMent()) . 37 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) .
38 * @type Filter 38 * @type Filter
39 */ 39 */
40 let siteWhitelist = null; 40 let siteWhitelist = null;
41 /** 41 /**
42 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) . 42 * Filter corresponding with "disable on site" menu item (set in fillIconMenu()) .
43 * @type Filter 43 * @type Filter
44 */ 44 */
45 let pageWhitelist = null; 45 let pageWhitelist = null;
46 46
47 /** 47 /**
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 380
381 if ("abp-status-popup" in this.overlay) 381 if ("abp-status-popup" in this.overlay)
382 { 382 {
383 let menuSource = this.overlay["abp-status-popup"]; 383 let menuSource = this.overlay["abp-status-popup"];
384 delete this.overlay["abp-status-popup"]; 384 delete this.overlay["abp-status-popup"];
385 385
386 if (this.overlay.all.length) 386 if (this.overlay.all.length)
387 this.overlay.all[0].appendChild(menuSource); 387 this.overlay.all[0].appendChild(menuSource);
388 if ("abp-toolbarbutton" in this.overlay) 388 if ("abp-toolbarbutton" in this.overlay)
389 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode (true), "abp-toolbar")); 389 this.overlay["abp-toolbarbutton"].appendChild(fixId(menuSource.cloneNode (true), "abp-toolbar"));
390 if ("abp-menuitem" in this.overlay)
391 this.overlay["abp-menuitem"].appendChild(fixId(menuSource.cloneNode(true ), "abp-menuitem"));
392 } 390 }
393 }, 391 },
394 392
395 /** 393 /**
396 * Gets called once the initialization is finished and Adblock Plus elements 394 * Gets called once the initialization is finished and Adblock Plus elements
397 * can be added to the UI. 395 * can be added to the UI.
398 */ 396 */
399 initDone: function() 397 initDone: function()
400 { 398 {
401 // The icon might be added already, make sure its state is correct 399 // The icon might be added already, make sure its state is correct
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 554
557 // Attach event handlers 555 // Attach event handlers
558 for (let i = 0; i < eventHandlers.length; i++) 556 for (let i = 0; i < eventHandlers.length; i++)
559 { 557 {
560 let [id, event, handler] = eventHandlers[i]; 558 let [id, event, handler] = eventHandlers[i];
561 let element = window.document.getElementById(id); 559 let element = window.document.getElementById(id);
562 if (element) 560 if (element)
563 element.addEventListener(event, handler.bind(null, window), false); 561 element.addEventListener(event, handler.bind(null, window), false);
564 } 562 }
565 window.addEventListener("popupshowing", this.onPopupShowing, false); 563 window.addEventListener("popupshowing", this.onPopupShowing, false);
564 window.addEventListener("popuphiding", this.onPopupHiding, false);
566 window.addEventListener("keypress", this.onKeyPress, false); 565 window.addEventListener("keypress", this.onKeyPress, false);
567 566
568 addBrowserLocationListener(window, function() 567 addBrowserLocationListener(window, function()
569 { 568 {
570 this.updateIconState(window, window.document.getElementById("abp-status")) ; 569 this.updateIconState(window, window.document.getElementById("abp-status")) ;
571 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton")); 570 this.updateIconState(window, window.document.getElementById("abp-toolbarbu tton"));
572 }.bind(this)); 571 }.bind(this));
573 addBrowserClickListener(window, this.onBrowserClick.bind(this, window)); 572 addBrowserClickListener(window, this.onBrowserClick.bind(this, window));
574 573
575 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event) 574 window.document.getElementById("abp-notification-close").addEventListener("c ommand", function(event)
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 618 }
620 else 619 else
621 { 620 {
622 let clone = window.document.getElementById(id); 621 let clone = window.document.getElementById(id);
623 if (clone) 622 if (clone)
624 clone.parentNode.removeChild(clone); 623 clone.parentNode.removeChild(clone);
625 } 624 }
626 } 625 }
627 626
628 window.removeEventListener("popupshowing", this.onPopupShowing, false); 627 window.removeEventListener("popupshowing", this.onPopupShowing, false);
628 window.removeEventListener("popuphiding", this.onPopupHiding, false);
629 window.removeEventListener("keypress", this.onKeyPress, false); 629 window.removeEventListener("keypress", this.onKeyPress, false);
630 removeBrowserLocationListeners(window); 630 removeBrowserLocationListeners(window);
631 removeBrowserClickListeners(window); 631 removeBrowserClickListeners(window);
632 }, 632 },
633 633
634 /** 634 /**
635 * The overlay information to be used when adding elements to the UI. 635 * The overlay information to be used when adding elements to the UI.
636 * @type Object 636 * @type Object
637 */ 637 */
638 overlay: null, 638 overlay: null,
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 let {contentContextMenu} = require("appSupport"); 1283 let {contentContextMenu} = require("appSupport");
1284 if ((typeof contentContextMenu == "string" && popup.id == contentContextMenu ) || 1284 if ((typeof contentContextMenu == "string" && popup.id == contentContextMenu ) ||
1285 (contentContextMenu instanceof Array && contentContextMenu.indexOf(popup .id) >= 0)) 1285 (contentContextMenu instanceof Array && contentContextMenu.indexOf(popup .id) >= 0))
1286 { 1286 {
1287 this.fillContentContextMenu(popup); 1287 this.fillContentContextMenu(popup);
1288 } 1288 }
1289 else if (popup.id == "abp-tooltip") 1289 else if (popup.id == "abp-tooltip")
1290 this.fillIconTooltip(event, popup.ownerDocument.defaultView); 1290 this.fillIconTooltip(event, popup.ownerDocument.defaultView);
1291 else 1291 else
1292 { 1292 {
1293 let match = /^(abp-(?:toolbar|status|menuitem)-)popup$/.exec(popup.id); 1293 let match = /^(abp-(toolbar|status|menuitem)-)popup$/.exec(popup.id);
1294 if (match) 1294 if (match)
1295 this.fillIconMenu(event, popup.ownerDocument.defaultView, match[1]); 1295 {
Thomas Greiner 2014/09/29 16:19:49 What about adding the following line to avoid acce
saroyanm 2014/10/02 07:53:56 I like it. Done.
1296 if (match[2] == "toolbar" || match[2] == "status")
1297 {
1298 let window = popup.ownerDocument.defaultView;
1299 let browser = window.document.getElementById(match[1] + "popup-browser ");
1300 browser.setAttribute("src", "chrome://adblockplus/content/ui/popup.htm l");
1301 }
1302 else
1303 this.fillIconMenu(event, popup.ownerDocument.defaultView, match[1]);
1304 }
1296 } 1305 }
1297 }, 1306 },
1298 1307
1308 /**
1309 * Called when some pop-up in the application window is being hidden
1310 */
1311 onPopupHiding: function(/**Event*/ event)
1312 {
1313 if (event.defaultPrevented)
1314 return;
1315
1316 let popup = event.originalTarget;
1317 if (popup.id == "abp-toolbar-popup")
1318 {
1319 let window = popup.ownerDocument.defaultView;
1320 let browser = window.document.getElementById("abp-toolbar-popup-browser");
1321 browser.setAttribute("src", "about:blank");
1322 }
1323 },
1324
1299 /** 1325 /**
1300 * Handles click on toolbar and status bar icons. 1326 * Handles click on toolbar and status bar icons.
1301 */ 1327 */
1302 onIconClick: function(/**Event*/ event) 1328 onIconClick: function(/**Event*/ event)
1303 { 1329 {
1304 if (event.eventPhase != event.AT_TARGET) 1330 if (event.eventPhase != event.AT_TARGET)
1305 return; 1331 return;
1306 1332
1307 let isToolbar = (event.target.localName != "statusbarpanel"); 1333 let isToolbar = (event.target.localName != "statusbarpanel");
1308 let action = 0; 1334 let action = 0;
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 window.document.getElementById("abp-notification-yes").onclick = buttonHan dler.bind(null, true); 1944 window.document.getElementById("abp-notification-yes").onclick = buttonHan dler.bind(null, true);
1919 window.document.getElementById("abp-notification-no").onclick = buttonHand ler.bind(null, false); 1945 window.document.getElementById("abp-notification-no").onclick = buttonHand ler.bind(null, false);
1920 } 1946 }
1921 1947
1922 panel.setAttribute("class", "abp-" + notification.type); 1948 panel.setAttribute("class", "abp-" + notification.type);
1923 panel.setAttribute("noautohide", notification.type === "question"); 1949 panel.setAttribute("noautohide", notification.type === "question");
1924 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null); 1950 panel.openPopup(button, "bottomcenter topcenter", 0, 0, false, false, null);
1925 } 1951 }
1926 }; 1952 };
1927 UI.onPopupShowing = UI.onPopupShowing.bind(UI); 1953 UI.onPopupShowing = UI.onPopupShowing.bind(UI);
1954 UI.onPopupHiding = UI.onPopupHiding.bind(UI);
1928 UI.onKeyPress = UI.onKeyPress.bind(UI); 1955 UI.onKeyPress = UI.onKeyPress.bind(UI);
1929 UI.onIconClick = UI.onIconClick.bind(UI); 1956 UI.onIconClick = UI.onIconClick.bind(UI);
1930 UI.init(); 1957 UI.init();
1931 1958
1932 /** 1959 /**
1933 * List of event handers to be registered for each window. For each event 1960 * List of event handers to be registered for each window. For each event
1934 * handler the element ID, event and the actual event handler are listed. 1961 * handler the element ID, event and the actual event handler are listed.
1935 * @type Array 1962 * @type Array
1936 */ 1963 */
1937 let eventHandlers = [ 1964 let eventHandlers = [
(...skipping 12 matching lines...) Expand all
1950 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)], 1977 ["abp-command-contribute", "command", UI.openContributePage.bind(UI)],
1951 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)] 1978 ["abp-command-contribute-hide", "command", UI.hideContributeButton.bind(UI)]
1952 ]; 1979 ];
1953 1980
1954 onShutdown.add(function() 1981 onShutdown.add(function()
1955 { 1982 {
1956 for (let window in UI.applicationWindows) 1983 for (let window in UI.applicationWindows)
1957 if (UI.isBottombarOpen(window)) 1984 if (UI.isBottombarOpen(window))
1958 UI.toggleBottombar(window); 1985 UI.toggleBottombar(window);
1959 }); 1986 });
OLDNEW
« chrome/skin/popup.css ('K') | « chrome/skin/popup.png ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld