Skip to content

Commit f014883

Browse files
committed
Fix support for Winter v1.2.10+
1 parent 3d9d9fe commit f014883

File tree

3 files changed

+51
-23
lines changed

3 files changed

+51
-23
lines changed

assets/js/pages-page.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@
599599

600600
var extension = this.getContentExtension(pane),
601601
mode = 'html',
602-
editor = $('[data-control=codeeditor]', pane)
602+
$editor = $('[data-control=codeeditor]', pane)
603603

604604
if (extension == 'html')
605605
extension = 'htm'
@@ -612,8 +612,11 @@
612612
$('[data-field-name=markup_html]', pane).show()
613613

614614
if (!initialization && $(pane).data('prev-extension') != 'htm') {
615-
var val = editor.codeEditor('getContent')
616-
$('div[data-control=richeditor]', pane).richEditor('setContent', val)
615+
var wrapper = $editor.data('oc.codeEditor')
616+
if (wrapper) {
617+
var val = wrapper.getValue()
618+
$('div[data-control=richeditor]', pane).richEditor('setContent', val)
619+
}
617620
}
618621
}
619622
else {
@@ -622,26 +625,44 @@
622625

623626
if (!initialization && $(pane).data('prev-extension') == 'htm') {
624627
var val = $('div[data-control=richeditor]', pane).richEditor('getContent')
625-
editor.codeEditor('setContent', val)
628+
var wrapper = $editor.data('oc.codeEditor')
629+
if (wrapper) {
630+
wrapper.setValue(val)
631+
}
626632
}
627633

628-
var modes = $.wn.codeEditorExtensionModes
634+
var monacoExtensionModes = {
635+
'htm': 'html',
636+
'html': 'html',
637+
'md': 'markdown',
638+
'txt': 'plaintext',
639+
'js': 'javascript',
640+
'less': 'less',
641+
'scss': 'scss',
642+
'sass': 'scss',
643+
'css': 'css'
644+
}
629645

630-
if (modes[extension] !== undefined)
631-
mode = modes[extension];
646+
if (monacoExtensionModes[extension] !== undefined)
647+
mode = monacoExtensionModes[extension]
632648

633649
var setEditorMode = function() {
634-
window.setTimeout(function(){
635-
editor.codeEditor('getEditorObject')
636-
.getSession()
637-
.setMode({ path: 'ace/mode/'+mode })
638-
}, 200)
650+
var wrapper = $editor.data('oc.codeEditor')
651+
if (wrapper) {
652+
wrapper.setLanguage(mode)
653+
}
639654
}
640655

641-
if (initialization)
642-
editor.on('oc.codeEditorReady', setEditorMode)
643-
else
656+
if (initialization) {
657+
window.Snowboard.on('backend.formwidget.codeeditor.create', function(widget) {
658+
if ($(widget.element).closest(pane).length > 0) {
659+
widget.setLanguage(mode)
660+
}
661+
})
662+
}
663+
else {
644664
setEditorMode()
665+
}
645666
}
646667

647668
if (!initialization)

classes/content/fields.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,8 @@ secondaryTabs:
2323
stretch: true
2424
type: codeeditor
2525
language: html
26-
theme: chrome
27-
showGutter: false
28-
highlightActiveLine: false
2926
fontSize: 13
3027
cssClass: pagesTextEditor
31-
margin: 20
3228

3329
markup_html:
3430
tab: cms::lang.editor.content

controllers/Index.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ public function index()
189189
$this->addJs('/plugins/winter/pages/assets/js/pages-snippets.js', 'Winter.Pages');
190190
$this->addCss('/plugins/winter/pages/assets/css/pages.css', 'Winter.Pages');
191191

192-
// Preload the code editor class as it could be needed
193-
// before it loads dynamically.
194-
$this->addJs('/modules/backend/formwidgets/codeeditor/assets/js/build-min.js', 'core');
195-
196192
$this->bodyClass = 'compact-container';
197193
$this->pageTitle = 'winter.pages::lang.plugin.name';
198194
$this->pageTitleTemplate = Lang::get('winter.pages::lang.page.template_title');
@@ -777,6 +773,21 @@ protected function pushObjectForm($type, $object, $alias = null): array
777773
$widget = $this->makeObjectFormWidget($type, $object, $alias);
778774
$widget->bindToController();
779775

776+
// Prevent Froala richeditor from parsing raw content as HTML for non-HTML
777+
// content files. The richeditor's valueFrom: markup causes it to receive the
778+
// raw content value which triggers XSS when Froala calls jQuery .html().
779+
if ($type === 'content') {
780+
$widget->bindEvent('form.extendFields', function () use ($widget, $object) {
781+
$extension = pathinfo($object->getFileName(), PATHINFO_EXTENSION);
782+
if (!in_array($extension, ['htm', 'html'])) {
783+
$field = $widget->getField('markup_html');
784+
if ($field) {
785+
$field->value = '';
786+
}
787+
}
788+
});
789+
}
790+
780791
$this->vars['canCommit'] = $this->canCommitObject($object);
781792
$this->vars['canReset'] = $this->canResetObject($object);
782793
$this->vars['objectPath'] = Request::input('path');

0 commit comments

Comments
 (0)