How can I add an onClick listener to a fileButton in CKEditor?

萝らか妹 提交于 2019-12-11 02:08:48

问题


I'm working in the image uploader plugin, and have a button definition like this:

{
    type : 'fileButton',
    id : 'uploadButton',
    filebrowser : 'info:txtUrl',
    label : editor.lang.image.btnUpload,
    'for' : [ 'Upload', 'upload' ],
    onClick : function() {alert('hey')}
}

I have tried defining the function to be called elsewhere as a named function, with no luck. I also haven't been able to add an onClick listener to other elements, but the buttonDefinition class here specifically says you should be able to add one to a button.


回答1:


Have you tried:

document.getElementById('uploadButton').onclick = function() {
    alert('Hey!');
}



回答2:


This is the class of FileButton in javascript

function FileButton(){
   this.type = 'fileButton';
   this.id ='uploadButton';
   this.filebrowser = 'info:txtUrl';
   this.label = "editor.lang.image.btnUpload";
   this.forr = [ 'Upload', 'upload' ];
}

FileButton.prototype.onClick = function() {alert('hey')}

Or if you have json object and want to wrap into javascript class object, define FileButton class and use jquery:

function FileButton(){
   this.type = 'fileButton';
   this.id ='uploadButton';
   this.filebrowser = 'info:txtUrl';
   this.label = "editor.lang.image.btnUpload";
   this.forr = [ 'Upload', 'upload' ];
}

FileButton.prototype.onClick = function() {alert('hey')};

var a = $.extend(new FileButton(), {
          type : 'fileButton',
          id : 'uploadButton',
          filebrowser : 'info:txtUrl',
          label : "editor.lang.image.btnUpload",
          forr : [ 'Upload', 'upload' ],
          onClick : function() {alert('hey')}
        });

console.log(a);
a.onClick();

JsFiddle.net link



来源:https://stackoverflow.com/questions/3059761/how-can-i-add-an-onclick-listener-to-a-filebutton-in-ckeditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!