tinymce获取删除图像的详细信息 [英] tinymce get image details on deletion
问题描述
我已经创建了一个插件来处理tinymce的图片上传。这一切都很好。我希望能够做的是从我的服务器中删除图像,如果它被用户删除,那么我最终不会得到孤立文件的演出。
I have created a plugin to handle image uploads for tinymce. THis is all working fine. What I want to be able to do is remove the image from my server if it is deleted by the user so that I don't end up with gigs of orphanged files.
我已经能够使用tinymce init的设置部分来监听nodechange envent
I have been able to listen for the nodechange envent using setup part of the tinymce init
<script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea",
plugins: "autoresize",
toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image jbimages",
relative_urls: false,
setup : function(ed) {
ed.on("NodeChange", function(e) {
console.log('change event', e);
});
}
});</script>
这给了我一个我可以在控制台看到的事件,但我找不到办法从事件中得到的东西告诉我已经执行了img删除,这样我就可以从服务器上删除图像了。
this gives me an event which I can see in the console, but I can't find a way of getting something from the event that tells me a img removal have been performed, so that i can delete the image from the server.
我在这里创建了一个小提琴 HERE
I have create a fiddle for this here HERE
如果您加载控制台并且删除图像你会看到我的意思。我缺少哪些属性或事件方法?
if you load up your console and delete the image you will see what I mean. is there some property or method of the event that I am missing?
提前致谢
推荐答案
我试图做同样的事情,但经过大量的网络拖网和调试我能看到实现这一目的的唯一方法是在编辑器中选择图像时观察编辑器中的删除或退格键。
I was trying to do the same thing, but after much internet trawling & debugging the only way I could see to achieve this was to watch the editor for the delete or backspace keys being pushed while an image was selected in the editor.
所以在你的内容中tinymce.initsetup功能:
So within your tinymce.init "setup" function:
ed.on('KeyDown', function (e) {
if ((e.keyCode == 8 || e.keyCode == 46) && editor.selection) { // delete & backspace keys
var selectedNode = editor.selection.getNode(); // get the selected node (element) in the editor
if (selectedNode && selectedNode.nodeName == 'IMG') {
MyCallback(selectedNode.src); // A callback that will let me invoke the deletion of the image on the server if appropriate for the image source.
}
}
});
我在一个新的插件中设置了这个,然后将回调添加为该插件的一个设置。
I set this up within a new plugin, then added the callback as one of the settings of that plugin.
这篇关于tinymce获取删除图像的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!