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)

This commit is contained in:
Veno Server 2009-10-02 02:16:49 -05:00
parent f865073ea8
commit 30e385c55f

View file

@ -6,11 +6,13 @@
/* Define some basic prototypes that we'll require later.. */ /* Define some basic prototypes that we'll require later.. */
Array.prototype.swap = function(a, b) { if(!Array.prototype.swap) {
var tmp = this[a]; Array.prototype.swap = function(a, b) {
this[a] = this[b]; var tmp = this[a];
this[b] = tmp; this[a] = this[b];
return true; /* For the sake of being complete */ this[b] = tmp;
return true; /* For the sake of being complete */
}
} }
/* allows numeric sorting for built in js sort */ /* allows numeric sorting for built in js sort */
@ -42,19 +44,21 @@ var franz = {
}, },
clone: function(obj) { clone: function(obj) {
/* Recursively iterate through objects and clone them (Don't even try to put this on the Object prototype (recursion fail)) */ if(typeof obj !== "undefined") {
var returnObj = (obj instanceof Array) ? [] : {}; /* 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) { for(i in obj) {
if(i == 'clone') continue; if(i == 'clone') continue;
if(obj[i] != null && typeof obj[i] == "object") { if(obj[i] != null && typeof obj[i] == "object") {
returnObj[i] = franz.clone(obj[i]); returnObj[i] = franz.clone(obj[i]);
} else { } else {
returnObj[i] = obj[i]; returnObj[i] = obj[i];
}
} }
}
return returnObj; return returnObj;
}
}, },
loadImg: function(img_src) { loadImg: function(img_src) {
@ -169,7 +173,7 @@ var franz = {
} }
document.getElementById("log_colors").innerHTML = docStr; document.getElementById("log_colors").innerHTML = docStr;
if(typeof jQuery != "undefined") { if(typeof jQuery !== "undefined") {
$("#container_bottom").fadeIn("fast"); $("#container_bottom").fadeIn("fast");
setTimeout(function() { $("#testLayout").fadeIn("slow"); }, 500); setTimeout(function() { $("#testLayout").fadeIn("slow"); }, 500);
} }