我正在尝试用ajax编辑wmd。 这里有bugged code
wdm代码基于github上的openlibrary fork
没有ajax就能很好地工作。
但是当我尝试在ajax表单上显示编辑器时,它不会加载。
非ajax版本产生这个html:
<div id="wmd-container">
<div id="wmd-button-bar"></div>
<div id="wmd-button-bar-0" class="wmd-button-bar"><ul class="wmd-button-row"><li style="background-position: 0px 0px;" title="Strong <strong> Ctrl+B" class="wmd-button wmd-bold-button"></li><li style="background-position: -20px 0px;" title="Emphasis <em> Ctrl+I" class="wmd-button wmd-italic-button"></li><li class="wmd-spacer"></li><li style="background-position: -40px 0px;" title="Hyperlink <a> Ctrl+L" class="wmd-button wmd-link-button"></li><li style="background-position: -60px 0px;" title="Blockquote <blockquote> Ctrl+Q" class="wmd-button wmd-quote-button"></li><li style="background-position: -80px 0px;" title="Code Sample <pre><code> Ctrl+K" class="wmd-button wmd-code-button"></li><li style="background-position: -100px 0px;" title="Image <img> Ctrl+G" class="wmd-button wmd-image-button"></li><li class="wmd-spacer"></li><li style="background-position: -120px 0px;" title="Numbered List <ol> Ctrl+O" class="wmd-button wmd-olist-button"></li><li style="background-position: -140px 0px;" title="Bulleted List <ul> Ctrl+U" class="wmd-button wmd-ulist-button"></li><li style="background-position: -160px 0px;" title="Heading <h1>/<h2> Ctrl+H" class="wmd-button wmd-heading-button"></li><li style="background-position: -180px 0px;" title="Horizontal Rule <hr> Ctrl+R" class="wmd-button wmd-hr-button"></li><li class="wmd-spacer"></li><li style="background-position: -200px -20px;" title="Undo - Ctrl+Z" class="wmd-button wmd-undo-button"></li><li style="background-position: -220px -20px;" title="Redo - Ctrl+Shift+Z" class="wmd-button wmd-redo-button"></li><li style="background-position: -240px 0px;" class="wmd-button wmd-help-button"><a title="WMD website" target="_blank" href="http://wmd-editor.com/"></a></li></ul></div><div id="wmd-button-bar-2" class="wmd-button-bar"></div><div id="wmd-button-bar-4" class="wmd-button-bar"></div><textarea id="wmd-input" class="resizable" name="post-text" cols="92" rows="15" tabindex="101"></textarea><div id="wmd-preview-4" class="wmd-preview"></div><div id="wmd-preview-2" class="wmd-preview"></div><div id="wmd-preview-0" class="wmd-preview"></div>
</div>
以ajax形式:
<div id="wmd-container">
<div id="wmd-button-bar"></div>
<div id="wmd-button-bar-1" class="wmd-button-bar"></div><div id="wmd-button-bar-3" class="wmd-button-bar"></div><textarea id="wmd-input" class="resizable" name="post-text" cols="92" rows="15" tabindex="101"></textarea><div id="wmd-preview-3" class="wmd-preview"></div><div id="wmd-preview-1" class="wmd-preview"></div>
</div>
任何帮助?
答案 0 :(得分:3)
我正在使用可用于多个textareas的版本。通过调用以下内容启动控件:
setup_wmd({
"input": "user_about",
"button_bar": "user_about-button-bar",
"preview": "user_about-preview"
});
使用“load”上的事件侦听器加载编辑器的问题ID,因此它仅在页面完全加载时加载。加载ajax表单时,由于页面已加载,此事件不会触发。“
<强>解决方案强>
在方法util.startEditor中替换以下行:
util.addEvent(top, "load", loadListener);
有这样的事情:
if (ajaxForm) {
loadListener(); //this loads the editor immediately
} else {
util.addEvent(top, "load", loadListener);
}
您可以在更改部分的顶部添加此行
var ajaxForm = wmd_options.ajaxForm || false
所以你可以调用这个方法立即加载编辑器:
setup_wmd({
"input": "user_about",
"button_bar": "user_about-button-bar",
"preview": "user_about-preview",
"ajaxForm": true
});
因此,您可以在加载ajax请求后加载编辑器来调用此方法。