/* ************************************** FILE ID: atom_cfl.js FILE TITLE: Common Function Library DESCRIPTION: Contains commonly used Javascript functions COMPATABILITY: IE8+ VERSION: 4.0 ***************************************** Index ----------------------------------------- line # : method name = description of method ----------------------------------------- 15: begsin = test if string begins with X 32: endsin = test if string ends with X ****************************************/ /* ************************************** *** GLOBAL DECLARATIONS ****************************************/ var art = "atom_cfl.js";//atom resource tag var dart = 'ATOM Resource Tag: '+art+'\nSource: '; var dsti = '\nSource Type: '; var dit = '\nIndication Tag: '; var dv = '\nIndication Value: '; var fn = 'Function'; var dstf = dsti+fn+dit; var act_scrpt = new Array();//active script file array act_scrpt[0]= art;//register library manually, push() not yet loaded ie5.5 and lower var act_nfac = new String();// active interface indicator var drg_el = new String();//active drag element drg_el = ""; act_nfac = ""; var foci_ctl=new Array(); var CLOUD_DEBUG_LOG="C:\\Server\\www\\cyphersystems.dev\\public_html\\cloud\\cloud_debugger.log"; /*************************************** *** FUNCTION: addClass *** DESC: adds a css class Selector to the className property of a DOM Object *** ARGUMENTS: *** cs=CSS Class Selector for DOM Object to add the new className to *** c=css class selector EXAMPLE: addClass(object,className); ***************************************/ function addClass(cs,c){ //var cs=getClasses(o); //alert('File: '+art+'\n\nFunction: addClass(cs,c):\ncs:'+cs+'\nc:'+c); var o=sel(cs); if(o.length){ //alert('o.length:'+o.length); var mx=o.length; for(var cnt=0;cnt3?arguments[3]:false; var trust=false; if(typeof(i)=="string"){ if(i=="document"){ var o=document; }else{ if(i=="window"){ var o=window; }else{ var o=sel(i)[0]; } } }else{ if(typeof(i)=="object"){ var o=i; }else{ alert(typeof(i)); } } if(o==null){ alert('The bindEvent function did not resolve an DOM object with the following id:\n\n'+i); return false; } if(document.all){ //alert('o.outerHTML:\n\n'+o.outerHTML); var rslt=o.attachEvent(sEvt,pFn); if(rslt==true){ //alert('Successfully attached event'); }else{ //alert('Error trying to attach event'); } }else{ sEvt=suffix(sEvt,"on"); //alert('binding '+sEvt); if(sEvt=="resize"){ //alert("pFn:"+pFn); if(i=="window"){ var o=window; }else{ var o=document; } } o.addEventListener(sEvt, pFn, capture, trust); } } /**************************************** FUNCTION: brighten DESC: Brightens a given color a given amount ARGS: clr=hexidecimal color amt=amount to increment in decimal EXAMPLE: var newColor=brighten(color,amount); ****************************************/ function brighten(clr,amt){ // example: var newClr='#'+brighten(clr,160); //alert(clr); var r=HexToR(clr); //alert('r:'+r); var g=HexToG(clr); var b=HexToB(clr); var r2=r+amt; var g2=g+amt; var b2=b+amt; r2=(r2>254)?255:r2; g2=(g2>254)?255:g2; b2=(b2>254)?255:b2; //alert('r2-'+r2); var r3=RGBToHex(r2); var g3=RGBToHex(g2); var b3=RGBToHex(b2); //alert(r3+'-'+g3+'-'+b3); var rslt=r3+g3+b3; return rslt; } function BUTTON(){ var o=document.createElement("INPUT"); o.type="button"; return o; } /**************************************** FUNCTION: caller DESC: Returns the name of the function that called the function which passed the args to this method ARGS: args=the arguments object of the function that calls this method RETVAL: [string] the name of the function COMPATABILITY: EX: function myFunc1(){ myFunc2(); } function myFunc2(){ var calledBy=caller(arguments); alert(calledBy); //displays myFunc1 } ****************************************/ function caller(args){ return fnName(args.callee.caller); } /**************************************** FUNCTION: childIndex DESC: returns the index of an element among sibling ELements SRC: http://stackoverflow.com/questions/378365/finding-dom-node-index ARGS: o=DOM Element to determine position of RETVAL: Integer: indicating elements position amongst siblings COMPATABILITY: EX: ****************************************/ function childIndex(e){ //var k=0; //while(e=(e.previousSibling)?e.previousSibling:null){k++} for(k=0;e=(e.previousSibling)?e.previousSibling:null;k++); return k; } function dated() { var ts = new Date(); var yy = ts.getFullYear(); var mm = padLeft(ts.getMonth()+1, '0', 2); var dd = padLeft(ts.getDate(), '0', 2); var hh = padLeft(ts.getHours(), '0', 2); var mn = padLeft(ts.getMinutes(), '0', 2); var ss = padLeft(ts.getSeconds(), '0', 2); var stamp = yy+"-"+mm+"-"+dd; return stamp; } /**************************************** FUNCTION: DOMButton DESC: Creates a DOM INPUT TYPE="button" ARGS: v=Text to appear on button RETVAL: A DOM INPUT TYPE=BUTTON Element COMPATABILITY: EX: var myButton=DOMButton("Continue"); bindEvent(myButton,"onclick",function(){myFunction(myArg)}); //note the use of anonymous function to pass arguments myDiv.appendChild(b1); ****************************************/ function DOMButton(v){ var b1=document.createElement("INPUT"); b1.type="BUTTON"; b1.value=v; return b1; } /**************************************** FUNCTION: clone DESC: creates a clone of an object, including properties and methods ARGS: o=object to clone RETVAL: copy of object COMPATABILITY: EX: var newObj=clone(oldObj); ****************************************/ function clone(o){ function OneShotConstructor(){} OneShotConstructor.prototype=o; return new OneShotConstructor(); } /* ************************************** FUNCTION: contentLeft ARGUMENTS: o = html element to calc left of content for RETURN VALUE: [int]: left of html element's content in pixels NOTES: currently only handles pixel measurements EXAMPLE: var rslt=contentLeft(o); ****************************************/ function contentLeft(o){ var tp=0; //add offsetTop if((o.offsetLeft!='undefined')&&(o.offsetLeft!='NaN')){ tp+=parseInt(o.offsetLeft); } //get borderWidth and padding if(document.defaultView){ //is mozilla browser var blw=document.defaultView.getComputedStyle(o, "")['borderLeftWidth']; var cpl=document.defaultView.getComputedStyle(o, "")['paddingLeft']; }else{ var blw=o.currentStyle.borderLeftWidth; var cpl=o.currentStyle.paddingLeft; } //var blw=o.currentStyle.borderLeftWidth; if((blw!='undefined')&&(blw!='NaN')&&(blw!='medium')&&(blw!='thin')&&(blw!='thick')){ var tmp=blw; tmp=tmp.replace("px",""); //currently only handles pixels tp+=parseInt(tmp); } //add padding //var cpl=o.currentStyle.paddingLeft; if((cpl!='undefined')&&(cpl!='NaN')){ var tmp=cpl; tmp=tmp.replace("px",""); //currently only handles pixels tp+=parseInt(tmp); } if(Parent(o)){ var p=Parent(o); //.parentNode; if(p.tagName=='BODY'){ return tp; }else{ tp+=contentLeft(p); } } return tp; } /**************************************** FUNCTION: contentTop DESCRIPTION: returns the offset top of the content of an element, after calculating the border and padding ARGS: o = the html element to find the content top of NOTES: currently only handles pixel measurements EX: var rslt=contentTop(o); ****************************************/ function contentTop(o){ var tp=0; //add offsetTop if((o.offsetTop!='undefined')&&(o.offsetTop!='NaN')){ tp+=parseInt(o.offsetTop); } //alert('offsetObtained\nelement:'+o.id+'\ntop:'+tp); //add borderWidth var brdTopWD=getXStyle(o,"borderTopWidth"); if((brdTopWD!=null)&&(brdTopWD!='undefined')&&(brdTopWD!='NaN')&&(brdTopWD!='medium')&&(brdTopWD!='thin')&&(brdTopWD!='thick')){ //alert('element:'+o.id+'\nborderHeight:'+o.currentStyle.borderTopWidth); //alert('borderObtained\nelement:'+o.id+'\no.currentStyle.borderTopWidth:'+o.currentStyle.borderTopWidth); var tmp=brdTopWD; tmp=tmp.replace("px",""); //currently only handles pixels tp+=parseInt(tmp); } //alert('borderTopWidth\nelement:'+o.id+'\ntop:'+tp); //add padding var pdTop=getXStyle(o, "paddingTop"); if((pdTop!='undefined')&&(pdTop!='NaN')){ //alert('element:'+o.id+'\nborderHeight:'+o.currentStyle.borderTopWidth); var tmp=pdTop; //o.currentStyle.paddingTop; tmp=tmp.replace("px",""); //currently only handles pixels tp+=parseInt(tmp); } //alert('paddingTop\nelement:'+o.id+'\ntop:'+tp); if(Parent(o)){ var p=Parent(o); //.parentNode; if(p.tagName=='BODY'){ //alert('top:'+tp); return tp; }else{ tp+=contentTop(p); } } return tp; } /**************************************** FUNCTION: copyClip DESC: places text in the clipboard ARGS: t=text to put into clipboard EX: copyClip(txt); ****************************************/ function copyClip(t){ if(window.clipboardData && clipboardData.setData){ clipboardData.setData("Text",t); } } /**************************************** FUNCTION: createFile DESC: creates a file ARGS: fp = file path (including file name) EX: createFile(filepath); ****************************************/ function createFile(fp){ var fso=new ActiveXObject("Scripting.FileSystemObject"); var tf=fso.CreateTextFile(fp, true); // "c:\\testfile.txt" // Write a line with a newline character. tf.Close(); } /* ************************************** FUNCTION: DIV ARGS: [atts] optional = an array of attributes, each attribute is itself an array key-val pair RetVal: A DIV element EX: var newDiv=DIV([AttributesArray]); ****************************************/ function DIV(){ var NumArgs=arguments.length; var tmp=document.createElement('div'); if(NumArgs>0){ atts=arguments[0]; if(atts.length>0){ var mx=atts.length; while(mx){ var itm=atts[mx-1]; var att=itm[0]; var val=itm[1]; switch(att){ case 'innerText':{ text(tmp,val); } } tmp.setAttribute(att,val); mx--; } } } return tmp; } /**************************************** FUNCTION: DOMParent DESC: returns the parent element in the DOM Heirarchy ARGS: i = css3 selector or DOM object EX: var rslt=DOMParent(cssSelector) ****************************************/ function DOMParent(i){ alert('cnb_cfl.php:DOMParent:DEPRECATED\n\nPlease use Parent(o) instead'); var p=null; var a=sel(i)[0]; if(document.all){ p=a.parentElement; }else{ p=a.parentNode; } return p; } /**************************************** FUNCTION: fnName DESC: returns the name of a function ARGS: o = function prototype EX: var rslt=fnName(o); ****************************************/ function fnName(o){ var fName = o.toString().match(/function ([^\(]+)/)[1]; return (!fName)?'anonymous':fName; } function functionName(fn){ var name=/\W*function\s+([\w\$]+)\(/.exec(fn); if(!name)return 'No name'; return name[1]; } /* ************************************** FUNCTION: getClasses DESC: returns an array of all css3 class selectors in an elements className attribute ARGS: o=DOM element RetVal: Integer indicating elements position EX: var ndx=getClasses(o); ****************************************/ function getClasses(o){ //alert(arguments.callee); //var self=this; //alert(self); var fnID="function: "+fnName(arguments.callee)+"\n\n"; //alert(fnID+"o.outerHTML:\n\n"+o.outerHTML); //alert('cnb_cfl.php:getClasses:o'+o); var cs=o.className; //alert(fnID+"cs:"+cs); return cs.split(" "); } /* ************************************** FUNCTION: get_cnstr DESC: RETURNS OBJECT CONSTRUCTOR ARGS: o = object to get contstuctor of RETVAL: constructor of object EX: var rslt=get_cnstr(o); ****************************************/ function get_cnstr(o){ return o.constructor; } /**************************************** FUNCTION: genTS DESC: Returns a timestamp RETVAL: [string] TIMESTAMP FORMAT (YYYY:MM:DD:HH:MM:ss) EX: var ts=genTS(); ****************************************/ function genTS() { var ts = new Date(); var yy = ts.getFullYear(); var mm = padLeft(ts.getMonth()+1, '0', 2); var dd = padLeft(ts.getDate(), '0', 2); var hh = padLeft(ts.getHours(), '0', 2); var mn = padLeft(ts.getMinutes(), '0', 2); var ss = padLeft(ts.getSeconds(), '0', 2); var stamp = yy+":"+mm+":"+dd+":"+hh+":"+mn+":"+ss; return stamp; } /* ************************************** FUNCTION: getDescendants(object, [filter], [format] DESC: Returns an array of all elements in object ARGS: o = DOM Element to return all descendants of s = querySelector as per W3C querySelector list f = integer indicating how descendants are returned: 0 [default]: as array of DOM objects 1: as array of ID or TagName string RETVAL: Array of descendants EX: var rslt=getDescendants(o); ****************************************/ function getDescendants(o){ alert("getDescendants should be optimized possibly using sel() with proper css selector"); var rslt=null; var NumArgs=arguments.length; var sel=(NumArgs>1)?arguments[1]:null; var format=(NumArgs>2)?arguments[2]:0; if(sel!=null){ var oAll=o.querySelectorAll(sel); // limit results by selector }else{ var oAll=o.querySelectorAll("*"); // return all descendants //alternative method for grabbing all descendants - backward comptability //var oAll=o.getElementsByTagName('*'); } var mx=oAll.length; if((format==1)&&(mx>0)){ var tmp=new Array(); for(var c=0;c=0){ loc=loc.substring(0,hasargs); } return loc; } /**************************************** FUNCTION: getPadLeft DESC: Returns the paddingLeft of an HTML element ARGS: o: HTML element to determine padding of RETVAL: [int] paddingLeft of element COMPATABILITY [201103311458]: chrome 10.0.648.151 (Win32,WinXP) ff 3.6.16 (Win32,WinXP) ie 8.0.6001.18702 (Win32,WinXP) opera 10.51.3315 (win32,WinXP) safari 5.0.4(7533.20.27) EX: var rslt=getPadLeft(o); ****************************************/ function getPadLeft(o){ var padLeft=0; if(document.defaultView){ //is mozilla browser var padLeft=document.defaultView.getComputedStyle(o, "")['paddingLeft']; }else{ //is ie var padLeft=o.currentStyle.paddingLeft; } padLeft=padLeft.replace(/px/gi,''); padLeft=parseInt(padLeft); return padLeft; } function getRandom(lwr,upr){ return Math.floor(Math.random()*upr+lwr); } /*************************************** FUNCTION: getXStyle DESC: returns the current runtime style for an element ARGS: el=[object] DOM Element to examine cssprop=[string] the name of the css rule RETVAL: the runtime value of the style COMPATABILITY: IE7,FF4.01 REFS: http://www.javascriptkit.com/dhtmltutors/dhtmlcascade4.shtml ***************************************/ function getXStyle(el, cssprop){ if(el.currentStyle){ //IE return el.currentStyle[cssprop]; }else{ if((document.defaultView)&&(document.defaultView.getComputedStyle)){ //Firefox return document.defaultView.getComputedStyle(el, "")[cssprop]; }else{ //try and get inline style return el.style[cssprop]; } } } /**************************************** FUNCTION: hasClass DESC: Determine if a DOMElement has a particular class assigned to it ARGS: o=DOMElement c=class RETVAL: true or false COMPATABILITY: EX: var rslt=hasClass(o,c); ****************************************/ function hasClass(o,c){ var cs=getClasses(o); if(cs.length){ return cs.contains(c); } return 0; } /**************************************** FUNCTION: hasInnertext DESC: determines if an element has an innerText property ARGS: o=DOM Element RETVAL: 1 or 0 COMPATABILITY: EX: var rslt=hasInnertext(o); ****************************************/ function hasInnertext(o){ //alert(o.outerHTML); return o.innerText!=undefined?1:0; } /**************************************** FUNCTION: hasProperty DESC: Determines if an object has a specific property ARGS: o = [object] object to test p = [string] property to check for RETVAL: 1 if property is not 'undefined' 0 if property is 'undefined' NOTES: Use this instead of browser version detection COMPATABILITY [201103311458]: chrome 10.0.648.151 (Win32,WinXP) ff 3.6.16 (Win32,WinXP) ie 8.0.6001.18702 (Win32,WinXP) opera 10.51.3315 (win32,WinXP) safari 5.0.4(7533.20.27) EX: var rslt=hasProperty(o,p); ****************************************/ function hasProperty(o,p){ if(typeof(o[p])=='undefined'){ rslt=0; }else{ rslt=1; } return rslt; } /**************************************** FUNCTION: hasval DESC: TESTS IF VARIABLE HAS VALUE ARGS: v = variable to test RETVAL: 1 if value is not 'undefined' 0 if value is 'undefined' EX: var rslt=hasval(v); ************************************************************/ function hasval(v){ return (typeof(v)!='undefined')?1:0; } /**************************************** FUNCTION: HexToR, HexToG, and HexToB DESC: Convert Hexidecimal values to Decimal values ARGS: h=hexidecimal string RETVAL: integer COMPATABILITY: EX: var rslt=HexToR(h); var rslt=HexToG(h); var rslt=HexToB(h); ****************************************/ function HexToR(h){return (h.length>4)?parseInt((suffix(h,"#")).substring(0,2),16):parseInt((suffix(h,"#")).substring(0,1),16)} function HexToG(h){return (h.length>4)?parseInt((suffix(h,"#")).substring(2,4),16):parseInt((suffix(h,"#")).substring(1,2),16)} function HexToB(h){return (h.length>4)?parseInt((suffix(h,"#")).substring(4,6),16):parseInt((suffix(h,"#")).substring(2,3),16)} /**************************************** FUNCTION: HIGHEST DESC: RETURNS HIGHER OF 2 VALUES ARGS: a & b = integers to test EX: var highNum=highest(a,b); ****************************************/ function highest(a,b){ return (a>b)?a:b; } /**************************************** FUNCTION: HILITE DESC: Toggle hi-lighting class of object ARGS: [o] = object to toggle class of NOTES: 1. All Hilite classes must be suffixed with "_on", while Un-hilited classes are simply the className OR Each object must have an OFF and ON attribute that define the colors for the hiliting EX: 1. Styles: .mytext{ color:#000; } .mytext_on{ color:#f00; } HTML: This is my Blue Highlighted Text This is my Red Highlighted Text JS: var o=sel('#mySpan2"); hilite(o); ****************************************/ function hilite(e){ if(arguments.length>0){ var o=arguments[0]; }else{ var o=which(e); } if((o.off)&&(o.on)){ var off=o.off; var on=o.on; o.style.color=(o.currentStyle['color']==off)?on:off; if(window.event.type=='mouseout'){ o.btnState='inactive'; } }else{ var cls=o.className; var val=cls.endsin("_on"); o.className=(val>0)?cls.substring(0,val):cls+"_on"; } } /* ************************************** FUNCTION: INCREMENT DESC: Increments an alphanumeric string ARGS: s = [string] : The string to increment RETVAL: [string] the passed string incremented by 1 EX: var rslt=increment("yz9"); returns: za0 ****************************************/ function increment(s){ alert("CFL:increment(s) needs to be tested"); var cleansernum=s.replace(/^\s+|\s+$/g,""); //alert(':'+cleansernum+':'); //break into alpha and numeric chunks //find first non-digit var complete=false; var chunks=new Array(); var cnt=1; var pattern=null; var hasem=null; //break into chunks; while(complete==false){ cnt++; //alert('searching through:'+cleansernum); if(cnt%2==0){ nondig=/[^0-9]/ hasem=cleansernum.search(nondig); }else{ dig=/[0-9]/ hasem=cleansernum.search(dig); } //alert('cnt:'+cnt+'\nhasem:'+hasem); if(hasem>-1){ var str=cleansernum.substring(0,hasem); chunks.push(str); //alert('hasem:'+hasem+" - "+typeof(chunks)); cleansernum=cleansernum.substring(hasem); if((cleansernum.length<1)||(cnt>7)){ complete=true; } }else{ //has only digits remaining so break into 8 character chunks if(cleansernum.length>8){ var digchunks=chunk(cleansernum,8); //alert('chunks type:'+typeof(chunks)); //showarray(chunks); //showarray(digchunks); //var fnlchunks=chunks.concat.digchunks; chunks=digchunks; //alert('afterchunks type:'+typeof(fnlchunks)); }else{ chunks.push(cleansernum); } complete=true; } } //reverse array complete=false; //alert('posttype:'+typeof(chunks)); //showarray(chunks); var parts=chunks.reverse(); //showarray(parts); for(var i=0;i= 65 && ltr.charCodeAt(ltr) <= 90){ var matrix="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; }else{ var matrix="abcdefghijklmnopqrstuvwxyz"; } var ndx=matrix.search(ltr); if(ndx+11){ h=arguments[1]; o.innerHTML=h; }else{ if(o.innerHTML){ return o.innerHTML; } } return null; } function INPUT(){ var o=document.createElement("INPUT"); o.type="text"; return o; } /**************************************** FUNCTION: inputFileName DESC: Displays input box for entering file path, and validates that input ends in "x.xxx[xxxx]" format (last 4 chars are optional) ARGS: t: prompt text to display d: default value of input box EX: var rslt=inputFileName(t,d); ****************************************/ function inputFileName(t,d){ filepath=prompt(t,d); var re=/^.+\.[A-z][A-z0-9]{1,7}$/ var rslt=re.test(filepath); return(rslt)?filepath:null; } /**************************************** FUNCTION: insertChild DESC: inserts and element into the given parent element at a specified position ARGS: o=the Element to insert p=parent Element i=position to insert (0-based) RETVAL: the actual position inserted at (which may be different than the i arg if there are fewer than i-1 children already in the parent COMPATABILITY: EX: ****************************************/ function insertChild(o,p,i){ var rslt=-1; //indicates failure if(typeof(o)=="undefined"){alert("Error:cnb_cfl:insertChild:argument 'o' is undefined");return false}; if(typeof(p)=="undefined"){alert("Error:cnb_cfl:insertChild:argument 'p' is undefined");return false}; if(p.children){ var kids=p.children; }else{ alert("Error:cnb_cfl:insertChild:argument 'p' is not a parent"); } var kidcount=kids.length; if(kidcount<=i){ p.insertAdjacentElement("beforeEnd",o); rslt=kidcount; }else{ //text(DTB,i); var e=p.children[i]; //alert('whiteflag2:\n\n'+o.outerHTML); e.insertAdjacentElement("beforeBegin",o); rslt=i; } return rslt; } /**************************************** FUNCTION: insertCSS DESC: inserts a Stylesheet LINK ELEMENT ARGS: ss=path of stylesheet EX: insertCSS(pathtostylesheet); ****************************************/ function insertCSS(ss){ var headID=document.getElementsByTagName("head")[0]; var cssNode=document.createElement('link'); cssNode.type='text/css'; cssNode.rel='stylesheet'; cssNode.href=ss; cssNode.media='screen'; headID.appendChild(cssNode); } /**************************************** FUNCTION: insertJS DESC: inserts a SCRIPT element into the document HEAD ARGS: js=path of script file EX: insertJS(pathToJSFile); ****************************************/ function insertJS(js){ var headID=document.getElementsByTagName("head")[0]; var newScript=document.createElement('script'); newScript.type='text/javascript'; newScript.src=js; alert("CFL:insertJS:jsLoaded:"+jsLoaded); newScript.onload=jsLoaded; headID.appendChild(newScript); } /**************************************** FUNCTION: isArray(o) DESC: Tests if an object is an array ARGS: o=variable to test RETVAL: 0|1 EX: var rslt=isArray(o); ****************************************/ function isArray(o){ return((typeof(o)=='object')&&("length" in o)&&("mergeUnique" in o))?1:0; } /* ********************************************************** FUNCTION: isEvent DESC: checks whether an object is an Event or not ARGS: o = [object] : The object to test RETURN VALUE: [boolean] true or false SYNTAX: var rslt=isEvent(o); ************************************************************/ function isEvent(o){ //grab the constructor for the unknown object var c=o.constructor; //convert constructor to string var s=c.toString(); /* declare IE RegExp pattern to match for 'object [Event]' */ if(document.all){ //set regExp pattern for IE var ptr=/\[object Event\]/; }else{ /* declare FIREFOX regExp pattern to match for 'object [*Event]' since it has several event types: UIEvent KeyboardEvent MouseEvent FocusEvent WheelEvent CompositionEvent StorageEvent CustomEvent (Requires Gecko 6.0) MutationEvent Both Custom and Mutation events are not recognized prior to Gecko 6.0, so if you want to use these, adjust regExp accordingly */ var ptr=/\[object (Keyboard|Mouse|Focus|Wheel|Composition|Storage)Event\]/; } return ptr.test(s); } /**************************************** FUNCTION: isHTMLElement(o) DESC: Test if an object is an HTML DOM Element ARGS: o = object to test EX: var rslt=isHTMLElement(o); ****************************************/ function isHTMLElement(o){ try{ return (o.constructor.toString().search(/\object HTML.+Element/)>-1)?true:false; }catch(e){ try{ if((o.textContent)||(o.innerText)||(o.innerHTML)||(o.tagName)){ return true; } }catch(e){ return false; } } return false; //redundant safety } /**************************************** FUNCTION: isNodeList(o) DESC: Test if an object is an HTML Node List ARGS: o = object to test EX: var rslt=isNodeList(o); ****************************************/ function isNodeList(o){ return (o.constructor.toString().search(/\object StaticNodeList/)>-1)?true:false; } /**************************************** FUNCTION: isNull DESC: Test if value is equal to null ARGS: v = variable to test RETVAL: 1|0 EX: var rslt=isnull(v); ****************************************/ function isNull(v){ return (v == null)?true:false; } /**************************************** FUNCTION: isNumber DESC: Test if value is of type number ARGS: v = variable to test RETVAL: 1|0 EX: var rslt=isNumber(v); ****************************************/ function isNumber(v){ return (typeof(v)=='number')?1:0; } /**************************************** FUNCTION: isNumeric DESC: Test if value is numeric ARGS: v = variable to test RETVAL: true|false EX: var rslt=isNumeric(v); ****************************************/ function isNumeric(v){ //if(is_number(v)){return 1} return !(isNaN(v)); //var s = dart+'xxx_function_name_xxx'+dstf+'xxx_test_val_xxx'+div+xxx_test_val_xxx; //alert(s); } /**************************************** FUNCTION: isNumericRollover DESC: Test if an integer is about to rollover if incremented ARGS: n = integer to test RETVAL: true|false EX: var rslt=isNumericRollover(n); ****************************************/ function isNumericRollover(n){ var s=n.toString(); var rslt=s.search(/[^9]/); if(rslt>-1){ return false; } return true; } /**************************************** FUNCTION: isXYOver DESC: returns 1 if the x,y coords are over the DOM Element ARGS: o=DOM Element x=x position y=y position RETVAL: 1 or 0 COMPATABILITY: EX: var isOver=isXYOver(myDOMElment,myX,myY); ****************************************/ function isXYOver(o,x,y){ var itmTop=contentTop(o); var itmLeft=contentLeft(o); var itmBottom=itmTop+o.offsetHeight; var itmRight=itmLeft+o.offsetWidth; if((x>=itmLeft)&&(x<=itmRight)){ if((y>=itmTop)&&(y<=itmBottom)){ return 1; } } return 0; } /**************************************** FUNCTION: left DESC: Returns the left portion of a string ARGS: s=[string] string to parse [n]=[integer:optional] RETVAL: string without preceeding spaces COMPATABILITY: SYNTAX: var s="Menzoberranzan"; var rslt=left(s,4);//returns Menz ****************************************/ function left(s){ var n=arguments.length>1?arguments[1]:1; n=(s.lengthb)?b:a; } /**************************************** FUNCTION: microtime DESC: Returns either a string or a float containing the current time in seconds and microseconds ARGS: get_as_float=true to return a float,false to return a string NOTES: version: 1107.2516 discuss at: http://phpjs.org/functions/microtime // + original by: Paulo Freitas EX: 1: var myTimeStamp=microtime(true); result: timeStamp>1000000000 && timeStamp < 2000000000 ****************************************/ function microtime(get_as_float){ var now=new Date().getTime()/1000; var s=parseInt(now,10); return (get_as_float)?now:(Math.round((now-s)*1000)/1000)+' '+s; } /**************************************** FUNCTION: midX DESC: Returns the mid-point of the object passed in ARGS: o = DOM object or css3 selector EX: var rslt=midX(css3sel); ****************************************/ function midX(o){ var e=sel(o); return(typeof(e=='object'))?Math.floor(e.offsetWidth/2):'error:'+e; } /**************************************** FUNCTION: midY DESC: Returns the mid-point in Y-axis of element ARGS: o = DOM object EX: var rslt=midY(css3sel); ****************************************/ function midY(o){ var ht=o.offsetHeight; //height(o); return parseInt(Math.floor(ht/2)); } /* ************************************** FUNCTION: mouseCoords DESC: Returns the x-y coords of mouse position ****************************************/ function mouseCoords(ev){ //alert("CFL:mouseCoords(ev) function requires testing"); if(ev.pageX||ev.pageY){ //firefox code return {x:ev.pageX,y:ev.pageY}; } //ie code return { x:ev.clientX+document.body.scrollLeft-document.body.clientLeft, y:ev.clientY+document.body.scrollTop-document.body.clientTop }; } /**************************************** FUNCTION: OL ARGS: [atts] optional = an array of attributes, each attribute is itself an array key-val pair RETVAL: A OL element EX: var rslt=OL([attributesarray]); ****************************************/ function OL(){ var NumArgs=arguments.length; var tmp=document.createElement('OL'); if(NumArgs>0){ atts=arguments[0]; if(atts.length>0){ var mx=atts.length; while(mx){ var itm=atts[mx-1]; var att=itm[0]; var val=itm[1]; switch(att){ case 'innerText':{ text(tmp,val); } } tmp.setAttribute(att,val); mx--; } } } return tmp; } /**************************************** FUNCTION: outerHTML ARGS: o = DOM Element RETVAL: outerHTML of object EX: var rslt=outerHTML(o); ****************************************/ function outerHTML(o){ try{ return o.outerHTML; }catch(e){ return new XMLSerializer().serializeToString(o); } } function Parent(o){ var p=null; if(document.all){ p=o.parentElement; }else{ p=o.parentNode; } return p; } /* ************************************** FUNCTION: padLeft DESCRIPTION: Pad left PARAMETERS: s = string to pad c = char to pad d = digits of entire final string EX: var rslt=padLeft(string,char,finallength); ****************************************/ function padLeft(s,c,d){ var pad=""; if(typeof(s)!='string'){ if(typeof(s)=='number'){ s=s.toString(); } } //alert('String:'+s+'\nLength:'+s.length+'\nDesired Length:'+d); if(s.length1?arguments[1]:true; if(o.removeNode){ //ie,opera o.removeNode(removeKids); }else{ //mozilla (ff,chrome,safari) o.parentNode.removeChild(o); } } /**************************************** FUNCTION: RemoveEvent SRC: http://bytes.com/topic/javascript/insights/741435-guide-coding-cross-browser-scripts-part-2-event-normalization DESC: removes an event from a DOM object ARGS: o = element to remove event from ev = event to remove (without 'on' prefix) fn = callback function cap = true|false - whether to capture event COMPATABILITY [201103311458]: chrome 10.0.648.151 (Win32,WinXP) ff 3.6.16 (Win32,WinXP) ie 8.0.6001.18702 (Win32,WinXP) opera 10.51.3315 (win32,WinXP) safari 5.0.4(7533.20.27) RETVAL: true | false EX: var rslt=RemoveEvent(o,'mouseup',SomeFunction,false); ****************************************/ function RemoveEvent(o,ev,fn,cap){ if(typeof(fn)!='function'){ return false; } if(o.removeEventListener){ o.removeEventListener(ev,fn,cap); return true; }else if(o.detachEvent){ o.detachEvent('on'+ev,fn); return true; } return false; } /*************************************** FUNCTION: replaceClass DESC: replace one className with another ARGS: o = DOM element nw = new className old = old className EX: replaceClass(o,newClass,oldClass); ***************************************/ function replaceClass(o,nw,old){ var cs=getClasses(o); cs=cs.remove(old); cs.push(nw); var cStr=cs.join(" "); o.className=cStr; } /**************************************** FUNCTION: RGBToHex DESC: accepts an RGB value and returns hex ARGS: rgb = an rgb integer EX: var rslt=RGBToHex(rgb); ****************************************/ function RGBToHex(rgb){ var char="0123456789ABCDEF"; return String(char.charAt(Math.floor(rgb / 16))) + String(char.charAt(rgb - (Math.floor(rgb / 16) * 16))); } /**************************************** FUNCTION: right DESC: Returns the right portion of a string ARGS: s=[string] string to parse [n]=[integer:optional] RETVAL: string without preceeding spaces COMPATABILITY: SYNTAX: var s="Menzoberranzan"; var rslt=right(s,6);//returns ranzan ****************************************/ function right(s){ var n=arguments.length>0?arguments[0]:1; n=(s.length0){ //if(i=='flushVPBottom'){ //was used for viewport functions // alert("found one"); //} if(rslt.length==1){ o=rslt[0]; }else{ o=rslt; } } */ if(rslt.length){ if(rslt.length==0){ rslt[0]=null; } } }else{ //if(i.tagName){ //object is a DOM object if(isHTMLElement(i)){ rslt[0]=i; }else{ if(i.length){ //object is an array of elements rslt=i; }else{ //unknown object type alert('Whiteflag\n\nCall to javascript function sel() with invalid reference.\n\nargument: i\ntype:'+typeof(i)+'\nValue:'+i); } } } return rslt; } /**************************************** FUNCTION: selectFromJSON DESC: Creates a SELECT element with options from a Choices JSON object ARGS: o=Choices JSON object RETVAL: An SELECT HTML DOM Object COMPATABILITY: EX: ****************************************/ function selectFromJSON(o){ //,cb){ var id=o.id; var opts=o.opts; var S=document.createElement("SELECT"); S.id=id; //bindEvent(S,"onchange",cb); for(p in opts){ var val=opts[p]; var nam=p; var opt=document.createElement("OPTION"); S.appendChild(opt); opt.text=val; opt.value=nam; } return S; } /*************************************** FUNCTION: selectIndexByValue DESC: Selects the index of the OPTION element in a SELECT element that has a matching value attribute ARGS: o = SELECT Element css3 selector v = value to compare RETVAL: the index of the matching OPTION element EX: var ndx=selectIndexByValue(o,v); ****************************************/ function selectIndexByValue(o,v){ var lb=sel(o); var opts=lb.options; var mx=opts.length; for(var cnt=0;cnt0){ var mx=atts.length; while(mx){ var itm=atts[mx-1]; var att=itm[0]; var val=itm[1]; //alert('att:'+att+'\nval:'+val); if(att.begsin("style.")){ att=att.substring(6); o.style[att]=val; }else{ if(att=="style"){ o.style.cssText=val; }else{ o.setAttribute(att,val); } } mx--; } } } /**************************************** FUNCTION: setClass(c); DESC: changes className property of DOM Element ARGS: c=new class name RETVAL: none COMPATABILITY: ie8 EX:setClass('mynewclass'); ****************************************/ function setClass(e,c){ if(typeof(e)=='string'){ var o=sel('#'+e)[0]; }else{ var o=which(e); } if(o.className){ o.className=c; }else{ alert('Error:\n\nSource: cnb_cfl.php:setClass\nDescription: Unable to determine className of object'); } } /**************************************** FUNCTION: showArray DESC: displays the contents of an array in an alert box 1 by 1 ARGS: a = array EX: showArray(ary); ****************************************/ function showArray(a){ for(var i=0;i b ARGS: a & b = strings to compare EX: var rslt=sortAlpha(str1,str2); ****************************************/ function sortAlpha(a,b) { if(typeof(a)!='string'){ alert('CFL:sortAlpha: argument a is not a string\n:typeof(a):'+typeof(a)); return 0; } if(typeof(b)!='string'){ alert('CFL:sortAlpha: argument b is not a string:\ntypeof(b):'+typeof(b)); return 0; } var sort_rule = " _-AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"; max = lowest(a.length, b.length); for(var x=0;xb_pos) { return 1; } else { return -1; } } } if(a.length!=b.length) { return a.length - b.length; } } /**************************************** FUNCTION: sortAsc(a,b) DESC: returns 1 if a > b ARGS: a & b = strings to compare EX: var rslt=sortAsc(str1,str2); ****************************************/ function sortAsc(a,b) { if (typeof(a) != 'number') { var val1 = a.split(':'); var val2 = b.split(':'); val1.toFixed(); val2.toFixed(); } else { val1 = a; val2 = b; } var rtn = (typeof(val1)=='number')?(a-b):(val1[0]-val2[0]); return rtn; } /**************************************** FUNCTION: sortDesc(a,b) DESC: returns 1 if b > a ARGS: a & b = strings to compare EX: var rslt=sortDesc(a,b); or myArray.sort(sortDesc); ****************************************/ function sortDesc(a,b) { return (b-a); } /**************************************** FUNCTION: sortRnd(a,b) DESC: randomly sorts an two values ARGUMENTS: a & b = values to compare EX; var Array.sort(sortRnd); ****************************************/ function sortRnd(a,b) { var i = Math.floor(Math.random()*2); if (i==0) { return a-b; } else { return b-a; } } /**************************************** FUNCTION: SPAN DESC: returns a HTML SPAN element EX: var mySpan=SPAN(); ****************************************/ function SPAN(){ return document.createElement('span'); } function standby(){ var SB=sel('#standbyPanel')[0]; if(SB){ removeElement(SB); }else{ var SB=DIV(); var tp=scrollTop()+204; tp=tp+"px"; SB.style.top=tp; var SBMsg=DIV(); SBMsg.className="standbyMsg"; text(SBMsg,"Accessing..."); SB.appendChild(SBMsg); SB.setAttribute("id","standbyPanel"); document.body.appendChild(SB); } } /*************************************** FUNCTION: suffix DESC: returns the suffix of a string appearing after the mtch ARGS: v=string to parse mtch=text to match against EX: var rslt=suffix(myString, "#"); ***************************************/ function suffix(v,mtch){ ptrn=mtch+"([0-9a-zA-Z\-\_]{1,})"; //ptrn=/([0-9a-zA-Z]{1,})([a-zA-Z]{1,})/ var rg=new RegExp(ptrn); rg.exec(v); return RegExp.$1; } /**************************************** FUNCTION: text DESC: cross-browser set innertext ARGS: i=css3 selector of object[s] to change the innertext of t=new text NOTES: moves previous text into an custom attribute called cnbtxt EX: var t=text(o,txt); ****************************************/ function text(i){ var NumArgs=arguments.length; var t=NumArgs>1?arguments[1]:" "; var rslt; //if(typeof(i)=='object'){ //handle objects // var o=i; //}else{//handle css selectors [string] var o=sel(i)[0]; //} if(o){ if(NumArgs>1){ if(document.all){ if(t==" "){ o.innerHTML=t; }else{ o.innerText=t; } }else{ if(t==" "){ o.innerHTML=t; }else{ o.textContent=t; } } return t; }else{ if(document.all){ rslt=o.innerText; }else{ rslt=o.textContent; } return rslt; } }else{ //alert("Whiteflag: unable to resolve css selector: "+x); } } /**************************************** FUNCTION: timelog DESC: gets a timestamp in form of yymmdd EX: var ts=timelog(); ****************************************/ function timelog(){ var d=new Date(); var yr1=d.getYear(); var yr2=yr1.toString().substr(2); var mn=d.getMonth()+1; var dy=d.getDate(); var mp=padLeft(mn,"0",2); var ds=yr2+mp.toString()+dy.toString(); return ds; } /**************************************** FUNCTION: toggleColor(o,a,b) DESC: toggles the color of an object's foreground color ARGS: o=[object] to change the change a=color to match against b=color to change to EX: toggleColor(o,clr1,clr2); ****************************************/ function toggleColor(o,a,b){ if(o.currentStyle){ o.style.color=(o.currentStyle.color==a)?b:a; } } function toggleIMG(evt,pth){ var o=which(evt); if(o.tagName){ //verify object is DOM Object if(o.tagName=="IMG"){ //if object is IMG element, change src to pth if(o.src){ o.src=pth; } }else{ //Otherwise change background: url property var val='url('+pth+')'; o.style.backgroundImage=val; } }else{ //raise error alert('cnb_cfl.php eror:toggleIMG\n\nUnable to determine DOM Element'); } } /* ************************************** FUNCTION: toEntity DESC: converts a number to an html entity ARGS: i = integer to convert EX: var myEnt=toEntity('8818'); ****************************************/ function toEntity(i) { var rtn = "&#"+i.toString()+";"; return rtn; } /**************************************** FUNCTION: toss DESC: returns undefined ****************************************/ function toss() { return(undefined); } /*************************************** FUNCTION: trim(s) DESC: removes whitespace from beginning and end of string ARGS: s=string to trim EX: 1. Basic trim usage var myString = " hello my name is "; var rslt=trim(myString); alert("*"+rslt+"*"); //returns "hello my name is" SRC: http://www.somacon.com/p355.php ***************************************/ function trim(s){ return s.replace(/^\s+|\s+$/g,""); } /**************************************** FUNCTION: TS DESC: returns a unix style timestamp RETVAL: 10 digit number eg. 1200204164 NOTES: c.f. genTS for yyyymmddhhmmss format c.f. timelog for yymmdd format EX: var myTimestamp=ts(); ****************************************/ function ts(){ var ts=Math.round(new Date().getTime()/1000); return ts; } /**************************************** FUNCTION: UL DESC: creates an Unordered List (UL) Element ARGS: [atts] optional = an array of attributes, each attribute is itself an array key-val pair RETVAL: A UL DOM element EX: var myUL=UL(atts); ****************************************/ function UL(){ var NumArgs=arguments.length; var tmp=document.createElement('UL'); if(NumArgs>0){ atts=arguments[0]; if(atts.length>0){ var mx=atts.length; while(mx){ var itm=atts[mx-1]; var att=itm[0]; var val=itm[1]; switch(att){ case 'innerText':{ text(tmp,val); } } tmp.setAttribute(att,val); mx--; } } } return tmp; } function urlargs(){ var loc=window.location.href; var hasargs=loc.indexOf("?"); //alert('loc:'+loc+'\nhasargs:'+hasargs); if(hasargs){ //alert('we have args'); var astr=loc.substring((hasargs+1),loc.length); var hasKV=astr.indexOf("="); if(hasKV){ var hasMulti=astr.indexOf("&"); if(hasMulti){ var KVPairs=astr.split("&"); var RSLT=new Array(); for(var pr=0;pr57))&&((ky <96)||(ky>105))&&((ky<37)||(ky>40))&&(ky!=8)&&(ky!=9)&&(ky!=16)&&(ky!=46)){ window.event.cancelBubble = true; window.event.returnValue = false; return false; } return ky; } /**************************************** FUNCTION: which() DESC: Returns the element that fired the event. A x-browser substitute for window.event.srcElement||window.event.target EX: var elm=which(); ************************************************************/ function which(e){ var evt=e||window.event; var o=(evt.srcElement)?evt.srcElement:evt.target; //alert(outerHTML(o)); return o; } /**************************************** FUNCTION: WND DESC: OPEN NEW WINDOW ARGS: [pth]=URL path, if not passed the path is retrieved from the Firing Element's href attribute EX: var newWnd=wnd(uri); ****************************************/ function wnd(e) { if(window.event){ window.event.cancelBubble=true; } var pth=(arguments.length>0)?arguments[0]:(which(e).href)?which(e).href:null; var w=window.open(pth,'_blank'); return false; } /*************************************** FUNCTION: wrap() DESC: wraps one element within another ARGS: s = inner HTML h = outer Element EX: var myElm=wrap(innerHTML, outerELM); ***************************************/ function wrap(s,h){ var e=document.createElement(h); e.setAttribute("innerHTML",s); return e; } /**************************************** FUNCTION: writeToLog DESC: writes text to a logfile ARGS: fp = file path (Note: this must be an absolute path with backslashes escaped as follows: var logPath="E:\\\\cnb\\projects\\cnbcom\\sitecontent\\testLog.txt"; txt = text to write to file [nw] = [optional] force new file/no appending 0 = create a new file only if it does not exist, present input to choose to overwrite, if not presents input to specify new file new 1 = create new file, overwriting previous versions 2 = append to file, creating new file if it does not exist RETVAL: returns true if successful, false otherwise EX: var rslt=writeToLog(fp,txt); ****************************************/ function writeToLog(fp,txt){ var rslt=false; if(document.all){ var NumArgs=arguments.length; var ForAppending=8; var ForWriting=2; var nw=0; var fcts=0; if(NumArgs>2){ nw=arguments[2]; //overwrite rule if(NumArgs>3){ fcts=arguments[3]; //filecreation timestamp indicator 0 = include file created timestamp, 1=do not include file timestamp } } try{ var fso=new ActiveXObject("Scripting.FileSystemObject"); var txtfile; if(fso.FileExists(fp)){ switch(nw){ case 0:{ //file exists, present input to choose to overwrite var overWrite=confirm("File already Exists:\n\nFile: "+fp+"\n\nWould you like to overwrite the file?"); if(overWrite){ txtfile=fso.OpenTextFile(fp,ForWriting,false); if(fcts==0){ txtfile.Write("*****************************************"); txtfile.Write("\nFile Created:"+genTS()); txtfile.Write("\n*****************************************"); } txtfile.Write(txt); txtfile.Close(); rslt=true; break; }else{ //present input box to enter new filename var newFP=inputFileName("Enter a new file name and path or Cancel the file writing operation.",fp); if(newFP==null){ return false; //user cancelled log operation }else{ writeToLog(newFP,txt); } } break; } case 1:{//tested when file exists GOOD txtfile=fso.OpenTextFile(fp,ForWriting,true); if(fcts==0){ txtfile.Write("*****************************************"); txtfile.Write("\nFile Created:"+genTS()); txtfile.Write("\n*****************************************"); } txtfile.Write(txt); txtfile.Close(); rslt=true; break; } case 2:{ //tested when file exists GOOD txtfile=fso.OpenTextFile(fp,ForAppending,false); txtfile.Write(txt); txtfile.Close(); rslt=true; break; } } }else{//tested when file does not exist var ForWriting=2; txtfile=fso.OpenTextFile(fp,ForWriting,true); if(fcts==0){ txtfile.Write("*****************************************"); txtfile.Write("\nFile Created:"+genTS()); txtfile.Write("\n*****************************************"); } txtfile.Write(txt); txtfile.Close(); rslt=true; } }catch(err){ //window.status='CNB Error Console:\n\nUnknown Error Detected\n\nFunction: writeToLog\n\n'+err; } } return rslt; } /*************************************** FUNCTION: XEvent() DESC: x-browser event object EX: var vnt=XEvent(); ***************************************/ function XEvent(){ var e=window.event; return e; } /**************************************** FUNCTION: XKeyCode() DESC: returns the keyCode for a pressed key RETVAL: ASCII keyCode EX: var ky=XKeyCode(); ****************************************/ function XKeyCode(){ e=XEvent(); var keyCode=0; if(e.keyCode){ keyCode=e.keyCode; }else{ keyCode=e.charCode; } return keyCode; } /**************************************** FUNCTION: zztop; SRC: src:http://greengeckodesign.com/blog/2007/07/get-highest-z-index-in-javascript.html DESC: Finds the highest zIndex in use RETVAL: integer indicating the highest z-index COMPATABILITY: EX: var myZ=zztop(); ****************************************/ function zztop(){ var highestIndex=0; var currentIndex=0; var elArray=Array(); elArray=document.getElementsByTagName('*'); for(var i=0;ihighestIndex){ highestIndex=currentIndex; } } return(highestIndex+1); } /************************************************************************************************************ FINISH FOLLOWING FUNCTIONS ************************************************************************************************************/ /* ********************************************************** *** FUNCTION: elementUnderPoint * *** DESC: Returns element at point with highest z-index * ************************************************************/ function elementUnderPoint(x,y){ //moot function -> modify to use element offsetWidth and offsetHeight as well as to accept two parameters, z for zIndex, and rel for 'belowZIndex', 'aboveZIndex', 'eqToZIndex'; var curOver=document.elementFromPoint(x,y); return curOver; } /* ********************************************************** *** FUNCTION: GET_NUM_PFX * *** DESCRIPTION: RETURNS NUMERIC PREFIX OF STRING * *** ARGUMENTS: * *** s = string to strip numeric prefix from * *** RETURN VALUE: * *** numeric prefix of string * ************************************************************/ function get_num_pfx(s) { alert("get_num_pfx(s) called: integrate this function with prefix(txt,sfx)"); var reg = /^(\d+)/ var matches = reg.exec(s); return matches[0]; } function get_ts(){ alert("get_ts() DEPRECATED: use genTS() instead"); } function getInnertext(o){ alert('getInnertext needs to be modified to use text() instead'); if(hasInnertext(o)){ return o.innerText; }else{ return o.textContent; } } /* ********************************************************** *** FUNCTION: getRule * *** DESCRIPTION: Returns the css rule DOM object that * *** matches the selector passed in * *** ARGUMENTS: * *** sel: css selector to match * *** RETURN VALUE: * *** [DOM Rule object] that matches the selector * ************************************************************/ function getRule(sel){ //alert(document.styleSheets.length); var ssmax=document.styleSheets.length; for(var sscnt=0;sscnt0){ var fn=rslt[1]; alert('filename:'+fn); }else{ var fn=null; } return fn; } function grandpa(o){ alert("call to CFL:grandpa(o): consider updating to use DOMParent(DOMParent(o))"); return DOMParent(DOMParent(o)); } function grandpasFirstKid(o){ alert("call to CFL:grandpa(o): consider updating to use double DOMParent()"); var k=grandpa(o); return k.children[0]; } /* ********************************************************** *** FUNCTION: htmlentitydecode * *** DESCRIPTION: Replaces HTML Entities with their * *** assigned HTML special character * *** ARGUMENTS: * *** s = [type] specification * *** RETURN VALUE: * *** [type] specification * *** EXAMPLE: * *** Given: * *** s="<div>Hello Menzoberranzan<div>" * *** Return Value: * ***
Hello Menzoberranzan
* NOTES: INCOMPLETE ************************************************************/ function htmlentitydecode(s){ alert("CFL:htmlentitydecode() is incomplete"); var re=/\<\;/ s=s.replace(re, "<"); re=/\>\;/ s=s.replace(re, ">"); return s; } /* ********************************************************** *** FUNCTION: htmlentityencode * *** DESCRIPTION: Replaces HTML special characters with * *** their assigned HTML Entity * *** ARGUMENTS: * *** s = [string] : The string to encode * *** RETURN VALUE: * *** [string] HTML Entity enconded string * *** EXAMPLE: * *** Given: * *** s="
Hello Menzoberranzan
" * *** Return Value: * *** <div>Hello Menzoberranzan<div> * ************************************************************/ function htmlentityencode(s){ alert("CFL:htmlentityencode() is incomplete"); var re=// s=s.replace(re, ">"); return s; } function isOrdinal(v) { alert("CFL:isOrdinal:INCOMPLETE FUNCTION:"); var sfx=v.substr((v.length-2),2); var s = dart+'is_ordinal'+dstf+'sfx'+div+sfx var sfxs = new Array('st','nd','rd','th'); if(sfxs.has(sfx)) { } } function jsLoaded(){ //used to indicate loading of a script or used as callback if modified to handle arguments alert('CFL:jsLoaded() INCOMPLETE FUNCTION:javacript loaded'); } /* **************************************************************** *** FUNCTION: LIST_SCRIPT_FILES * *** DESCRIPTION: DISPLAYS LIST OF ALL ACTIVE SCRIPT FILES * *******************************************************************/ function list_script_files() { alert("CFL:list_script_files() INCOMPLETE"); var msg = new String(); msg = 'The following script files are registered:\n\n'; for (var x=0; x0){ for(x=0;x-1){ e.attachEvent(att,eval(val)); } else { e.setAttribute(att,val); } } } } return p.appendChild(e); } /* ********************************************************** *** FUNCTION: assignEventHandler DEPRECATED cf. bindEvent instead *** ARGUMENTS: * *** sel = css3 selector * *** evt = mozilla event name, eg "mousedown" * *** fn = function pointer * *** NOTE: * *** only tested for mousedown event, other events may * *** require conversion of some sort * *** COMPATABILITY [201103311458]: * *** chrome 10.0.648.151 (Win32,WinXP) * *** ff 3.6.16 (Win32,WinXP) * *** ie 8.0.6001.18702 (Win32,WinXP) * *** opera 10.51.3315 (win32,WinXP) * *** safari 5.0.4(7533.20.27) * ************************************************************/ function assignEventHandler(sel,evt,fn){ var msevt="on"+evt; var lnkCats=document.querySelectorAll(sel); if(lnkCats.length){ var maxCats=lnkCats.length; while(maxCats){ var itm=lnkCats[maxCats-1]; if(itm.attachEvent){ itm.attachEvent(msevt,fn); }else{ itm.addEventListener(evt,fn,true); } maxCats--; } }else{ alert('No elements found that match the css3 selector provided\n\nCSS3 Selector:'+sel); } } /************************************************************ *** FUNCTION: DEL * *** DESCRIPTION: getElementById * *** ARGUMENTS: * *** i = id string or object reference to element * DEPRECATED: Use RemoveElement instead ************************************************************/ function del(i){ alert("del() DEPRECATED: Use RemoveElement instead"); var o=(typeof(i)=="string")?gel(i):i; o.innerHTML=""; removeElement(o); } function div(){ alert("div() function is deprecated\n\nUse the DIV() function [NOTE THE UPPERCASE] instead"); } /**************************************** FUNCTION: echo() ****************************************/ function echo(i){ //alias for alert alert("echo() DEPRECATED: use alert() instead"); //alert(i); } /************************************************************ * *** FUNCTION: ELM * * *** ReturnValue: an HTML element * ************************************************************/ function elm(o){ alert("elm(o) DEPRECATED use DIV(), SPAN, or document.createElement instead"); var el=null; var mkr=o.mkr; switch(mkr){ case 'c':{ el=cbx(); break; } case 'd':{//div el=DIV(); break; } case 's':{//span el=span(); break; } case 'b':{//button el=btn(); break; } case 'n':{//input el=npt(); break; } case 'r':{//radio el=rdo(); break; } case 't':{//textarea el=txt(); break; } } var att=o.att; el=set_att(el,att); return el; } /* *** FUNCTION eventElm * *** ex: var o=eventElm(); DEPRECATED: only works in ie, work on getEvent function instead */ function eventElm(){ alert("eventElm() DEPRECATED use which() instead"); var o=(window.event.srcElement)?window.event.srcElement:window.event.target; return o; } /* ******************************************************* *** FUNCTION: filterById(ol) * *** DESCRIPTION: Returns the array of DOM elements * *** with with elements having the given id removed * *** PARAMETERS: * *** ol = an array of DOM elements * *** i = [string]: ID to match * *** DEPRECATED: use sel(i) instead * *********************************************************/ function filterById(ol,i){ alert("filterById() DEPRECATED use sel(csssel) instead"); var tmp=new Array(); //alert('haslength'+ol.length); for(var x=0;x USE set(id) instead *** DESCRIPTION: getElementById *** Parameters: *** i = id of element *** Returns: DOM ref to element DEPRECATED: use set1(instead) ************************************************************/ function gel(i) { alert("gel() DEPRECATED use sel(csssel) instead"); if((i==null)||(i=="")) { if(err){return err.raise()}else{return false} } var o = document.getElementById(i); return o; } /* ********************************************************** *** FUNCTION: getAll (DEPRECATED -> USE set1(id) instead* *** DESCRIPTION: gets all elements by selector * *** Parameters: * *** sel = id of element * *** Returns: DOM ref to element * DEPRECATED: use sel(instead) ************************************************************/ function getAll(sel){ alert("getAll(sel) DEPRECATED: use sel(css) instead"); var rslt=null; if(arguments.length>1){ parentSEL=arguments[1]; //var oLimit = document.querySelector("#second"); //var oAllPs = oLimit.querySelectorAll("div"); var parents=document.querySelector(parentSEL); rslt=parents.querySelectorAll(sel); } else{ rslt=document.querySelectorAll(sel); } //var sFound=(oAllPs==null)?"No matches found" : allPs.length; return rslt; } /* ********************************************************** *** FUNCTION: getChildByAttrib * *** DESCRIPTION: returns the DOM element child that * *** both is the child of a given element, passed as * *** argument[0] and that has the given class name, * *** passed as argument[1] *** Return Value: Returns one of: * *** 1) a DOM element * *** 2) an array of matching DOM * *** elements * *** 3) an array of mis-matching * *** children * ************************************************************/ function getChildByAttrib(o,attrib){ alert("DEPRECATED use sel() with proper CSS Selectors"); var list=new Array(); for(x in o.children){ c=o.children[x]; for(a in c){ if(a==attrib){ //alert('class found'); return c; }else{ list[list.length]=a; } } } return list; } /* ********************************************************** *** FUNCTION: getChildByClass * *** DESCRIPTION: returns the DOM element child that * *** both is the child of a given element, passed as * *** argument[0] and that has the given class name * *** passed as argument[1] * *** Return Value: Returns one of: * *** 1) a DOM element * *** 2) an array of matching DOM * *** elements * *** 3) an array of mis-matching * *** children * ************************************************************/ function getChildByClass(o,cls){ alert("getChildByClass(o,cls) DEPRECATED: use sel() with proper CSS Selector"); var list=new Array(); for(x in o.children){ c=o.children[x]; if(c.className==cls){ return c; }else{ list[list.length]=x.className; } } return list; } /* ********************************************************** *** FUNCTION: getChildrenByTag * *** DESCRIPTION: returns the DOM element child that * *** both is the child of a given element, passed as * *** argument[0] and that has the given tag name, * *** passed as argument[1] * *** Return Value: Returns one of: * *** 1) a DOM element * *** 2) an array of matching DOM * *** elements * *** 3) null * ************************************************************/ function getChildrenByTag(obj,tnam){ alert("getChildrenByTag DEPRECATED: use sel() with proper CSS selector instead"); var list=new Array(); var o=sel(obj); if(o.children){ for(x in o.children){ c=o.children[x]; if(c.tagName==tnam){//change to str.toUpper() or whatever jscript Case-switching function is list.push(c); } } switch(list.length){ case 0:{ list=null; break; } case 1:{ list=list[0]; break; } } return list; } return null; } /* ************************************** FUNCTION: getChildPos DESC: returns the index of the elements position in relation to its siblings ARGS: o=the element to determine position of RETVAL: Integer indicating elements position EX: var ndx=getChildPos(o); ****************************************/ function getChildPos(o){ alert("getChildPos(o) DEPRECATED: use childIndex(o) instead"); var pos=0; var p=DOMParent(o); var kds=p.childNodes; var mx=kds.length; while(mx){ var itm=kds[mx-1]; if(itm===o){ return mx-1; } mx--; } } function getFullHeight(i){ alert('getFullHeight DEPRECATED: use obj.offsetHeight instead'); var o=sel(i); var oHT=o.offsetHeight; return oHT; } function getFullWidth(i){ alert('getFullWidth DEPRECATED: use obj.offsetWidth instead'); var o=sel(i); var oWD=o.offsetWidth; //var oBL=prefix(o.style.borderLeftWidth,'px'); //var oBR=prefix(o.style.borderRightWidth,'px'); //var oTotWD=parseInt(oWD)+parseInt(oBL)+parseInt(oBR); return oWD; } /* ********************************************************** *** FUNCTION: getFunctionName(s) * *** DESCRIPTION: getElementById * *** Parameters: * *** s = passed arguments.callee.toString(); from * *** inside function in question * *** Returns: DOM ref to element * ************************************************************/ function getFunctionName(s){ alert("getFunctionName(s) DEPRECATED: use fnName(o) instead"); var nam=s.match(/^function\s([A-Za-z][A-Za-z0-9]*)\s*\(/); return(nam!=null)?nam[1]:nam; } /* ********************************************************** *** FUNCTION: getSelectors * *** DESCRIPTION: Returns an array of all the css * *** selectors in an elements className attribute * *** ARGUMENTS: * *** o: DOM element to inspect for css selectors * *** RETURN VALUE: * *** [array] containing all selectors in objects className * ************************************************************/ function getSelectors(o){ alert("getSelectors DEPRECATED: use getClasses(o) instead"); //alert('getting selector for '+o); var c=trim(o.className); if(c){ var sels=c.split(" "); if(isArray(sels)){ return sels; }else{ //alert('Error: non-array detected while parsing className for selectors\nSource File:cnb_cfl.js\nSource Object: function getSelectors\nSelectors detected:'+sels+'\nelment outerhtml:\n\n'+o.outerHTML); } }else{ return []; } } function getStyle(){ alert("getStyle DEPRECATED: use getClasses(o) instead"); } /* ********************************************************** *** FUNCTION: hasProp * *** DESCRIPTION: Returns true if Object o has property p* *** PARAMETERS: * *** o = object to test * *** p = property to check for * *** RETURN VALUE: * *** true if value is not 'undefined' * *** false if value is 'undefined' * ************************************************************/ function hasProp(i,p){ alert("CFL:hasProp(i,p) DEPRECATED: use hasProperty instead"); var o=sel(i); if(o){ alert('object exists'); } /**** UNFINISHED * */ } /* ********************************************************** *** FUNCTION: height * *** PARAMETERS: * *** o = html element to measure height of * *** RETURN VALUE: * *** [int]: height of html element in pixels * *** NOTES: * *** currently only handles pixel measurements * ************************************************************/ function height(o){ var clr=caller(arguments); alert("CFL:height(o) DEPRECATED use o.offsetHeight instead\n\nCaller:\n"+clr); var ht=0; //add offset height if(o.offsetHeight!='undefined'){ ht+=o.offsetHeight; } //get border height if(o.currentStyle.borderTopWidth!='undefined'){ //alert('element:'+o.id+'\nborderHeight:'+o.currentStyle.borderTopWidth); var tmp=o.currentStyle.borderTopWidth; tmp=tmp.replace("px",""); //currently only handles pixels /* tmp=tmp.replace("cm",""); tmp=tmp.replace("mm",""); tmp=tmp.replace("in",""); tmp=tmp.replace("pt",""); tmp=tmp.replace("pc",""); */ ht+=parseInt(tmp); } return ht; } function init_dsply(){ alert("CFL: init_dsply DEPRECATED: use layout.php:initDisplay() instead"); } /**************************************** FUNCTION: is_array() DEPRECATED: used isArray instead * DESC: Returns 1(one) if variable is an array * o (zero) otherwise * ARGS: * o = variable to test * ************************************************************/ function is_array(o){ alert("CFL:is_array(o) is DEPRECATED: use CFL:isArray() instead"); if((typeof(o)=='object')&&("length" in o)&&("mergeUnique" in o)){ return 1; } return 0; } function isnull(v){ alert("CFL:isnull is DEPRECATED: use isNull(v) instead"); return (v == null)?true:false; } function is_number(v){ alert("CFL:is_number(v) is DEPRECATED: use isNumber() instead"); return (typeof(v)=='number')?1:0; } function is_numeric(v){ alert("CFL:is_numeric(v) is DEPRECATED: use isNumeric(v) instead"); return (typeof(v)=='number')?1:0; } function is_ordinal(v){ alert("CFL:is_ordinal(v) is DEPRECATED: use isOrdinal instead"); } function mid(){ alert("CFL:mid(o) DEPRECATED: use midX instead"); } /* ********************************************************** *** FUNCTION: NONULL * *** DESCRIPTION: RETURNS TRUE IF VARIABLE IS NOT NULL * *** PARAMETERS: * *** v = variable to test * ************************************************************/ function nonull(v) { alert("CFL:nonull(v) is DEPRECATED: use isNull(v) instead"); return (v == null)?false:true; } function pad_lft(){ alert("CFL:pad_lft(s,c,d) is DEPRECATED: use padLeft(s,c,d) instead"); } function parent(o){ alert('Deprecated: use Parent(o) instead'); //return o.parentNode; } function stripPoundSymbol(h){ alert("CFL:stripPoundSymbol DEPRECATED: use suffix(h,'#') instead"); return (h.charAt(0)=="#") ? h.substring(1,h.length):h } /* ********************************************************** *** FUNCTION: SET * *** DESCRIPTION: Returns a DOM element * *** ARGUMENTS: * *** i = [string] id of DOM element to return * *** or * *** i = [object] a DOM element to verify and return * ************************************************************/ function set(i){ alert("set(i) DEPRECATED: use sel(css) instead"); //alert('NOTICE: set function deprecated\n\nReplace with sel() function in project\n\nNo other changes are required'); var o=null; if(typeof(i)=='string'){ if(document.getElementById(i)){ o=document.getElementById(i); }else{ alert('Whiteflag\n\nCall to javascript function set() with invalid reference.\n\nargument: i\ntype:'+typeof(i)+'\nValue:'+i); } }else{ if(i.tagName){ o=i; }else{ alert('Whiteflag\n\nCall to javascript function set() with invalid reference.\n\nargument: i\ntype:'+typeof(i)+'\nValue:'+i); } } return o; } /* ********************************************************** *** FUNCTION: SET1 * *** DESCRIPTION: Same as set() but uses querySelector * *** ARGUMENTS: * *** i=[string] querySelector of DOM elements to return * *** DEPRECATED: Use sel(i) instead ************************************************************/ function set1(i){ alert("set1(i) DEPRECATED: use sel(css) instead"); var cr=arguments.callee; var callerName=cr.caller.name; var callerFN=cr.caller.toString(); alert('NOTICE: set1 function deprecated\n\nReplace with sel() function in project\n\nCaller Name: '+callerName+'\nCaller Code:\n\n'+callerFN); for(x in cr){ alert('x: '+x+'\n\ncaller[x]:'+arguments.caller[x]); } var o=null; if(typeof(i)=='string'){ var rslt=document.querySelectorAll(i); if(rslt.length>0){ if(rslt.length==1){ o=rslt[0]; }else{ o=rslt; } } }else{ if(i.tagName){ o=i; }else{ alert('Whiteflag\n\nCall to javascript function set() with invalid reference.\n\nargument: i\ntype:'+typeof(i)+'\nValue:'+i); } } return o; } function setButton(i,cls){ alert("cnb_cfl.php:setButton: Deprecated\n\nUse setClass instead"); /* i = id of object, st=state to set button to: Active, Off, On */ //var o=which(e); //alert("myObj.outerHTML:"+outerHTML(myObj)); //if(typeof(i)=='string'){ var myCls=i+cls; var cs='#'+i; var o=sel(cs)[0]; //}else{ //alert(typeof(i)); // var o=i; //} //alert("i:"+i+"\nst:"+st+"\nmyCls:"+myCls); //o.active="1"; o.className=cls; } /* ********************************************************** *** FUNCTION: setInnertext(o,[txt]) * *** DESCRIPTION: sets the innerText or textContent of an * *** an element to the text passed as second argument* *** or "" if no text was passed as second argument * *** ARGUMENTS: * *** o = HTML Element * *** [txt] = [string][optional] * *** DEPRECATED: use text() instead * ************************************************************/ function setInnertext(o){ alert("setInnertext(o) DEPRECATED: use text(o,txt) instead"); var cr=arguments.callee; var callerName=cr.caller.name; var callerFN=cr.caller.toString(); var msg='Error: Call to function name\n'; msg+='Desc: setInnertext function has been deprecated.\n'; msg+='Resolution: use text(sel) function instead\n'; msg+='Caller Name: '+callerName+'\nCaller Code:\n\n'+callerFN; //alert(msg); var NumArgs=arguments.length; var txt=(NumArgs>1)?arguments[1]:""; if(hasInnertext(o)){ o.innerText=txt; }else{ o.textContent=txt; } } /* ********************************************************** *** FUNCTION: span() * *** DESCRIPTION: returns a HTML span element * ************************************************************/ function span(){ alert("span() DEPRECATED: use SPAN() instead (note uppercase)"); //alert("span() function in cnb_cfl.php is DEPRECATED.\n\nReplace all calls with SPAN()\n\n***Notice the UPPERCASE"); return document.createElement('span'); }