From 9dff2861eea60a501d14d500a3c6d7cca38f64cd Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Fri, 14 Apr 2023 13:06:55 +0200 Subject: [PATCH] fix: quiqqer/quiqqer#1223 --- bin/Editor.js | 281 +++++++++++++++++++++++++++++++------------------- 1 file changed, 175 insertions(+), 106 deletions(-) diff --git a/bin/Editor.js b/bin/Editor.js index c5c48e2..bf6548a 100644 --- a/bin/Editor.js +++ b/bin/Editor.js @@ -22,14 +22,14 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ 'Ajax', 'qui/utils/Math', 'qui/utils/Elements', + 'qui/utils/String', 'package/quiqqer/ckeditor4/bin/Settings', 'css!package/quiqqer/ckeditor4/bin/Editor.css' -], function (require, QUI, Editor, Locale, Ajax, QUIMath, QUIElements, Settings) { +], function (require, QUI, Editor, Locale, Ajax, QUIMath, QUIElements, QUIStringUtils, Settings) { "use strict"; - return new Class({ Extends: Editor, @@ -74,7 +74,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @param {Object} data - Editor data */ $onLoad: function (data) { - var self = this; + const self = this; if ("CKEDITOR" in window) { self.$loadInstance(data); @@ -85,7 +85,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ require([URL_OPT_DIR + 'ckeditor/ckeditor/ckeditor.js'], function () { // set global events window.CKEDITOR.on('instanceReady', function (ev) { - var Editor = QUI.Controls.getById(ev.editor.name); + const Editor = QUI.Controls.getById(ev.editor.name); if (Editor && "$onInstanceReadyListener" in Editor) { Editor.$onInstanceReadyListener(ev); @@ -94,7 +94,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ // http://docs.ckeditor.com/#!/guide/dev_howtos_dialog_windows window.CKEDITOR.on('dialogDefinition', function (ev) { - var Editor = QUI.Controls.getById(ev.editor.name); + const Editor = QUI.Controls.getById(ev.editor.name); Editor.$imageDialog(ev); Editor.$image2Dialog(ev); @@ -113,15 +113,15 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @param {Object} data - Editor settings data */ $loadInstance: function (data) { - if (typeof window.CKEDITOR === 'undefined') { return; } - var self = this, - Container = this.getContainer(), - Textarea = false, - size = Container.getSize(); + const self = this, + Container = this.getContainer(); + + let Textarea = false, + size = Container.getSize(); if (!Container.getElement('textarea')) { Textarea = new Element('textarea', { @@ -137,7 +137,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ Textarea = Container.getElement('textarea'); } - var instance = Textarea.get('id'); + const instance = Textarea.get('id'); if (window.CKEDITOR.instances[instance]) { window.CKEDITOR.instances[instance].destroy(true); @@ -147,20 +147,20 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ // parse the buttons for the ckeditor - var b, g, i, len, blen, glen, group, items, + let b, g, i, len, blen, glen, group, items, buttonEntry, lineEntry, groupEntry; - var buttons = data.toolbar, - lines = buttons.lines || [], - toolbar = []; + const buttons = data.toolbar, + lines = buttons.lines || [], + toolbar = []; for (i = 0, len = lines.length; i < len; i++) { - items = []; + items = []; lineEntry = lines[i]; // groups for (g = 0, glen = lineEntry.length; g < glen; g++) { - group = []; + group = []; groupEntry = lineEntry[g]; // buttons @@ -181,7 +181,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ toolbar.push('/'); } - var height = size.y, + let height = size.y, width = size.x; if (self.getAttribute('width')) { @@ -192,10 +192,10 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ height = self.getAttribute('height'); } - var zIndex = QUIElements.getComputedZIndex(Container); + const zIndex = QUIElements.getComputedZIndex(Container); // parse styles to fckedit styles - var entry, styles = []; + let entry, styles = []; if (!("styles" in data)) { data.styles = []; @@ -225,15 +225,15 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ Settings.getConfig().then(function (config) { - var plugins = config.plugins; + let plugins = config.plugins; plugins = self.$parseToolbarToPlugins(toolbar).concat(plugins); plugins = plugins.unique(); - var pluginPath = config.pluginPath; - var extraPlugins = plugins.join(","); + const pluginPath = config.pluginPath; + const extraPlugins = plugins.join(","); - var i, len, pluginName; + let i, len, pluginName; for (i = 0, len = plugins.length; i < len; i++) { pluginName = plugins[i]; @@ -273,7 +273,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ // because of font awesome window.CKEDITOR.dtd.$removeEmpty.span = false; - window.CKEDITOR.dtd.$removeEmpty.i = false; + window.CKEDITOR.dtd.$removeEmpty.i = false; }); }, @@ -284,7 +284,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @param {Object} Editor - controls/editors/Editor */ $onDestroy: function (Editor) { - var Instance = Editor.getInstance(); + const Instance = Editor.getInstance(); if (!Instance || !(name in Instance)) { return; @@ -319,14 +319,17 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ } // resize the editor - var Container = this.getContainer(), - containerSize = Container.getSize(); + const Container = this.getContainer(), + containerSize = Container.getSize(); // fckeditor resize, setHeight is sooooooooooo mysterious instance.editor.resize(containerSize.x, containerSize.y); this.setInstance(instance.editor); - this.fireEvent('loaded', [this, instance.editor]); + this.fireEvent('loaded', [ + this, + instance.editor + ]); instance.editor.focus(); }, @@ -335,9 +338,9 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * event : on resize */ $onResize: function () { - var Container = this.getContainer(), - Instance = this.getInstance(), - containerSize = Container.getSize(); + const Container = this.getContainer(), + Instance = this.getInstance(), + containerSize = Container.getSize(); Instance.resize(containerSize.x, containerSize.y); }, @@ -396,7 +399,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * Hide the toolbar */ hideToolbar: function () { - var Toolbar = this.getElm().getElement('.cke_top'); + const Toolbar = this.getElm().getElement('.cke_top'); if (Toolbar) { Toolbar.setStyle('display', 'none'); @@ -407,7 +410,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * show the toolbar */ showToolbar: function () { - var Toolbar = this.getElm().getElement('.cke_top'); + const Toolbar = this.getElm().getElement('.cke_top'); if (Toolbar) { Toolbar.setStyle('display', null); @@ -447,16 +450,16 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @param {Object} Editor - controls/editor/Editor */ $onAddCSS: function (file, Editor) { - var Instance = this.getInstance(); + const Instance = this.getInstance(); this.$cssFiles[file] = true; if (Instance) { - var Doc = Editor.getDocument(), - Link = Doc.createElement('link'); + const Doc = Editor.getDocument(), + Link = Doc.createElement('link'); Link.href = file; - Link.rel = "stylesheet"; + Link.rel = "stylesheet"; Link.type = "text/css"; Doc.head.appendChild(Link); @@ -468,9 +471,9 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @param {Object} params */ $onDrop: function (params) { - var Instance = this.getInstance(); + const Instance = this.getInstance(); - for (var i = 0, len = params.length; i < len; i++) { + for (let i = 0, len = params.length; i < len; i++) { Instance.insertHtml("<img src=" + params[i].url + " />"); } }, @@ -482,14 +485,14 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @return Array */ $parseToolbarToPlugins: function (toolbar) { - var extra = [], + let extra = [], buttonList = []; if (typeOf(toolbar) === 'array') { buttonList = toolbar.flatten(); } - for (var i = 0, len = buttonList.length; i < len; i++) { + for (let i = 0, len = buttonList.length; i < len; i++) { switch (buttonList[i]) { case 'Templates': extra.push('templates'); @@ -656,9 +659,9 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ $imageDialog: function (ev) { // Take the dialog name and its definition from the event data. - var self = this, - dialogName = ev.data.name, - dialogDefinition = ev.data.definition; + const self = this, + dialogName = ev.data.name, + dialogDefinition = ev.data.definition; /** * Image dialog @@ -668,27 +671,29 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ } - var oldOnShow = dialogDefinition.onShow; + const oldOnShow = dialogDefinition.onShow; // Get a reference to the "Link Info" tab. dialogDefinition.onShow = function () { - var Button; + let Button; oldOnShow.bind(this)(); // image button - var UrlGroup = this.getContentElement('info', 'txtUrl') - .getElement().$; + const UrlGroup = this.getContentElement('info', 'txtUrl') + .getElement().$; - var UrlInput = UrlGroup.getElement('input[type="text"]'); + const UrlInput = UrlGroup.getElement('input[type="text"]'); - var HeightInput = this.getContentElement('info', 'txtHeight') + /* + let HeightInput = this.getContentElement('info', 'txtHeight') .getElement().$ .getElement('input[type="text"]'); + */ - var WidthInput = this.getContentElement('info', 'txtWidth') - .getElement().$ - .getElement('input[type="text"]'); + const WidthInput = this.getContentElement('info', 'txtWidth') + .getElement().$ + .getElement('input[type="text"]'); UrlGroup.getElement('label').setStyles({ @@ -702,7 +707,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ html : '<span class="fa fa-picture-o"></span>', events : { click: function () { + let fileId = false; + + if (UrlInput.value !== '') { + let urlParams = QUIStringUtils.getUrlParams(UrlInput.value); + + if (typeof urlParams.project !== 'undefined' && + typeof urlParams.id !== 'undefined' && + urlParams.project === self.$Project.getName()) { + + fileId = urlParams.id; + } + } + self.openMedia({ + fileid: fileId, events: { onSubmit: function (Win, data) { UrlInput.value = data.url; @@ -710,7 +729,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ Ajax.get('ajax_media_details', function (fileData) { if (fileData.image_height > 500 || fileData.image_width > 500) { - var result = QUIMath.resizeVar( + const result = QUIMath.resizeVar( fileData.image_height, fileData.image_width, 500 @@ -749,16 +768,13 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ // link button - var LinkGroup = this.getContentElement('Link', 'txtUrl') - .getElement() - .$; - + const LinkGroup = this.getContentElement('Link', 'txtUrl').getElement().$; if (LinkGroup.getElement('.qui-button')) { return; } - var LinkInput = LinkGroup.getElement('input[type="text"]'); + const LinkInput = LinkGroup.getElement('input[type="text"]'); Button = new Element('button', { 'class': 'qui-button', @@ -777,7 +793,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ }).inject(LinkGroup); - var Prev = Button.getPrevious(); + const Prev = Button.getPrevious(); Prev.setStyles({ 'float': 'left', @@ -790,9 +806,9 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ $image2Dialog: function (ev) { // Take the dialog name and its definition from the event data. - var self = this, - dialogName = ev.data.name, - dialogDefinition = ev.data.definition; + const self = this, + dialogName = ev.data.name, + dialogDefinition = ev.data.definition; /** * Image dialog @@ -801,30 +817,28 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ return ev; } - var oldOnShow = dialogDefinition.onShow; + const oldOnShow = dialogDefinition.onShow; // Get a reference to the "Link Info" tab. dialogDefinition.onShow = function () { - var Button; - oldOnShow.bind(this)(); - console.log(this); + // image button - var UrlGroup = this.getContentElement('info', 'src') - .getElement().$; + const UrlGroup = this.getContentElement('info', 'src') + .getElement().$; - var HeightInput = this.getContentElement('info', 'height') + /* + let HeightInput = this.getContentElement('info', 'height') .getElement().$ .getElement('input[type="text"]'); + */ - var WidthInput = this.getContentElement('info', 'width') - .getElement().$ - .getElement('input[type="text"]'); + const WidthInput = this.getContentElement('info', 'width') + .getElement().$ + .getElement('input[type="text"]'); - console.log('#############'); - console.log(UrlGroup); - var UrlInput = UrlGroup.getElement('input[type="text"]'); + const UrlInput = UrlGroup.getElement('input[type="text"]'); if (!UrlGroup.getElement('.qui-button')) { new Element('button', { @@ -835,7 +849,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ }, events : { click: function () { + let fileId = false; + + if (UrlInput.value !== '') { + let urlParams = QUIStringUtils.getUrlParams(UrlInput.value); + + if (typeof urlParams.project !== 'undefined' && + typeof urlParams.id !== 'undefined' && + urlParams.project === self.$Project.getName()) { + + fileId = urlParams.id; + } + } + self.openMedia({ + fileid: fileId, events: { onSubmit: function (Win, data) { UrlInput.value = data.url; @@ -843,7 +871,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ Ajax.get('ajax_media_details', function (fileData) { if (fileData.image_height > 500 || fileData.image_width > 500) { - var result = QUIMath.resizeVar( + const result = QUIMath.resizeVar( fileData.image_height, fileData.image_width, 500 @@ -892,7 +920,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ */ $linkDialog: function (ev) { // Take the dialog name and its definition from the event data. - var dialogName = ev.data.name; + const dialogName = ev.data.name; /** * Link dialog @@ -905,11 +933,11 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ //dialogDefinition.getContents( 'info' ).remove( 'protocol'); // remove protokoll at insertion - var Protokoll; + let Protokoll; - var dialogDefinition = ev.data.definition, - Url = dialogDefinition.getContents('info').get('url'), - orgCommit = Url.commit; + const dialogDefinition = ev.data.definition, + Url = dialogDefinition.getContents('info').get('url'), + orgCommit = Url.commit; Url.commit = function (data) { orgCommit.call(this, data); @@ -926,8 +954,8 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ }; }; - var self = this, - oldOnShow = dialogDefinition.onShow; + const self = this, + oldOnShow = dialogDefinition.onShow; self.$turnLinkRelInputToSelect(dialogDefinition); @@ -936,15 +964,15 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ dialogDefinition.onShow = function () { oldOnShow.bind(this)(); - var UrlGroup = this.getContentElement('info', 'url') - .getElement() + const UrlGroup = this.getContentElement('info', 'url') + .getElement() .$; if (UrlGroup.getElement('.qui-button')) { return; } - var UrlInput = UrlGroup.getElement('input[type="text"]'); + const UrlInput = UrlGroup.getElement('input[type="text"]'); Protokoll = this.getContentElement('info', 'protocol') .getElement() @@ -956,7 +984,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ width : UrlInput.getSize().x - 100 }); - var Links = new Element('button', { + const Links = new Element('button', { 'class': 'qui-button', html : '<span class="fa fa-home"></span>', events : { @@ -964,7 +992,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ self.openProject({ events: { onSubmit: function (Win, data) { - UrlInput.value = data.urls[0]; + UrlInput.value = data.urls[0]; Protokoll.value = ''; } } @@ -979,10 +1007,24 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ html : '<span class="fa fa-picture-o"></span>', events : { click: function () { + let fileId = false; + + if (UrlInput.value !== '') { + let urlParams = QUIStringUtils.getUrlParams(UrlInput.value); + + if (typeof urlParams.project !== 'undefined' && + typeof urlParams.id !== 'undefined' && + urlParams.project === self.$Project.getName()) { + + fileId = urlParams.id; + } + } + self.openMedia({ + fileid: fileId, events: { onSubmit: function (Win, data) { - UrlInput.value = data.url; + UrlInput.value = data.url; Protokoll.value = ''; } } @@ -1002,8 +1044,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @return {DOMEvent} ev - CKEvent */ $html5AudioDialog: function (ev) { - - var dialogname = ev.data.name, + let dialogname = ev.data.name, dialogDefinition = ev.data.definition, Button = null; @@ -1011,21 +1052,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ return ev; } - var self = this; + const self = this; - var oldOnShow = dialogDefinition.onShow || function () { + const oldOnShow = dialogDefinition.onShow || function () { }; dialogDefinition.onShow = function () { oldOnShow.bind(this)(); - var UrlGroup = this.getContentElement("info", "url").getElement().$; + const UrlGroup = this.getContentElement("info", "url").getElement().$; if (UrlGroup.getElement('.qui-button')) { return; } - var UrlInput = UrlGroup.getElement('input[type="text"]'); + const UrlInput = UrlGroup.getElement('input[type="text"]'); Button = new Element('button', { @@ -1033,7 +1074,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ html : '<span class="fa fa-picture-o"></span>', events : { click: function () { + let fileId = false; + + if (UrlInput.value !== '') { + let urlParams = QUIStringUtils.getUrlParams(UrlInput.value); + + if (typeof urlParams.project !== 'undefined' && + typeof urlParams.id !== 'undefined' && + urlParams.project === self.$Project.getName()) { + + fileId = urlParams.id; + } + } + self.openMedia({ + fileid: fileId, events: { onSubmit: function (Win, data) { UrlInput.value = data.url; @@ -1048,7 +1103,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ }).inject(UrlGroup); - var Label = UrlGroup.getElement("label"); + const Label = UrlGroup.getElement("label"); Label.setStyles({ width : "100%", @@ -1066,7 +1121,7 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ $html5VideoDialog: function (ev) { - var dialogname = ev.data.name, + let dialogname = ev.data.name, dialogDefinition = ev.data.definition, Button = null; @@ -1075,21 +1130,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ return ev; } - var self = this; + const self = this; - var oldOnShow = dialogDefinition.onShow || function () { + const oldOnShow = dialogDefinition.onShow || function () { }; dialogDefinition.onShow = function () { oldOnShow.bind(this)(); - var UrlGroup = this.getContentElement("info", "url").getElement().$; + const UrlGroup = this.getContentElement("info", "url").getElement().$; if (UrlGroup.getElement('.qui-button')) { return; } - var UrlInput = UrlGroup.getElement('input[type="text"]'); + const UrlInput = UrlGroup.getElement('input[type="text"]'); Button = new Element('button', { @@ -1097,7 +1152,21 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ html : '<span class="fa fa-picture-o"></span>', events : { click: function () { + let fileId = false; + + if (UrlInput.value !== '') { + let urlParams = QUIStringUtils.getUrlParams(UrlInput.value); + + if (typeof urlParams.project !== 'undefined' && + typeof urlParams.id !== 'undefined' && + urlParams.project === self.$Project.getName()) { + + fileId = urlParams.id; + } + } + self.openMedia({ + fileid: fileId, events: { onSubmit: function (Win, data) { UrlInput.value = data.url; @@ -1129,20 +1198,20 @@ define('package/quiqqer/ckeditor4/bin/Editor', [ * @return boolean */ $turnLinkRelInputToSelect: function (DialogDefinition) { - var AdvancedTab = DialogDefinition.getContents("advanced"); + const AdvancedTab = DialogDefinition.getContents("advanced"); if (!AdvancedTab) { return false; } - var RelationInput = AdvancedTab.get('advRel'); + const RelationInput = AdvancedTab.get('advRel'); if (!RelationInput) { return false; } if (RelationInput) { - RelationInput.type = 'select'; + RelationInput.type = 'select'; RelationInput.items = [ ['alternate'], ['author'], -- GitLab