Present mode to display only the parsed markdown in code

pull/1/head
yflory 7 years ago
parent 515214aed1
commit f43606f71d

@ -44,6 +44,10 @@
flex-flow: row; flex-flow: row;
height: 100%; height: 100%;
overflow: hidden; overflow: hidden;
&.cp-app-code-present {
.CodeMirror { display: none; }
#cp-app-code-preview { border: 0; }
}
} }
#cp-app-code-preview { #cp-app-code-preview {
flex: 1; flex: 1;

@ -62,10 +62,14 @@ define([
'xml', 'xml',
]); ]);
var mkPreviewPane = function (editor, CodeMirror, framework) { var mkPreviewPane = function (editor, CodeMirror, framework, isPresentMode) {
var $previewContainer = $('#cp-app-code-preview'); var $previewContainer = $('#cp-app-code-preview');
var $preview = $('#cp-app-code-preview-content'); var $preview = $('#cp-app-code-preview-content');
var $editorContainer = $('#cp-app-code-editor');
var $codeMirror = $('.CodeMirror'); var $codeMirror = $('.CodeMirror');
var $previewButton = framework._.sfCommon.createButton(null, true);
var forceDrawPreview = function () { var forceDrawPreview = function () {
try { try {
DiffMd.apply(DiffMd.render(editor.getValue()), $preview); DiffMd.apply(DiffMd.render(editor.getValue()), $preview);
@ -73,11 +77,10 @@ define([
}; };
var drawPreview = Util.throttle(function () { var drawPreview = Util.throttle(function () {
if (CodeMirror.highlightMode !== 'markdown') { return; } if (CodeMirror.highlightMode !== 'markdown') { return; }
if (!$previewContainer.is(':visible')) { return; } if (!$previewButton.is('.cp-toolbar-button-active')) { return; }
forceDrawPreview(); forceDrawPreview();
}, 150); }, 150);
var $previewButton = framework._.sfCommon.createButton(null, true);
$previewButton.removeClass('fa-question').addClass('fa-eye'); $previewButton.removeClass('fa-question').addClass('fa-eye');
$previewButton.attr('title', Messages.previewButtonTitle); $previewButton.attr('title', Messages.previewButtonTitle);
var previewTo; var previewTo;
@ -126,12 +129,16 @@ define([
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
if (data !== false) { if (data !== false) {
$previewContainer.show(); $previewContainer.show();
$previewButton.addClass('active'); $previewButton.addClass('cp-toolbar-button-active');
$codeMirror.removeClass('cp-app-code-fullpage'); $codeMirror.removeClass('cp-app-code-fullpage');
if (isPresentMode) {
$editorContainer.addClass('cp-app-code-present');
}
} }
}); });
return; return;
} }
$editorContainer.removeClass('cp-app-code-present');
$previewButton.hide(); $previewButton.hide();
$previewContainer.hide(); $previewContainer.hide();
$previewButton.removeClass('active'); $previewButton.removeClass('active');
@ -224,11 +231,11 @@ define([
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
var andThen2 = function (editor, CodeMirror, framework) { var andThen2 = function (editor, CodeMirror, framework, isPresentMode) {
var common = framework._.sfCommon; var common = framework._.sfCommon;
var previewPane = mkPreviewPane(editor, CodeMirror, framework); var previewPane = mkPreviewPane(editor, CodeMirror, framework, isPresentMode);
var evModeChange = Util.mkEvent(); var evModeChange = Util.mkEvent();
evModeChange.reg(previewPane.modeChange); evModeChange.reg(previewPane.modeChange);
@ -335,8 +342,12 @@ define([
editor = CodeMirror.editor; editor = CodeMirror.editor;
}).nThen(waitFor()); }).nThen(waitFor());
}).nThen(function (waitFor) {
common.getSframeChannel().onReady(waitFor());
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
andThen2(editor, CodeMirror, framework); common.isPresentUrl(function (err, val) {
andThen2(editor, CodeMirror, framework, val);
});
}); });
}; };
main(); main();

Loading…
Cancel
Save