编程语言
首页 > 编程语言> > javascript – 如何为CKFinder创建重命名后或删除后事件挂钩?

javascript – 如何为CKFinder创建重命名后或删除后事件挂钩?

作者:互联网

如果在CKFinder中删除或重命名文件,我需要编辑内容并告知用户各种事情.我以为我可以创建一个JavaScript解决方案然后使用一些简单的AJAX将逻辑卸载到后端,具体如下:

CKFinder.on('successfulFileRename', function(event, oldpath, newpath) {
    // Contact backend, see where file was used, inform user etc etc
});

但是,唉,我找不到任何事件系统.我如何为CKFinder实现此功能?我需要的事件是文件/文件夹 – 重命名/删除/移动.它不一定是前端解决方案,但我更喜欢它的简单性.我的后端是ASP.net MVC3.

(CKF的替代品作为评论欢迎,但它们需要与它具有相同的功能.)

解决方法:

经过documentation我也无法找到像扩展点这样的事件.

然而,通过查看一些源代码,我在CKFinder.dataTypes.Connector上找到了sendCommandPost method,每次需要将某些东西发送到服务器时都会调用它.因此,在每个重要事件,如文件/文件夹 – 重命名/删除/移动.

因此,您可以轻松创建自定义插件,您可以在其中访问CKFinderAPI实例,然后您可以覆盖sendCommandPost并添加自定义逻辑

CKFinder.addPlugin( 'myplugin', function( api ) {
    var orginalsendCommandPost = api.connector.sendCommandPost;
    api.connector.sendCommandPost = function() {

      // call the original function
      var result = orginalsendCommandPost.apply(this, arguments);

      // commandname as string: 'CreateFolder', 'MoveFiles', 'RenameFile', etc
      console.log(arguments[0]); 
      // arguments as object
      console.log(JSON.stringify(arguments[1]));

      return result;
    }
} );

并注册插件:

config.extraPlugins = "myplugin";
var ckfinder = new CKFinder( config );

标签:javascript,asp-net-mvc,ckfinder
来源: https://codeday.me/bug/20190629/1324835.html