Skip to content

Instantly share code, notes, and snippets.

@Linrstudio
Created July 27, 2015 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linrstudio/32452b36369fcacb4ce7 to your computer and use it in GitHub Desktop.
Save Linrstudio/32452b36369fcacb4ce7 to your computer and use it in GitHub Desktop.
var $preventAllEvents = $('input');
// The magic code
var oldAddEventListener = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function(eventName, eventHandler)
{
oldAddEventListener.call(this, eventName, function(event) {
if(!$preventAllEvents.is(':checked'))
eventHandler(event);
});
};
function clickHandler (event) {
$(this).toggleClass('distinctive')
}
$('.level1').on('click', clickHandler);
$('.level2').on('click', clickHandler);
$('.level3').on('click', clickHandler);
// css
div {
border: 8px solid #8cf;
padding: 16px;
margin: 8px;
text-align: center;
border-radius: 5px;
background-color: cornflowerblue;
cursor: pointer;
}
.level1 {
width: 300px;
}
.distinctive {
background-color: hotpink;
}
//html
<div class="level1">Level 1 <span></span>
<div class="level2">Level 2<span></span>
<div class="level3">Level 3<span></span>
</div>
</div>
</div>
<br/><br/>
<input type="checkbox" id="stop"></input>
<label for="stop">Prevent all events</label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment