Created
July 27, 2015 05:17
-
-
Save Linrstudio/32452b36369fcacb4ce7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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