3

我正在使用这个很棒的编辑器,但我不知道如何使用 imageUpload 和 clipboardUpload 传递额外的参数。

当用户将图像传递到编辑器时,我希望能够发布额外的参数

$el.redactor({
    imageUpload: '/WebUpload/Save',
    clipboardUploadUrl: '/WebUpload/Save',
});

http://imperavi.com/redactor/


更新

从 Redacor v10 开始,额外的参数包括在内,只需使用uploadImageFields

$el.redactor({
    imageUpload: '/WebUpload/Save',
    clipboardUploadUrl: '/WebUpload/Save',
    uploadImageFields: {
                id: 1234,
                name: "test123"
            },
});
4

1 回答 1

3

在任何地方都找不到答案,所以我破解了核心 redactor.js 文件

我添加了

$.Redactor.opts = {
        imageUploadExtraParams: {},

到选项并更改帖子以将这些参数包含在pasteClipboardUploadMozillapasteClipboardUpload

pasteClipboardUploadMozilla: function() {
    var imgs = this.$editor.find('img[data-mozilla-paste-image]');

    $.each(imgs, $.proxy(function(i, s) {

        var $s = $(s);
        var arr = s.src.split(",");
        var data = arr[1]; // raw base64
        var contentType = arr[0].split(";")[0].split(":")[1];

        var postData = {
            contentType: contentType,
            data: data,
        };
        var extraParams = this.opts.imageUploadExtraParams || {};
        for (var propName in extraParams) {
            postData[propName] = extraParams[propName];
        }

        $.post(this.opts.clipboardUploadUrl, postData,

并改变了

pasteClipboardUploadMozilla: function() {
    var imgs = this.$editor.find('img[data-mozilla-paste-image]');

    $.each(imgs, $.proxy(function(i, s) {

        var $s = $(s);
        var arr = s.src.split(",");
        var data = arr[1]; // raw base64
        var contentType = arr[0].split(";")[0].split(":")[1];

        var postData = {
            contentType: contentType,
            data: data,
        };
        var extraParams = this.opts.imageUploadExtraParams || {};
        for (var propName in extraParams) {
            postData[propName] = extraParams[propName];
        }

        $.post(this.opts.clipboardUploadUrl, postData,

现在我可以通过添加imageUploadExtraParams对象来发布额外的参数

$el.redactor({
    imageUpload: '/WebUpload/Save',
    clipboardUploadUrl: '/WebUpload/Save',
    imageUploadExtraParams: {
                id: 1234,
                name: "test123"
            },
});

更新

从 Redacor v10 开始,额外的参数包括在内,只需使用uploadImageFields

$el.redactor({
    imageUpload: '/WebUpload/Save',
    clipboardUploadUrl: '/WebUpload/Save',
    uploadImageFields: {
                id: 1234,
                name: "test123"
            },
});
于 2013-12-18T01:04:08.590 回答