[Pkg-mozext-commits] [requestpolicy] 80/280: [refact] create `DOMUtils.removeChildren`

David Prévot taffit at moszumanska.debian.org
Sat May 2 20:30:02 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository requestpolicy.

commit 69711ceab61537d54c4b3dc6d8ef7062d78f2b9f
Author: Martin Kimmerle <dev at 256k.de>
Date:   Wed Dec 31 12:59:10 2014 +0100

    [refact] create `DOMUtils.removeChildren`
---
 src/content/lib/utils/dom.jsm | 50 +++++++++++++++++++++++++++++++++++++++++++
 src/content/ui/menu.js        | 28 +++++++++++-------------
 src/content/ui/overlay.js     |  7 +++---
 3 files changed, 65 insertions(+), 20 deletions(-)

diff --git a/src/content/lib/utils/dom.jsm b/src/content/lib/utils/dom.jsm
new file mode 100644
index 0000000..0b8dd89
--- /dev/null
+++ b/src/content/lib/utils/dom.jsm
@@ -0,0 +1,50 @@
+/*
+ * ***** BEGIN LICENSE BLOCK *****
+ *
+ * RequestPolicy - A Firefox extension for control over cross-site requests.
+ * Copyright (c) 2008-2012 Justin Samuel
+ * Copyright (c) 2014 Martin Kimmerle
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see {tag: "http"://www.gnu.org/licenses}.
+ *
+ * ***** END LICENSE BLOCK *****
+ */
+
+const Ci = Components.interfaces;
+const Cc = Components.classes;
+const Cu = Components.utils;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+let EXPORTED_SYMBOLS = ["DOMUtils"];
+
+let DOMUtils = {};
+
+/**
+ * Function that takes a DOM Element or an Array of DOM elements and removes
+ * all their children.
+ */
+DOMUtils.removeChildren = function(aElement) {
+  if (aElement instanceof Array) {
+    // if aElement is an Array, recursively call `DOMUtils.removeChildren` on
+    // its elements
+    while (aElement.length > 0) {
+      DOMUtils.removeChildren(aElement.pop())
+    }
+  } else {
+    while (aElement.firstChild) {
+      aElement.removeChild(aElement.firstChild);
+    }
+  }
+};
diff --git a/src/content/ui/menu.js b/src/content/ui/menu.js
index 1ac363a..4c89b8a 100644
--- a/src/content/ui/menu.js
+++ b/src/content/ui/menu.js
@@ -40,6 +40,7 @@ requestpolicy.menu = (function() {
     "ruleset",
     "gui-location",
     "string-utils",
+    "utils/dom",
 
     "requestpolicy-service",
     "constants"
@@ -50,7 +51,8 @@ requestpolicy.menu = (function() {
       Ruleset = mod.Ruleset, GUILocation = mod.GUILocation,
       GUIOrigin = mod.GUIOrigin, GUIDestination = mod.GUIDestination,
       GUILocationProperties = mod.GUILocationProperties,
-      StringUtils = mod.StringUtils, rpService = mod.rpService;
+      StringUtils = mod.StringUtils, DOMUtils = mod.DOMUtils,
+      rpService = mod.rpService;
 
 
   Cu.import("chrome://requestpolicy/content/lib/script-loader.jsm");
@@ -187,12 +189,13 @@ requestpolicy.menu = (function() {
     self._originItem.removeAttribute("default-policy");
     self._originItem.removeAttribute("requests-blocked");
 
-    self._removeChildren(self._otherOriginsList);
-    self._removeChildren(self._blockedDestinationsList);
-    self._removeChildren(self._mixedDestinationsList);
-    self._removeChildren(self._allowedDestinationsList);
-    self._removeChildren(self._removeRulesList);
-    self._removeChildren(self._addRulesList);
+    DOMUtils.removeChildren([
+        self._otherOriginsList,
+        self._blockedDestinationsList,
+        self._mixedDestinationsList,
+        self._allowedDestinationsList,
+        self._removeRulesList,
+        self._addRulesList]);
     document.getElementById('rp-other-origins').hidden = true;
     document.getElementById('rp-blocked-destinations').hidden = true;
     document.getElementById('rp-mixed-destinations').hidden = true;
@@ -201,7 +204,7 @@ requestpolicy.menu = (function() {
   };
 
   self._populateList = function(list, values) {
-    self._removeChildren(list);
+    DOMUtils.removeChildren(list);
 
     // check whether there are objects of GUILocation or just strings
     var guiLocations = values[0] && (values[0] instanceof GUILocation);
@@ -340,8 +343,7 @@ requestpolicy.menu = (function() {
   self._populateDetails = function() {
     var origin = self._currentlySelectedOrigin;
     var dest = self._currentlySelectedDest;
-    self._removeChildren(self._removeRulesList);
-    self._removeChildren(self._addRulesList);
+    DOMUtils.removeChildren([self._removeRulesList, self._addRulesList]);
 
     var ruleData = {
       'o' : {
@@ -444,12 +446,6 @@ requestpolicy.menu = (function() {
     self._populateDetailsRemoveDenyRules(self._removeRulesList);
   };
 
-  self._removeChildren = function(el) {
-    while (el.firstChild) {
-      el.removeChild(el.firstChild);
-    }
-  };
-
   self._addListItem = function(list, cssClass, value, numRequests) {
     var hbox = document.createElement("hbox");
     hbox.setAttribute("class", cssClass);
diff --git a/src/content/ui/overlay.js b/src/content/ui/overlay.js
index 47e5a02..f82a2f8 100644
--- a/src/content/ui/overlay.js
+++ b/src/content/ui/overlay.js
@@ -43,12 +43,14 @@ requestpolicy.overlay = (function() {
     "request-processor",
     "domain-util",
     "string-utils",
+    "utils/dom",
     "requestpolicy-service",
     "policy-manager"
   ], mod);
   let MMID = mod.MMID, Logger = mod.Logger, rpPrefBranch = mod.rpPrefBranch,
       Prefs = mod.Prefs, RequestProcessor = mod.RequestProcessor,
       DomainUtil = mod.DomainUtil, StringUtils = mod.StringUtils,
+      DOMUtils = mod.DOMUtils,
       rpService = mod.rpService, PolicyManager = mod.PolicyManager;
 
   //let _extensionConflictInfoUri = "http://www.requestpolicy.com/conflict?ext=";
@@ -470,12 +472,9 @@ requestpolicy.overlay = (function() {
                                              [cropUri(redirectTargetUri, 50)],
                                              1);
 
-    // TODO: create `XULUtils.removeAllChildren`
     var addRuleMenuName = "requestpolicyRedirectAddRuleMenu";
     var addRulePopup = document.getElementById(addRuleMenuName);
-    while (addRulePopup.firstChild) {
-      addRulePopup.removeChild(addRulePopup.firstChild);
-    }
+    DOMUtils.removeChildren(addRulePopup);
 
     let m = requestpolicy.menu;
     var origin = m._addWildcard(DomainUtil.getBaseDomain(redirectOriginUri));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/requestpolicy.git



More information about the Pkg-mozext-commits mailing list