Skip to content

Commit ad974da

Browse files
committed
Hide the editor buttons if the editor is in "preview" mode
1 parent 8331169 commit ad974da

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

themes/grav/js/mdeditor.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,30 +148,36 @@
148148
this.preview.container = this.preview;
149149

150150
this.mdeditor.on('click', '.grav-mdeditor-button-code, .grav-mdeditor-button-preview', function(e) {
151-
var task = 'task' + GravAdmin.config.param_sep;
152-
e.preventDefault();
153-
154-
if ($this.mdeditor.attr('data-mode') == 'tab') {
155-
if ($(this).hasClass('grav-mdeditor-button-preview')) {
156-
GravAjax({
157-
dataType: 'JSON',
158-
url: $this.element.data('grav-urlpreview') + '/' + task + 'processmarkdown',
159-
method: 'post',
160-
data: $this.element.parents('form').serialize(),
161-
toastErrors: true,
162-
success: function (response) {
163-
$this.preview.container.html(response.message);
164-
}
165-
});
166-
}
151+
var task = 'task' + GravAdmin.config.param_sep;
152+
e.preventDefault();
153+
154+
if ($this.mdeditor.attr('data-mode') == 'tab') {
155+
if ($(this).hasClass('grav-mdeditor-button-preview')) {
156+
GravAjax({
157+
dataType: 'JSON',
158+
url: $this.element.data('grav-urlpreview') + '/' + task + 'processmarkdown',
159+
method: 'post',
160+
data: $this.element.parents('form').serialize(),
161+
toastErrors: true,
162+
success: function (response) {
163+
$this.preview.container.html(response.message);
164+
}
165+
});
166+
}
167+
168+
$this.mdeditor.find('.grav-mdeditor-button-code, .grav-mdeditor-button-preview').removeClass('mdeditor-active').filter(this).addClass('mdeditor-active');
167169

168-
$this.mdeditor.find('.grav-mdeditor-button-code, .grav-mdeditor-button-preview').removeClass('mdeditor-active').filter(this).addClass('mdeditor-active');
170+
$this.activetab = $(this).hasClass('grav-mdeditor-button-code') ? 'code' : 'preview';
171+
$this.mdeditor.attr('data-active-tab', $this.activetab);
172+
$this.editor.refresh();
169173

170-
$this.activetab = $(this).hasClass('grav-mdeditor-button-code') ? 'code' : 'preview';
171-
$this.mdeditor.attr('data-active-tab', $this.activetab);
172-
$this.editor.refresh();
174+
if ($this.activetab == 'preview') {
175+
$('.grav-mdeditor-toolbar').hide();
176+
} else {
177+
$('.grav-mdeditor-toolbar').show();
173178
}
174-
});
179+
}
180+
});
175181

176182
this.mdeditor.on('click', 'a[data-mdeditor-button]', function() {
177183

0 commit comments

Comments
 (0)