-
-
Save csuwildcat/1157453 to your computer and use it in GitHub Desktop.
Revisions
-
ibolmo revised this gist
Aug 19, 2011 . 2 changed files with 42 additions and 54 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ /*<ltIE9>*/ if (!window.addEventListener) (function(){ var update = function(event){ event.target.store('$change:last', { type: event.type, value: event.target.checked }); }; Element.Events._change = { base: 'change' }; Element.Events.change = { base: 'click', condition: function(event){ var target = event.target, type = target.type, last = target.retrieve('$change:last', {}); if (type == 'text' || /textarea|select/.test(target.get('tag'))) return event.type == 'change'; if (type == 'radio' && last.type != 'mousedown' && /up|down|left|right/.test(target.retrieve('$change:key', ''))) return true; return target.checked != last.value; }, onAdd: function(fn){ this.addEvents(this.retrieve('$change:events', { keydown: update, mousedown: update, _change: function(event){ if (!/radio|checkbox/.test(event.target.type)) fn.call(this, event); }, keyup: function(event) { event.target.store('$change:key', event.key); return event.code != 16 && event.key != 'tab'; } })); }, onRemove: function(){ this.removeEvents(this.retrieve('$change:events')).eliminate('$change:events'); } }; })(); /*</ltIE9>*/ 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 charactersOriginal file line number Diff line number Diff line change @@ -1,54 +0,0 @@ -
ibolmo renamed this gist
Aug 19, 2011 . 1 changed file with 9 additions and 12 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,15 @@ /* --- name: Element.Events.change description: Contains Element methods for normalizing change events across browsers for checkboxes and radios. license: MIT-style license. requires: Element.Event provides: Element.Events.change ... */ @@ -25,12 +25,6 @@ var update = function(event){ }); }; Element.Events.change = { base: 'click', condition: function(event){ @@ -44,7 +38,10 @@ Element.Events.change = { focus: update, keydown: update, keyup: function(event){ var code = event.which || event.keyCode, element = event.target, value = element.retrieve('$change').value; if (!hasListener && value != null && value != element.checked){ if ((type == 'checkbox' && code == 32) || (type == 'radio' && code >= 37 && code <= 39)) fn.call(this, event) } } }); }, @@ -54,4 +51,4 @@ Element.Events.change = { }; })(); -
ibolmo revised this gist
Aug 19, 2011 . 1 changed file with 22 additions and 33 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,53 +16,42 @@ provides: Element.Event.Change (function(){ var hasListener = !!window.addEventListener; var update = function(event){ event.target.store('$change', { type: event.type, value: event.target.checked }); }; var hasChanged = function(element, code){ var value = element.retrieve('$change').value; if (hasListener || value == null || value == element.checked) return false; return (type == 'radio') ? (code >= 37 && code <= 39) : (key == 'space'); }; Element.Events.change = { base: 'click', condition: function(event){ var target = event.target; if (target.get('type') != 'radio') return true; return (event.type == 'keyup') ? !target.checked : target.checked; }, onAdd: function(fn){ var type = this.get('type'); if (type == 'checkbox' || type == 'radio') this.addEvents(this.retrieve('$change:events', { focus: update, keydown: update, keyup: function(event){ if (hasChanged(event.target, event.which || event.keyCode)) fn.call(this, event); } }); }, onRemove: function(){ this.removeEvents(this.retrieve('$change:events')).eliminate('$change:events'); } }; })(); -
ibolmo revised this gist
Aug 15, 2011 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ var getValue = function(element){ return element[type == 'radio' || type == 'checkbox' ? 'checked' : 'value']; } var update = function(event){ event.target.store('$change', { type: event.type, value: getValue(event.target) @@ -55,8 +55,8 @@ Element.Events.change = { keyup: function(event){ if (hasChanged(event)) fn.call(this, event); }, focus: update, keydown: update }; this.store('$changeEvents', events).addEvents(events); }, -
ibolmo revised this gist
Aug 15, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ provides: Element.Event.Change (function(){ var hasListener = !!window.addEventListener var getValue = function(element){ var type = element.get('type'); -
ibolmo revised this gist
Aug 15, 2011 . 1 changed file with 10 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -17,24 +17,22 @@ provides: Element.Event.Change (function(){ var hasListener = window.addEventListener; var getValue = function(element){ var type = element.get('type'); return element[type == 'radio' || type == 'checkbox' ? 'checked' : 'value']; } var storeChange = function(event){ event.target.store('$change', { type: event.type, value: getValue(event.target) }); }; var hasChanged = function(event){ var target = event.target, value = target.retrieve('$change').value; if (value == null || value == getValue(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'; @@ -53,22 +51,17 @@ Element.Events.change = { return target.get('type') == 'radio' ? (event.type == 'keyup' ? !target.checked : target.checked) : true; }, onAdd: function(fn){ var events = { keyup: function(event){ if (hasChanged(event)) fn.call(this, event); }, focus: storeChange, keydown: storeChange }; this.store('$changeEvents', events).addEvents(events); }, onRemove: function(fn){ this.removeEvents(this.retrieve('$changeEvents')).eliminate('$changeEvents'); } } -
ibolmo revised this gist
Aug 15, 2011 . 1 changed file with 43 additions and 5 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,46 @@ /* --- name: Element.Event.Change description: Contains Element methods for normalizing change events across browsers. license: MIT-style license. requires: [Element, Event] provides: Element.Event.Change ... */ (function(){ var hasListener = window.addEventListener; var getValue = function(element){ var type = element.get('type'); return element[type == 'radio' || type == 'checkbox' ? 'checked' : 'value']; } var storeChange = function(event){ event.target.store('$change', { type: event.type, value: getValue(event.target) }); }; var hasChanged = function(element){ var value = element.retrieve('$change').value; return (value != null && value != getValue(element)); }; var keychange = 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(){ @@ -20,14 +54,18 @@ Element.Events.change = { }, onAdd: function(fn){ this.addEvents({ keyup: function(event){ if (keychange(event)) fn.call(this, event); }, focus: storeChange, keydown: storeChange }); }, onRemove: function(fn){ this.removeEvents({ keyup: function(event){ if (keychange(event)) fn.call(this, event); }, focus: storeChange, keydown: storeChange }); -
ibolmo created this gist
Aug 15, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ 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 }); } } })();