Post by Chris on Nov 15, 2006 11:42:06 GMT -8
Overview: Adds a function/script jump to the header and footer textareas for easier navigation while editing. This was part of a previous project but was rewritten to make compatible with an XPCNativeWrapper environment. This means the script can be installed as a greasemonkey script instead of taking up space in the PB footer.
Installation:
Preview:
Installation:
- add to global footer
- or if you have greasemonkey installed then copy and paste to a text editor and remove the script tags then save with a file extension of .user.js. Open the saved file in Firefox (file menu>open file) and greasemonkey should take over from there.
Preview:
<script type="text/javascript">
/* Installation: place in global footer or install as a greasemonkey script*/
// ==UserScript==
// @name Proboards Function Jump
// @author Eton Bones
// @namespace http://support.proboards.com/index.cgi?board=codedatabase
// @description Function indexer for Proboards Header and Footer codes
// @include http://*.proboards*.com/index.cgi?action=headersfooters2*
// ==/UserScript==
function funcJump(e){
if(e && e.preventDefault){e.preventDefault();}
if(!HFT){ return false;}
if(evAdd && evAdd==true){
if(HFT.addEventListener){
HFT.addEventListener("mouseout",arguments.callee,false);
//HFT.addEventListener("blur",arguments.callee,false);
HFT.addEventListener("mouseover",function(){HFT=this;},false);
HFT.addEventListener("select",function(){HFT=this;},false);
HFT.addEventListener("keypress",function(){HFT=this;},false);
}else{
HFT.onmouseout=arguments.callee;
//HFT.attachEvent("onblur",arguments.callee);
HFT.onmouseover=function(){HFT=this;}
HFT.onselect=function(){HFT=this;}
HFT.onkeypress=function(){HFT=this;}
}
}
var selct=document.getElementById("functions"+HFT.name);
var ta= "document.getElementById('"+HFT.name+"')";
var txtarea=eval(ta);
if(selct && txtarea && txtarea.value==txtarea.getAttribute("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;
if(funcs.addEventListener){
funcs.addEventListener("change",function(){HFT = document.getElementById(this.id.substr(9));if(this.options[this.selectedIndex].value){eval(this.options[this.selectedIndex].value);} document.getElementById(this.id.substr(9)).focus();} ,false);
}else{
//funcs.attachEvent("onchange",function(){HFT = document.getElementById(this.id.substr(9));if(this.options[this.selectedIndex].value){eval(this.options[this.selectedIndex].value);} document.getElementById(this.id.substr(9)).focus();} );
funcs.onchange=function(){HFT = document.getElementById(this.id.substr(9));if(this.options[this.selectedIndex].value){eval(this.options[this.selectedIndex].value);} document.getElementById(this.id.substr(9)).focus();}
}
var opts=[];
opts[opts.length] = document.createElement("option");
opts[opts.length-1].innerHTML="Function Jump";
//funcs.options[i]=new Option("Function Jump","");i++;
opts[opts.length] = document.createElement("option")
opts[opts.length-1].innerHTML="--------------------";
opts[opts.length] = document.createElement("option");
opts[opts.length-1].setAttribute("value",ta+".scrollTop=0;");
opts[opts.length-1].innerHTML="\u00BB Go to first line";
opts[opts.length] = document.createElement("option");
opts[opts.length-1].setAttribute("value",ta+".scrollTop="+ta+".scrollHeight;");
opts[opts.length-1].innerHTML="\u00BB Go to last line";
opts[opts.length] = document.createElement("option")
opts[opts.length-1].innerHTML="--------------------";
var start=0;
if(HFT.setSelectionRange){
/* workaround for mozilla bug 232405 */
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();";
}
}
str.replace(/(^ *function\s+(\w+))\(|(^ *<\s*script)/gim,function (m,p1,p2,p3,offset,s){
if(p3){
script++;
if( opts[opts.length-1].text!="--------------------"){
opts[opts.length]=document.createElement("option")
opts[opts.length-1].innerHTML="--------------------";
}
opts[opts.length]=document.createElement("option")
opts[opts.length-1].innerHTML="\u00BB script "+script;
opts[opts.length-1].setAttribute("value",jump.replace(/%s/g,String(offset)).replace(/%e/g,String(offset+p3.length)));
opts[opts.length]=document.createElement("option")
opts[opts.length-1].innerHTML="--------------------";
}else{
opts[opts.length]=document.createElement("option")
opts[opts.length-1].innerHTML="- "+p2;
opts[opts.length-1].setAttribute("value",jump.replace(/%s/g,String(offset)).replace(/%e/g,String(offset+p1.length)));
}
return m;
}
);
for(var i=0;i<opts.length;i++){funcs.appendChild(opts[i]);}
if(document.getElementById("functions"+HFT.name)) {
document.getElementById("functions"+ HFT.name).parentNode.removeChild(selct); //document.getElementById("functions"+HFT.name))
}
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);
//indicate change made and need to be saved
if(txtarea.value!=txtarea.getAttribute("lastValue")){HFT.style.borderColor="red"; }
if(txtarea.value==txtarea.defaultValue){ HFT.style.borderColor="#ECE9D8";}
txtarea.setAttribute("lastValue",str);
}
}
if(location.href.match(/action=headersfooters2/i) ){
var HFT;
var evAdd=true;
var T=document.getElementsByTagName('textarea');
// uncomment following line if using as greasemonkey script
//if(!T){return}
for(var x=0;x<T.length;x++){
T[x].id=T[x].name;
T[x].setAttribute("lastValue",T[x].value);
HFT=T[x]; funcJump();
}
evAdd=false;
}
//ChangeLog:
// 10/16/2006 -versio 0.2 - made cross-browser for PB install
// 10/15/2006 -version 0.1 - original release
</script>