From 9bb8145730fa350ee7048cab1bc1328b3e313f73 Mon Sep 17 00:00:00 2001 From: chuck911 Date: Fri, 6 Sep 2013 11:25:56 +0800 Subject: [PATCH] ImageUpload plugin update --- plugins/ImageUpload/default.php | 6 +++--- plugins/ImageUpload/js/imageupload.js | 24 +++++++++++++++--------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/plugins/ImageUpload/default.php b/plugins/ImageUpload/default.php index 46fb1e858b4..10d14190f21 100644 --- a/plugins/ImageUpload/default.php +++ b/plugins/ImageUpload/default.php @@ -2,8 +2,8 @@ $PluginInfo['ImageUpload'] = array( 'Name' => 'ImageUpload', - 'Description' => 'Easy image uploader', - 'Version' => '1.0', + 'Description' => 'lightweight and simple image uploader', + 'Version' => '1.1', 'RequiredApplications' => array('Vanilla' => '2.0.18.4'), 'RequiredTheme' => FALSE, 'RequiredPlugins' => FALSE, @@ -48,7 +48,7 @@ public function PostController_Imageupload_create() $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS.'/imageupload', '', TRUE); $Props = $UploadImage->SaveImageAs($TmpImage,$TargetImage,C('Plugins.UploadImage.MaxHeight',''),C('Plugins.UploadImage.MaxWidth',650)); - echo $Props['Url']; + echo json_encode(array('url'=>$Props['Url'],'name'=>$UploadImage->GetUploadedFileName())); } catch (Exception $e) { header('HTTP/1.0 400', TRUE, 400); echo $e; diff --git a/plugins/ImageUpload/js/imageupload.js b/plugins/ImageUpload/js/imageupload.js index 454d15341c3..53af5c5907b 100644 --- a/plugins/ImageUpload/js/imageupload.js +++ b/plugins/ImageUpload/js/imageupload.js @@ -25,30 +25,36 @@ $(function(){ }); uploader.bind('FileUploaded',function(uploader,file,response){ - var url = response.response; + var data = $.parseJSON(response.response); + var url = data.url; + var filename = data.name.substr(0, data.name.lastIndexOf('.')); $('#Form_Body').focus(); var inputFormat = getInputFormat(); var imageCode; switch(inputFormat) { case 'Html': - imageCode = '\r\n'; + imageCode = ''+filename+'\r\n'; break; case 'BBCode': - imageCode = '[img]'+url+'[/img]\r\n'; + imageCode = '[img alt="'+filename+'" title="'+filename+'"]'+url+'[/img]\r\n'; break; case 'Markdown': - imageCode = '![]('+url+')\r\n'; + imageCode = '!['+filename+']('+url+' "'+filename+'")\r\n'; break; default: imageCode = url+'\r\n'; break; } - $('#Form_Body').val($('#Form_Body').val() + imageCode); var editor = $('#Form_Body').get(0).editor; - if (editor) { - // Update the frame to match the contents of textarea - editor.updateFrame(); - } + if (editor) { + // Update the frame to match the contents of textarea + editor.updateFrame(); + }else if($('#Form_Body').data('wysihtml5')) { //check Wysihtml5 + var wysihtml5 = $('#Form_Body').data('wysihtml5').editor; + wysihtml5.setValue(wysihtml5.getValue() + imageCode); + }else { + $('#Form_Body').val($('#Form_Body').val() + imageCode); + } }); uploader.bind('UploadComplete',function(uploader,files){