Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery('#summernote4').summernote({
- callbacks: {
- onImageUpload: function(files) {
- for(let i=0; i < files.length; i++) {
- sendFile4(files[i]);
- }
- }
- },
- });
- function sendFile4(file) {
- data = new FormData();
- data.append('file', file, file.name);
- jQuery.ajax({
- data: data,
- type: "POST",
- xhr: function() {
- var xhr = new window.XMLHttpRequest();
- xhr.upload.addEventListener("progress", function(evt) {
- if (evt.lengthComputable) {
- var percentComplete = (evt.loaded / evt.total)*100;
- console.log(percentComplete);
- var x = document.getElementById("snackbar");
- x.className = "show";
- jQuery('#snackbar').text(Math.round(percentComplete)+' % complete');
- if(percentComplete==100)
- {
- setTimeout(function(){ x.className = x.className.replace("show", ""); },3000);
- }
- }
- }, false);
- xhr.addEventListener("progress", function(evt) {
- if (evt.lengthComputable) {
- var percentComplete = evt.loaded / evt.total;
- console.log(percentComplete);
- }
- }, false);
- return xhr;
- },
- url: "<?php echo base_url('summer-image');?>",
- cache: false,
- contentType: false,
- processData: false,
- success: function(img) {
- console.log(img);
- jQuery('#summernote4').summernote('insertImage', img);
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.error(textStatus + " " + errorThrown);
- }
- });
- }
Add Comment
Please, Sign In to add comment