Last active
November 23, 2019 22:59
-
-
Save quantumsheep/3b6f97e136344fe88cfc970e2457f7b3 to your computer and use it in GitHub Desktop.
Summernote - OnImageUpload: Place image in editor if size is under 1Mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#summernote').summernote({ | |
callbacks: { | |
onImageUpload: function(image) { | |
if((image[0].size/1024/1024) > 1) { | |
alert("Merci de déposer une image inférieure à 1 Mo, sinon uploadez-là sur un site d'hébergement d'image ou sur PETERPAN et utilisez la fonction image."); | |
return false; | |
} else { | |
var file = image[0]; | |
var reader = new FileReader(); | |
reader.onloadend = function() { | |
var image = $('<img>').attr('src', reader.result); | |
$('#summernote').summernote("insertNode", image[0]); | |
} | |
reader.readAsDataURL(file); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment