Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for broken events when event targets are SVGElementInstances (in Safari) #1970

Open
wants to merge 1 commit into
base: dev-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/event/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Event Infrastructure Change History
@VERSION@
------

* No changes.
* Fixed broken event delegation when the event target is an SVGElementInstance.

3.18.0
------
Expand Down
7 changes: 7 additions & 0 deletions src/event/js/delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ delegate._applyFilter = function (filter, args, ce) {
match = [],
isContainer = false;

// safari's svg element instance needs special handling
if (typeof SVGElementInstance !== 'undefined') {
if (!target.nodeType && target.correspondingElement) {
target = target.correspondingUseElement || target.correspondingElement;
}
}

// Resolve text nodes to their containing element
if (target.nodeType === 3) {
target = target.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion src/node/HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Node Change History
@VERSION@
------

* No changes.
* Fixed broken Y.one/Y.all wrappers when the node is an SVGElementInstance.

3.18.0
------
Expand Down
9 changes: 9 additions & 0 deletions src/node/js/node-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ Y_Node.scrubVal = function(val, node) {
if (typeof val == 'object' || typeof val == 'function') { // safari nodeList === function
if (NODE_TYPE in val || Y_DOM.isWindow(val)) {// node || window
val = Y.one(val);
} else if (typeof SVGElementInstance !== 'undefined' && val.correspondingElement) { // svg node
val = Y.one(val.correspondingUseElement || val.correspondingElement);
} else if ((val.item && !val._nodes) || // dom collection or Node instance
(val[0] && val[0][NODE_TYPE])) { // array of DOM Nodes
val = Y.all(val);
Expand Down Expand Up @@ -286,6 +288,13 @@ Y_Node.one = function(node) {
return node; // NOTE: return
}

// safari's svg element instance needs special handling
if (typeof SVGElementInstance !== 'undefined') {
if (!node.nodeType && node.correspondingElement) {
node = node.correspondingUseElement || node.correspondingElement;
}
}

if (node.nodeType || Y.DOM.isWindow(node)) { // avoid bad input (numbers, boolean, etc)
uid = (node.uniqueID && node.nodeType !== 9) ? node.uniqueID : node._yuid;
instance = Y_Node._instances[uid]; // reuse exising instances
Expand Down
2 changes: 2 additions & 0 deletions src/node/js/nodelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var NodeList = function(nodes) {
nodes = Y.Selector.query(nodes);
} else if (nodes.nodeType || Y_DOM.isWindow(nodes)) { // domNode || window
nodes = [nodes];
} else if (typeof SVGElementInstance !== 'undefined' && nodes.correspondingElement) { // svg node
nodes = [nodes.correspondingUseElement || nodes.correspondingElement];
} else if (nodes._node) { // Y.Node
nodes = [nodes._node];
} else if (nodes[0] && nodes[0]._node) { // allow array of Y.Nodes
Expand Down