Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_texteditor.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2017-02-16 17:33:34 +0300
committerRobin Appelman <robin@icewind.nl>2017-02-22 23:25:32 +0300
commit04c902a7eaad3405dddc33b139eecdd26f4e2025 (patch)
treef46d9024fed3cde90fb5c6b87ba13dcfafda62d6 /js
parentc02cb715c298726e1c1533dd1912707edc9dc67b (diff)
Add toggle between edit only/edit with preview/preview only
Fixes https://github.com/icewind1991/files_markdown/issues/24 Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'js')
-rw-r--r--js/editor.js49
1 files changed, 49 insertions, 0 deletions
diff --git a/js/editor.js b/js/editor.js
index 59b7fc4..c03fddc 100644
--- a/js/editor.js
+++ b/js/editor.js
@@ -316,6 +316,7 @@ var Files_Texteditor = {
var text = window.aceEditor.getSession().getValue();
_self.previewPluginOnChange(text, _self.preview);
window.aceEditor.resize();
+ _self.loadPreviewControlBar();
} else {
_self.previewPluginOnChange = null;
}
@@ -349,6 +350,54 @@ var Files_Texteditor = {
},
+ setPreviewMode: function(mode) {
+ var container = $('#app-content-texteditor');
+ var controlBar = $('#preview_editor_controls');
+ controlBar.find('button').removeClass('active');
+ controlBar.find('button[data-type="' + mode + '"]').addClass('active');
+ switch (mode) {
+ case 'mixed':
+ container.find('#editor_container').addClass('hasPreview');
+ container.find('#editor').show();
+ container.find('#preview_wrap').css('width', '50%');
+ break;
+ case 'text':
+ container.find('#editor_container').removeClass('hasPreview');
+ container.find('#editor').show();
+ container.find('#preview_wrap').css('width', '50%');
+ break;
+ case 'image':
+ container.find('#editor_container').addClass('hasPreview');
+ container.find('#editor').hide();
+ container.find('#preview_wrap').css('width', '100%');
+ break;
+ }
+ },
+
+ loadPreviewControlBar: function() {
+ var makeButton = function (type, tooltip, active) {
+ var button = $('<button/>');
+ button.tooltip({
+ title: tooltip,
+ container: 'body',
+ placement: 'bottom',
+ delay: {show: 500, hide: 0}
+ });
+ if (active) {
+ button.addClass('active');
+ }
+ button.click(this.setPreviewMode.bind(this, type));
+ button.attr('data-type', type);
+ return button.css('background-image', 'url("' + OC.imagePath('files_texteditor', type) + '")');
+ }.bind(this);
+
+ var controls = $('<span/>').attr('id', 'preview_editor_controls');
+ controls.append(makeButton('text', t('files_texteditor', 'Edit')));
+ controls.append(makeButton('mixed', t('files_texteditor', 'Mixed'), true));
+ controls.append(makeButton('image', t('files_texteditor', 'Preview')));
+ $('#editor_close').after(controls);
+ },
+
/**
* Removes the control bar
*/