使用“更新的 WMD 编辑器” 在 AJAX 表单加载的文本区域中

发布于 2024-07-18 09:34:43 字数 977 浏览 9 评论 0原文

我们正在尝试使用 Stackoverflow 优秀的 WMD / Markdown 编辑器 (http://blog.stackoverflow.com /2009/01/updated-wmd-editor/http://github.com/2009/01/updated-wmd-editor/ com/derobins/wmd/tree/master)在 Symfony 项目上。

这在不涉及任何 AJAX 的文本区域上效果很好。 但是,当我们必须首先包含 wmd.js,然后在用户交互(即“单击链接”)中通过 AJAX 加载文本区域时,我们完全无法使 WMD 工作,Firebug 给我们

elem is null

addEvent()()wmd.js (Linie 110)
setupEvents()()wmd.js (Linie 1790)
init()()wmd.js (Linie 1970)
previewManager()()wmd.js (Linie 1987)
loadListener()()wmd.js (Linie 1763)

[Break on this error] if (elem.attachEvent) {

加载页面(即之前文本区域加载)。

Symfony 的 AJAX 加载器似乎 eval() 标签之间的所有内容。 我们尝试将整个脚本直接包含在这些标签之间,我们尝试转义这个和那个,但没有成功,出现了不同的错误。

此时我们认为我们必须将脚本包含在普通页面中,并且在 AJAX 调用之后我们必须手动启动 WMD - 我们必须调用哪些函数? 我们是否完全偏离了轨道,需要使用不同的方法?

谢谢你!

We're trying to use Stackoverflow's excellent WMD / Markdown editor (http://blog.stackoverflow.com/2009/01/updated-wmd-editor/, http://github.com/derobins/wmd/tree/master) on a Symfony project.

This works excellent on textareas without any AJAX involved. But when we have to include wmd.js first, and then later on user interaction (i.e. "click on link") have the textarea loaded via AJAX we utterly fail to make WMD work, Firebug is giving us

elem is null

addEvent()()wmd.js (Linie 110)
setupEvents()()wmd.js (Linie 1790)
init()()wmd.js (Linie 1970)
previewManager()()wmd.js (Linie 1987)
loadListener()()wmd.js (Linie 1763)

[Break on this error] if (elem.attachEvent) {

on loading the page (i.e. before textarea loading).

Symfony's AJAX Loader seems to eval() everything between tags. We tried including the whole script directly between those tags, we tried escaping this and that, but had no success with differnt errors coming up.

At this point we think we have to include the script in the normal page and after the AJAX call we have to initiate WMD manually - what functions do we have to call? Are we completely off track and need to use a different approach?

Thank you!

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

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

发布评论

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

评论(3

静赏你的温柔 2024-07-25 09:34:43

你可以使用我的版本。 只需将构造函数调用、配置值以及对 start() 方法的调用放入处理从 AJAX 请求获取的结果的回调函数中即可。 我的 mooWMD 版本。

You can use my version. Simply put the constructor call, config values and the call to the start() method in the callback function that handles the results you get from the AJAX request. My version of mooWMD.

宫墨修音 2024-07-25 09:34:43

github 上的 wmd 的 drobins 分支也正在解决 AJAX 问题。

drobins fork of wmd on github is solving the AJAX issues as well.

绳情 2024-07-25 09:34:43

我遇到了同样的问题,一旦我的文本区域被异步添加到页面,我就会初始化 WMD。

这是我的代码:

function loadTextEditor()
{
    var instances = [];

    if (!Attacklab || !Attacklab.wmd) {
                alert("WMD hasn't finished loading!");
                return;
            }
    /***** build the preview manager *****/
    var textArea = document.getElementById('postcontent');
    var previewPane = document.getElementById('postPreview');

    var panes = {input:textArea, preview:previewPane, output:null};
    var previewManager = new Attacklab.wmd.previewManager(panes);

    /***** build the editor and tell it to refresh the preview after commands *****/
    var editor = new Attacklab.wmd.editor(textArea,previewManager.refresh);

    // save everything so we can destroy it all later
    instances.push({ta:textarea, div:previewDiv, ed:editor, pm:previewManager});

}

I had this same issue and I initialize WMD once my textarea has been added to the page asynchronously.

Heres my code:

function loadTextEditor()
{
    var instances = [];

    if (!Attacklab || !Attacklab.wmd) {
                alert("WMD hasn't finished loading!");
                return;
            }
    /***** build the preview manager *****/
    var textArea = document.getElementById('postcontent');
    var previewPane = document.getElementById('postPreview');

    var panes = {input:textArea, preview:previewPane, output:null};
    var previewManager = new Attacklab.wmd.previewManager(panes);

    /***** build the editor and tell it to refresh the preview after commands *****/
    var editor = new Attacklab.wmd.editor(textArea,previewManager.refresh);

    // save everything so we can destroy it all later
    instances.push({ta:textarea, div:previewDiv, ed:editor, pm:previewManager});

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