diff --git a/README.md b/README.md index d76ece3..e84d39f 100644 --- a/README.md +++ b/README.md @@ -91,41 +91,24 @@ $('#myEditor').markdownEditor({ }); ``` -## Implementing the image upload +## Implementing the file uploads You have to implement the server side part of the upload process. -To activate the image uploads you have to use the following options: +To activate the file uploads you have to use the following options: ```javascript $('#myEditor').markdownEditor({ - imageUpload: true, // Activate the option + fileUpload: true, // Activate the option uploadPath: 'upload.php' // Path of the server side script that receive the files }); ``` -In your server side script you have to return an array of the **public path** of the successfully uploaded images in json format. - -Example in PHP: - -```php -$uploadedFiles = array(); - -if (! empty($_FILES)) { - foreach ($_FILES as $file) { - if (superAwesomeUploadFunction($file)) { - $uploadedFiles[] = '/img/' . urlencode($file['name']); - } - } -} - -echo json_encode($uploadedFiles); -``` - -Response example: +In your server side script you have to return an array of the successfully uploaded files in following json format. ``` -["/path/to/my-picture.jpg"] +[{"filelink": "/path/to/my-picture.jpg", "filetype":"image", "filename": "My Picture"}] ``` +`filetype` can be ether "image" or file. ## Shortcuts diff --git a/src/bootstrap-markdown-editor.js b/src/bootstrap-markdown-editor.js index 871e924..33e8dbd 100644 --- a/src/bootstrap-markdown-editor.js +++ b/src/bootstrap-markdown-editor.js @@ -71,7 +71,7 @@ // Image drag and drop and upload events - if (defaults.imageUpload) { + if (defaults.fileUpload) { container.find('.md-input-upload').on('change', function() { var files = $(this).get(0).files; @@ -261,7 +261,15 @@ } for (var i = 0; i < uploadedFiles.length; i++) { - snippetManager.insertSnippet(editor, '' + separation); + var tag = '['; + if (uploadedFiles[i]['filename'] != undefined){ + tag = tag + uploadedFiles[i]['filename']; + } + tag = tag + '](' + uploadedFiles[i]['filelink'] + ')' + separation; + if (uploadedFiles[i]['filetype'] != 'file'){ + tag = '!' + tag + } + snippetManager.insertSnippet(editor, tag); } }).always(function () { @@ -365,7 +373,7 @@ html += '