mirror of
https://github.com/Karaka-Management/oms-Editor.git
synced 2026-01-11 17:18:42 +00:00
Use js modules
This commit is contained in:
parent
5a77399798
commit
4d65fec042
|
|
@ -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();
|
||||
|
|
@ -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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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 || {}));
|
||||
};
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user