Skip to content

Commit 14614d2

Browse files
committed
Initial Version 1.0.0
1 parent a2b4bf5 commit 14614d2

File tree

13 files changed

+397
-2
lines changed

13 files changed

+397
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# AceEditor - Changelog
2+
3+
## Version 1.0.0 - 20.05.2023
4+
5+
* Erste Version des AddOns erstellt von @aeberhard
6+
* Version src-min-noconflict v1.21.1 des AceEditors - https://github.com/ajaxorg/ace-builds/releases/tag/v1.21.1
7+
* Der Editor wird nur geladen wenn Textareas entsprechend den Optionen vorhanden sind
8+
* Entwickelt mit rexstan und rexfactor

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) REDAXO, www.redaxo.org
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
1-
# aceeditor
2-
🐣 The high performance code editor for REDAXO
1+
# AceEditor - The high performance code editor for **REDAXO**
2+
3+
Dieses AddOn bindet den Code-Editor **AceEditor** v1.21.1 im Backend ein.
4+
5+
Verwendet wird src-min-noconflict Version v1.21.1 von https://github.com/ajaxorg/ace-builds/
6+
7+
https://github.com/ajaxorg/ace-builds/releases/tag/v1.21.1
8+
9+
Website: https://ace.c9.io/

assets/css/aceeditor.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.acefullscreenbody {
2+
overflow: hidden !important;
3+
}
4+
5+
.acefullscreen {
6+
position: fixed;
7+
top:0;
8+
left:0;
9+
bottom:0;
10+
right:0;
11+
width:100% !important;
12+
height:100% !important;
13+
z-index: 9999999;
14+
}
15+
16+
.acerexmode{
17+
border: solid 1px #c1c9d4;
18+
}
19+
.acerexdarkmode{
20+
border: solid 1px rgba(21, 28, 34, 0.8);
21+
}

assets/css/aceeditor.min.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/aceeditor.js

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// Load AceEditor for Textareas
2+
$(document).on('rex:ready', function () {
3+
4+
// Select Textareas
5+
let aceTextAreas = document.querySelectorAll(rex.aceeditor_selectors);
6+
7+
// Load AceEditor only if needed
8+
if (aceTextAreas.length > 0) {
9+
10+
// Load AceEditor-Script
11+
var script = document.createElement('script');
12+
script.src = '../assets/addons/aceeditor/vendor/aceeditor/ace.js';
13+
document.head.appendChild(script);
14+
script.onload = function () {
15+
16+
for (var i = 0; i < aceTextAreas.length; i++) {
17+
let textArea = aceTextAreas[i];
18+
19+
// Insert DIV for AceEditor
20+
let editorNode = document.createElement('div');
21+
editorNode.style.width = '100%';
22+
editorNode.style.height = $(textArea).height() + 'px' || '250px';
23+
textArea.parentNode.insertBefore(editorNode, textArea);
24+
25+
// Hide Textarea
26+
textArea.style.display = 'none';
27+
28+
// Initiate AceEditor and set Value
29+
let editor = ace.edit(editorNode);
30+
editor.getSession().setValue(textArea.value);
31+
32+
// General Options from Settings-Page
33+
try {
34+
ace_options = JSON.parse(rex.aceeditor_options);
35+
} catch (e) {
36+
// Default on Error
37+
ace_options = {
38+
"showLineNumbers": true,
39+
"showGutter": true,
40+
"showInvisibles": false,
41+
"fontSize": 15,
42+
"mode": "ace/mode/php"
43+
};
44+
console.warn('Addon aceeditor: Error in aceeditor-Options! Using minimum default configuration!');
45+
}
46+
47+
// Additional Settings from Attribute aceeditor-options
48+
add_options = textArea.getAttribute('aceeditor-options');
49+
if (null !== add_options) {
50+
try {
51+
new_options = JSON.parse(add_options);
52+
} catch (e) {
53+
// Default on Error
54+
new_options = {};
55+
console.warn('Addon aceeditor: Error in Attribute aceeditor-options! Options ignored!');
56+
}
57+
ace_options = $.extend(ace_options, new_options);
58+
}
59+
60+
// Set options
61+
editor.setOptions(ace_options);
62+
63+
// Set theme Default / Darkmode
64+
let theme = rex.aceeditor_defaulttheme;
65+
let darkmode = false;
66+
67+
let systemDarkModeDetector = null;
68+
if (window.matchMedia) {
69+
systemDarkModeDetector = window.matchMedia('(prefers-color-scheme: dark)');
70+
// Query system settings
71+
if (systemDarkModeDetector.matches) {
72+
theme = rex.aceeditor_defaultdarktheme;
73+
darkmode = true;
74+
}
75+
// Setting from profile
76+
if (document.body.classList.contains('rex-theme-light')) {
77+
theme = rex.aceeditor_defaulttheme;
78+
} else if (document.body.classList.contains('rex-theme-dark')) {
79+
theme = rex.aceeditor_defaultdarktheme;
80+
darkmode = true;
81+
}
82+
// Detect dark/light switching on the system side
83+
systemDarkModeDetector.addEventListener('change', function (e) {
84+
if (systemDarkModeDetector.matches) {
85+
theme = rex.aceeditor_defaultdarktheme;
86+
darkmode = true;
87+
} else {
88+
theme = rex.aceeditor_defaulttheme;
89+
}
90+
if (document.body.classList.contains('rex-theme-light')) {
91+
theme = rex.aceeditor_defaulttheme;
92+
} else if (document.body.classList.contains('rex-theme-dark')) {
93+
theme = rex.aceeditor_defaultdarktheme;
94+
darkmode = true;
95+
}
96+
});
97+
}
98+
99+
// Set theme from Attribute aceeditor-theme
100+
let attrtheme = textArea.getAttribute('aceeditor-theme');
101+
if (null !== attrtheme) {
102+
theme = attrtheme;
103+
}
104+
105+
// Set theme
106+
editor.setTheme('ace/theme/' + theme);
107+
108+
// Set mode from Attribute aceeditor-mode
109+
let mode = textArea.getAttribute('aceeditor-mode');
110+
if (null !== mode) {
111+
editor.getSession().setMode('ace/mode/' + mode);
112+
}
113+
114+
// Set border color
115+
if (darkmode === true) {
116+
editor.container.classList.add('acerexdarkmode');
117+
} else {
118+
editor.container.classList.add('acerexmode');
119+
}
120+
121+
// Set lineHeight
122+
editor.container.style.lineHeight = 1.5;
123+
editor.renderer.updateFontSize();
124+
125+
// Fullscreen-Toggle F11 + ESC
126+
editor.commands.addCommand({
127+
name: 'fullScreenF11',
128+
bindKey: { win: 'F11', mac: 'F11' },
129+
exec: function (editor) {
130+
editor.container.classList.toggle('acefullscreen');
131+
document.body.classList.toggle('acefullscreenbody');
132+
editor.resize();
133+
}
134+
});
135+
editor.commands.addCommand({
136+
name: 'fullScreenESC',
137+
bindKey: { win: 'ESC', mac: 'ESC' },
138+
exec: function (editor) {
139+
editor.container.classList.toggle('acefullscreen');
140+
document.body.classList.toggle('acefullscreenbody');
141+
editor.resize();
142+
}
143+
});
144+
145+
// Changes direct to Textarea
146+
editor.session.addEventListener('change', function (item) {
147+
let textArea = editorNode.nextElementSibling;
148+
textArea.value = editor.getSession().getValue();
149+
});
150+
}
151+
152+
};
153+
}
154+
155+
});

assets/js/aceeditor.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/vendor/aceeditor.zip

2.32 MB
Binary file not shown.

boot.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$addon = rex_addon::get('aceeditor');
6+
7+
$config = $addon->getConfig();
8+
9+
if (true === rex::isBackend() && null !== rex::getUser() && '|1|' === $addon->getConfig('active')) {
10+
11+
if (true === rex_plugin::get('be_style', 'customizer')->isInstalled() && 1 === rex_plugin::get('be_style', 'customizer')->getConfig('codemirror')) {
12+
return;
13+
}
14+
15+
rex_view::setJsProperty('aceeditor_selectors', $config['selectors']);
16+
rex_view::setJsProperty('aceeditor_defaulttheme', $config['theme']);
17+
rex_view::setJsProperty('aceeditor_defaultdarktheme', $config['darktheme']);
18+
rex_view::setJsProperty('aceeditor_options', $config['options']);
19+
20+
rex_view::addCssFile($addon->getAssetsUrl('css/aceeditor.min.css'));
21+
22+
rex_view::addJsFile($addon->getAssetsUrl('js/aceeditor.min.js'), [rex_view::JS_IMMUTABLE => true]);
23+
24+
}

install.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
$addon = rex_addon::get('aceeditor');
6+
7+
/* AceEditor-Assets entpacken */
8+
$message = '';
9+
$zipArchive = new ZipArchive();
10+
11+
// use path relative to __DIR__ to get correct path in update temp dir
12+
$path = __DIR__ . '/assets/vendor/aceeditor.zip';
13+
14+
try {
15+
if (true === $zipArchive->open($path) &&
16+
$zipArchive->extractTo($addon->getAssetsPath('vendor/'))
17+
) {
18+
$zipArchive->close();
19+
} else {
20+
$message = rex_i18n::msg('aceeditor_error_unzip') . '<br>' . $path;
21+
}
22+
} catch (Exception $exception) {
23+
$message = rex_i18n::msg('aceeditor_error_unzip') . '<br>' . $path;
24+
$message .= '<br>' . $exception->getMessage();
25+
}
26+
27+
if (!$addon->hasConfig('theme')) {
28+
$addon->setConfig('theme', 'eclipse');
29+
}
30+
31+
if (!$addon->hasConfig('darktheme')) {
32+
$addon->setConfig('darktheme', 'dracula');
33+
}
34+
35+
if ('' !== $message) {
36+
throw new rex_functional_exception($message);
37+
}

0 commit comments

Comments
 (0)