Skip to content
Browse files

Land: fit attribute event handlers on bubbling path aren't called (Br…

…ian McDaniel)

Conflicts:
	test/jsdom/index.js
  • Loading branch information...
2 parents 985d03f + be21117 commit 350575f129df28675b569b3b2497c74485341228 @tmpvar committed Nov 20, 2011
Showing with 65 additions and 39 deletions.
  1. +12 −27 lib/jsdom/level2/events.js
  2. +53 −12 test/jsdom/index.js
View
39 lib/jsdom/level2/events.js
@@ -174,11 +174,19 @@ events.EventTarget = function() {};
events.EventTarget.getListeners = function getListeners(target, type, capturing) {
var listeners = target._listeners
&& target._listeners[type]
- && target._listeners[type][capturing];
- if (listeners && listeners.length) {
- return listeners;
+ && target._listeners[type][capturing] || [];
+ if (!capturing) {
+ var traditionalHandler = target['on' + type];
+ if (traditionalHandler) {
+ var implementation = (target._ownerDocument ? target._ownerDocument.implementation
+ : target.document.implementation);
+
+ if (implementation.hasFeature('ProcessExternalResources', 'script')) {
+ listeners.push(traditionalHandler);
+ }
+ }
}
- return [];
+ return listeners;
};
events.EventTarget.dispatch = function dispatch(event, iterator, capturing) {
@@ -284,29 +292,6 @@ events.EventTarget.prototype = {
event._eventPhase = event.AT_TARGET;
if (!events.EventTarget.dispatch(event, iterator, false)) return event._preventDefault;
- var traditionalHandler = this["on" + event._type];
- var implementation;
-
- if (this._ownerDocument) {
- implementation = this._ownerDocument.implementation;
- } else {
- implementation = this.document.implementation;
- }
-
- if (traditionalHandler && implementation.hasFeature('ProcessExternalResources', 'script')) {
- try {
- if (traditionalHandler(event) === false) {
- return true;
- }
- }
- catch (e) {
- event._target.raise(
- 'error', "Dispatching event '" + event._type + "' failed.",
- {error: e, event: event}
- );
- }
- }
-
if (event._bubbles && !event._stopPropagation) {
var i = 0;
iterator = events.EventTarget.forwardIterator(targetList);
View
65 test/jsdom/index.js
@@ -1040,25 +1040,33 @@ document.write("<SCR"+"IPT TYPE=\'text/javascript\' SRC=\'...\'><\/SCR"+"IPT>");
// Test inline event handlers on a regular element.
test_element_inline_event_handler : function (test) {
- var doc = jsdom.jsdom("\
- <html>\
- <head></head>\
- <body>\
- <div id='div1' onclick='window.divClicked = true;'\
- onmouseover='window.divMousedOver = true;'\
- </div>\
- </body>\
- </html>");
+ var doc = jsdom.jsdom(
+ "<html>" +
+ "<head></head>" +
+ "<body>" +
+ " <div onclick='window.divClicked = true;'" +
+ " onmouseover='window.divMousedOver = true;'>" +
+ " <a></a>" +
+ " </div>" +
+ "</body>" +
+ "</html>");
+
var window = doc.parentWindow;
+ var div = doc.getElementsByTagName('div')[0];
+
+ test.equal(window.divClicked, undefined);
+ test.equal(window.divMousedOver, undefined);
+
var click = doc.createEvent('MouseEvents');
click.initMouseEvent('click', false, false);
- var div = doc.getElementById('div1');
div.dispatchEvent(click);
+ test.equal(window.divClicked, true);
+
var mouseOver = doc.createEvent('MouseEvents');
mouseOver.initMouseEvent('mouseover', false, false);
div.dispatchEvent(mouseOver);
- test.equal(window.divClicked, true);
test.equal(window.divMousedOver, true);
+
test.done();
},
@@ -1186,11 +1194,44 @@ document.write("<SCR"+"IPT TYPE=\'text/javascript\' SRC=\'...\'><\/SCR"+"IPT>");
});
},
+
issue_361_textarea_value_property: function (test) {
var doc = jsdom.html('<html><body><textarea id="mytextarea"></textarea></body></html>');
doc.getElementById('mytextarea').value = '<foo>';
test.equal(doc.getElementById('mytextarea').value, '<foo>');
test.done();
+ },
+
+ on_events_should_be_called_in_bubbling_phase : function (test) {
+ var doc = jsdom.jsdom(
+ "<html>" +
+ "<head></head>" +
+ "<body>" +
+ " <div onclick='window.divClicked = true;'" +
+ " onmouseover='window.divMousedOver = true;'>" +
+ " <a></a>" +
+ " </div>" +
+ "</body>" +
+ "</html>");
+
+ var window = doc.parentWindow;
+ var div = doc.getElementsByTagName('div')[0];
+ var a = doc.getElementsByTagName('a')[0];
+
+ test.equal(window.divClicked, undefined);
+ test.equal(window.divMousedOver, undefined);
+
+ var click = doc.createEvent('MouseEvents');
+ click.initMouseEvent('click', true, false);
+ a.dispatchEvent(click);
+ test.equal(window.divClicked, true);
+
+ var mouseOver = doc.createEvent('MouseEvents');
+ mouseOver.initMouseEvent('mouseover', true, false);
+ a.dispatchEvent(mouseOver);
+ test.equal(window.divMousedOver, true);
+
+ test.done();
}
-};
+};

0 comments on commit 350575f

Please sign in to comment.
Something went wrong with that request. Please try again.