Javascript 源编辑区域上的CKEditor checkDirty()
每当我的一个或多个CKEditor WYSIWYG实例发生更改时,我都会给相应的textarea赋予属性Javascript 源编辑区域上的CKEditor checkDirty(),javascript,jquery,ckeditor,event-listener,Javascript,Jquery,Ckeditor,Event Listener,每当我的一个或多个CKEditor WYSIWYG实例发生更改时,我都会给相应的textarea赋予属性data dirty=“1”,这样我的应用程序就知道它已更改 我将使用以下代码段进行此操作: $('textarea.wysiwyg').ckeditor(ckeditor_config, function () { var call_once = false; this.on('change', function () { if (this.checkDirt
data dirty=“1”
,这样我的应用程序就知道它已更改
我将使用以下代码段进行此操作:
$('textarea.wysiwyg').ckeditor(ckeditor_config, function () {
var call_once = false;
this.on('change', function () {
if (this.checkDirty()) {
if (!call_once) {
$(this.element).attr('data-dirty', 1);
$('#edit_form').change();
}
call_once = true;
}
});
});
这很好,除非用户只通过编辑HTML。在这种情况下,checkDirty()
似乎不会被解雇
有人知道如何在编辑器的两个视图上使用此功能吗?我使用的是最新版本的CKEditor(CKEditor 4.5.7),完整版,所以插件也是最新版本
提前感谢。由于国家:
请注意,change
事件仅在中触发。为了在源代码模式下实现类似的功能,您可以监听事件或本机输入
事件(Internet Explorer 8不支持)
如果在一个页面中使用jQuery适配器和多个编辑器实例,可以尝试以下操作:
$( '#editor1' ).ckeditor( function(){ this.on( 'mode',
function( evt ) {
if ( this.mode == 'source' ) {
var editable = this.editable();
// Get the textarea
var element = $(this.element);
editable.attachListener( editable, 'input', function( ev ) {
// Handle changes made in the source mode.
console.log( ev );
// Set an attribute on the textarea for handling
element.attr('data-dirty',1);
} );
}
});
});
以上是将在单个编辑器实例上执行的示例,但如果指定选择器覆盖多个编辑器实例,例如
.myeditor
,则侦听器将附加到通过此方法创建的每个编辑器实例。我将研究此解决方案,并让您知道。谢谢你,安娜!嗨,Anna,我一直在尝试这个,但是无法使用jQuery适配器使它工作。另外,请注意我的页面中有几个ckeditor实例。你能给我指一下正确的方向吗?嗨,j·斯维德斯基。谢谢你。我现在可以在源代码中注册更改,唯一的障碍仍然是将属性data dirty=1
添加到源文本区域。你能靠进去吗?我找到了。该元素存储在此中。
$( '#editor1' ).ckeditor( function(){ this.on( 'mode',
function( evt ) {
if ( this.mode == 'source' ) {
var editable = this.editable();
// Get the textarea
var element = $(this.element);
editable.attachListener( editable, 'input', function( ev ) {
// Handle changes made in the source mode.
console.log( ev );
// Set an attribute on the textarea for handling
element.attr('data-dirty',1);
} );
}
});
});