upload image from local into tinyMCE

后端 未结 8 830
小鲜肉
小鲜肉 2021-02-04 02:33

tinyMCE has an insert image button, but how to handle its functionality pls give some code

8条回答
  •  野性不改
    2021-02-04 02:57

    It works for image upload.Is this possible for file upload ? I want to add a custom file upload option from local into tinyMCE and want to show it by url .

     Code is something like below which not working:
    
    
       ed.addButton('mybutton2', {
            text:"File",
            icon: false,
    
            onclick: function(e) {
                console.log($(e.target));
                if($(e.target).prop("tagName") == 'BUTTON'){
                    console.log($(e.target).parent().parent().find('input').attr('id'));
                    if($(e.target).parent().parent().find('input').attr('id') != 
    'tinymce-uploader') {
                        $(e.target).parent().parent().append('');
                    }
                    $('#tinymce-uploader').trigger('click');
                    $('#tinymce-uploader').change(function(){
                        var input, file, fr, img;
    
                        if (typeof window.FileReader !== 'function') {
                            write("The file API isn't supported on this browser yet.");
                            return;
                        }
    
                        input = document.getElementById('tinymce-uploader');
                               // var URL = document.my_form.my_field.value;
           alert(input.files[0]);
                        if (!input) {
                            write("Um, couldn't find the imgfile element.");
                        } else if (!input.files) {
                            write("This browser doesn't seem to support the `files` 
                  property of file inputs.");
    
                        } else if (!input.files[0]) {
                            write("Please select a file before clicking 'Load'");
                           alert( input.files[0]);
                        } else {
                            file = input.files[0];
                            fr = new FileReader();
                            fr.onload = createFile;
                            fr.readAsDataURL(file);
                                //  alert(fr.result);
    
                        }
    
                        function createFile() {
                           //what should I write here?
                          ed.insertContent('download 
          file_name');
                        }
                    });
    
                }
    
    
    
    
    
    
    
            }
        });
    

提交回复
热议问题