/* +------------------------------------------------+ | @FILE: functions.js | | @AUTHOR: [NUTS] Rodrigo Souza | | @DATE: Sex 27 Out 2006 12:38:22 BRST | | @LAST CHANGE: Seg 27 Nov 2006 12:35:22 BRST:: | +------------------------------------------------+ */ /* * @DESC The method has one optional boolean argument * deep which when set recursively creates a * deep copy, otherwise (when deep is false * or not defined) a shallow copy is created. */ /*Object.prototype.clone = function(deep) { objectClone = new this.constructor(); for (var property in this) { if (!deep) objectClone[property] = this[property]; else if (typeof this[property] == 'object') objectClone[property] = this[property].clone(deep); else objectClone[property] = this[property]; } return objectClone; }*/ /* * */ var func = { "json" : false, "attachEvent" : function(obj, eventName, eventHandler) { if ( obj ) { if ( eventName.substring(0, 2) == 'on' ) { eventName = eventName.substring(2,eventName.length); } if ( obj.addEventListener ) { obj.addEventListener(eventName, eventHandler, false); } else if ( obj.attachEvent ) { obj.attachEvent('on'+eventName, eventHandler); } } }, "byId" : function() { var elements = new Array(); for ( var i = 0; i < arguments.length; i++ ) { element = arguments[i]; if ( this.isString(element) ) element = document.getElementById(element); if (arguments.length == 1) return element; elements.push(element); } return elements; }, "byTag" : function() { var elements = new Array(); for ( var i = 0; i < arguments.length; i++ ) { element = arguments[i]; if ( this.isString(element) ) element = document.getElementsByTagName(element); if ( arguments.length == 1 ) return element; elements.push(element); } return elements; }, "client_height" : function() { if( typeof( window.innerWidth ) == 'number' ) { //Non-IE return window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientHeight; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible return document.body.clientHeight; } }, "client_width" : function() { if( typeof( window.innerWidth ) == 'number' ) { //Non-IE return window.innerWidth; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' return document.documentElement.clientWidth; } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { //IE 4 compatible return document.body.clientWidth; } }, "_confEl" : function(pElement, pAttribute, pValue) { if ( !func.isString(pValue) ) return false; if ( this.isString(pElement) ) { pElement = document.getElementById(pElement); } switch ( pAttribute ) { /* * No IE a propriedade style nÃo funciona se adicionada via setAttribute() */ case 'style' : pElement.style.cssText = pValue; break; case 'class' : pElement.setAttribute(pAttribute, pValue); pElement.setAttribute(pAttribute+'Name', pValue); // IE break; default : pElement.setAttribute(pAttribute, pValue); } /* switch */ }, "confEl" : function() { switch ( arguments.length ) { case 1 : matriz = arguments[0]; if ( !this.isArray(matriz) ) return false; for ( var i in matriz ) { pElement = matriz[i]['element']; delete matriz[i]['element']; for ( var j in matriz[i] ) { this._confEl(pElement, j, matriz[i][j]); } } break; case 2 : var pElement = arguments[0]; if ( !this.isArray(arguments[1]) ) return false; for ( var i in arguments[1] ) { this._confEl(pElement, i, arguments[1][i]); } break; case 3 : var pElement = arguments[0]; this._confEl(pElement, arguments[1], arguments[2]); break; } }, "elH" : function(pEl) { // no IE a funcao scrollHeight não retorna o valor correto return document.getElementById(pEl).offsetHeight; }, "elHW" : function(pEl) { aux = { h:this.elH(pEl), w:this.elW(pEl) }; return aux; }, "elW" : function(pEl) { return document.getElementById(pEl).offsetWidth; }, "interface" : function(_XmlDoc) { var data = _XmlDoc.getElementsByTagName('retorno').item(0); if ( data.childNodes.length == 1 ) data = data.firstChild.nodeValue; if ( /^("(\\.|[^"\\\n\r])*?"|[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t])+?$/.test(data) ) { eval('data = ' + data); if ( this.json ){ this.json = false; }else{ data = this.json2array(data); } } return data; }, "insEl" : function() { try { if ( arguments.length == 1 ) { var body = document.getElementsByTagName('body'); body[0].appendChild(arguments[0]); } else { var parentEl; switch ( typeof arguments[arguments.length-1] ) { case 'object' : parentEl = arguments[arguments.length-1]; break; case 'string' : parentEl = document.getElementById(arguments[arguments.length-1]); break; case 'boolean' : parentEl = document.getElementsByTagName('body').item(0); } for ( var i = 0; i < arguments.length-1; i++ ) { if ( this.isString(arguments[i]) ) arguments[i] = document.createTextNode(arguments[i]); parentEl.appendChild(arguments[i]); } } /* else */ return true; } catch(e) {} }, "insElB" : function() { try { if ( arguments.length < 2 ) { return false; } else { var referenceEl; var parentEl; switch ( typeof arguments[arguments.length-1] ) { case 'object' : parentEl = arguments[arguments.length-1].parentNode; referenceEl = arguments[arguments.length-1]; break; case 'string' : referenceEl = document.getElementById(arguments[arguments.length-1]); parentEl = referenceEl.parentNode; } for ( var i = 0; i < arguments.length-1; i++ ) { parentEl.insertBefore(arguments[i], referenceEl); } } /* else */ return true; } catch(e) {} }, "isArray" : function(a) { return this.isObject(a) && a.constructor == Array; }, "isFunction" : function(a) { return typeof a == 'function'; }, "isNumber" : function(a) { return typeof a == 'number' && isFinite(a); }, "isNull" : function(a) { return a === null; }, "isObject" : function(a) { return (a && typeof a == 'object') || this.isFunction(a); }, "isString" : function(a) { return typeof a == 'string'; }, "isUndefined" : function(a) { return typeof a == 'undefined'; }, "json2array" : function(pObject) { var retorno = []; for( var i in pObject ) if( pObject[i].constructor == Object ) { retorno[i] = []; retorno[i] = this.json2array(pObject[i]); } else retorno[i] = pObject[i]; return retorno; }, "newEl" : function(pElement) { if ( arguments.length == 1 ) { switch ( typeof pElement) { case 'string' : return document.createElement(pElement); break; case 'object' : var retorno = new Array(); if (this.isArray(pElement)) { for (var i in pElement) { retorno[i] = document.createElement(pElement[i]); } return retorno; } break; } /* switch */ } /* if */ else { var retorno = new Array(); for ( var i = 0; i < arguments.length; i++ ) { retorno[i] = document.createElement(arguments[i]); } return retorno; } }, "trim" : function(pString) { return pString.replace(/^( )*|( )*$/g, ''); } }