From 70c60b518c8017156c452d8ce689c791b17a8b77 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Thu, 5 Aug 2010 07:09:15 -0400 Subject: Remove elements based on the configuration JSON file (configData.killNodes object). --- lib/bzpage.js | 6 ++++++ lib/util.js | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/bzpage.js b/lib/bzpage.js index 5e81a74..07e7ea9 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -94,6 +94,12 @@ var BZPage = function BZPage(win, config) { this.setUpLogging(); } + if ("killNodes" in config.gJSONData.configData && + this.hostname in config.gJSONData.configData.killNodes) { + var killConf = config.gJSONData.configData.killNodes[this.hostname]; + util.killNodes(this.doc, killConf[0], killConf[1]) + } + this.setConfigurationButton(); this.submitHandlerInstalled = false; this.bugNo = util.getBugNo(this.doc.location.toString()); diff --git a/lib/util.js b/lib/util.js index 0ab44ce..54af598 100644 --- a/lib/util.js +++ b/lib/util.js @@ -175,6 +175,30 @@ var filterByRegexp = exports.filterByRegexp = } }; +/** + * remove elements from the page based on their IDs + * + * @param doc Document object + * @param target String/Array with ID(s) + * @param remove Boolean indicating whether the node should be + * actually removed or just hidden. + * @return none + * TODO remove parameter could be replaced by function which would + * do actual activity. + */ +exports.killNodes = function killNodes(doc, target, remove) { + target = target.trim(); + var targetArr = target instanceof Array ? target : target.split(/,\s*/); + targetArr.forEach(function(x) { + if (remove) { + var targetNode = doc.getElementById(x); + targetNode.parentNode.removeChild(targetNode); + } else { + x.style.display = "none"; + } + }); +}; + exports.getObjectKeys = function getObjectKeys(obj) { var keys = []; for (var key in obj) { -- cgit