From c5d73ca811bcdadbfcdafe39ffdecfe3fed9acff Mon Sep 17 00:00:00 2001 From: Beckie Choi Date: Thu, 9 Oct 2014 16:37:47 -0400 Subject: [PATCH] Make sure Y.Node/Event uses a workable DOM node when dealing with SVG elements in Safari --- src/event/HISTORY.md | 2 +- src/event/js/delegate.js | 7 +++++++ src/node/HISTORY.md | 2 +- src/node/js/node-core.js | 9 +++++++++ src/node/js/nodelist.js | 2 ++ 5 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/event/HISTORY.md b/src/event/HISTORY.md index 228d5337964..1548b922850 100644 --- a/src/event/HISTORY.md +++ b/src/event/HISTORY.md @@ -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 ------ diff --git a/src/event/js/delegate.js b/src/event/js/delegate.js index 718fd23dd55..3f7f809391d 100644 --- a/src/event/js/delegate.js +++ b/src/event/js/delegate.js @@ -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; diff --git a/src/node/HISTORY.md b/src/node/HISTORY.md index 489ef16b088..a21314acd10 100644 --- a/src/node/HISTORY.md +++ b/src/node/HISTORY.md @@ -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 ------ diff --git a/src/node/js/node-core.js b/src/node/js/node-core.js index dc4c0105fcc..a3163a1bdf5 100644 --- a/src/node/js/node-core.js +++ b/src/node/js/node-core.js @@ -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); @@ -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 diff --git a/src/node/js/nodelist.js b/src/node/js/nodelist.js index 9f764dbb8ea..b56fc13a837 100644 --- a/src/node/js/nodelist.js +++ b/src/node/js/nodelist.js @@ -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