/////////////////////////////////// /* prototypes properties/methods */ //-------------------------------// // OBJECT EXTENDING ////////////////////////////////// // Object.extend = function(destination,source,override) { if(!destination) destination = {}; for (property in source) { if((override === false && destination[property] === undefined) || override !== false) destination[property] = source[property]; } return destination; } Object.wipe = function(o,f){ Object.each(o, function(oEl){ Try(f,oEl); delete oEl }); } Object.each = function(o,f){ if(o) for(var i in o) f(o[i],i); } //-------------------------- // STRING EXTENDING //////////////////////////// // Object.extend(String,{ // Separates charsets on understandable // names charSets: { // lowercase letters lL:"abcdefghijklmnopqrstuvwxyz", // uppercase letters uL:"ABCDEFGHIJKLMNOPQRSTUVWXYZ", // numbers N:"0123456789" }, //====================== // String.random() //====================== // @ int size : size of the string to be returned // @ array from : the types of characters to be used (look above) //----------------------------------------------------------------// // Created a random key string from the selected charset, look above // for the charset. You can always add charset. // default charset is uL+lL+N (upper/lowerletter + numbers) // random: function(size,from){ if(!(from instanceof Array)) from = ["uL","lL","N"]; else from = from.split(","); var s = "",str = "",a=0; for(var i=0;i0?this.substring(to,this.length):""); }, //============================ // String.substringreplace() //============================ // @ str replacement : string to be added // @ int from : remove starting from 'from' // @ int to : remove until 'to', if not given, it will remove // from+replacement.length //-------------------------------------------// // Replaces the string from 'from' to 'to' for the 'replacement' // substringreplace: function(replacement,from,to){ // In the case of 'from' not existing, it's 0 default if(!from) from = 0 // if 'to' is not set, it'll be if(!(to>0)) to = from + String(replacement).length; return this.substring(0,from)+replacement+this.substring(to,this.length); }, //=========================== // String.addslashes() //=========================== // Replaces any of the following \, ', " // for "\" + the matching entry // addslashes: function () { return this.replace(/('|\\|")/g,"\\$1"); }, //=========================== // String.stripslashes() //=========================== // Replaces any of the following \\, \', \" // for the matching entry withou the slash // in front of it // stripslashes: function() { return this.replace(/\\('|\\|")/g,"$1"); } }); //----------------------- // ARRAY EXTENDING ///////////////////////// // Object.extend(Array.prototype, { sum: function(){ var s = 0; for(var i=0;i15) {d>>=4;h=Number.hexString.substr(d&15,1)+h;} return h; } }); Object.extend(String.prototype, { replaceall: function(w,r){ var c = this; while( c != (c=c.replace(w,r))) {} return c; }, // n stands for not_all_matches regexpEscape: function(){ return this.replaceall(/(^|[^\\])(\^|\.|\-|\*|\+|\?|\$|\[|\]|\{|\}|\(|\))/g,"$1\\$2") } }); // Converts to array if the target // is NOT an array function array(o){ return (!(o instanceof Array)) ? ( o ? [o] : []) : o; } ///---------------------- // Easy-Access Functions ///---------------------- function $t(name,o){ return (o||document).getElementsByTagName(name) } function Try(w){ try{ if(typeof w=='string') eval(w); else{ var args=[] for(var i=1;i 0 ? __loadingCount-1 : 0; if(__loadingCount > 0){ if(__loadingDisplay.o.hi.isAbsolute){ __loadingDisplay.o.hi.rTop(); __loadingDisplay.o.hi.onresize.disabled = __loadingDisplay.o.hi.onscroll.disabled = false; } __loadingDisplay.show(); } else{ if(__loadingDisplay.o.hi.isAbsolute) __loadingDisplay.o.hi.onresize.disabled = __loadingDisplay.o.hi.onscroll.disabled = true; __loadingDisplay.hide(); } } // Object extra // ---------------------------------- // htmlObject /* handles htmlobjects with some utilities */ var h = function(obj,p){ // if its already a 'h' class object, // nothing to do but return it if(obj instanceof h) return obj; // we can't make an obj class out of nothing if(obj === undefined) return false; // makes sure it's an object, not a simple // called function if(window === this) return new h(obj,p); this.o = this.parseObject(obj,p); // collection holding h's info // on that object if(!this.o.hi) this.o.hi = { anims: {}, events: {} }; } // Defines main config element, used within all the // script // defines which browser is being used // // ----------------------------------- // var b = navigator.userAgent.toLowerCase(); h.browser = { safari: /webkit/.test(b), opera: /opera/.test(b), msie: /msie/.test(b) && !/opera/.test(b), mozilla: /mozilla/.test(b) && !/(compatible|webkit)/.test(b) }; // defines extra info // // --------------------- var brdThick = h.browser.mozilla ? 6 : 5; h.ex = { // retrieves javascript-level link to the host 1 , 3 , 5 hostLink: "http://localhost/sites/new_sites/fonts/http/", brdSizeByName: {medium: brdThick-2 ,thin:brdThick-4,thick:brdThick} }; // stores collections // // --------------------- // object which holds all the floatables created // withing the h element // --------------------------- h.floatables = []; // extends h for some objectless methods Object.extend(h , { //======================== // h.closeAllFloatables() //======================== // @ string class : floatable's class to be closed // @ object cfg : shared configuration of h.closeFloating // 'CFG' EXTRA PROPERTIE(S) // ------------------------------- // @ object condition : condition object that must be true when // tested against h.condition() // ------------------------------------------------------------------------------ // Closes all floatables of the selected class, if no class is given, ALL THE // FLOATABLES are closed. // closeAllFloatables: function(Class,cfg){ if(!cfg) cfg = {}; var floatable; for(var i=0;i it is shown; false -> it is hidden var tempDA = h(floatable.childNodes[0]); showStatus = !(floatable.childNodes[0].hi.showstatus != "show"); // toggling display if(cOpt.find("toggle")!==false){ if(showStatus) tempDA.closeFloatable(); else tempDA.show(cfg.showcfg); } } return true; } } var relativeObj = h((cfg.relativeObj || document.body)), dA,dR,dS,div,evDiv; if(!cfg.type) cfg.type = 'R'; if(cfg.type=='R' || cfg.type=='A'){ dA = h("DIV"); dA.o.style.position = 'absolute'; dA.append(this.o); if(cfg.type=='R'){ // creates the divRelative which holds the // absolute floatable dR = h("DIV"); dR.o.style.position = 'relative'; dR.append(dA.o); } } else dS = h("DIV").append(this.o); div = dR||dA||dS; evDiv = dA||dS; // ... > appending the floatable relative to the // relative object (cfg.appendTo||relativeObj.o).appendChild(div.o); // ------------------ // DEFINES THE EVENTS // ------------------ // function called once it's closed/hidden evDiv.o.hi.onhide = cfg.onhide; // function called once it's shown evDiv.o.hi.onshow = cfg.onshow; // function to be called everytime it starts hiding evDiv.o.hi.onstarthide = function(){ // it should go right to the end // of z stacking div.o.style.zIndex = cfg.zIndex || 0; Try(cfg.onstarthide); }; // function to be called everytime it starts showing evDiv.o.hi.onstartshow = function(){ // it should go to the front div.o.style.zIndex = cfg.zIndex || 1; Try(cfg.onstartshow) }; // standard close configuration // to be used everytime the floatable // is closed with closeFloating div.o.hi.closecfg = cfg.closecfg; // ---------------------------------------------- // positions the absolute to the target relative // object if(dA) dA.setPosition(cfg.left,cfg.top,relativeObj,cfg.pos,cfg.event); // sets identification div.o.hi.floatclass = cfg.Class; div.o.hi.floatid = cfg.id; // defines whether it is or not a floatable // object div.o.hi.isFloatable = true; // stores the float parent pointer this.o.hi.floatParent = div; // appends the object to the floatables array // stored on 'h' (h.floatables) if(h.floatables.find(div.o)===false) h.floatables.push(div.o); // it must be contracted as its // the firts time its popping // to minimum size div.o.style.zIndex = cfg.zIndex if(cfg.showcfg || cfg.show){ if(cfg.showcfg) cfg.showcfg.contractSize = true; evDiv.display(false).show(cfg.showcfg); } return div; }, setPosition: function(offsetLeft,offsetTop,relativeObj,pos,evt){ var top = left = setW = setH = 0, oH = this.o.offsetHeight, oW = this.o.offsetWidth, onBody = (this.o.parentNode||this.o.parentElement) == document.body; if(pos){ relativeObj = h(relativeObj); if(typeof pos == 'string') pos = pos.split("-"); switch(pos[0]){ case "top": top = - oH + ( onBody ? relativeObj.getTotalOffsetTop() : - relativeObj.o.offsetHeight + Int(relativeObj.getStyle("borderTopWidth")) + Int(relativeObj.getStyle("paddingTop")) ); break; case "bottom": top = ( onBody ? relativeObj.getTotalOffsetTop() + relativeObj.o.offsetHeight: 0 ); break case "mouse": top += evt.clientY + document.body.scrollTop; left += evt.clientX + document.body.scrollLeft; if(relativeObj.o !== document.body) switch(pos[1]){ case "top" : top -= relativeObj.o.offsetHeight + oH; case "bottom": top += relativeObj.o.offsetHeight - (evt.clientY + document.body.scrollTop - relativeObj.getTotalOffsetTop()); break; } } // adjusts additional positioning // if(pos[0]=='bottom'||pos[0]=='top'){ switch(pos[1]){ case "left": left += onBody ? relativeObj.getTotalOffsetLeft(): - Int(relativeObj.getStyle("borderLeftWidth")) - Int(relativeObj.getStyle("paddingLeft")) break; case "center": left += (onBody ? relativeObj.getTotalOffsetLeft() : 0) - (oW-relativeObj.o.offsetWidth)/2; } // not implemented yet //else if (pos[1]=='right') } // size related to the relativeObj if(pos[2]){ if(typeof pos[2] == 'string') pos[2] = pos[2].split(","); switch(pos[2][0]){ case "full": setW = relativeObj.o.offsetWidth; break; default: if(Int(pos[2][0])) setW = pos[2][0]; if(Int(pos[2][1])) setH = pos[2][1]; } } } // avoid clipping var setLeft = (offsetLeft||0) + left, setTop = (offsetTop||0) + top; this.o.style.width = setW||"auto"; this.o.style.height = setH||"auto"; // sets the floatable position this.o.style.top = setTop; this.o.style.left = setLeft; // recall the function if the obj size has changed if((!setH && this.o.offsetHeight!=oH) || (!setW && this.o.offsetWidth!=oW)){ return this.setPosition(offsetLeft,offsetTop,relativeObj,pos,evt); } return this; }, //=================== // h.closeFloatable() //=================== // @ object cfg : configuration to be called on hide // ------------------------------------------------------------ // Closes the floatable to which 'this.o' object belongs to. // closeFloatable: function(cfg){ var p = this.getParentFloatable(); if(!p) return; try{ // The floating is starting to get closed // the first ChildNode would be the absolute floatable div h(p.o.childNodes[0]) // ... .hide(Object .extend(cfg,p.o.hi.closecfg), function(){ // okay, callback to when animation is finished and // floatable is totally closed if(cfg.remove===true) p.remove(); } ); return true; } catch(e){ return false; } }, showFloatable: function(cfg){ var p = this.getParentFloatable(); if(!p) return; h(p.o.childNodes[0]).show(cfg ? cfg.showcfg : null); }, //========================= // h.getParentFloatable() //========================= // <- bool/object parentObj // ------------------------------------- // Returns the parent floatable // after a loop looking for one // if there's none, 'false' is returned // getParentFloatable: function(){ var p = this; // if it finds a stored floatParent on the element's // properties, it will be returned if(this.o.hi.floatParent) return this.o.hi.floatParent; if(!p.o.hi.isFloatable) p=this.parent({"hi.isFloatable":true}); // sets the stored floatParent to be recalled and returns it if(p.o.hi.isFloatable){ this.o.hi.floatParent = p; return p; } return false; }, //=============== // h.tip() //=============== // @ string text : tip's innerHTML context // @ object evt : event object // @ bool followMouse : should it follow mouse or stand still ? // @ string pos : position to be used // // @ string id : id to make the tip unique and don't keep on // creating multiple tips of the same stuff // @ bool showOverTip : if !== false it will not hide the tip when the mouse // goes off the object and over the tip // ------------------------------------------------ // displays a tip div // note that the tip is unique as 'h.tippingDiv' // tip: function(text,evt,followMouse,pos,showOverTip){ evt = window.event || evt; // fixes some issues if(evt.type == 'mouseover' && !this.mouseIsOver(evt)) return; // retrieves tip div if it already exists var tip = h.tipDiv, hasTip = !!(tip); //boolean // it wont follow only if followMouse === false followMouse = !(followMouse === false); // if there's no tip we are creating one if(!hasTip){ tip = h("DIV"); tip.o.hi.tipParent = this.o; h.tipDiv = tip; // defines the element calling the tip tip.o.hi.tipParent = this; tip.o.className = "tip"; // initializes the following responsible event tip.o.hi.followMouseEv = new Event(document,"onmousemove", function(e){ tip.getParentFloatable().setPosition(0,0,tip.o.hi.tipParent.o,tip.o.hi.defaultPos,e); }); // it should resize when the window resizes. tip.o.hi.followResizeEv = new Event(window,"onresize", function(e){ tip.getParentFloatable().setPosition(0,0,tip.o.hi.tipParent.o,tip.o.hi.defaultPos,e); }); } if(tip.o.hi.tipParent.o!=this.o) tip.o.hi.tipParent = this; // default positioning tip.o.hi.defaultPos = pos || tip.o.hi.defaultPos || "mouse-bottom"; tip.o.hi.showOverTip = showOverTip; // enables the event tip.o.hi.followMouseEv.disabled = !followMouse; if(tip.o.innerHTML != text) tip.o.innerHTML = text; // if the tip has just been created, we'll initialize it, // meaning its events & properties if(!hasTip){ // creates the floatable tip.float({ relativeObj: this.o, appendTo: document.body, type: "A", zIndex:100, pos:tip.o.hi.defaultPos, event: evt }); } // retrieves the parentFloatable var pF = tip.getParentFloatable(); if(!hasTip){ // defines the custom closeTip function // to be called everytime we have to close it var closeTip = function(e){ pF.o.hi.tipMouseMove.disabled = true; tip.o.hi.followMouseEv.disabled = true; tip.closeFloatable(); } // initializes floatable parent on mouse out event, so we // can handle it as a part of the tip parent and dont // close it when the mouse goes out parent but goes over it pF.o.hi.tipMouseMove = new Event(document,'onmousemove',function(e){ if((tip.o.hi.showOverTip===false || !pF.mouseIsOver(e)) && !tip.o.hi.tipParent.mouseIsOver(e)) closeTip(); }); } else{ tip.showFloatable(); pF.setPosition(0,0,tip.o.hi.tipParent.o,tip.o.hi.defaultPos,evt); pF.o.hi.tipMouseMove.disabled = false; } }, closeTip: function(){ if(h.tipDiv && this.o == h.tipDiv.o.hi.tipParent.o){ h.tipDiv.getParentFloatable().o.hi.tipMouseMove.disabled = true; h.tipDiv.o.hi.followMouseEv.disabled = true; h.tipDiv.closeFloatable(); } return this; }, // // HIDE/SHOW FUNCTION //////////////////////// // // show: function(cfg,callback,args){ return this.hideshowFunction("show",cfg,callback,args); }, hide: function(cfg,callback,args){ return this.hideshowFunction("hide",cfg,callback,args); }, hideshowFunction: function(w,cfg,callback,args){ if(w!='show')w='hide'; var wbool = w=='show'?true:false; // returns if its already hidden if(this.o.hi.showstatus==w) return this; // this function must be unique // within the animations this.clearAnim(true); this.o.hi.showstatus = w; Try(this.o.hi["onstart"+w]); if(cfg && cfg.type){ cfg.action = w; var t = this; var c = function(){ t.display(wbool); Try(t.o.hi["on"+w]); Try(callback); }; this.anim(cfg,c,array(args)); } else{ Try(this.o.hi["on"+w]); Try(callback); this.display(wbool); } return this; }, // // ANIMATION //////////////// // cfg config: // - speed ; of interval // - type ; of animation // - uspeed ; unit speed (pixel) // //intervalSpeed iSpeed: {uslow:220,xslow:190,slow:150,medium:100,fast:50,xfast:30,ufast:20,uufast:5}, // pixelSizeDec ( for animations changing width/height ) pSizeDec: {fast:11,uslow:1,vslow:3,slow:5,medium:8,xfast:14,vfast:17,ufast:20}, //============================ // // animates objects // anim: function(config,callback,args){ // new object must be created // values overriding var cfg = Object.extend({},config); this.animate(cfg,callback,args); }, animate: function(cfg,callback,args){ // sets the default config cfg.speed = this.iSpeed[cfg.speed] || this.iSpeed.ufast; cfg.uspeed = this.pSizeDec[cfg.uspeed] || this.pSizeDec.medium; if(!cfg.type) return false; cfg.loops = 0; // t: this object, f: function to call on anim var t = this,f,type = cfg.type.split("-"); switch(type[0]){ // // slide-(down|up|...) variables // /////////////////////////////////// case "slide": // oOv: old overflow to be restored, oSz: old size //var oOv = this.style("overflow"); //var oSz = this.getExpandedSize((cfg.expandWidth!==false),(cfg.expandWidth!==false)); this.o.style.overflow = "hidden" // ... // tI : topIncrement , -1 going top | 1 going bottom; // sI : sizeIncrement , -1 dec hei | 1 inc hei; // n: [tI,sI] var n; if(type[1] == 'up' ) if(cfg.fixedAt == 'bottom' || cfg.action == 'show') n = [-1,1]; else n = [0,-1]; if(type[1] == 'down') if(cfg.fixedAt == 'bottom' || cfg.action == 'hide') n = [1,-1]; else n = [0,1]; var mS = [1,1]; switch(cfg.action){ case "show":mS = this.getExpandedSize(); mS = (cfg.height || cfg.width) ? [(cfg.width || mS[0] ),(cfg.height || mS[1])] : mS; if(cfg.contractSize) this.contractSize(false,true,false,(n[0]!==0)); break; } this.display(true); // defines which function will be used by // the given type sharing its variables with // others switch(type[1]){ case "up": case "down": f = function(){ var sz = t.o.offsetHeight, us = cfg.uspeed; // avoid over/undersizing if((mS[1] - (sz + n[1]*us))*n[1] < 0) us = Math.abs(mS[1]-sz); if(sz != mS[1] && mS[1] != 0){ if(n[0]!==0) t.o.style.top = t.o.offsetTop+n[0]*us; t.o.style.height = sz+n[1]*us; return false; } return true; } break; } break; default: } // // starts the animation proccess // var loop = new loopTimeout(cfg.speed,function(){ if(!f || (f && f() === true)){ if(callback) callback.apply(this,args); t.clearAnim(this.id) return false; } return true; }); this.o.hi.anims[loop.id] = loop loop.start(); return this; }, clearAnim: function(id){ // which collection should i use? loopTimeout.erase(id,this.o.hi.anims); return this; }, // sets its height / width to offsetHeight / offsetWidth or to w / h expandSize: function(w,h,tw,th){ var pos = this.getStyle("position"); var isFloatable = (pos == "absolute" || pos == "relative"); this.display(true); if(w!==false) this.o.style.width = w || this.o.offsetWidth; if(h!==false){ h = !isNaN(parseFloat(h)) ? h : this.o.offsetHeight; if(isFloatable && th !== false) this.o.style.top = this.o.offsetTop + this.o.offsetHeight - h; this.o.style.height = h; } return this }, contractSize: function(w,h,tw,th){ return this.expandSize( w !== false ? 1 : w , h !== false ? 1 : h,tw,th); }, // (...) setOpacity: function(v){ if(h.browser.mozilla) this.o.style.MozOpacity = v/100; else if (h.browser.msie) this.o.style.filter= "alpha(opacity=" + v + ");"; else this.o.style.opacity = v/100; }, // //////////////// // RETRIEVING // ////////////////////////// // // DOES NOT CONVERT UNITS <--- // // //================ // this.getStyle() //================ // @ str styleEl : specifies the style element being requested // ------------------------------------------------------------------ // Retrieves the style being used by the element, even if it's not // an inline value. // getStyle: function(styleEl){ var value; if(window.getComputedStyle) value = window.getComputedStyle(this.o,styleEl)[styleEl]; else if(this.o.currentStyle) value = this.o.currentStyle[styleEl]; else value = this.o.style[styleEl]; if(/border((Width)|(Top)|(Left)|(Bottom))Width/.test(styleEl) && h.ex.brdSizeByName[value]) value = h.ex.brdSizeByName[value]; return value; }, //================ // this.getProp() //================ // @str propEl : specifies the property element to be retrieved // example: prop1.prop2.prop3\\.stillprop3.prop4 // // <- mixed propertyValue // ------------------------------------------------------------------- // Retrieves the nested/or not property // getProp: function(propEl){ var props = propEl.match(/((\\\.)|[^\.])+/g),temp_obj = this.o; for(var x=0;x= oLeft && bLeft <= oLeft+width+1 && bTop >= oTop && bTop <= oTop+height+1) return true; return false; }, // w | h (false) not with visible overflow getExpandedSize: function(w,h){ // sets the display to true so we can // retrieve real sizes and stores its // old overflow on 'o' var o = this .display(true) .getStyle("overflow"); // var bw = this.o.offsetWidth, bh = this.o.offsetHeight, oh = this.getStyle("height"); this.o.style.overflow = "visible"; this.o.style.height = "auto"; if(w!==false) bw = this.o.offsetWidth; if(h!==false) bh = this.o.offsetHeight; var r = [bw,bh]; this.o.style.overflow = o; this.o.style.height = oh; this.display(false); return r; }, // //////////////// // CLASSWORK // /////////////////////////////////////// // manages/sets classes // 'class' seems to be RESERVED, using // 'Class' instead // Class: function(){ return this.o.className.match(/([^\s]+)/g) || []; }, removeClass: function(c){ if(c===true){ this.o.className = "" return this; } c = array(c); var cs = this.Class(); for(var i=0;i