在Internet Explorer中初始化Rangy.js时出错

时间:2015-08-08 23:03:28

标签: javascript angularjs internet-explorer rangy textangular

我正在开发一个使用textAngular的角度应用,它取决于rangy-core和rangy-selectionsaverestore。我在最新的IE中遇到以下错误:

Module 'WrappedSelection' failed to load: Unspecified error.
Error: Unspecified error.
    at Anonymous function (js/plugins/textAngular/rangy-core.js:2970:29)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:2923:14)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:415:21)
    at Module.prototype.init (js/plugins/textAngular/rangy-core.js:387:13)
    at init (js/plugins/textAngular/rangy-core.js:294:17)
    at loadHandler (js/plugins/textAngular/rangy-core.js:3825:17)

Module 'SaveRestore' failed to load: Unable to get property 'isDirectionBackward' of undefined or null reference
TypeError: Unable to get property 'isDirectionBackward' of undefined or null reference
    at Anonymous function (js/plugins/textAngular/rangy-selectionsaverestore.js:30:9)
    at Anonymous function (js/plugins/textAngular/rangy-core.js:415:21)
    at Module.prototype.init (js/plugins/textAngular/rangy-core.js:387:13)
    at init (js/plugins/textAngular/rangy-core.js:294:17)
    at loadHandler (js/plugins/textAngular/rangy-core.js:3825:17)

这个错误似乎发生在rangy初始化期间。

奇怪的是,TextAngular演示在Internet Explorer上运行良好。演示和我的应用程序之间的一个不同之处在于我使用的是未经授权的rangy库。最后,Chrome或Firefox上不会发生这些错误。

虽然app加载(我认为上面的错误只是控制台中的警告),但当我点击textAngular字段时,我看到以下错误:

对象不支持属性或方法' getSelection' 文件:textAngular.js,行:693,列:4

我无法在textAngular或rangy github中找到解决这些问题的任何内容。有没有人以前遇到过这些问题?

如果有帮助,我可以将链接发布到我们的应用程序。

谢谢!

4 个答案:

答案 0 :(得分:3)

看起来textAngular过早地初始化rangy select。我通过在检查rangy库之前更新textAngular / dist / textAngular.js ln 2036以等待onload来修复此问题

    window.onload = function() {
        // Ensure that rangy and rangy.saveSelection exists on the window (global scope).
        // TODO: Refactor so that the global scope is no longer used.
        if(!window.rangy){
            throw("rangy-core.js and rangy-selectionsaverestore.js are required for textAngular to work correctly, rangy-core is not yet loaded.");
        }else{
            window.rangy.init();
            if(!window.rangy.saveSelection){
                throw("rangy-selectionsaverestore.js is required for textAngular to work correctly.");
            }
        }
    };

答案 1 :(得分:1)

我遇到了同样的问题。我尝试了window.onload修复建议,但它只是让我得到另一个关于textAngularSetup未被加载的错误。我把window.onload修复了并包含了textAngularSetup.js文件。它现在在Chrome和IE中运行良好。我很困惑,因为我没有看到演示文稿中包含该文件。

答案 2 :(得分:0)

sharing my solution, I also got the same issue in IE 11(edge mode), tried with above solution(window.onload), but issue was still persisted in the app.

I have done following changes,

  1. Added window.onload as in above solution, textangular.js - run() function

  2. Replaced textangular-rangy.min.js with rangy.core and rangy-selectionsaverestore dependencies,

Modified the core code to handle the exception,

File: rangy-core.js, line number:2967-2972

                        var r2;
                        try {
                            // code generating above exception 
                            r2 = r1.cloneRange()
                            r1.setStart(textNode, 0);
                            r2.setEnd(textNode, 3);
                            r2.setStart(textNode, 2);
                            sel.addRange(r1);
                            sel.addRange(r2);
                            selectionSupportsMultipleRanges = (sel.rangeCount == 2);
                        } catch (e) {
                            selectionSupportsMultipleRanges = false;
                        }

It might help, tested in IE11 and chrome

答案 3 :(得分:0)

我在将第三方工具加载到模态弹出窗口时面临同样的问题,其中我依赖textangular-rangy.min.js

我用rangy.core和rangy-selectionsaverestore依赖项替换了textangular-rangy.min.js, 修改了核心代码以处理异常,

档案:rangy-core.js,行号:2967-2972

 var r2;
                        try {
                            // code generating above exception 
                            r2 = r1.cloneRange()
                            r1.setStart(textNode, 0);
                            r2.setEnd(textNode, 3);
                            r2.setStart(textNode, 2);
                            sel.addRange(r1);
                            sel.addRange(r2);
                            selectionSupportsMultipleRanges = (sel.rangeCount == 2);
                        } catch (e) {
                            selectionSupportsMultipleRanges = false;
                        }

它适用于IE11和chrome:)