diff --git a/common/js/plugins/ckeditor/ckeditor/plugins/rx_upload/plugin.js b/common/js/plugins/ckeditor/ckeditor/plugins/rx_upload/plugin.js new file mode 100644 index 000000000..7af7b291d --- /dev/null +++ b/common/js/plugins/ckeditor/ckeditor/plugins/rx_upload/plugin.js @@ -0,0 +1,105 @@ +'use strict'; + +/** + * Upload plugin for Rhymix + */ +CKEDITOR.plugins.add('rx_upload', { + + init: function(editor) { + + /** + * Prevent the clipboard plugin from interfering with us. + */ + editor.plugins.clipboard._supportedFileMatchers.unshift(function() { return true; }); + if (editor.config.clipboard_handleImages) { + editor.config.clipboard_handleImages = false; + } + + /** + * The main event handler for paste and drop. + */ + editor.on('paste', function(event) { + + // Check if the pasted data contains any files. + const method = event.data.method; + const dataTransfer = event.data.dataTransfer; + const files_count = dataTransfer.getFilesCount(); + if (!files_count) { + return; + } + + // Prevent the default plugin from touching these files. + event.stop(); + + // Read and upload each file. + for (let i = 0; i < files_count; i++) { + uploadFile(dataTransfer.getFile(i)); + } + }); + + /** + * Upload function. + */ + const uploadFile = function(file) { + + // Get the editor sequence. + const editor_container = $(editor.container.$).closest('.rx_ckeditor'); + const upload_container = editor_container.nextAll('.xefu-container').first(); + const editor_sequence = editor_container.data('editorSequence'); + + // Generate the form data. + const form = new FormData(); + form.append('mid', window.editor_mid ? window.editor_mid : window.current_mid); + form.append('act', 'procFileUpload'); + form.append('editor_sequence', editor_sequence); + form.append('Filedata', file); + + // Upload! + $.ajax({ + url: window.request_uri, + type: 'POST', + contentType: false, + processData: false, + cache: false, + data: form, + dataType: 'json', + success: function(data) { + if (data.error == 0) { + insertFile(upload_container, data); + reloadFileList(upload_container, data); + } else { + displayError(8, data.message); + } + }, + error: function(jqXHR) { + displayError(9, jqXHR.responseText); + } + }); + }; + + /** + * Insert file into editor. + */ + const insertFile = function(container, data) { + const html = container.data('instance').generateHtml(container, data); + editor.insertHtml(html, 'unfiltered_html'); + }; + + /** + * Reload the file list. + */ + const reloadFileList = function(container, data) { + container.data('editorStatus', data); + container.data('instance').loadFilelist(container, true); + }; + + /** + * Display an error message. + */ + const displayError = function(type, message) { + alert(window.xe.msg_file_upload_error + ' (Type ' + type + ")\n" + message); + }; + + } + +}); diff --git a/common/js/plugins/jquery.fileupload/js/main.js b/common/js/plugins/jquery.fileupload/js/main.js index d504d0284..579f93b93 100644 --- a/common/js/plugins/jquery.fileupload/js/main.js +++ b/common/js/plugins/jquery.fileupload/js/main.js @@ -174,36 +174,24 @@ } if(result.error == 0) { - if(/\.(gif|jpe?g|png|webp)$/i.test(result.source_filename) && opt.autoinsertTypes.image) { - temp_code += '' + result.source_filename + ''; + var filename = String(result.source_filename); + if (filename.match(/\.(gif|jpe?g|png|webp)$/i) && opt.autoinsertTypes.image) { + temp_code = self.generateHtml($container, result); } - else if(/\.(mp3|wav|ogg|flac|aac)$/i.test(result.source_filename) && opt.autoinsertTypes.audio) { - temp_code += '