You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by gu...@apache.org on 2017/09/26 04:25:28 UTC

[26/47] incubator-weex git commit: * [html5] add prevent attr for a and support href of javascript:void(0)

* [html5] add prevent attr for a and support href of javascript:void(0)


Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/386a0c61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/386a0c61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/386a0c61

Branch: refs/heads/dev
Commit: 386a0c611184da024fe1132e26d857cd4c4839a0
Parents: ec5b791
Author: MrRaindrop <te...@gmail.com>
Authored: Fri Sep 8 12:52:21 2017 +0800
Committer: MrRaindrop <te...@gmail.com>
Committed: Fri Sep 8 12:52:21 2017 +0800

----------------------------------------------------------------------
 html5/render/vue/env/event-manager.js | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/386a0c61/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 06a00a3..70166bc 100644
--- a/html5/render/vue/env/event-manager.js
+++ b/html5/render/vue/env/event-manager.js
@@ -124,6 +124,8 @@ function _init (doc) {
          */
         if (evtName === 'click' && isANode(elm)) {
           const href = elm.getAttribute('href')
+          const voidHrefReg = /^\s*javascript\s*:\s*void\s*(?:\(\s*0\s*\)|0)\s*;?\s*$/
+          const prevent = elm.getAttribute('prevent')
           disposed = true
           /**
            * Give the chance to the listeners binding on doc or doc.body for
@@ -131,16 +133,15 @@ function _init (doc) {
            * 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)) {
+          if (window._should_intercept_a_jump && window._should_intercept_a_jump(elm)
+            || href.match(voidHrefReg)
+            || prevent === '' || prevent === 'true') {
             // do nothing. leave it to the intercept handler.
           }
-          else {
-            if (!!href) {
-              location.href = href
-            }
-            else {
-              console.warn('[vue-render] If you want to use the A tag jump, set the href attribute')
-            }
+          else if (href) {
+            location.href = href
+          } else if (process.env.NODE_ENV === 'development') {
+            console.warn('[vue-render] If you want to use the A tag jump, set the href attribute')
           }
         }