From 30e385c55f492ddc99341f7244f501743a48eae8 Mon Sep 17 00:00:00 2001 From: Veno Server Date: Fri, 2 Oct 2009 02:16:49 -0500 Subject: [PATCH] Minor sanity check fixes in functions - don't attempt to deep clone an object that might not exist, check for the existance of a native Array.swap before implementing our own, and properly check for jQuery support when displaying changes (ideally this'll be moved out anyway) --- js/franz.js | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/js/franz.js b/js/franz.js index c880fde..73b73b3 100644 --- a/js/franz.js +++ b/js/franz.js @@ -6,11 +6,13 @@ /* Define some basic prototypes that we'll require later.. */ -Array.prototype.swap = function(a, b) { - var tmp = this[a]; - this[a] = this[b]; - this[b] = tmp; - return true; /* For the sake of being complete */ +if(!Array.prototype.swap) { + Array.prototype.swap = function(a, b) { + var tmp = this[a]; + this[a] = this[b]; + this[b] = tmp; + return true; /* For the sake of being complete */ + } } /* allows numeric sorting for built in js sort */ @@ -42,19 +44,21 @@ var franz = { }, clone: function(obj) { - /* Recursively iterate through objects and clone them (Don't even try to put this on the Object prototype (recursion fail)) */ - var returnObj = (obj instanceof Array) ? [] : {}; + if(typeof obj !== "undefined") { + /* Recursively iterate through objects and clone them (Don't even try to put this on the Object prototype (recursion fail)) */ + var returnObj = (obj instanceof Array) ? [] : {}; - for(i in obj) { - if(i == 'clone') continue; - if(obj[i] != null && typeof obj[i] == "object") { - returnObj[i] = franz.clone(obj[i]); - } else { - returnObj[i] = obj[i]; + for(i in obj) { + if(i == 'clone') continue; + if(obj[i] != null && typeof obj[i] == "object") { + returnObj[i] = franz.clone(obj[i]); + } else { + returnObj[i] = obj[i]; + } } - } - return returnObj; + return returnObj; + } }, loadImg: function(img_src) { @@ -169,7 +173,7 @@ var franz = { } document.getElementById("log_colors").innerHTML = docStr; - if(typeof jQuery != "undefined") { + if(typeof jQuery !== "undefined") { $("#container_bottom").fadeIn("fast"); setTimeout(function() { $("#testLayout").fadeIn("slow"); }, 500); }