From bf37735be16fffeebe3ea039125f6bac4ba69b68 Mon Sep 17 00:00:00 2001 From: "Reza Haidari .A" Date: Wed, 29 Mar 2017 17:57:59 +0430 Subject: [PATCH 1/3] fix target _blank when anchor has children Couple of days ago, we have faced an issue with out non-SPA project: Once you add a child element to a ```` with ``target="_blank"`` attribute, it wouldn't fire on a new tab. check this fiddle: https://jsfiddle.net/asynchronous/dnLs1dm4/10/ I've changed ``gaurdEvent`` method in ``link`` component so it could fix this issue. --- src/components/link.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/components/link.js b/src/components/link.js index c7dc439dd..5e9109974 100644 --- a/src/components/link.js +++ b/src/components/link.js @@ -82,7 +82,12 @@ export default { return h(this.tag, data, this.$slots.default) } } - +// return first anchor parent of element +function getAnchorParent (event) { + return event.path.find(parent => { + return parent.localName === 'a' + }) +} function guardEvent (e) { // don't redirect with control keys if (e.metaKey || e.ctrlKey || e.shiftKey) return @@ -91,8 +96,16 @@ function guardEvent (e) { // don't redirect on right click if (e.button !== undefined && e.button !== 0) return // don't redirect if `target="_blank"` + if (e.target && e.target.getAttribute) { - const target = e.target.getAttribute('target') + let target + // check if anchor tag + if (e.target.localName === 'a') { + target = e.target.getAttribute('target') + } else { + // get anchor parent of element and assign target attribute + target = getAnchorParent(e).getAttribute('target') + } if (/\b_blank\b/i.test(target)) return } // this may be a Weex event which doesn't have this method From d5bf2c52a6d01fc614c0f6bd7b03d29da4d06e8e Mon Sep 17 00:00:00 2001 From: "Reza Haidari .A" Date: Wed, 29 Mar 2017 18:51:09 +0430 Subject: [PATCH 2/3] Update link.js --- src/components/link.js | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/components/link.js b/src/components/link.js index 5e9109974..88b24960b 100644 --- a/src/components/link.js +++ b/src/components/link.js @@ -82,12 +82,7 @@ export default { return h(this.tag, data, this.$slots.default) } } -// return first anchor parent of element -function getAnchorParent (event) { - return event.path.find(parent => { - return parent.localName === 'a' - }) -} + function guardEvent (e) { // don't redirect with control keys if (e.metaKey || e.ctrlKey || e.shiftKey) return @@ -96,16 +91,8 @@ function guardEvent (e) { // don't redirect on right click if (e.button !== undefined && e.button !== 0) return // don't redirect if `target="_blank"` - if (e.target && e.target.getAttribute) { - let target - // check if anchor tag - if (e.target.localName === 'a') { - target = e.target.getAttribute('target') - } else { - // get anchor parent of element and assign target attribute - target = getAnchorParent(e).getAttribute('target') - } + const target = e.currentTarget.getAttribute('target') if (/\b_blank\b/i.test(target)) return } // this may be a Weex event which doesn't have this method From 0eab797106257c079193f729d1b1cdc7e04a2312 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 29 Mar 2017 16:32:28 +0200 Subject: [PATCH 3/3] Update link.js --- src/components/link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/link.js b/src/components/link.js index 88b24960b..e715ea1d2 100644 --- a/src/components/link.js +++ b/src/components/link.js @@ -91,7 +91,7 @@ function guardEvent (e) { // don't redirect on right click if (e.button !== undefined && e.button !== 0) return // don't redirect if `target="_blank"` - if (e.target && e.target.getAttribute) { + if (e.currentTarget && e.currentTarget.getAttribute) { const target = e.currentTarget.getAttribute('target') if (/\b_blank\b/i.test(target)) return }