From ea71f2b3c7d6b7e8a2a63669aa818d79ad85ffa0 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 2 Mar 2011 16:23:39 +0100 Subject: Separate logging front-end into special content script. --- data/lib/util.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'data/lib/util.js') diff --git a/data/lib/util.js b/data/lib/util.js index 6c204ff..0ecc318 100644 --- a/data/lib/util.js +++ b/data/lib/util.js @@ -80,6 +80,56 @@ function getBugNoFromURL(url) { } } +/** + * Create a A element leadink nowhere, but with listener running a callback on the click + * + * @param id String with a id to be added to the element + * @param text String with a string to be added as a textContent of the element + * @param parent Node which is a parent of the object + * @param callback Function to be called after clicking on the link + * @param params Array with parameters of the callback + * @param Boolean before if there should be a
element before. + * @return none + */ +function createDeadLink (id, text, parent, callback, params, before, covered, accesskey) { + params = valToArray(params); + var locParent = {}; + + // Yes, I want != here, not !== + if (covered != null) { + locParent = document.createElement(covered); + parent.appendChild(locParent); + } else { + locParent = parent; + } + + var newAElem = document.createElement("a"); + newAElem.setAttribute("id", id); + if (accesskey) { + newAElem.setAttribute("accesskey", accesskey); + } + newAElem.textContent = text; + + if (typeof callback === "string") { + newAElem.setAttribute("href", callback); + } else { + newAElem.setAttribute("href", ""); + newAElem.addEventListener("click", function(evt) { + callback.apply(null, params); + evt.stopPropagation(); + evt.preventDefault(); + }, false); + } + + if ((before === "br") || (before === true)) { + locParent.appendChild(document.createElement("br")); + } else if (before === "dash") { + locParent.appendChild(document.createTextNode("\u00A0-\u00A0")); + } + + locParent.appendChild(newAElem); +} + /* * From element diggs out just plain email address * Note that bugzilla.gnome.org doesn't have mailto: url but -- cgit