run |
/* click to delete elements. hit any key to cancel the effect. */
new function(me){
var color = '#ccc', out = true;
var getCS = document.defaultView
? document.defaultView.getComputedStyle
: function(elm){ return elm.currentStyle };
return me = {
exclude: /^(?:html|body)$/i,
setColor: function(c){ return color = c },
elements: document.getElementsByTagName('*'),
remover: function(v){ v ?1: v = event;
var elm = v.srcElement || v.target;
v.stopPropagation ? v.stopPropagation() : v.cancelBubble = true;
return !elm.parentNode.removeChild(elm);
},
encolor: function(v){ v ?1: v = event;
if(!out) return;
out = false;
var k, elm = v.srcElement || v.target;
elm.__ = getCS(elm, '').backgroundColor;
elm.style.backgroundColor = color;
v.stopPropagation ? v.stopPropagation() : v.cancelBubble = true;
},
decolor: function(v){ v ?1: v = event;
var k, k_, elm = v.srcElement || v.target;
if(elm.__) elm.style.backgroundColor = elm.__;
elm.__ = null;
out = true;
v.stopPropagation ? v.stopPropagation() : v.cancelBubble = true;
},
modify: self.attachEvent
? function(elm, evn, fun){ elm.attachEvent('on'+ evn, fun) }
: function(elm, evn, fun){ elm.addEventListener(evn, fun, false) },
go: function(){ with(this){
for(var e, i = 0; e = elements[i++];) if(!exclude.test(e.tagName)){
modify(e, 'mousedown', remover);
modify(e, 'mouseover', encolor);
modify(e, 'mouseout', decolor);
}
modify(document, 'keydown', quit);
return this;
}},
quit: function(){
var undo = self.detachEvent
? function(elm, evn, fun){ elm.detachEvent('on'+ evn, fun) }
: function(elm, evn, fun){ elm.removeEventListener(evn, fun, false) };
me.modify = function(elm, evn, fun){
undo(elm, evn, fun);
if(elm.__) elm.style.backgroundColor = elm.__;
}
me.go();
}
}.go();
}
|