aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib/util.js
diff options
context:
space:
mode:
Diffstat (limited to 'data/lib/util.js')
-rw-r--r--data/lib/util.js50
1 files changed, 50 insertions, 0 deletions
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 <br> 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 <a> element diggs out just plain email address
* Note that bugzilla.gnome.org doesn't have mailto: url but