Virajsinh

summernote

Jun 26th, 2020
399
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.       jQuery('#summernote4').summernote({
  2.           callbacks: {
  3.             onImageUpload: function(files) {
  4.                 for(let i=0; i < files.length; i++) {
  5.                     sendFile4(files[i]);
  6.                 }
  7.             }
  8.         },
  9.       });
  10.       function sendFile4(file) {
  11.           data = new FormData();
  12.           data.append('file', file, file.name);
  13.           jQuery.ajax({
  14.               data: data,
  15.               type: "POST",
  16.               xhr: function() {
  17.                   var xhr = new window.XMLHttpRequest();
  18.                   xhr.upload.addEventListener("progress", function(evt) {
  19.                       if (evt.lengthComputable) {
  20.                           var percentComplete = (evt.loaded / evt.total)*100;
  21.                           console.log(percentComplete);
  22.                           var x = document.getElementById("snackbar");
  23.                           x.className = "show";
  24.                           jQuery('#snackbar').text(Math.round(percentComplete)+' % complete');
  25.                           if(percentComplete==100)
  26.                           {
  27.                             setTimeout(function(){ x.className = x.className.replace("show", ""); },3000);
  28.                           }
  29.                       }
  30.                  }, false);
  31.  
  32.                  xhr.addEventListener("progress", function(evt) {
  33.                      if (evt.lengthComputable) {
  34.                          var percentComplete = evt.loaded / evt.total;
  35.                          console.log(percentComplete);
  36.                      }
  37.                  }, false);
  38.  
  39.                  return xhr;
  40.               },
  41.               url: "<?php echo base_url('summer-image');?>",
  42.               cache: false,
  43.               contentType: false,
  44.               processData: false,
  45.               success: function(img) {
  46.                 console.log(img);
  47.                 jQuery('#summernote4').summernote('insertImage', img);
  48.               },
  49.               error: function (jqXHR, textStatus, errorThrown) {
  50.                 console.error(textStatus + " " + errorThrown);
  51.               }
  52.           });
  53.       }
Add Comment
Please, Sign In to add comment