[22/47] incubator-weex git commit: * [html5] intercept the a-jump.
* [html5] intercept the a-jump. Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b8aae6ff Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b8aae6ff Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b8aae6ff Branch: refs/heads/master Commit: b8aae6ffc9e95677641046a7dd47b1e3650028e0 Parents: 0ae0fcf Author: MrRaindrop Authored: Mon Sep 4 18:34:22 2017 +0800 Committer: MrRaindrop Committed: Mon Sep 4 18:34:22 2017 +0800 -- html5/render/vue/env/event-manager.js | 38 +- 1 file changed, 17 insertions(+), 21 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b8aae6ff/html5/render/vue/env/event-manager.js -- diff --git a/html5/render/vue/env/event-manager.js b/html5/render/vue/env/event-manager.js index 243daa0..06a00a3 100644 --- a/html5/render/vue/env/event-manager.js +++ b/html5/render/vue/env/event-manager.js @@ -27,20 +27,6 @@ const needPassive = ['touchmove'] const events = gestureEvents.concat(nativeEvents) -// /** -// * is a element in a '' tag? -// * @param {HTMLElement} el -// */ -// function isInANode (el) { -// let parent = el.parentNode -// while (parent && parent !== document.body) { -// if (parent.tagName.toLowerCase() === 'a') { -// return true -// } -// parent = parent.parentNode -// } -// } - /** * if el is a `` element. * @param {HTMLElement} el @@ -82,7 +68,12 @@ function _init (doc) { _inited = true const _sp = supportsPassive() events.forEach(function (evt) { -const option = evt === 'click' +/** + * use capture for click handling, therefore there's a chance to handle + * it before any other listeners binding on document or document.body. + */ +const option = + evt === 'click' ? true : needPassive.indexOf(evt) > -1 && _sp ? { passive: true } : false doc.addEventListener(evt, function (e) { @@ -133,19 +124,24 @@ function _init (doc) { */ if (evtName === 'click' && isANode(elm)) { const href = elm.getAttribute('href') - const target = elm.getAttribute('target') disposed = true - if (target !== '_blank') { + /** + * Give the chance to the listeners binding on doc or doc.body for + * handling the a-jump. + * Should set a _should_intercept_a_jump function on window to test + * whether we should intercept the a-jump. + */ + if (window._should_intercept_a_jump && window._should_intercept_a_jump(elm)) { +// do nothing. leave it to the intercept handler. + } + else { if (!!href) { location.href = href } else { - console.warn('[weex-vue-render] If you want to use the A tag jump, set the href attribute') + console.warn('[vue-render] If you want to use the A tag jump, set the href attribute') } } - else { -// do nothing. - } } if (disposed) {
[22/47] incubator-weex git commit: * [html5] intercept the a-jump.
* [html5] intercept the a-jump. Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b8aae6ff Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b8aae6ff Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b8aae6ff Branch: refs/heads/dev Commit: b8aae6ffc9e95677641046a7dd47b1e3650028e0 Parents: 0ae0fcf Author: MrRaindrop Authored: Mon Sep 4 18:34:22 2017 +0800 Committer: MrRaindrop Committed: Mon Sep 4 18:34:22 2017 +0800 -- html5/render/vue/env/event-manager.js | 38 +- 1 file changed, 17 insertions(+), 21 deletions(-) -- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b8aae6ff/html5/render/vue/env/event-manager.js -- diff --git a/html5/render/vue/env/event-manager.js b/html5/render/vue/env/event-manager.js index 243daa0..06a00a3 100644 --- a/html5/render/vue/env/event-manager.js +++ b/html5/render/vue/env/event-manager.js @@ -27,20 +27,6 @@ const needPassive = ['touchmove'] const events = gestureEvents.concat(nativeEvents) -// /** -// * is a element in a '' tag? -// * @param {HTMLElement} el -// */ -// function isInANode (el) { -// let parent = el.parentNode -// while (parent && parent !== document.body) { -// if (parent.tagName.toLowerCase() === 'a') { -// return true -// } -// parent = parent.parentNode -// } -// } - /** * if el is a `` element. * @param {HTMLElement} el @@ -82,7 +68,12 @@ function _init (doc) { _inited = true const _sp = supportsPassive() events.forEach(function (evt) { -const option = evt === 'click' +/** + * use capture for click handling, therefore there's a chance to handle + * it before any other listeners binding on document or document.body. + */ +const option = + evt === 'click' ? true : needPassive.indexOf(evt) > -1 && _sp ? { passive: true } : false doc.addEventListener(evt, function (e) { @@ -133,19 +124,24 @@ function _init (doc) { */ if (evtName === 'click' && isANode(elm)) { const href = elm.getAttribute('href') - const target = elm.getAttribute('target') disposed = true - if (target !== '_blank') { + /** + * Give the chance to the listeners binding on doc or doc.body for + * handling the a-jump. + * Should set a _should_intercept_a_jump function on window to test + * whether we should intercept the a-jump. + */ + if (window._should_intercept_a_jump && window._should_intercept_a_jump(elm)) { +// do nothing. leave it to the intercept handler. + } + else { if (!!href) { location.href = href } else { - console.warn('[weex-vue-render] If you want to use the A tag jump, set the href attribute') + console.warn('[vue-render] If you want to use the A tag jump, set the href attribute') } } - else { -// do nothing. - } } if (disposed) {