2016年1月5日 星期二

[筆記] Summernote 0.7.1 upload Image Function

 $('#summernote').summernote({  
   height: 200,  
   callbacks: {  
     onImageUpload : function(files, editor, welEditable) {  
        for(var i = files.length - 1; i >= 0; i--) {  
            sendFile(files[i], this);  
       }  
     }  
   }  
 });  

 function sendFile(file, el) {  
 var form_data = new FormData();  
 form_data.append('file', file);  
 $.ajax({  
   data: form_data,  
   type: "POST",  
   url: 'uploader.php'  
   cache: false,  
   contentType: false,  
   processData: false,  
   success: function(url) {  
     $(el).summernote('editor.insertImage', url);  
   }  
 });  
 }  

跟以往不同在於 callbacks 拉出來變成一個屬性了

而網址的替換則需要呼叫外部 API

沒有留言:

搜尋此網誌