如何:redactor.js imageUpload Post Extra参数

时间:2013-12-17 04:51:34

标签: javascript jquery wysiwyg redactor redactor.js

我正在使用这个很棒的编辑器,但我不知道如何使用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"
            },
});

1 个答案:

答案 0 :(得分:2)

无法在任何地方找到答案,所以我攻击了核心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"
            },
});