如何在销毁实例后重新初始化 ckeditor (4),这样我就不必重新加载页面。我在通过ajax将内容保存到mysql之前销毁它们以清理内联div(请参阅我对原因的评论)
这是我的代码:
<!DOCTYPE html>
<html>
<head>
<title>Massive inline editing — CKEditor Sample</title>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="/ckeditor/ckeditor.js"></script>
<script>
// The "instanceCreated" event is fired for every editor instance created.
CKEDITOR.on('instanceCreated', function(event) {
var editor = event.editor,
element = editor.element;
});
</script>
</head>
<body>
<!-- START CONTAINER DIV -->
<div id="container">
<div id="headerLeft" contenteditable="true">
<!-- START HEADERLEFT DIV -->
<h2 id="sampleTitle">
CKEditor<br> Goes Inline!
</h2>
<h3>
Lorem ipsum dolor sit amet dolor duis blandit vestibulum faucibus a, tortor.
</h3>
</div>
<!-- END headerLeft DIV -->
<div id="headerRight" contenteditable="true">
<!-- START HEADERRIGHT DIV -->
<p>Lorem ipsum dolor sit amet enim. Etiam ullamcorper. Suspendisse a pellentesque dui, non felis. Maecenas malesuada elit lectus felis, malesuada ultricies.
</p>
<p>Curabitur et ligula. Ut molestie a, ultricies porta urna. Vestibulum commodo volutpat a, convallis ac, laoreet enim. Phasellus fermentum in, dolor. Pellentesque facilisis. Nulla imperdiet sit amet magna. Vestibulum dapibus, mauris nec malesuada
fames ac.
</p>
</div>
<!-- END headerRight DIV -->
</div>
<!-- END CONTAINER DIV -->
<div style="clear:both;"></div>
<input type="button" id="clickME" value="Save Changes">
<script>
$("#clickME").click(function() {
//START FOR STATEMENT
// Cleaning up the div's that contain contenteditable="true" because ckeditor is changing them form
// <div id="headerRight" contenteditable="true"> TO
// <div id="headerLeft" contenteditable="true" class="cke_editable cke_editable_inline cke_contents_ltr" tabindex="0" spellcheck="false" style="position: relative; " role="textbox" aria-label="Rich Text Editor, headerLeft" title="Rich Text Editor, headerLeft" aria-describedby="cke_53">
// Without this for statement
// IS THERE AN ALTERNATIVE TO PREVENT DESTROYING CKEDITOR INSTANCES????
for (name in CKEDITOR.instances) {
CKEDITOR.instances[name].destroy()
}
// END FOR STATEMENT
// GET CONTENTS FROM CONTAINER DIV
var htmlStr = $('#container').html();
// CALL FUNCTION TO SAVE CONTENT FROM CONTAINER DIV VIA AJAX
addHit(htmlStr);
// HOW TO RE INITIALIZE CKEDITOR HERE SO CKEDITOR WORKS AGAIN?????
});
// START FUNCTION TO SAVE DATA VIA AJAX
function addHit(data1) {
$.ajax({
type: "POST",
url: "/save.php",
data: "var1=" + data1,
success: function(msg) {
alert("Data Saved: " + msg); //Anything you want
}
});
}
// END FUNCTION TO SAVE DATA VIA AJAX
</script>
</body>
</html>