Skip to content

Commit

Permalink
Hide the editor buttons if the editor is in "preview" mode
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviocopes committed Oct 5, 2015
1 parent 8331169 commit ad974da
Showing 1 changed file with 27 additions and 21 deletions.
48 changes: 27 additions & 21 deletions themes/grav/js/mdeditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,30 +148,36 @@
this.preview.container = this.preview;

this.mdeditor.on('click', '.grav-mdeditor-button-code, .grav-mdeditor-button-preview', function(e) {
var task = 'task' + GravAdmin.config.param_sep;
e.preventDefault();

if ($this.mdeditor.attr('data-mode') == 'tab') {
if ($(this).hasClass('grav-mdeditor-button-preview')) {
GravAjax({
dataType: 'JSON',
url: $this.element.data('grav-urlpreview') + '/' + task + 'processmarkdown',
method: 'post',
data: $this.element.parents('form').serialize(),
toastErrors: true,
success: function (response) {
$this.preview.container.html(response.message);
}
});
}
var task = 'task' + GravAdmin.config.param_sep;
e.preventDefault();

if ($this.mdeditor.attr('data-mode') == 'tab') {
if ($(this).hasClass('grav-mdeditor-button-preview')) {
GravAjax({
dataType: 'JSON',
url: $this.element.data('grav-urlpreview') + '/' + task + 'processmarkdown',
method: 'post',
data: $this.element.parents('form').serialize(),
toastErrors: true,
success: function (response) {
$this.preview.container.html(response.message);
}
});
}

$this.mdeditor.find('.grav-mdeditor-button-code, .grav-mdeditor-button-preview').removeClass('mdeditor-active').filter(this).addClass('mdeditor-active');

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

$this.activetab = $(this).hasClass('grav-mdeditor-button-code') ? 'code' : 'preview';
$this.mdeditor.attr('data-active-tab', $this.activetab);
$this.editor.refresh();
if ($this.activetab == 'preview') {
$('.grav-mdeditor-toolbar').hide();
} else {
$('.grav-mdeditor-toolbar').show();
}
});
}
});

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

Expand Down

0 comments on commit ad974da

Please sign in to comment.