-
-
Save csuwildcat/1157453 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 hasChanged = function(event){ | |
| var target = event.target; | |
| if (!hasChanged(target)) return false; | |
| if (target.get('tag') == 'select') return true; | |
| if (!hasListener) switch(event.key){ | |
| case 'up': case 'down': case 'left': case 'right': return target.get('type') == 'radio'; | |
| case 'space': return target.get('type') == 'checkbox'; | |
| } | |
| }; | |
| Element.Events.change = { | |
| base: function(){ | |
| var type = this.get('type'); | |
| return (!hasListener && (type == 'checkbox' || type == 'radio')) ? 'click' : 'change'; | |
| }, | |
| condition: function(event){ | |
| var target = event.target; | |
| if (hasListener && event.type == 'change' && target.get('tag') == 'select' && target.retrieve('$change').type == 'keydown') return false; | |
| return target.get('type') == 'radio' ? (event.type == 'keyup' ? !target.checked : target.checked) : true; | |
| }, | |
| onAdd: function(fn){ | |
| this.addEvents({ | |
| keyup: hasChanged, | |
| focus: storeChange, | |
| keydown: storeChange | |
| }); | |
| }, | |
| onRemove: function(fn){ | |
| this.removeEvents({ | |
| keyup: hasChanged, | |
| focus: storeChange, | |
| keydown: storeChange | |
| }); | |
| } | |
| } | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment