Skip to content

Commit

Permalink
IE<=8 has an event triggered each time you add a new custom handler b…
Browse files Browse the repository at this point in the history
…ecause of the unnecessary assignment to self of the _on<event> property
  • Loading branch information
rvagg committed Sep 17, 2011
1 parent 786962d commit e6f0e3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/bean.js
Expand Up @@ -36,7 +36,9 @@
listener = W3C_MODEL ? function (element, type, fn, add) {
element[add ? addEvent : removeEvent](type, fn, false);
} : function (element, type, fn, add, custom) {
custom && add && (element['_on' + custom] = element['_on' + custom] || 0);
if (custom && add && element['_on' + custom] === null) {
element['_on' + custom] = 0;
}
element[add ? attachEvent : detachEvent]('on' + type, fn);
},

Expand Down
7 changes: 6 additions & 1 deletion tests/tests.js
@@ -1,4 +1,3 @@
//stub this for ie crap
if (!window.console) {
window.console = { log: function () {}}
}
Expand Down Expand Up @@ -111,6 +110,12 @@ sink('add', function (test, ok) {
Syn.click(el2);
});

test('add: shouldn\'t trigger event when adding additional custom event listeners', 0, function () {
var el = document.getElementById('input');
bean.add(el, 'foo', function () {ok(true, 'additional custom event listeners trigger event 1')});
bean.add(el, 'foo', function () {ok(true, 'additional custom event listeners trigger event 2')});
});

})

sink('fire', function (test, ok) {
Expand Down

0 comments on commit e6f0e3d

Please sign in to comment.