jQuery + InnovaStudio 所见即所得编辑器

发布于 2024-08-29 12:43:08 字数 1882 浏览 2 评论 0原文

我试图避免对这个所见即所得编辑器的每个实例进行硬编码,因此我使用 jQuery 根据函数名称创建each() 循环。令人烦恼的是,当我尝试时,InnovaStudio 似乎会爆炸。

文档

尝试 #1

<script type="text/javascript">

            /*
            id = $(this).attr('id');
            if(id.length == 0)
            {
                id = 'wysiwyg-' + wysiwyg_count;
                 $(this).attr('id', id);
            }

            WYSIWYG[wysiwyg_count] = new InnovaEditor('WYSIWYG[' + wysiwyg_count + ']');
            WYSIWYG[wysiwyg_count].REPLACE(id);
            */

            var demo = new InnovaEditor('demo');
            demo.REPLACE('wysiwyg-1');

            console.log('loop');

 </script>

效果

工作正常,但当然只适用于编辑器的单个实例。如果我想要多个实例,我需要使用each。

尝试#2:

<script type="text/javascript">

var wysiwyg_count = 1;
//var WYSIWYG = [];
var demo;

(function($) {
    $(function() {

        $('.wysiwyg-simple').each(function(){

            /*
            id = $(this).attr('id');
            if(id.length == 0)
            {
                id = 'wysiwyg-' + wysiwyg_count;
                 $(this).attr('id', id);
            }

            WYSIWYG[wysiwyg_count] = new InnovaEditor('WYSIWYG[' + wysiwyg_count + ']');
            WYSIWYG[wysiwyg_count].REPLACE(id);
            */

            demo = new InnovaEditor('demo');
            demo.REPLACE('wysiwyg-1');

            console.log('loop');
        });

    });
})(jQuery);
 </script>

效果

用所见即所得相关代码替换我页面的整个 HTML 正文,并抱怨没有 JS 可用(甚至 Firebug 都没有,所以无法调试) 。

请注意,我仍然对名称进行硬编码。我正在测试的页面上只有一个实例,因此当我使这个硬编码名称正常工作时,我将使注释掉的代码按照相同的方式工作。


有人知道这里到底发生了什么事吗?

I am trying to avoid hard-coding each instance of this WYSIWYG editor so I am using jQuery to create an each() loop based on function name. Annoyingly InnovaStudio seems to explode when I try.

Documentation

Attempt #1

<script type="text/javascript">

            /*
            id = $(this).attr('id');
            if(id.length == 0)
            {
                id = 'wysiwyg-' + wysiwyg_count;
                 $(this).attr('id', id);
            }

            WYSIWYG[wysiwyg_count] = new InnovaEditor('WYSIWYG[' + wysiwyg_count + ']');
            WYSIWYG[wysiwyg_count].REPLACE(id);
            */

            var demo = new InnovaEditor('demo');
            demo.REPLACE('wysiwyg-1');

            console.log('loop');

 </script>

Effect

Works fine, but of course only works for a single instance of the editor. If I want multiple instances I need to use an each.

Attempt #2:

<script type="text/javascript">

var wysiwyg_count = 1;
//var WYSIWYG = [];
var demo;

(function($) {
    $(function() {

        $('.wysiwyg-simple').each(function(){

            /*
            id = $(this).attr('id');
            if(id.length == 0)
            {
                id = 'wysiwyg-' + wysiwyg_count;
                 $(this).attr('id', id);
            }

            WYSIWYG[wysiwyg_count] = new InnovaEditor('WYSIWYG[' + wysiwyg_count + ']');
            WYSIWYG[wysiwyg_count].REPLACE(id);
            */

            demo = new InnovaEditor('demo');
            demo.REPLACE('wysiwyg-1');

            console.log('loop');
        });

    });
})(jQuery);
 </script>

Effect

Replaces the entire HTML body of my page with JUST WYSIWYG related code and complains as no JS is available (not even Firebug, so can't debug).

Notice that I am hardcoding the name still. I only have one instance on the page I am testing it on, so when I get this hard-coded name working I will get the commented out code working along the same lines.


Does anybody know what the hell is going on here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱本泡沫多脆弱 2024-09-05 12:43:09

即使您选择了 CKEditor,您也可能对解决方案感兴趣。您可以向 REPLACE 函数提供第二个参数。第二个参数也应该是一个 id,来自能够接受 html 输出的元素(如 div、span、p)的 id。

demo = new InnovaEditor('demo');
demo.REPLACE('wysiwyg-1', 'wysiwyg-1-replaceDiv');

当省略第二个参数时,InnovaStudio 只需使用以下命令即可将 html 输出写入文档:

document.write();

希望这会有所帮助!

Even though you went for CKEditor you might be interested in a solution. You can supply a second argument to the REPLACE function. This second argument should also be a id, id from a element able to accept html output (like div, span, p).

demo = new InnovaEditor('demo');
demo.REPLACE('wysiwyg-1', 'wysiwyg-1-replaceDiv');

When the second argument is left out, InnovaStudio, writes the html output to the document by simply using:

document.write();

Hope this helps!

青衫负雪 2024-09-05 12:43:09

从4.3版本开始为什么不使用自己的初始化代码:

    <textarea class="innovaeditor">
content here...
</textarea>


<script>
oUtil.initializeEditor("innovaeditor", 
{width:"700px", height:"450px"}
);
</script>

方法是oUtil.initializeEditor(selector, option)。第一个参数是选择器,第二个参数是 JSON 格式的编辑器属性。

选择器可以是:

Css类名,如果指定了类名,则所有具有指定类名的文本区域将被替换为编辑器。
文本区域 ID。如果是Id,则必须添加前缀'#',例如oUtil.initializeEditor("#mytextarea")。
文本区域对象。
第二个参数是编辑器的属性。可以在此处指定所有有效的编辑器属性,例如宽度、高度、cmdAssetManager、toolbarMode 等。

请注意,可以从页面加载或文档就绪事件或页面加载期间调用此方法(只要选择器引用的对象已经呈现) )。当页面包含编辑器脚本时,此方法自动可用。

Why don't you use their own initialization code since version 4.3:

    <textarea class="innovaeditor">
content here...
</textarea>


<script>
oUtil.initializeEditor("innovaeditor", 
{width:"700px", height:"450px"}
);
</script>

The method is oUtil.initializeEditor(selector, option). The first parameter is selector and second is editor properties in JSON format.

The selector can be:

Css class name, if class name is specified all textareas with specified class name will be replaced with editor.
Textarea Id. If it is an Id, a prefix '#' must be added, for example oUtil.initializeEditor("#mytextarea").
Textarea object.
The second parameter is editor's properties. All valid editor's properties can be specified here for example width, height, cmdAssetManager, toolbarMode, etc.

Note that this method can be called from page onload or document ready event or during page load (as long as the object referred by selector are already rendered). This method available automatically when the page include the editor script.

一笑百媚生 2024-09-05 12:43:08

解决方案:不要尝试使用 InnovaStudio,而是使用 CKEditor。

Solution: Don't bother trying to use InnovaStudio, went with CKEditor instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文