【问题标题】:Quill.js and zombie.jsQuill.js 和zombie.js
【发布时间】:2016-05-10 00:20:17
【问题描述】:

尝试在zombie.js 无头浏览器中测试quill.js 编辑器(contenteditable div)。

  1. 抱怨缺少 document.getSelection
  2. 抱怨缺少 document.createTreeWalker
  3. 如果我使用编辑器的 DOM 节点手动调度更改事件,似乎没有响应。

有人知道怎么做吗?

【问题讨论】:

    标签: node.js contenteditable jsdom zombie.js quill


    【解决方案1】:

    好的,这是我找到的:

    1. zombie.js 使用的当前(旧)版本的 jsdom 不支持 document.getSelection。我现在不得不对其进行修补。有一个针对zombie.js 的待处理 PR 应该将 jsdom 更新到可用的更高版本:https://github.com/assaf/zombie/issues/939
    2. document.createTreeWalker - 相同
    3. 原来 quill.js 正在侦听“keyup”或“keydown”而不是“change”,因此需要调度它们。

    以下是缺少的 DOM 方法的一些可怕的猴子补丁,这些补丁足以测试最低限度的 quill.js:

    var zombie = require( "zombie" );
    zombie.Pipeline.addHandler(function(browser, request, response) {
    
        browser.document.getSelection = browser.window.getSelection = function() {
    
            console.warn( "getSelection called - monkey-patched, incorrect implementation" );
            return null;
    
        };
        browser.document.createTreeWalker = function( x ) {
    
            console.warn( "createTreeWalker called - monkey-patched, incorrect implementation" );
            return {
    
                currentNode: x,
                nextNode: function() {
    
                    if( this.currentNode.childNodes && this.currentNode.childNodes.length ) {
    
                        this.currentNode = this.currentNode.childNodes[ 0 ];
    
                    } else if( this.currentNode.nextSibling ) {
    
                        this.currentNode = this.currentNode.nextSibling;
    
                    } else if( this.currentNode.parentNode ) {
    
                        this.currentNode = this.currentNode.parentNode.nextSibling;
    
                    }
                    return this.currentNode || null;
    
                }
    
            };
    
        };
        return response;
    
    } );
    

    【讨论】:

      猜你喜欢
      • 2013-07-26
      • 2017-06-22
      • 2012-10-25
      • 1970-01-01
      • 2014-05-24
      • 2020-05-24
      • 2017-01-25
      • 2017-01-27
      • 2014-01-15
      相关资源
      最近更新 更多