Skip to content

Commit

Permalink
Merge pull request #121 from PubliAlex/master
Browse files Browse the repository at this point in the history
JS optimizations
  • Loading branch information
Samuell1 authored Sep 15, 2023
2 parents 7af76a0 + 22b5ae0 commit 8f6980c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions assets/contenteditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ editor.addEventListener('saved', function (ev) {

for (name in regions) {
if (regions.hasOwnProperty(name)) {
var component = $('*[data-file="' + name + '"]').data('component'); // check for component name
$.request(component, {
var component = document.querySelector('*[data-file="' + name + '"]').dataset.component; // check for component name
oc.ajax(component, {
data: {
file: name,
content: regions[name]
Expand Down
4 changes: 2 additions & 2 deletions components/ContentEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public function onRun()
// put content tools js + css
$this->addCss('assets/content-tools.min.css');
$this->addCss('assets/contenteditor.css');
$this->addJs('assets/content-tools.min.js');
$this->addJs('assets/contenteditor.js');
$this->addJs('assets/content-tools.min.js', ['defer' => true]);
$this->addJs('assets/contenteditor.js', ['defer' => true]);

// Add scripts only once
$this->renderPartial('@scripts.htm');
Expand Down
40 changes: 21 additions & 19 deletions components/contenteditor/scripts.htm
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{% put scripts %}
<script type="text/javascript">
/* CONTENT EDITOR SCRIPT START */
ContentTools.StylePalette.add([
{% for style in __SELF__.palettes %}
new ContentTools.Style('{{ style.name ? style.name : style.class }}', '{{ style.class }}', {{ style.allowed_tags|json_encode()|raw }}),
{% endfor %}
]);
editor.toolbox().tools([
[
{% for value in __SELF__.buttons %}
'{{ value }}',
{% endfor %}
],
[
'undo',
'redo',
'remove'
]
]);
/* CONTENT EDITOR SCRIPT END */
/* CONTENT EDITOR SCRIPT START */
document.addEventListener('page:loaded', function() {
ContentTools.StylePalette.add([
{% for style in __SELF__.palettes %}
new ContentTools.Style('{{ style.name ? style.name : style.class }}', '{{ style.class }}', {{ style.allowed_tags|json_encode()|raw }}),
{% endfor %}
]);
editor.toolbox().tools([
[
{% for value in __SELF__.buttons %}
'{{ value }}',
{% endfor %}
],
[
'undo',
'redo',
'remove'
]
]);
/* CONTENT EDITOR SCRIPT END */
});
</script>
{% endput %}
{% put styles %}
Expand Down

0 comments on commit 8f6980c

Please sign in to comment.