选项:cleanup_callback

这个选项允许你定义 TinyMCE 的清理逻辑。当清理执行时这个函数会被调用。这个过程发生在保存/提交内容,用户点击清理按钮以及显示HTML源代码编辑对话框时。函数格式是:customCleanup(type, value)。当内容从 TinyMCE 提取时,type="get_from_editor"。例如:当用户提交表单时。type="insert_to_editor" 用在初始化时有新的内容插入编辑器或者当HTML源代码编辑对话框提交新内容时。type="get_from_editor_dom" 用于清理过程包含一个有效的 DOM 树,并且内容从编辑器中提取。type="insert_to_editor_dom"用于编辑器有一个有效的 DOM 树,并且内容已经被插入编辑器。下面的例子展示了所有的种类。

cleanup_callback 选项的使用示例:

function myCustomCleanup(type, value) {
	switch (type) {
		case "get_from_editor":
			alert("Value HTML string: " + value);

			// Do custom cleanup code here

			break;

		case "insert_to_editor":
			alert("Value HTML string: " + value);

			// Do custom cleanup code here

			break;

		case "get_from_editor_dom":
			alert("Value DOM Element " + value);

			// Do custom cleanup code here

			break;

		case "insert_to_editor_dom":
			alert("Value DOM Element: " + value);

			// Do custom cleanup code here

			break;
	}

	return value;
}

tinyMCE.init({
	...
	cleanup_callback : "myCustomCleanup"
});