Created
July 23, 2009 18:11
-
-
Save infynyxx/153334 to your computer and use it in GitHub Desktop.
JS custom event handling based on PrototypeJS
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
//Custom Event handling | |
Event.observe(document, 'dom:loaded', function() { | |
$('enableInputEvents').observe('click', function(e) { | |
document.fire('CheckBox:Enabled', {checked: $('enableInputEvents').checked}); | |
}); | |
}); | |
document.observe('CheckBox:Enabled', function(e) { | |
Event.stop(e); | |
if (e.memo.checked) { | |
console.log("all elements with CSS class input are ENABLED"); | |
$$('.input').each(function(t) { | |
t.observe('change', function() { | |
alert(t.value); | |
}); | |
}); | |
} | |
else { | |
console.log("all elements with CSS class input are DISABLED"); | |
$$('.input').invoke('stopObserving'); | |
} | |
}); | |
/** | |
IMPLEMENTATION | |
<fieldset> | |
<legend> | |
JS Custom Events | |
</legend> | |
<div> | |
<input type="checkbox" value="1" id="enableInputEvents" /> Enable events for text box and combo box<br/> | |
</div> | |
<div id="inputs_elements"> | |
Text Box 1: <input type="text" id="textbox1" value="" class="input" /><br/> | |
Text Box 2: <input type="text" id="textbox2" value="" /><br/> | |
Select Search Engine: <select id="search-engine-selector" class="input"> | |
<option value="">Go to</option> | |
<option value="http://www.google.com">Google</option> | |
<option value="http://www.yahoo.com">Yahoo!</option> | |
<option value="http://www.live.com">Live</option> | |
</select> | |
</div> | |
</fieldset> | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment