简体   繁体   English

内陆CKEditor在Durandal

[英]Inline CKEditor in Durandal

I'm using Durandal to create a single page application, and I want to use CKEditor in it. 我正在使用Durandal创建一个单页应用程序,并且我想在其中使用CKEditor。 I've had some issues with Durandal using javascript within an html page, but given what I'm doing, I don't know an alternative to put the necessary javascript in the js file. 我在Durantal在html页面中使用javascript时遇到了一些问题,但是鉴于我在做什么,我不知道将必需的javascript放在js文件中的替代方法。 The html file works fine on its own, but when Durandal runs it, the javascript seems to be ignored. html文件本身可以正常工作,但是当Durandal运行它时,javascript似乎被忽略了。

By clicking in the div, CKEditor should display a toolbar for editing the html inline, but that doesn't happen when I run it with Durandal. 通过单击div,CKEditor应该显示一个工具栏来编辑html内联,但是当我使用Durandal运行它时不会发生。

createCourse.html createCourse.html

<section style="max-height: 20%;max-width: 100%">
    <script src="../viewmodels/createCourse.js"></script>
    <h2>Create a Course</h2>
    <div id="editor1" contenteditable="true">
        <h1>Inline Editing in Action!</h1>
        <p>The "div" element that contains this text is now editable.
    </div>

</section>

createCourse.js createCourse.js

define(["plugins/http", "durandal/app", "knockout", "ckeditor"], function (http, app, ko, cke) {
    var ctor = function () {
        this.displayName = "Create a Course";
        this.description = "Add a new course";
    };

    return ctor;
});

What can I do to allow CKEditor to work with Durandal? 如何允许CKEditor与Durandal一起使用?

To fix this, I updated createCourse.js to 为了解决这个问题,我将createCourse.js更新为

define(["plugins/http", "durandal/app", "knockout", "ckeditor"], function (http, app, ko, cke) {
    var ctor = function () {
        this.displayName = "Create a Course";
        this.description = "Add a new course";
        this.attached = function () {
            CKEDITOR.disableAutoInline = true;
            var cke = CKEDITOR.inline('editor', {/*some settings*/});

            cke.on('instanceReady', function (ev) {
                var editor = ev.editor;
                editor.setReadOnly(false);
            });
        };
    };

    return ctor;
});

and now it works. 现在可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM