How to add a field to POST values in CKeditor upload

后端 未结 6 1905
清歌不尽
清歌不尽 2020-12-31 21:21

I use django and ckeditor to provide wysiwyg taste to TextEdits. I would like to use CKEditor file upload function (in filebrowser / image dialog), but the

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 21:59

    I experienced a similar problem when integrating image uploading through CKEditor for Elgg. The least intrusive solution I came up with was to bind to the onClick event for the submit button and modify the form directly from that:

    CKEDITOR.on('dialogDefinition', function (ev) {
        var dialogName = ev.data.name;
        var dialogDefinition = ev.data.definition;
    
        if (dialogName === 'image') {
            var uploadTab = dialogDefinition.getContents('Upload');
    
            for (var i = 0; i < uploadTab.elements.length; i++) {
                var el = uploadTab.elements[i];
    
                if (el.type !== 'fileButton') {
                    continue;
                }
    
                // add onClick for submit button to add inputs or rewrite the URL
                var onClick = el.onclick;
    
                el.onClick = function(evt) {
                    var dialog = this.getDialog();
                    var fb = dialog.getContentElement(this['for'][0], this['for'][1]);
                    var action = fb.getAction();
                    var editor = dialog.getParentEditor();
                    editor._.filebrowserSe = this;
    
                    // if using jQuery
                    $(fb.getInputElement().getParent().$).append('');
    
                    // modifying the URL
                    fb.getInputElement().getParent().$.action = '/my/new/action?with&query¶ms=1';
    
    
                    if (onClick && onClick.call(evt.sender, evt) === false) {
                            return false;
                    }
    
                    return true;
                };
            }
        }
    });
    

提交回复
热议问题