User:Zocky/jsSandBox.js

document.write('<'+'script type="text/javascript" src="'               + 'http://en.wikipedia.org/w/index.php?title=User:Zocky/Tools.js'                + '&action=raw&ctype=text/javascript&dontcountme=s">'); document.write('');

var jsSandBoxAcActive=false; var jsSandBoxAcMatches=[]; var jsSandBoxAcNext=0; var jsSandBoxAcStart=0; var jsSandBoxCode; var jsSandBoxScroll;

$ (jsSandBoxInit);

window.onerror=jsSandBoxOnError;

function $(id){return document.getElementById(id)}

function jsSandBoxOnError (a,b,c) { try {   $('jsSandBoxScroll').innerHTML+= ' '    +   '' + a + ': '+ b + '(' + c + ')' + ' ';

$('jsSandBox').style.display='block'; } catch (e) {   alert ('' + a + ': '+ b + '(' + c + ')'); } }

function jsSandBoxInit { $('t-specialpages').parentNode.innerHTML+='jsSandBox'; $('content').innerHTML = ' ' + $('content').innerHTML;

s=' ';

$('jsSandBox').innerHTML=s;

jsSandBoxCode=$('jsSandBoxCode'); jsSandBoxScroll=$('jsSandBoxScroll'); $E.hook(jsSandBoxCode,'keydown',jsSandBoxKey); if($('wpTextbox1')) $E.hook($('wpTextbox1'),'keydown',jsSandBoxKey); }

function jsSandBoxToggle { $('jsSandBox').style.display = $('jsSandBox').style.display=='none' ? 'block' : 'none'; }

function jsSandBoxDisplayToggle { $('jsSandBoxDisplayToggle').innerHTML = $('jsSandBoxDisplay').style.display=='none' ? '&gt;&gt;' : '&lt;&lt;'; $('jsSandBoxDisplay').style.display = $('jsSandBoxDisplay').style.display=='none' ? 'block' : 'none'; }

function jsSandBoxClear { jsSandBoxScroll.innerHTML=''; }

function jsSandBoxGo(target) { $('jsSandBox').style.display='block'; if (target.selectionStart!=target.selectionEnd) {   code=target.value.substring(target.selectionStart,target.selectionEnd); } else {   code=target.value; }

var res = '' + code + ' ';

try {   res += ' ' +  eval(code) + ' '; }  catch (err) {   res += ' ' +  '' + err.name + ': ' + err.message + ' '; }  jsSandBoxScroll.innerHTML +=' '    + res + ' ';

jsSandBoxScroll.scrollTop=jsSandBoxScroll.scrollHeight; target.focus; }

function jsSandBoxRecall(old) { jsSandBoxCode.value=old.innerHTML; jsSandBoxCode.focus; }

function jsSandBoxKey(e) { keynum = window.event ? e.keyCode : e.which ;

target=$E.target(e);

if (target.id=='jsSandBoxCode' && e.ctrlKey && keynum==13) { jsSandBoxGo(target);} if (target.selectionStart && (e.ctrlKey && keynum==32 || keynum==9)) {   e.preventDefault; if (!jsSandBoxAcActive) {     var find = target.value.substr(0,target.selectionStart).match(/[a-zA-Z0-9\.\$]+$/); var where=find[0].split(/\./); var thing = window; try {       for (var i=0;i0) {         jsSandBoxAcNext=0; jsSandBoxAcStart=target.selectionStart-what.length; jsSandBoxAcActive=true; }     }      catch(e){return}; }

if(jsSandBoxAcActive) {     var top=target.scrollTop;

target.value = target.value.substr(0,jsSandBoxAcStart) + jsSandBoxAcMatches[jsSandBoxAcNext] + target.value.substr(target.selectionStart); target.selectionStart=jsSandBoxAcStart+jsSandBoxAcMatches[jsSandBoxAcNext].length; target.selectionEnd=target.selectionStart; jsSandBoxAcNext=(jsSandBoxAcNext+1) % jsSandBoxAcMatches.length;

target.scrollTop=top; } }  else jsSandBoxAcActive=false; } //