Skip to content

Commit

Permalink
ImageUpload plugin update
Browse files Browse the repository at this point in the history
  • Loading branch information
chuck911 committed Sep 6, 2013
1 parent 5b823f1 commit 9bb8145
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions plugins/ImageUpload/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 15 additions & 9 deletions plugins/ImageUpload/js/imageupload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<img src="'+url+'"/>\r\n';
imageCode = '<img src="'+url+'" alt="'+filename+'" title="'+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){
Expand Down

0 comments on commit 9bb8145

Please sign in to comment.