如何实现图片上传到下一页末降价编辑器? [英] How to implement image upload to the PageDown markdown editor?

查看:133
本文介绍了如何实现图片上传到下一页末降价编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要实现图片上传到下一页末降价编辑器,我已经修改了一些code关于编辑器。

To implement image upload to the PageDown markdown editor, I have modified some code about the editor.

Markdown.Editor.js

VAR defaultsStrings = {imagedialog:<输入ID =形象类型=文件/>}

var defaultsStrings = { imagedialog : "< input id='image' type='file' />" }

在选择一个图片,然后点击确定按钮,发送Ajax请求。它可以返回的图像路径​​。

When select a picture and then click ok button to sent ajax request. It can return image path.

var okButton = doc.createElement("input");
        okButton.type = "button";
        okButton.onclick = function () { 
            var data = new FormData();
            data.append('file', $( '#image' )[0].files[0] );
            $.ajax({
                url: 'uploadFile',
                data: data,
                processData: false,
                contentType: false,
                type: 'POST',
                success: function ( data ) {
                    alert(path);
                }
            });
            return close(false);};

如何preVIEW在编辑器preVIEW区域的图像?

推荐答案

文章提供了一个有用的方法,

This article provide a useful method,

editor.hooks.set("insertImageDialog", function (callback) {
 var $input = $('<input type="file" name="File" id="file_0" class = "fileUpload"/>');
 var $okButton = $('<a class="okButton">'+uploadOK()+'</a>');
 $okButton.click(function(){
        var data = new FormData();
        var file = $input[0].files[0];
       if (file === undefined || null === file) {
          // alert("error message);
       } else {
         data.append('file',  file);
        $.ajax({
            url: 'uploadFile',
            data: data,
            dataType : 'json',
            processData: false,
            contentType: false,
            type: 'POST',
            success: function ( data ) {
                  callback(data.dataObject.url);
            },
            error : function(data){
                  // error
            }
        });    
      }
    }); )

这篇关于如何实现图片上传到下一页末降价编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆