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

chrome浏览器对文本域进行Ctrl+V操作,会触发DOMNodeRemoved事件 #441

Closed
RubyLouvre opened this issue Jul 25, 2014 · 0 comments

Comments

@RubyLouvre
Copy link
Owner

<!DOCTYPE html>
<html>
    <head>
        <title>by 司徒正美</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <script>

            window.onload = function() {
                document.getElementById("input").addEventListener("DOMNodeRemoved", function(e) {
                    console.log(e)
                })
                var div = document.getElementById("div")
                div.addEventListener("DOMNodeRemoved", function(e) {
                    console.log(e)
                })
                setTimeout(function() {
                    document.body.removeChild(div)
                }, 2000)
            }

        </script>


    </head>
    <body>
        <p><input id="input"></p>
        <div id="div">111111</div>

    </body>
</html>

这个BUG会影响到avalon的UI组件 ,触发widgetVM的$remove方法……

  if (supportMutationEvents) {
                        elem.addEventListener("DOMNodeRemoved", function(e) {
                            if (e.target === this && !this.msRetain ){
                                offTree()
                            }
                        })
                    } else {
                        elem.offTree = offTree
                        launchImpl(elem)
                    }

现在修正如下

  if (supportMutationEvents) {
                        elem.addEventListener("DOMNodeRemoved", function(e) {
                            if (e.target === this && !this.msRetain &&
                                    (window.chrome ? this.tagName === "INPUT" && this.relatedNode.nodeType === 1 : 1)) {
                                offTree()
                            }
                        })
                    } else {
                        elem.offTree = offTree
                        launchImpl(elem)
                    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant