aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib/util.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-23 20:18:23 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-23 20:18:23 +0100
commit2e5993bc9bd0d468f4e9d12dd39e0548ba9adda1 (patch)
treef31a0d612efbfa5beb78e4718768c55c650f14d8 /data/lib/util.js
parentc662ccddab2cbcc6d13f49a21c04a6aea808f457 (diff)
downloadbugzilla-triage-2e5993bc9bd0d468f4e9d12dd39e0548ba9adda1.tar.gz
Fix indentation and else for Mozilla coding guidelines.
Diffstat (limited to 'data/lib/util.js')
-rw-r--r--data/lib/util.js293
1 files changed, 149 insertions, 144 deletions
diff --git a/data/lib/util.js b/data/lib/util.js
index e51a657..f336a7f 100644
--- a/data/lib/util.js
+++ b/data/lib/util.js
@@ -19,31 +19,31 @@
* operations are used (to normalize results across browsers).
*/
function parseURL(url) {
- var a = document.createElement('a');
- a.href = url;
- return {
- source: url,
- protocol: a.protocol.replace(':',''),
- host: a.hostname,
- port: a.port,
- query: a.search,
- params: (function(){
- var ret = {},
- seg = a.search.replace(/^\?/,'').split('&'),
- len = seg.length, i = 0, s;
- for (;i<len;i++) {
- if (!seg[i]) { continue; }
- s = seg[i].split('=');
- ret[s[0]] = s[1];
- }
- return ret;
- })(),
- file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
- hash: a.hash.replace('#',''),
- path: a.pathname.replace(/^([^\/])/,'/$1'),
- relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
- segments: a.pathname.replace(/^\//,'').split('/')
- };
+ var a = document.createElement('a');
+ a.href = url;
+ return {
+ source: url,
+ protocol: a.protocol.replace(':',''),
+ host: a.hostname,
+ port: a.port,
+ query: a.search,
+ params: (function(){
+ var ret = {},
+ seg = a.search.replace(/^\?/,'').split('&'),
+ len = seg.length, i = 0, s;
+ for (;i<len;i++) {
+ if (!seg[i]) { continue; }
+ s = seg[i].split('=');
+ ret[s[0]] = s[1];
+ }
+ return ret;
+ })(),
+ file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1],
+ hash: a.hash.replace('#',''),
+ path: a.pathname.replace(/^([^\/])/,'/$1'),
+ relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [,''])[1],
+ segments: a.pathname.replace(/^\//,'').split('/')
+ };
}
/**
@@ -54,18 +54,18 @@ function parseURL(url) {
* @return XML object
*/
function parseXMLfromString (inStuff) {
- // if (typeof inStuff !== 'string') In future we should recognize this.response
- // and get just .text property out of it. TODO
- var respStr = inStuff.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551
- return new XML(respStr);
+ // if (typeof inStuff !== 'string') In future we should recognize this.response
+ // and get just .text property out of it. TODO
+ var respStr = inStuff.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551
+ return new XML(respStr);
}
/**
* Get a bug no
*/
function getBugNo() {
- console.log("bugNo = " + document.forms.namedItem('changeform').getElementsByName("id")[0].value);
- return document.forms.namedItem('changeform').getElementsByName("id")[0].value;
+ console.log("bugNo = " + document.forms.namedItem('changeform').getElementsByName("id")[0].value);
+ return document.forms.namedItem('changeform').getElementsByName("id")[0].value;
}
/**
@@ -74,10 +74,10 @@ function getBugNo() {
* @return String with the bug ID
*/
function getBugNoFromURL(url) {
- var params = parseURL(url).params;
- if (params && params.id) {
- return params.id;
- }
+ var params = parseURL(url).params;
+ if (params && params.id) {
+ return params.id;
+ }
}
/**
@@ -92,43 +92,46 @@ function getBugNoFromURL(url) {
* @return none
*/
function createDeadLink (id, text, parent, callback, params, before, covered, accesskey) {
- params = valToArray(params);
- var locParent = {};
+ params = valToArray(params);
+ var locParent = {};
- // Yes, I want != here, not !==
- if (covered != null) {
- locParent = document.createElement(covered);
- parent.appendChild(locParent);
- } else {
- locParent = parent;
- }
+ // 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;
+ 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) {
- evt.stopPropagation();
- evt.preventDefault();
- // We need apply, because params could be array of parameters
- callback.apply(null, params);
- }, false);
- }
+ if (typeof callback === "string") {
+ newAElem.setAttribute("href", callback);
+ }
+ else {
+ newAElem.setAttribute("href", "");
+ newAElem.addEventListener("click", function(evt) {
+ evt.stopPropagation();
+ evt.preventDefault();
+ // We need apply, because params could be array of parameters
+ callback.apply(null, params);
+ }, false);
+ }
- if ((before === "br") || (before === true)) {
- locParent.appendChild(document.createElement("br"));
- } else if (before === "dash") {
- locParent.appendChild(document.createTextNode("\u00A0-\u00A0"));
- }
+ if ((before === "br") || (before === true)) {
+ locParent.appendChild(document.createElement("br"));
+ }
+ else if (before === "dash") {
+ locParent.appendChild(document.createTextNode("\u00A0-\u00A0"));
+ }
- locParent.appendChild(newAElem);
+ locParent.appendChild(newAElem);
}
/*
@@ -141,19 +144,19 @@ function createDeadLink (id, text, parent, callback, params, before, covered, ac
*
*/
function parseMailto(aElement) {
- var emailStr = "", hrefStr = "";
- // use url utils
- if (aElement) {
- hrefStr = decodeURIComponent(aElement.getAttribute("href"));
- emailStr = hrefStr.split(":");
- // workaround for Gnome bugzilla ... no mailto: here.
- if (emailStr.length < 2) {
- var params = parseURL("https://" + window.location.hostname + "/" + hrefStr).params;
- return decodeURI(params.login);
- }
- return emailStr[1];
+ var emailStr = "", hrefStr = "";
+ // use url utils
+ if (aElement) {
+ hrefStr = decodeURIComponent(aElement.getAttribute("href"));
+ emailStr = hrefStr.split(":");
+ // workaround for Gnome bugzilla ... no mailto: here.
+ if (emailStr.length < 2) {
+ var params = parseURL("https://" + window.location.hostname + "/" + hrefStr).params;
+ return decodeURI(params.login);
}
- return null;
+ return emailStr[1];
+ }
+ return null;
}
/**
@@ -163,12 +166,12 @@ function parseMailto(aElement) {
* @return string with the formatted date
*/
function getISODate(dateStr) {
- function pad(n) {
- return n < 10 ? '0' + n : n;
- }
- var date = new Date(dateStr);
- return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' +
- pad(date.getDate());
+ function pad(n) {
+ return n < 10 ? '0' + n : n;
+ }
+ var date = new Date(dateStr);
+ return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' +
+ pad(date.getDate());
}
/**
@@ -180,10 +183,10 @@ function getISODate(dateStr) {
* @return position of the string in the list, or -1 if none found.
*/
function isInList(mbr, list) {
- if (!list) {
- return false;
- }
- return (list.indexOf(mbr) !== -1);
+ if (!list) {
+ return false;
+ }
+ return (list.indexOf(mbr) !== -1);
};
/**
@@ -196,10 +199,10 @@ function isInList(mbr, list) {
* the result will be untouched actual argument of the call.
*/
function valToArray(val) {
- var isArr = val &&
- val.constructor &&
- val.constructor.name === "Array";
- return isArr ? val : [val];
+ var isArr = val &&
+ val.constructor &&
+ val.constructor.name === "Array";
+ return isArr ? val : [val];
}
/**
@@ -210,18 +213,18 @@ function valToArray(val) {
* @return String with merged lists
*/
function addCSVValue(str, value) {
- var parts = (str.trim().length > 0 ? str.split(/[,\s]+/) : []);
- if (!value) {
- return str;
- }
- if (!isInList(value, parts)) {
- var newValue = valToArray(value);
- parts = parts.concat(newValue);
- }
- // this is necessary to get comma-space separated string even when
- // value is an array already
- parts = parts.join(",").split(",");
- return parts.join(", ");
+ var parts = (str.trim().length > 0 ? str.split(/[,\s]+/) : []);
+ if (!value) {
+ return str;
+ }
+ if (!isInList(value, parts)) {
+ var newValue = valToArray(value);
+ parts = parts.concat(newValue);
+ }
+ // this is necessary to get comma-space separated string even when
+ // value is an array already
+ parts = parts.join(",").split(",");
+ return parts.join(", ");
}
/**
@@ -232,13 +235,13 @@ function addCSVValue(str, value) {
* @return String with the resulting list comma separated
*/
function removeCSVValue(str, value) {
- str = str.trim();
- var parts = str ? str.split(/[,\s]+/) : [];
- var valueArr = value instanceof Array ? value : value.split(/[,\s]+/);
- parts = parts.filter(function (e, i, a) {
- return (!isInList(e, valueArr));
- });
- return parts.join(", ");
+ str = str.trim();
+ var parts = str ? str.split(/[,\s]+/) : [];
+ var valueArr = value instanceof Array ? value : value.split(/[,\s]+/);
+ parts = parts.filter(function (e, i, a) {
+ return (!isInList(e, valueArr));
+ });
+ return parts.join(", ");
}
/**
@@ -250,17 +253,18 @@ function removeCSVValue(str, value) {
* @return Object chosen element
*/
function filterByRegexp(list, chosingMark) {
- var chosenPair = [];
- if (list.length > 0) {
- chosenPair = list.filter(function (pair) {
- return new RegExp(pair.regexp, "i").test(chosingMark);
- });
- }
- if (chosenPair.length > 0) {
- return chosenPair[0].addr;
- } else {
- return "";
- }
+ var chosenPair = [];
+ if (list.length > 0) {
+ chosenPair = list.filter(function (pair) {
+ return new RegExp(pair.regexp, "i").test(chosingMark);
+ });
+ }
+ if (chosenPair.length > 0) {
+ return chosenPair[0].addr;
+ }
+ else {
+ return "";
+ }
}
/**
@@ -275,16 +279,17 @@ function filterByRegexp(list, chosingMark) {
* do actual activity.
*/
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";
- }
- });
+ 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";
+ }
+ });
}
/**
@@ -295,22 +300,22 @@ function killNodes(doc, target, remove) {
*/
function removeDuplicates (arr) {
for (var i = 0; i < arr.length; i++) {
- for (var j = i + 1; j < arr.length; j++) {
- if (arr[i] == arr[j]) {
- arr.splice (j, 1);
- }
+ for (var j = i + 1; j < arr.length; j++) {
+ if (arr[i] == arr[j]) {
+ arr.splice (j, 1);
}
}
+ }
return arr;
}
// ============================================
/**
* object to pack messaging. Use as in
- postMessage(new Message("GetPassword", {
- login: login,
- hostname: location.hostname
- }));
+ postMessage(new Message("GetPassword", {
+ login: login,
+ hostname: location.hostname
+ }));
*/
function Message(cmd, data) {
this.cmd = cmd;
@@ -322,10 +327,10 @@ function log(msg) {
}
var NotLoggedinException = function NotLoggedinException (message) {
- this.message = message;
- this.name = "NotLoggedinException";
+ this.message = message;
+ this.name = "NotLoggedinException";
};
NotLoggedinException.prototype.toString = function () {
- return this.name + ': "' + this.message + '"';
+ return this.name + ': "' + this.message + '"';
};