95328fb0bb6c720fc0c74d951fb7a15924d1de97 tdreszer Wed Jun 4 13:05:08 2014 -0700 Undeclared variables do not pass the 'truthiness' test without error. Redmine #13385. diff --git src/hg/js/utils.js src/hg/js/utils.js index 748f690..36cbe07 100644 --- src/hg/js/utils.js +++ src/hg/js/utils.js @@ -88,31 +88,31 @@ } else { // NS 4.x - I gave up trying to get this to work. if (debugLevel>2) alert("arrayOfInputsThatMatch is unimplemented for this browser"); } return found; } function normed(thing) { // RETURNS undefined, the lone member of the set or the full set if more than one member. // Used for normalizing returns from jquery DOM selects (e.g. $('tr.track').children('td.data')) // jquery returns an "array like 'object'" with 0 or more entries. // May be used on non-jquery objects and will reduce single element arrays to the element. // Use this to treat 0 entries the same as undefined and 1 entry as the item itself - if (thing === undefined || thing === null + if (typeof(thing) === 'undefined' || thing === null || (thing.length !== undefined && thing.length === 0) // Empty array (or 'array like object') || ($.isPlainObject(thing) && $.isEmptyObject(thing))) // Empty simple object return undefined; if (thing.length && thing.length === 1 && jQuery.type(thing) !== 'string') // string is overkill return thing[0]; // Container of one item should return the item itself. return thing; } function waitCursor(obj) // DEAD CODE? { //document.body.style.cursor="wait" obj.style.cursor="wait"; } function endWaitCursor(obj) // DEAD CODE? @@ -849,73 +849,74 @@ } function getHgsid() {// return current session id // .first() because hgTracks turned up 3 of these! var hgsid = normed($("input[name='hgsid']").first()); if (hgsid) return hgsid.value; hgsid = getURLParam(window.location.href, "hgsid"); if (hgsid.length > 0) return hgsid; // This may be moved to 1st position as the most likely source - if (common && common.hgsid !== undefined && common.hgsid !== null) + if (typeof(common) !== 'undefined' && typeof(common.hgsid) !== 'undefined' + && common.hgsid !== null) return common.hgsid; hgsid = normed($("input#hgsid").first()); if (hgsid) return hgsid.value; return ""; } function getDb() { var db = normed($("input[name='db']").first()); if (db) return db.value; db = getURLParam(window.location.href, "db"); if (db.length > 0) return db; // This may be moved to 1st position as the most likely source - if (common && common.db) + if (typeof(common) !== 'undefined' && typeof(common.db) !== 'undefined') return common.db; db = normed($("input#db").first()); if (db) return db.value; return ""; } function getTrack() { var track = normed($("input[name='g']").first()); if (track) return track.value; track = getURLParam(window.location.href, "g"); if (track.length > 0) return track; // This may be moved to 1st position as the most likely source - if (common && common.track) + if (typeof(common) !== 'undefined' && typeof(common.track) !== 'undefined') return common.track; track = normed($("input#g").first()); if (track) return track.value; return ""; } function Rectangle() // DEAD CODE? { // Rectangle object constructor: // calling syntax: // // new Rectangle(startX, endX, startY, endY)