Post by Chris on Nov 1, 2006 6:33:27 GMT -8
Overview: Find spelling or casing errors more quickly by viewing javascript code in color. Forgot to escape a quote within a quote? You'll spot it immediately.
Wondering if that code is cross-browser? You'll see methods and properties exclusive to a browser platform jump out at you with a color of your choice.
Validate the code to make sure some unnoticed mistake is not hiding in there. Options defining how strict or lax you want the validation are user definable.
Preview:
To Do:
Known Bugs:
Edit:
Wondering if that code is cross-browser? You'll see methods and properties exclusive to a browser platform jump out at you with a color of your choice.
Validate the code to make sure some unnoticed mistake is not hiding in there. Options defining how strict or lax you want the validation are user definable.
Preview:
<script type="text/javascript" language="Javascript1.5">
<!--
/*
Name: CODE HIGHLIGHTER
Created by EtonBones at yahoo d o t com
Do not redistribute without permission
Feel free to edit provided a notation is
added to this header stating that fact.
THIS HEADER MUST REMAIN INTACT.
Location: Global Footer
*/
/* =======Start user editable options========== */
var comment_color="green";
var string_color="blue";
var tag_color="lime";
var keyword_color="#9932CC";
var property_color="brown";
var DOM_property_color="brown";
var DOM_IE_property_color="sandybrown"; //MSIE exclusive properties
var DOM_Moz_property_color="sandybrown"; //Mozilla exclusive properties
var method_color="orange";
var DOM_IE_method_color="peru"; //MSIE exclusive methods
var DOM_Moz_method_color="peru"; //Mozilla exclusive methods
var javaEvent_color="#FF00FF";
var Obj_event_color="tan"; //Event object attribs common to both platforms
var Obj_IE_event_color="tan"; //MSIE exclusive event object attribs
var Obj_Moz_event_color="tan"; //Mozilla exclusive event object attribs
/* ========End user editable options========== */
var HFT;
var AT;
var tStyle;
var xmpSetInline=false;
var taBorderColor;
var comment_block;
var comment_line;
var quoted_string;
var keywords;
var properties;
var Moz_properties;
var IE_properties;
var methods;
var Moz_methods;
var IE_methods;
var javaEvents;
var br=""; if(document.all){br="<br/>";}
var tags=/<(script|style).*?>(\w|\W)*?<\/\1>/gim
var parts=new Array();
var xO="<xm"+"p>";
var xE="<"+"/xm"+"p>";
var xid=" id='hi"+"lightJS'";
if(location.href.match(/action=headersfooters2/i) ){
var font=document.getElementsByTagName('textarea');
if(font && document.getElementsByName('footer')){
taBorderColor= font[0].style.borderColor;
font=font[0].parentNode;
TABS=document.createElement('div');
TABS.style.align="left";
TABS.id="tabSet_";
TABS.style.display="inline";
var tabs= "<button class='tab active' onclick='setActive(this); HFT=this.divparent.textarea; codeDiv.style.display=\"none\"; funcJump();' type='button'> ";
tabs+="Edit Source</button> ";
tabs+= "<button class='tab' onclick=' setActive(this); HFT=this.divparent.textarea; addTabs();' type='button'>";
tabs+="View Syntax</button> ";
tabs+= "<button class='tab' onclick='setActive(this); HFT=this.divparent.textarea; addTabs(); validateCode(HFT); ' type='button' > ";
tabs+="Validate Code</button> ";
tabs+= "<button class='tab' onclick='setActive(this); HFT=this.divparent.textarea; addTabs(); document.getElementById(\"code\").innerHTML=manageCode();' type='button'>";
tabs+="Manage Code</button>"+br;
TABS.innerHTML=tabs;
var T=document.getElementsByTagName('textarea');
for(i=0;i<T.length;i++){
T[i].onselect=function(){getControl(this);}
T[i].onclick=function(){getControl(this);}
T[i].onmouseover= function(){getControl(this);}
T[i].onmouseout=function(){funcJump();}
T[i].setAttribute("WRAP","SOFT");
T[i].id=T[i].name;
T[i].lastValue=T[i].value;
HFT=T[i]; funcJump();
tabs=TABS.cloneNode(true);
tabs.id=tabs.id+T[i].name;
tabs.textarea=T[i];
for(var j=0;j< tabs.childNodes.length;j++){tabs.childNodes[j].divparent=tabs;}
font.replaceChild(tabs,T[i].previousSibling);
if(T[i].name=="footer" ){var x=T[i];}
}
if(T[0].value.length){HFT=T[0];}else{HFT=T[1]}
document.getElementById("tabSet_"+HFT.name).focus();
var codeDiv=document.createElement('div');
font.insertBefore(codeDiv,HFT);
if(x){
while(x.tagName.toLowerCase()!="input" && x.accessKey!="s" && x.value!="Save changes"){
x=x.nextSibling;
}
if (x && x.addEventListener){
x.addEventListener("click", confirmScripts, true);
}else if (x && x.attachEvent){
x.attachEvent("onclick", confirmScripts);
}
}
with(codeDiv.style){
position="absolute";
margin="2px auto";
overflow="hidden";
background="white";
align="center";
border="2px solid #000";
display="none";
}
tStyle=document.getElementsByTagName('style')[0].innerHTML.match(/textarea.*/i);
var gRules=document.styleSheets[0];
if(gRules.addRule){
gRules.addRule("xmp", "display:inline");
}else if(gRules.insertRule){
gRules.insertRule("xmp {display:inline}",0);
gRules.insertRule("button.tab {background-color: #f0f0f0; color: #000000; border: 1px solid #000000; border-bottom-width: 0px; padding: 2px 1em 2px 1em; text-decoration: none;}",0);
gRules.insertRule("button.tab[disabled] {color: #c0c0c0;}",0);
gRules.insertRule("button.tab:hover {background-color: #d0d0d0;}",0);
gRules.insertRule("button.tab.active, button.tab[disabled].active, button.tab:hover.active { background-color: #b0b0b0; color: #000000;}",0);
}else{
xmpSetInline=true;
}
}
}
function setActive(button){
if(!button) { return false;}
var a=button.divparent;
var b=a.getElementsByTagName('button');
for(var c=0;c<b.length;c++){
b[c].className="tab"
}
button.className="tab active";
AT=button;
a=document.getElementById("tabSet_"+((a.id.match('footer'))?"header":"footer"));
b=a.getElementsByTagName('button');
for(c=1;c<b.length;c++){
b[c].className="tab"
}
b[0].className="tab active";
}
function getControl(ta){ HFT=ta;}
function addTabs(){
var code="";
var Tools="";
tStyle=tStyle.toString(); tStyle=tStyle.replace(/textarea/i,"").replace(/\{/,"").replace(/\}/,"");
tStyle+=" overflow:auto; width:"+String(HFT.offsetWidth-((document.all)?5:0))+"px;"
var scrptH="";
var scrptF="";
if( typeof HFT!="undefined" ){
code=getText();
document.body.innerHTML.match(/This is your forum's (\w+)/i);
var loc=RegExp.$1;
if(AT && AT.innerHTML=="View Syntax"){Tools="<input type='button' value='View UBBC' onclick= 'document.getElementById(\"code\").innerHTML= toUBBC(hilight(document.getElementById(\"code\").innerHTML)); codeDiv.style.display=\"block\"; this.parentNode.removeChild(this); ' >";}
if(!loc){document.body.innerHTML.match(/will be displayed on (.*?)?\./i); loc=RegExp.$1;}
loc=loc.substr(0,1).toUpperCase()+loc.substr(1);
loc=loc+" "+HFT.name.substr(0,1).toUpperCase()+HFT.name.substr(1);
loc="<div class='titlebg' id='tools' style='border:2px solid #000;' top=0px width=100%><div align=\"center\" ><h3>"+loc+"</h3></div>"+Tools+"</div><div style=' "+tStyle+"' WRAP=SOFT id='code'>";
code=xO+code+xE;
var pg="<html><head><title>Highlighted Code</title>"+scrptH+"</head><body contentEditable='true'>"+loc+hilight(code)+"</div>"+scrptF+"</div></body></html>";
codeDiv.style.width=HFT.offsetWidth+"px";
codeDiv.style.height=HFT.offsetHeight+"px";
codeDiv.style.display="block";
codeDiv.style.zIndex=9999;
codeDiv.innerHTML=pg;
if(codeDiv.nextSibling!=HFT){
font.removeChild(codeDiv);
font.insertBefore(codeDiv,HFT);
}
document.getElementById('code').style.height= (codeDiv.offsetHeight-document.getElementById('tools').offsetHeight-5)+"px";
codeDiv.focus();
var re=new RegExp('&l'+'t;','gi');
var x=document.getElementsByTagName('xmp');
for(i=0;i<x.length;i++){
if(x[i].innerHTML.match(re)){
var pre=document.createElement('pre');
pre.innerHTML=x[i].innerHTML;
pre.style.display="inline";
x[i].parentNode.replaceChild(pre,x[i]);
if(document.all){pre.parentNode.insertBefore(document.createTextNode(' '),pre);}
}
}
}else{
HFT=document.getElementById('footer');
}
}
function hilight(str){
if(AT && AT.innerHTML!="View Syntax" && AT.innerHTML!="Format UBBC"){return "nothing to display";}
str=str.replace(/<(?!(xmp|\/xmp|style|\/style|script|\/script|\?|\/\?|!--))/gim, "&l"+"t;");
if(document.all){str=str.replace(/<!--/gim, xE+"<co"+"de> "+"&l"+"t;!"+"-- </code>"+br+xO); }
var topTags=str.match(tags);
if(!topTags){topTags=[]; topTags[0]=getText(); }
for(var i=0;i<topTags.length;i++){
if(topTags[i].search(/<\s*script/i)==0){
topTags[i].match(/<\s*script.*?(?:(?:type|language)=(?:\'|\")(\w+)(?:\'|\"))?>/i);
var m=RegExp.$1
if(m.match(/javascript/i)){
jsSyntax();
str=str.replace(topTags[i],highlightJS(topTags[i]));
}else{
jsSyntax();
str=str.replace(topTags[i],highlightJS(topTags[i]));
}
}
}
var re=new RegExp(xO,"gim");
if(xmpSetInline){str=str.replace(re,"<xm"+"p style='display:inline' >");}
return str
}
function highlightJS(str){
var index=(arguments[1])?arguments[1]:0;
if(index>=parts.length){return str;}
var piece=str.split(xO.substr(1));
var i;
var j;
var reMatch;
var fStyleStart=(parts[index][2])?parts[index][2]:"";
var fStyleEnd=(parts[index][3])?parts[index][3]:"";
var reLookBehind=parseInt( (parts[index][4])?parts[index][4]:"0");
for(i=0;i<piece.length;i++){
if(piece[i] && !piece[i].match(/id=(\'|\")?hilightJS/)){
if(reLookBehind==0){
piece[i]=piece[i].replace(parts[index][0], xE+"<span "+xid+" style='color:"+parts[index][1]+"'>"+fStyleStart+"$1"+fStyleEnd+"</sp"+"an>"+xO);
}else{
reMatch=piece[i].match(parts[index][0]);
if(reMatch!=null){
for(j=0;j<reMatch.length;j++){
piece[i]=piece[i].replace(reMatch[j],reMatch[j].substr(0,reLookBehind)+xE+"<span"+xid+" style='color:"+parts[index][1]+"'>"+fStyleStart+reMatch[j].substr(reLookBehind)+fStyleEnd+"</sp"+"an>"+xO);
}
}
}
}
}
str=piece.join(xO.substr(1))
str=highlightJS(str,index+1);
return str;
}
function jsSyntax(){
comment_block=/[^\\](\/\*(?:\w|\W)*?[^\\]\*\/)/gim
comment_line=/[^\:\\](\/{2,}.*)$/gim
quoted_string=/[^\\]((\"|\').*?[^\\]\2)/gi
keywords= /\b(abstract|boolean|break|byte|case|catch|char|class|const|continue|debugger|default|delete|do|double|else|enum|export|extends|false|final|finally|float|for|function|goto|if|implements|import|in|instanceof|int|interface|long|native|new|null|package|private|protected|public|return|short|static|super|switch|synchronized|this|throw|throws|transient|true|try|typeof|var|void|volatile|while|with)\b/gm
properties= /\b(attributes|body|childNodes|className|clientHeight|clientLeft|clientTop|clientWidth|compatMode|doctype|documentElement|domain|dir|firstChild|id|innerHTML|lang|lastChild|length|localName|name|namespaceURI|nextSibling|nodeName|nodeType|nodeValue|offsetHeight|offsetLeft|offsetParent|offsetTop|offsetWidth|ownerDocument|parentNode|prefix|previousSibling|screen\.(availWidth|availHeight|colorDepth|height|width)|scrollHeight|scrollLeft|scrollTop|scrollWidth|styleSheets|style|tabIndex|tagName|textContent|title|URL)\b/gm
Moz_properties= /\b(innerWidth|innerHeight|outerWidth|outerHeight|pageXOffset|pageYOffset|pixelDepth|screenX|screenY|scrollX|scrollY)\b/gm
IE_properties= /\b(readyState|screenLeft|screenTop)\b/gm
methods= /\b(appendChild|blur|click|cloneNode|createAttribute|createCaption|createComment|createDocumentFragment|createElement|createTextNode|createTFoot|createTHead|deleteCaption|deleteCell|deleteRow|deleteTFoot|deleteTHead|focus|getAttribute|getAttributeNS|getAttributeNode|getAttributeNodeNS|getElementById|getElementsByName|getElementsByTagName|getElementsByTagNameNS|hasAttribute|hasAttributeNS|hasAttributes|hasChildNodes|implementation|insertBefore|insertCell|InsertRow|item|moveRow|normalize|removeAttribute|removeAttributeNS|removeAttributeNode|removeChild|replaceChild|resizeBy|resizeTo|scrollBy|scrollTo|setAttribute|setAttributeNS|setAttributeNode|setAttributeNodeNS|sizeToContent|supports)\b/gm
Moz_methods= /\b(addEventListener|dispatchEvent|getComputedStyle|removeEventListener|scrollByLines|scrollByPages)\b/gm
IE_methods=/\b(attachEvent|detachEvent|scrollIntoView)\b/gm
javaEvents= /\b(onblur|onchange|onclick|ondblclick|onfocus|onkeydown|onkeypress|onkeyup|onmousedown|onmousemove|onmouseout|onmouseover|onmouseup|onresize)\b/gm
var eventsObj=/(\w+\.(altKey|ctrlKey|shiftKey|clientX|clientY|type)\b)/gm
var Moz_eventsObj=/(\w+\.(stopPropagation|relatedTarget|charCode|preventDefault|target)\b)/gm
var IE_eventsObj=/\b(event\.(cancelBubble|fromElement|toElement|keyCode|offsetX|offsetY|returnValue|srcElement))\b/gm
parts[0]=[comment_block, comment_color,"<i>","</i>"+br,"1"];
parts[1]=[comment_line, comment_color,"<i>","</i><br/>","1"];
parts[2]=[quoted_string, string_color,,,"1"];
parts[3]=[keywords,keyword_color,"<b>","</b>"];
parts[4]=[eventsObj,Obj_event_color];
parts[5]=[IE_eventsObj,Obj_IE_event_color,"<s>","</s>"];
parts[6]=[Moz_eventsObj,Obj_Moz_event_color,"<s>","</s>"];
parts[7]=[properties,property_color];
parts[8]=[IE_properties,DOM_IE_property_color,"<s>","</s>"];
parts[9]=[Moz_properties,DOM_Moz_property_color,"<s>","</s>"];
parts[10]=[methods,method_color];
parts[11]=[IE_methods,DOM_IE_method_color,"<s>","</s>"];
parts[12]=[Moz_methods,DOM_Moz_method_color,"<s>","</s>"];
parts[13]=[javaEvents,javaEvent_color];
}
function validateCode(){
var count=1;
var codelet;
var results;
var o= {
laxLineEnd:true, //Lax line breaking
plusplus:false, //++ and -- considered harmful
cap:true, //Tolerate HTML case
jscript:true, //Tolerate JScript deviations
debug:true, //Allow debugger statements
evil:true, //Tolerate eval
undef:true, //Detect undefined variables
redef:true, //Allow var redefinition
browser:true, //Assume a browser (global objects such as window and document)
widget:false, //Assume a Yahoo Widget
passfail:false //Stop on first error
}
document.getElementById('code').innerHTML ="";
var topTags;
if(HFT.value!=getText() || !HFT.value.match(tags)){topTags=[]; topTags[0]=getText();}else{topTags=HFT.value.match(tags);}
for(var i=0;i<topTags.length;i++){
if(topTags[i].search(/<\s*script/gim)!=-1){
topTags[i].match(/<\s*script.*?(?:(?:type|language)=(?:\'|\")(.+)(?:\'|\"))?\s*>/i);
var m=RegExp.$1;
document.getElementById('code').innerHTML += "<hr><h2> script: "+count+"</h2>";
if(m.match(/[^-]javascript/i) || m==""){
topTags[i].match(/(<\s*(script).*?>)((?:\w|\W)*?)(<\/\2>)/im);
codelet=RegExp.$3;
if(codelet!=null){
JSLINT(codelet,o);
results=JSLINT.report();
}
}else{
results="<div style='background-color:yellow;'><blockquote>Skipped ("+((m.match(/x-javascript/i))?"disabled":"not javascript")+")</blockquote></div>";
}
count++
}else{
JSLINT(topTags[0],0)
results=JSLINT.report();
document.getElementById('code').innerHTML="<hr><h2>-Partial Script-</h2>";
}
if (results==""){
results="<div style='background-color:lightgreen;'><blockquote>No problems found </blockquote></div>";
}
document.getElementById('code').innerHTML +=results;
}
}
function getText(txtArea){
if(!txtArea){txtArea=HFT;}
if(!txtArea){return "";}
if(typeof document.selection!="undefined"){
var txt=document.selection.createRange().text;
if(!txt){txt=txtArea.value;}
}else{
txt=txtArea.value.substr(txtArea.selectionStart,txtArea.selectionEnd-txtArea.selectionStart)
if(!txt){txt=txtArea.value;}
}
return txt;
}
function funcJump(){
if(!HFT){ return false;}
var selct=document.getElementById("functions"+HFT.name);
var ta= "document.getElementById('"+HFT.name+"')";
var txtarea=eval(ta);
if(selct && txtarea && txtarea.value==txtarea.lastValue){return false;}
var str=HFT.value.replace(/\r/g,'');
var func=str.search(/(function\s+(\w+))\(|(<\s*script)/im);
var script=0;
if(func>-1){
var funcs=document.createElement('select');
funcs.id="functions"+HFT.name;
funcs.onchange=function(){
if(codeDiv){codeDiv.style.display="none";}
setActive(document.getElementById("tabSet_"+ this.id.substr(9)).getElementsByTagName('button')[0]);
if(this.options[this.selectedIndex].value){
eval(this.options[this.selectedIndex].value)
}
this.options[0].selected=true;
document.getElementById(this.id.substr(9)).focus();
}
funcs.options[0]=new Option("Function Jump","");
funcs.options[1]=new Option("--------------------","");
funcs.options[2]=new Option("\u00BB Go to first line",ta+".scrollTop=0;");
funcs.options[3]=new Option("\u00BB Go to last line",ta+".scrollTop="+ta+".scrollHeight;");
funcs.options[4]=new Option("--------------------","");
var start=0;
if(HFT.setSelectionRange){
var jump="var ta="+ta+"; ta.scrollTop=ta.scrollHeight; ta.setSelectionRange(%s,%s+1); var ev = document.createEvent ('KeyEvents'); ev.initKeyEvent('keypress', true, true, window,false, false, false, false, 0,ta.value.charCodeAt(%s)); ta.dispatchEvent(ev); ta.setSelectionRange(%s,%s);";
}else if(document.selection){
var jump="var ta="+ta+"; ta.scrollTop=ta.scrollHeight; var r=ta.createTextRange(); r.collapse(true); r.moveEnd('character', %s); r.moveStart('character', %s); r.select();";
}
}
var re1;
var re2;
var re3;
while(func>-1 && str.substr(start).match(/(function\s+(\w+))\(|(<\s*script)/im)){
re1=RegExp.$1;
re2=RegExp.$2;
re3=RegExp.$3;
if(re3){
script++; re1=re3;
if( funcs.options[funcs.options.length-1].text!="--------------------"){
funcs.options[funcs.options.length]=new Option("--------------------","");
}
funcs.options[funcs.options.length]=new Option("\u00BB script "+script, jump.replace(/%s/g,String(func)).replace(/%e/g,String(func+re1.length)));
funcs.options[funcs.options.length]=new Option("--------------------","");
}else{
funcs.options[funcs.options.length]=new Option("- "+re2, jump.replace(/%s/g,String(func)).replace(/%e/g,String(func+re1.length)));
}
start=func+1;
func=str.substr(start).search(/(function\s+(\w+))\(|(<\s*script)/im)+start;
}
if(document.getElementById("functions"+HFT.name)) {
document.getElementById("functions"+ HFT.name).parentNode.removeChild(selct);
}
if(funcs){
var tfunc =document.getElementById('tfunc'+HFT.name);
if(!tfunc){
tfunc=document.createElement('table');
tfunc.id='tfunc'+HFT.name;
tfunc.width=HFT.offsetWidth+"px";
tfunc.insertRow(-1);
var td= tfunc.rows[0].insertCell(-1);
td.align="right";
HFT.parentNode.insertBefore(tfunc,HFT.nextSibling.nextSibling);
}
tfunc.rows[0].cells[0].appendChild(funcs);
if(txtarea.lastValue){HFT.style.borderColor="fuchsia"; }
if(txtarea.value==txtarea.defaultValue){HFT.style.borderColor=taBorderColor;}
txtarea.lastValue=str;
}
}
function confirmScripts(e){
var ta=document.getElementsByTagName('textarea')
for(var i=0;i<ta.length;i++){
var s1=ta[i].value.match(/<\s*script/gim);
var s2=ta[i].value.match(/<(script).*?>(?:\w|\W)*?<\/\1>/gim);
if(ta[i].name.match(/(header|footer)/i) && ((s1 && s2 && s1.length>s2.length)||s1 && s2==null)){
if(s2==null){s2=[];}
var agree=confirm("Script opener tags: "+s1.length+"\nScript closer tags: "+s2.length+" \nSection: "+ta[i].name+"\nLeaving the code in this state is not recommended \nsince it could lead to you being unable to return to this \npage without the &NOHEADER=1 parameter.\n Are you sure you want to save the changes?");
if(!agree){
if(e && e.preventDefault){e.preventDefault();}
return false;
}
}
}
}
function toUBBC(str){
var pb_charLimit=25600;
var warnText="Warning!\\nSelected UBBC text exceeds the amount of \\ncharacters allowed in a Proboards post \\nProboards Character Limit :"+pb_charLimit+"\\nCurrent Character Count:";
codeDiv.style.visibility="hidden";
str=str.replace(/<(br)\/*?>/gim, "
");
str=str.replace(/^\s+/gm,function (m,offset,s){ return m.replace(/ /g,"&nb"+"sp;")});
str=str.replace(/&(lt);/gim, "<");
str=str.replace(/&(gt);/gim, ">");
str=str.replace(/rgb\((\d+), (\d+), (\d+)\)/gi, function (m,p1,p2,p3,offset,s){ return "\#"+hex(p1)+hex(p2)+hex(p3); });
str=str.replace(/<span\s+id=(\'|\")?hilightJS\1\s+style=(?:\'|\")?color:\W*#?(\w+|[0-9a-f]+);*(?:\'|\")?.*?>((\w|\W)+?)<\/span>/gim,function (m,p1,p2,p3,p4,offset,s){ return "[color="+p2+"]"+p3+"[/color]";});
str=str.replace(/<(pre)>(\w|\W)*?<\/pre>/gim,"$2");
str=str.replace(/<\/xmp>/ig,"");
str=str.replace(/<xmp.*?>/ig,"");
str=str.substr(0,12).replace(/<font>/i,"")+str.substr(12);
str=str.substr(0,str.length-12)+str.substr(str.length-12).replace(/<\/font>/i,"")
str=str.replace(/(\[\s*)(i|b|u|s)(\s*\])/gim,"$1$2"+"[i][/i]$3");
str=str.replace(/<\s*(\/)*(i|b|u|s)\s*>/gim,"[$1$2]");
codeDiv.style.visibility="visible";
var tHeight=(document.all)?"100%":document.getElementById('code').offsetHeight;
return "<text"+"area style='border:0px; overflow:visible; position:absolute; height:"+tHeight+"; width:100%;' onselect='var m=getText(this); if(m.length>"+pb_charLimit+"){alert(\""+warnText+"\"+m.length);}' >"+str+"</text"+"area>";
}
var hD="0123456789ABCDEF";
function hex(d) {
var h = hD.substr(d&15,1);
while(d>15) {d>>=4;h=hD.substr(d&15,1)+h;}
if (h.length==1){h="0"+h}
return h;
}
function manageCode(){
if(!HFT){return "Error: header/footer not selected";}
var opts=document.getElementById('functions'+HFT.name);
opts=opts.options;
var ret="<fo"+"rm ><br/>";
for(var a=0;a<opts.length;a++){
if(opts[a].text.substr(0,8)=="\u00BB script"){
opts[a].value.match(/(setSelectionRange\(|character',)(\d+)/im);
var offset=RegExp.$2;
var tag=HFT.value.substr(offset,HFT.value.substr(offset).search(/>/)+1);
var preview=HFT.value.substr(offset).split('\n').join('\n');
preview=preview.split(/<\/script>/)[0].replace(/</gm,"&l"+"t;");
var status=(tag.match(/x-/))?"Enable":"Disable";
ret+="<b>"+opts[a].text.substr(1)+"</b>&nb"+"sp;<text"+"area style='width:80%; overflow:auto; border-color:"+((status=="Disable")?"lime":"red")+";' readonly rows=3 title='Preview'>"+preview+"</text"+"area><br/><input type='button' value='"+status+"' stag='"+escape(tag)+"' lineNum='"+(HFT.value.substr(0,offset).split('\n').length-1)+"' onclick='setCodeStatus(this);'><br/><br/>"}
}
ret+="</fo"+"rm>"
return ret;
}
function setCodeStatus(btn){
var a=unescape(btn.getAttribute("stag"));
var b=HFT.value.split('\n');
if(btn.value=="Disable"){
if(!a.match(/type=/i)){
a=a.replace(/>/," type=\"text/x-javascript\" >").replace(/(language=(\'|\")?)/i,"$1x-")
}else{
a=a.replace(/(text(\/|\\))/i,"$1x-").replace(/(language=(\'|\")?)/i,"$1x-");
}
}else{
a=a.replace(/x-/gi,"");
}
btn.setAttribute("stag",escape(a))
b[btn.getAttribute("lineNum")]=a;
HFT.value=b.join('\n');
if(btn.value=="Disable"){
btn.value="Enable"; btn.previousSibling.previousSibling.style.borderColor="red";
}else{
btn.value="Disable"; btn.previousSibling.previousSibling.style.borderColor="lime";
}
funcJump();
}
//-->
</script>
<!-- http://www.jslint.com/lint.html -->
<!-- place this part in GLOBAL HEADER -->
<script type="text/javascript" src="http://www.jslint.com/jslint.js"></script>
To Do:
- add other languages (e.g. vbscript, PHP, etc.)
Known Bugs:
- Intermittent NS_ERROR_DOM_NOT_FOUND_ERR in FF (think I have it licked now)
Edit:
- 11/11/2006 - added function jump for easier navigation
- 11/30/2006 - added selective enable/disable of scripts