Permalink
Browse files

Merge pull request #82 from ggilder/master

Add js code to fire HTML5 input event
  • Loading branch information...
2 parents c042457 + 1aa0c2d commit af6a1bccd87fc6dfd238b0442a3a4d308a8b0f46 @jonleighton jonleighton committed Jun 13, 2012
@@ -101,6 +101,11 @@ class PoltergeistAgent.Node
event.initEvent('change', true, false)
@element.dispatchEvent(event)
+ input: ->
+ event = document.createEvent('HTMLEvents')
+ event.initEvent('input', true, false)
+ @element.dispatchEvent(event)
+
keyupdowned: (eventName, keyCode) ->
event = document.createEvent('UIEvents')
event.initEvent(eventName, true, true)
@@ -170,6 +175,7 @@ class PoltergeistAgent.Node
this.keyupdowned('keyup', keyCode)
this.changed()
+ this.input()
this.trigger('blur')
isMultiple: ->
@@ -150,6 +150,13 @@ PoltergeistAgent.Node = (function() {
return this.element.dispatchEvent(event);
};
+ Node.prototype.input = function() {
+ var event;
+ event = document.createEvent('HTMLEvents');
+ event.initEvent('input', true, false);
+ return this.element.dispatchEvent(event);
+ };
+
Node.prototype.keyupdowned = function(eventName, keyCode) {
var event;
event = document.createEvent('UIEvents');
@@ -241,6 +248,7 @@ PoltergeistAgent.Node = (function() {
this.keyupdowned('keyup', keyCode);
}
this.changed();
+ this.input();
return this.trigger('blur');
};
@@ -80,6 +80,10 @@
@session.find(:css, '#changes').text.should == "Hello!"
end
+ it 'fires the input event' do
+ @session.find(:css, '#changes_on_input').text.should == "Hello!"
+ end
+
it 'accepts numbers in a maxlength field' do
element = @session.find(:css, '#change_me_maxlength')
element.set 100
@@ -13,6 +13,9 @@ $(function() {
.change(function(event) {
$('#changes').text($(this).val())
})
+ .bind('input', function(event) {
+ $('#changes_on_input').text($(this).val())
+ })
.keydown(function(event) {
$('#changes_on_keydown').text(increment)
})
@@ -18,6 +18,7 @@
<input type="text" name="change_me_withname" id="change_me_withname">
</p>
<p id="changes"></p>
+ <p id="changes_on_input"></p>
<p id="changes_on_keydown"></p>
<p id="changes_on_keyup"></p>
<p id="changes_on_focus"></p>

0 comments on commit af6a1bc

Please sign in to comment.