Skip to content

Commit

Permalink
Land: fit attribute event handlers on bubbling path aren't called (Br…
Browse files Browse the repository at this point in the history
…ian McDaniel)

Conflicts:
	test/jsdom/index.js
  • Loading branch information
tmpvar committed Nov 20, 2011
2 parents 985d03f + be21117 commit 350575f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 39 deletions.
39 changes: 12 additions & 27 deletions lib/jsdom/level2/events.js
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
65 changes: 53 additions & 12 deletions test/jsdom/index.js
Expand Up @@ -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();
},

Expand Down Expand Up @@ -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.