//--debug.js--// if (!window.KJD){window.KJD = new Object;} KJD.debug_mode = ''; //alert|status|window|div|none var dump = function(obj,dest,match) { dest = (dest) ? dest : KJD.debug_mode; var str = ""; var prop_name; var prop_value; if (typeof(obj) == 'string'){ str = obj +' [String]'; } else { for (var prop in obj){ prop_name = prop; prop_value = obj[prop_name]; try { if (match){ if (match == '-f' && (prop_value.search('function') == -1)){ str += "obj." + prop_name + " = " + prop_value + "\n"; } else if (prop_name.search(match) != -1){ str += "obj." + prop_name + " = " + prop_value + "\n"; } } else { str += "obj." + prop_name + " = " + prop_value + "\n"; } } catch (e){ str += "ERROR:\n"; } } } debug(str,dest); } var debug = function(text,destination){ var var_type = typeof(text); var msg = text +' ['+ var_type +']'; //defaults destination = (destination) ? destination : KJD.debug_mode; switch (destination){ //pop-up an alert box case 'a': case 'alert': window.alert(msg); break; //write to the status bar case 's': case 'status': //replace any line breaks in the msg msg = msg.replace(/\n/gi,'|'); window.status = msg; if (KJD.debugTimeOut){clearTimeout(KJD.debugTimeOut);} KJD.debugTimeOut = window.setTimeout('window.status="";',3000); break; //send the text to a pop-up window. //NOTE: pop-up blockers will stop this window from opening case 'w': case 'window': var win_options = 'height=600,width=250,directories=no'; var debug_win = window.open('','DEBUG_WINDOW',win_options); if (debug_win){ debug_win.document.write(text +'
'); debug_win.focus(); } else { throw Error('Debugging window couldn\'t be opened.\n\n'+ msg); } break; //send to a
in the document case 'd': case 'div': var div = document.getElementById('debug'); if (!div){ div = document.createElement('div'); div.id = 'debug'; document.body.appendChild(div); } div.innerHTML += text +'
'; break; //do nothing case '': case 'none': break; default : throw Error('Invalid debug destination ('+ destination +')'); } } //-------------start common.js-------------------// if (!window.KJD){window.KJD = new Object;} //object for holding all my functions/object to give them all their own namespace //you should be able to do a find/replace with the string 'KJD' (case sensitive) //if the script conflicts with someone elses script. KJD.test = function(){ window.open('','bob','resizable=yes,width=300,height=300'); } KJD.baseUrl = 'http://localhost/contextify/'; KJD.debug_mode = 'alert'; //alert|status|window|div|none KJD.error_mode = ''; // [alert|log|ignore] or leave empty for normal (browser based) error handling KJD.error_log = ''; //for logging errors to another domain //'http://www.webfoundry.co.nz/javascript_error.php'; //this page should return an empty string or some javascript KJD.error_handler = function(description, url, line){ //supress all errors within the error handler //otherwise endless loops could occur? window.onerror = null; //defaults //mozilla doesn't give a url or line number. url = (url) ? url : window.location; line = (line) ? line : 'unknown'; var msg = 'Msg = '+ description +'\nUrl = '+ url +'\nLine = '+ line; switch (KJD.error_mode){ case 'alert': window.alert(msg); break; case 'log': //log to a script src if (KJD.error_log == ''){ throw Error('Error Log Src not set.'); break; } else { //MZ: errors are still caught by the built in error handler var script = document.createElement('script'); script.src = KJD.error_log +'?msg='+ escape(description) +'&url='+ escape(url) +'&line='+ line; if (document.body){ document.body.appendChild(script); } else { //nothing we can do //FIXME: save to cookie maybe? } } break; case 'ignore': //do nothing break; default: throw Error('Invalid error_mode ('+ KJD.error_mode +')'); } //restore the error handler window.onerror = KJD.error_handler; return true; } //set error handler event if (KJD.error_mode != ''){ window.onerror = KJD.error_handler; } //add activeElement to the document //register event handlers //a couple of useful string functions String.prototype.trim = function(){ //trims leading and trailing whitespace from a string var s = this.replace(/^\s+/,''); s = s.replace(/\s+$/,''); return s; } KJD.decToHex = function(num, min_length){ //Converts a decimal to its hex string var HEX_STR = "0123456789ABCDEF"; //validate input num = Math.floor(num); if (!min_length){min_length=2;} var mod=0; var hex=''; while (num > 0){ mod = num % 16; hex = HEX_STR.charAt(mod) + hex; num = (num - mod) / 16; } //pad to required length for (var i=hex.length; i is clicked) e.preventDefault = function(){ e.returnValue = false; } e.which = e.button; //now fudge it if (e.button == 2){e.which = 3;} if (e.button == 4){e.which = 2;} if (existing_event){ existing_event(e); } func(e); } //KLUDGE: //events cannot be added to an iframes document with addEvent we need to add it explicitly //NOTE: this will remove any handler that aready exists for the iframes document. //FIXME: keep document events //test to see if the event was added //iframe events in IE5 ... if (obj.parentWindow && (obj.parentWindow != top)){ obj['on'+ event_name] = event_handler; return true; //? } else { return obj.attachEvent("on"+ event_name, event_handler); } /* FIXME if (KJD.isdef(obj.title) && (obj != document)){ } else { if (event_name == 'mouseover'){ debug(event_name); } return obj.attachEvent("on"+ event_name, event_handler); } */ } //unknown else { throw Error("Unable to addEvent()"); return false; } } KJD.Event = Object; KJD.Event.convert = function(e){ //converts an ie event object into a moz compatible one //event source if (!e.target && e.srcElement){ e.target = e.srcElement; } //event bubbling e.stopPropagation = function(){ e.cancelBubble = true; } //prevent default action (eg form submittal when an is clicked) e.preventDefault = function(){ e.returnValue = false; } return e; } KJD.Event.target = function(e, valid_tag_list){ //returns the element the triggered the event var ele; if (!e){return null;} //have we been passed an element instead? if (e.nodeType){ return e; } else if (e.target){ return KJD.getParent(e.target, valid_tag_list, true); } else if (e.srcElement){ return KJD.getParent(e.srcElement, valid_tag_list, true); } else { return null; } } KJD.writeStyle = function(style){ //writes a '); } KJD.uniqueId = function(prefix){ var id = ''; var i = 0; do { id = prefix +'_'+ i; i++; } while (document.getElementById(id)); return id; } KJD.getQuery = function(key,default_value){ //returns a value from the query string default_value = (default_value) ? default_value : ''; var exp = new RegExp('\\b'+ key +'=([^&]*)','i'); var loc = window.location.toString(); var match = loc.match(exp); return (match) ? match[1] : default_value; } KJD.loadCSS = function(src){ //loads an external style sheet by writing directly to the document //should only be called in the of a document document.write(''); } KJD.importCSS = function(src, doc){ //imports a style sheet (to be used if the document is already loaded); if (!doc){doc = document;} var link = doc.createElement('link'); link.rel = 'stylesheet'; link.href = src; link.type = 'text/css'; var head = doc.getElementsByTagName('head')[0]; //doc.body.appendChild(link); head.appendChild(link); } KJD.addScript = function(src){ //appends a script to the bottom of the page var script = document.createElement('script'); script.src = src; document.body.appendChild(script); } KJD.winClose = function(delay){ if (delay && !KJD.closing){ //set a timer to close the window setTimeout(KJD.winClose, delay * 1000); return; } else { //close the window now window.returnValue = 1; window.close(); } } KJD.getStyleSheet = function(doc){ //verify the document doc = (doc) ? doc : window.document; if (doc.styleSheets){ if (doc.styleSheets.length == 0){ //import a blank style sheet KJD.importCSS(''); } return doc.styleSheets[doc.styleSheets.length-1]; } else { debug('Unable to find or create a style sheet'); return null; } }; KJD.addStyle = function(style_name, rule){ //adds a style to the last style sheet of a document var style_sheet = KJD.getStyleSheet(); //IE if (!style_sheet) if (style_sheet.addRule){ style_sheet.addRule(style_name, rule); return true; } //MZ else if (style_sheet.insertRule && style_sheet.cssRules) { rule = style_name + ' {' + rule + ';}'; style_sheet.insertRule(rule , style_sheet.cssRules.length); return true; } //? else { return false; } } KJD.getStyle = function(ele, style, datatype){ //returns the calculated style for any element var obj_style; //IE if (ele.currentStyle){ obj_style = ele.currentStyle; } else if (document.defaultView && document.defaultView.getComputedStyle){ obj_style = document.defaultView.getComputedStyle(ele,null); } else if (ele.style){ obj_style = ele.style; } else { //no style available for this element return false; } //try to find the style var value = eval('obj_style.'+ style); if (!value){ return false; } //return the //number switch (datatype){ case 'int': value = parseInt(value,10); return (value==NaN) ? 0 : value; case 'string': default: return value; } } KJD.isBrowserSupported = function(){ // var a_func = Array( 'document.getElementById', 'document.getElementsByTagName', 'document.createElement', 'document.createTextNode', 'document.body.innerHTML', 'document.body.parentNode', 'document.body.parentNode.insertBefore', 'document.body.appendChild', 'document.execCommand', 'document.queryCommadValue', 'document.className' ); for (var i; i 0 KJD.fade_speed = 200; //Total Time to fade from visible to hidden speed (in milliseconds) KJD.getOpacity = function(id){ //returns the opacity value of en element var ele = this.getId(id); //make sure the element can be faded KJD.addClass(ele,'alpha'); //mz if (this.isdef(ele.style.MozOpacity)){ if (ele.style.MozOpacity == ''){ //Set initial opacity //NOTE: don't make the opacity 1 as it causes a flicker when it is first changed to //a semi-transparent state. ele.style.MozOpacity = (ele.style.visibility == 'hidden') ? 0 : 0.99; } return parseFloat(ele.style.MozOpacity); } else { try { //if (isdef(ele.filters) && isdef(ele.filters.alpha) && isdef(ele.filters.alpha.opacity )){ return parseFloat(ele.filters.alpha.opacity / 100); //} } catch (e){ //object hasn't got alpha style set yet //NOTE: in IE the filter style must be set in the stylesheet of the element //before fading can occur. return false; } } } KJD.setOpacity = function(id, opacity){ var ele = this.getId(id); //validate input if (opacity > 0.99){opacity = 0.99;} if (opacity < 0){opacity = 0;} //mz if (this.isdef(ele.style.MozOpacity)){ ele.style.MozOpacity = opacity; return true; } else { //ie is wierd try and find out if the object supports the alpha filter try { //no need to check if it supports as it's in a try {} catch {} block //if (isdef(ele.filters) && isdef(ele.filters.alpha) && isdef(ele.filters.alpha.opacity )){ ele.filters.alpha.opacity = parseInt(opacity * 100); return true; //} } catch (e){ return false; } } } KJD.fadeOut = function(id){ var ele = KJD.getId(id); //validate element if (!ele.id){throw Error('Element requires an "id" attribute to fadeOut');} var fade_steps = ele.getAttribute('fade_steps') ? ele.getAttribute('fade_steps') : KJD.fade_steps; var fade_speed = ele.getAttribute('fade_speed') ? ele.getAttribute('fade_speed') : KJD.fade_speed; var opac = KJD.getOpacity(ele); var step = (0.99 / fade_steps); //clear the timer if (ele.fade_timer){ clearTimeout(ele.fade_timer); } //object doesn't support alpha blending if (opac === false){ ele.style.visibility = 'hidden'; return false; } //supports blending, is it visible? else if (opac > 0){ KJD.setOpacity(ele, opac - step); //we need to keep getting less visible until the element dissapears ele.fade_timer = setTimeout('KJD.fadeOut(\''+ ele.id +'\')', (fade_speed / fade_steps)); return true; } //completely invisible else { ele.style.visibility = 'hidden'; return true; } } KJD.fadeIn = function (id){ var ele = KJD.getId(id); //validate element if (!ele.id){throw Error('Element requires an "id" attribute to fadeIn');} var fade_steps = ele.getAttribute('fade_steps') ? ele.getAttribute('fade_steps') : KJD.fade_steps; var fade_speed = ele.getAttribute('fade_speed') ? ele.getAttribute('fade_speed') : KJD.fade_speed; var opac = KJD.getOpacity(ele); var step = (0.99 / fade_steps); //make sure you can see the object ele.style.visibility = 'visible'; //clear the timer if (ele.fade_timer){ clearTimeout(ele.fade_timer); } if (opac === false){ //object doesn't support alpha blending return false; } else if (opac < .99){ KJD.setOpacity(ele, opac + step); ele.fade_timer = setTimeout('KJD.fadeIn(\''+ ele.id +'\')', (fade_speed / fade_steps)); return true; } else { return true; } } //NOTE ie requires the alpha filter to be loaded in the style sheet BEFORE the element //can be faded in or out. //Also: setting the element to be partially transparent (0.99) removes the flicker when changing drawing styles in Mozilla // KJD.addStyle('.alpha','filter:alpha(opacity=99);'); KJD.addStyle('.alpha','-moz-opacity:0.99;'); //--end fade.js--//if (!window.KJD){window.KJD = new Object;} //some functions KJD.Iframe = new Object(); KJD.Iframe.getDoc = function(iframe){ //returns the iframes current document //get ref to the iframes document if (iframe.contentDocument) { return iframe.contentDocument; } // For IE5.5 and IE6 and MZ else if (iframe.contentWindow) { return iframe.contentWindow.document; } // For IE5: major kludge included else if (iframe.document) { //IE5.0 gives the window's document instead if (iframe.document === window.document){ if (!iframe.id){ //iframe MUST have an id to access in IE5.0 iframe.id = KJD.uniqueId('iframe'); } return document.frames[iframe.id].document; } else { return iframe.document; } } else { throw Error('Cannot access iframe document'); return null; } } KJD.Iframe.setBody = function(iframe, html){ var doc = KJD.Iframe.getDoc(iframe); doc.body.innerHTML = html; } KJD.Iframe.setHTML = function(iframe, html){ //debug(iframe.location); var doc = KJD.Iframe.getDoc(iframe); doc.body.innerHTML = html; /* //IE doesn't have a document yet, we could pause but making a new document also works else { //we need to load the parent KJD object (containing all of our functions and objects) into this window if ((!html) || html.search(/]*>/i) == -1){ //convert into proper document html = '