diff --git a/Controller.js b/Controller.js index 447e98d..60b03bc 100644 --- a/Controller.js +++ b/Controller.js @@ -1,16 +1,17 @@ -(function (jsOMS) -{ - "use strict"; +import { Autoloader } from '../../jsOMS/Autoloader.js'; +import { Application } from '../../Web/Backend/js/backend.js'; +import { Editor } from './Models/Editor.js'; - jsOMS.Autoloader.defineNamespace('jsOMS.Modules'); +Autoloader.defineNamespace('jsOMS.Modules'); - jsOMS.Modules.Editor = function(app) +jsOMS.Modules.Editor = class { + constructor(app) { this.app = app; this.editors = {}; }; - jsOMS.Modules.Editor.prototype.bind = function(id) + bind (id) { const e = typeof id === 'undefined' ? document.getElementsByClassName('m-editor') : [id], length = e.length; @@ -20,7 +21,7 @@ } }; - jsOMS.Modules.Editor.prototype.bindElement = function(id) + bindElement (id) { if(typeof id === 'undefined' || !id) { // todo: do logging @@ -28,14 +29,9 @@ return; } - this.editors[id] = new jsOMS.Modules.Models.Editor.Editor(id); + this.editors[id] = new Editor(id); this.editors[id].bind(); }; -}(window.jsOMS = window.jsOMS || {})); +}; -jsOMS.ready(function () -{ - "use strict"; - - window.omsApp.moduleManager.get('Editor').bind(); -}); +window.omsApp.moduleManager.get('Editor').bind(); \ No newline at end of file diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e0d417b..bde6cc4 100644 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -48,8 +48,7 @@ final class BackendController extends Controller public function setUpEditorEditor(RequestAbstract $request, ResponseAbstract $response, $data = null) : void { $head = $response->get('Content')->getData('head'); - $head->addAsset(AssetType::JSLATE, 'Modules/Editor/Models/Editor.js'); - $head->addAsset(AssetType::JSLATE, 'Modules/Editor/Controller.js'); + $head->addAsset(AssetType::JSLATE, 'Modules/Editor/Controller.js', ['type' => 'module']); } /** diff --git a/Models/Editor.js b/Models/Editor.js index 19bc78e..75c5ba0 100644 --- a/Models/Editor.js +++ b/Models/Editor.js @@ -1,16 +1,11 @@ -(function (jsOMS) -{ - "use strict"; - - jsOMS.Autoloader.defineNamespace('jsOMS.Modules.Models.Editor'); - - jsOMS.Modules.Models.Editor.Editor = function (id) +export class Editor { + constructor (id) { this.id = id; this.editor = document.getElementById(id); }; - jsOMS.Modules.Models.Editor.Editor.prototype.bind = function() + bind () { const editorButtons = document.querySelectorAll('#' + this.id + '-tools .editor-button'), editorTitle = this.editor.getElementsByClassName('editor-title')[0], @@ -27,7 +22,7 @@ } }; - jsOMS.Modules.Models.Editor.Editor.prototype.toolsButton = function (e, event) + toolsButton (e, event) { let textarea = this.editor.getElementsByTagName('textarea')[0]; @@ -111,7 +106,7 @@ textarea.setSelectionRange(cursorPosition, cursorPosition); }; - jsOMS.Modules.Models.Editor.Editor.prototype.getSelectedText = function() + getSelectedText () { let text = ''; const activeEl = document.activeElement; @@ -128,4 +123,4 @@ return text; }; -}(window.jsOMS = window.jsOMS || {})); \ No newline at end of file +}; \ No newline at end of file diff --git a/Theme/Backend/Components/Editor/BaseView.php b/Theme/Backend/Components/Editor/BaseView.php index 270cd9d..c2a1f1a 100644 --- a/Theme/Backend/Components/Editor/BaseView.php +++ b/Theme/Backend/Components/Editor/BaseView.php @@ -41,8 +41,7 @@ class BaseView extends View parent::__construct($app, $request, $response); $this->setTemplate('/Modules/Editor/Theme/Backend/Components/Editor/inline-editor-tools'); - $response->get('Content')->getData('head')->addAsset(AssetType::JSLATE, 'Modules/Editor/Models/Editor.js'); - $response->get('Content')->getData('head')->addAsset(AssetType::JSLATE, 'Modules/Editor/Controller.js'); + $response->get('Content')->getData('head')->addAsset(AssetType::JSLATE, 'Modules/Editor/Controller.js', ['type' => 'module']); $view = new TextView($app, $request, $response); $this->addData('text', $view);