Added three more triggers that enable an animation to be shown when a file is uploaded.

This commit is contained in:
Didi Hoffmann 2017-03-08 12:11:14 +01:00
parent 401e5f5167
commit 29845b9425
2 changed files with 23 additions and 2 deletions

View file

@ -302,10 +302,13 @@ class ImageUploadView(FormView):
# JS events
Each markdownx jQuery object triggers two basic events:
Each markdownx jQuery object triggers these basic events:
* 'markdownx.init'
* 'markdownx.update' also returns 'response' variable containing markdownified text
* 'markdownx.update' also returns 'response' variable containing markdownified text.
* 'markdownx.begin_file_upload' - is triggered when the file is posted.
* 'markdownx.end_file_upload' - is triggered when the file has been uploaded. Will contain 'response' variable.
* 'markdownx.error_file_upload' - is triggered if the upload didn't work.
```js
$('.markdownx').on('markdownx.init', function() {
@ -315,6 +318,19 @@ $('.markdownx').on('markdownx.init', function() {
$('.markdownx').on('markdownx.update', function(e, response) {
console.log("UPDATE" + response);
});
$('.markdownx').on('markdownx.begin_file_upload', function(e) {
console.log("Start some animation");
});
$('.markdownx').on('markdownx.end_file_upload', function(e) {
console.log("End animation");
});
$('.markdownx').on('markdownx.error_file_upload', function(e) {
console.log("End animation and open error modal or something");
});
```

View file

@ -81,6 +81,7 @@
beforeSend: function() {
console.log("uploading...");
markdownxEditor.fadeTo("fast", 0.3);
markdownx.trigger('markdownx.begin_file_upload');
},
success: function(response) {
@ -88,18 +89,22 @@
if (response.image_code) {
insertImage(response.image_code);
console.log("success", response);
markdownx.trigger('markdownx.end_file_upload', [response]);
} else if (response.image_path) {
// For backwards-compatibility
insertImage("![](" + image_path + ")");
console.log("success", response);
markdownx.trigger('markdownx.end_file_upload', [response]);
} else {
console.log('error: wrong response', response);
markdownx.trigger('markdownx.error_file_upload', [response]);
}
},
error: function(response) {
console.log("error", response);
markdownxEditor.fadeTo("fast", 1);
markdownx.trigger('markdownx.error_file_upload', [response]);
}
});
};