-
-
Save ArcCosine/46016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function(doc) { | |
var add = doc.addEventListener; | |
add('mouseover',overHandler,false); | |
add('mouseout',outHandler,false); | |
add('click',clickHandler,false); | |
add('keypress',keyHandler,false); | |
function removeListeners(){ | |
var rm = doc.removeEventListener; | |
rm('mouseover',overHandler,false); | |
rm('mouseout',outHandler,false); | |
rm('click',clickHandler,false); | |
rm('keypress',keyHandler,false); | |
} | |
var theElm; | |
function overHandler(e){ | |
theElm = e.target; | |
addBG(theElm); | |
} | |
function outHandler(e){ | |
removeBG(theElm); | |
} | |
function clickHandler(){ | |
removeBG(theElm); | |
killOthers(theElm); | |
removeListeners(); | |
} | |
function addBG(elm){ | |
var st = elm.style; | |
if(st.backgroundColor)st.origBG = st.backgroundColor; | |
st.backgroundColor = 'orange'; | |
} | |
function removeBG(elm){ | |
if(!elm)return; | |
var st = elm.style; | |
st.backgroundColor = st.origBG||''; | |
st.origBG=null; | |
} | |
function keyHandler(e){ | |
try{Hash[e.keyCode||e.which](e)&&e.preventDefault();}catch(e){} | |
} | |
var Hash = { | |
27:function(){removeBG(theElm);removeListeners();return true}/*Esc*/ | |
,38:function(){if(theElm!=doc.body){removeBG(theElm);theElm=theElm.parentNode;addBG(theElm);}return true}/*up*/ | |
,13:function(){clickHandler();return true;}/*Enter*/ | |
}; | |
function killOthers(ele){ | |
while(ele!=doc.body){ | |
[].forEach.call(ele.parentNode.childNodes,function(e){if(e!=ele && e.style)e.style.display='none'}); | |
var st = ele.style; | |
st.width='100%'; | |
st.padding=st.margin=0; | |
ele=ele.parentNode; | |
} | |
} | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment