Javascript ContentTools-无法使用自定义编辑按钮重新激活
我正在使用ContentTools,使用标准点火开关时一切正常。但是,当我不使用蓝色按钮“添加我自己的”来开始编辑/保存和放弃更改时,编辑器无法重新激活。这意味着用户可以编辑,然后保存一次。所有随后的重新激活尝试都会以静默方式失败 初始化代码:Javascript ContentTools-无法使用自定义编辑按钮重新激活,javascript,html,Javascript,Html,我正在使用ContentTools,使用标准点火开关时一切正常。但是,当我不使用蓝色按钮“添加我自己的”来开始编辑/保存和放弃更改时,编辑器无法重新激活。这意味着用户可以编辑,然后保存一次。所有随后的重新激活尝试都会以静默方式失败 初始化代码: window.addEventListener('load', function() { editor = ContentTools.EditorApp.get(); editor.init('.editable', 'id');
window.addEventListener('load', function() {
editor = ContentTools.EditorApp.get();
editor.init('.editable', 'id');
ContentTools.IMAGE_UPLOADER = imageUploader;
$('#btnStartEdit').click(function() {
editor.start();
$(this).hide();
$('#btnSaveChanges').fadeIn();
$('#btnDiscardChanges').fadeIn();
});
$('#btnSaveChanges').click(function() {
editor.save();
$('#btnStartEdit').fadeIn();
$('#btnSaveChanges').fadeOut();
$('#btnDiscardChanges').fadeOut();
});
$('#btnDiscardChanges').click(function() {
editor.revert();
$('#btnStartEdit').fadeIn();
$('#btnSaveChanges').fadeOut();
$('#btnDiscardChanges').fadeOut();
});
ContentTools.EditorApp.get()._ignition.unmount();
});
不要直接使用
save()
和revert()
方法,我建议您使用stop(true)
进行保存,使用stop(false)
进行取消/还原
save
和revert
方法不会停止编辑器(例如save(true)
可用于在用户继续编辑时自动保存内容)。使用stop
应允许您重新启动编辑器,例如:
window.addEventListener('load', function() {
editor = ContentTools.EditorApp.get();
editor.init('.editable', 'id');
ContentTools.IMAGE_UPLOADER = imageUploader;
$('#btnStartEdit').click(function() {
editor.start();
$(this).hide();
$('#btnSaveChanges').fadeIn();
$('#btnDiscardChanges').fadeIn();
});
$('#btnSaveChanges').click(function() {
editor.stop(true);
$('#btnStartEdit').fadeIn();
$('#btnSaveChanges').fadeOut();
$('#btnDiscardChanges').fadeOut();
});
$('#btnDiscardChanges').click(function() {
editor.stop(false);
$('#btnStartEdit').fadeIn();
$('#btnSaveChanges').fadeOut();
$('#btnDiscardChanges').fadeOut();
});
ContentTools.EditorApp.get()._ignition.unmount();
});
这真的很有道理,非常感谢!