[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 (function () { 2 'use strict'; 3 4 /* eslint-disable no-undef */ 5 tinymce.PluginManager.add('jdragndrop', function (editor) { 6 var responseData; // Reset the drop area border 7 8 tinyMCE.DOM.bind(document, 'dragleave', function (e) { 9 e.stopPropagation(); 10 e.preventDefault(); 11 editor.contentAreaContainer.style.borderWidth = '1px 0 0'; 12 return false; 13 }); // Fix for Chrome 14 15 editor.on('dragenter', function (e) { 16 e.stopPropagation(); 17 return false; 18 }); // Notify user when file is over the drop area 19 20 editor.on('dragover', function (e) { 21 e.preventDefault(); 22 editor.contentAreaContainer.style.borderStyle = 'dashed'; 23 editor.contentAreaContainer.style.borderWidth = '5px'; 24 return false; 25 }); 26 27 function uploadFile(name, content) { 28 var _data; 29 30 var url = editor.settings.uploadUri + "&path=" + editor.settings.comMediaAdapter; 31 var data = (_data = {}, _data[editor.settings.csrfToken] = '1', _data.name = name, _data.content = content, _data.parent = editor.settings.parentUploadFolder, _data); 32 Joomla.request({ 33 url: url, 34 method: 'POST', 35 data: JSON.stringify(data), 36 headers: { 37 'Content-Type': 'application/json' 38 }, 39 onSuccess: function onSuccess(resp) { 40 var response; 41 42 try { 43 response = JSON.parse(resp); 44 } catch (e) { 45 editor.windowManager.alert(Joomla.Text._('ERROR') + ": {e}"); 46 } 47 48 if (response.data && response.data.path) { 49 responseData = response.data; 50 var urlPath; // For local adapters use relative paths 51 52 var _Joomla$getOptions = Joomla.getOptions('system.paths'), 53 rootFull = _Joomla$getOptions.rootFull; 54 var parts = response.data.url.split(rootFull); 55 if (parts.length > 1) { 56 urlPath = "" + parts[1]; 57 } else if (responseData.url) { 58 // Absolute path for different domain 59 urlPath = responseData.url; 60 } 61 62 var dialogClose = function dialogClose(api) { 63 var dialogData = api.getData(); 64 var altEmpty = dialogData.altEmpty ? ' alt=""' : ''; 65 var altValue = dialogData.altText ? " alt=\"" + dialogData.altText + "\"" : altEmpty; 66 var lazyValue = dialogData.isLazy ? ' loading="lazy"' : ''; 67 var width = dialogData.isLazy ? " width=\"" + responseData.width + "\"" : ''; 68 var height = dialogData.isLazy ? " height=\"" + responseData.height + "\"" : ''; 69 editor.execCommand('mceInsertContent', false, "<img src=\"" + urlPath + "\"" + altValue + lazyValue + width + height + "/>"); 70 }; 71 72 editor.windowManager.open({ 73 title: Joomla.Text._('PLG_TINY_DND_ADDITIONALDATA'), 74 body: { 75 type: 'panel', 76 items: [{ 77 type: 'input', 78 name: 'altText', 79 label: Joomla.Text._('PLG_TINY_DND_ALTTEXT') 80 }, { 81 type: 'checkbox', 82 name: 'altEmpty', 83 label: Joomla.Text._('PLG_TINY_DND_EMPTY_ALT') 84 }, { 85 type: 'checkbox', 86 name: 'isLazy', 87 label: Joomla.Text._('PLG_TINY_DND_LAZYLOADED') 88 }] 89 }, 90 buttons: [{ 91 type: 'cancel', 92 text: 'Cancel' 93 }, { 94 type: 'submit', 95 name: 'submitButton', 96 text: 'Save', 97 primary: true 98 }], 99 initialData: { 100 altText: '', 101 isLazy: true, 102 altEmpty: false 103 }, 104 onSubmit: function onSubmit(api) { 105 dialogClose(api); 106 api.close(); 107 }, 108 onCancel: function onCancel(api) { 109 dialogClose(api); 110 } 111 }); 112 } 113 }, 114 onError: function onError(xhr) { 115 editor.windowManager.alert("Error: " + xhr.statusText); 116 } 117 }); 118 } 119 120 function readFile(file) { 121 // Create a new file reader instance 122 var reader = new FileReader(); // Add the on load callback 123 124 reader.onload = function (progressEvent) { 125 var result = progressEvent.target.result; 126 var splitIndex = result.indexOf('base64') + 7; 127 var content = result.slice(splitIndex, result.length); // Upload the file 128 129 uploadFile(file.name, content); 130 }; 131 132 reader.readAsDataURL(file); 133 } // Listeners for drag and drop 134 135 136 if (typeof FormData !== 'undefined') { 137 // Logic for the dropped file 138 editor.on('drop', function (e) { 139 e.preventDefault(); // We override only for files 140 141 if (e.dataTransfer && e.dataTransfer.files && e.dataTransfer.files.length > 0) { 142 var files = [].slice.call(e.dataTransfer.files); 143 files.forEach(function (file) { 144 // Only images allowed 145 if (file.name.toLowerCase().match(/\.(jpg|jpeg|png|gif)$/)) { 146 // Upload the file(s) 147 readFile(file); 148 } 149 }); 150 } 151 152 editor.contentAreaContainer.style.borderWidth = '1px 0 0'; 153 }); 154 } else { 155 Joomla.renderMessages({ 156 error: [Joomla.Text._('PLG_TINY_ERR_UNSUPPORTEDBROWSER')] 157 }); 158 editor.on('drop', function (e) { 159 e.preventDefault(); 160 return false; 161 }); 162 } 163 }); 164 165 }());
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |