Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 6 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 12 additions & 4 deletions src/bootstrap-markdown-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -261,7 +261,15 @@
}

for (var i = 0; i < uploadedFiles.length; i++) {
snippetManager.insertSnippet(editor, '![](' + uploadedFiles[i] + ')' + 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 () {
Expand Down Expand Up @@ -365,7 +373,7 @@
html += '<div class="btn-group">';
html += '<button type="button" data-mdtooltip="tooltip" title="' + options.label.btnLink + '" class="md-btn btn btn-sm btn-default" data-btn="link"><span class="glyphicon glyphicon-link"></span></button>';
html += '<button type="button" data-mdtooltip="tooltip" title="' + options.label.btnImage + '" class="md-btn btn btn-sm btn-default" data-btn="image"><span class="glyphicon glyphicon-picture"></span></button>';
if (options.imageUpload === true) {
if (options.fileUpload === true) {
html += '<div data-mdtooltip="tooltip" title="' + options.label.btnUpload + '" class="btn btn-sm btn-default md-btn-file"><span class="glyphicon glyphicon-upload"></span><input class="md-input-upload" type="file" multiple accept=".jpg,.jpeg,.png,.gif"></div>';
}
html += '</div>'; // .btn-group
Expand Down Expand Up @@ -399,7 +407,7 @@
theme: 'tomorrow',
softTabs: true,
fullscreen: true,
imageUpload: false,
fileUpload: false,
uploadPath: '',
preview: false,
onPreview: function (content, callback) {
Expand Down