From b8971cdc2309f009e0413dbd7129bbf1eda12d19 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 30 Aug 2017 18:47:50 +0200 Subject: [PATCH] Add previewMode settings to code2 --- www/code2/inner.js | 93 +++++++++++++++---------------- www/common/sframe-common-outer.js | 15 +++++ www/common/sframe-common.js | 16 ++++++ www/common/sframe-protocol.js | 4 ++ www/common/userObject.js | 1 + 5 files changed, 81 insertions(+), 48 deletions(-) diff --git a/www/code2/inner.js b/www/code2/inner.js index f59c6e8fa..aa2a50624 100644 --- a/www/code2/inner.js +++ b/www/code2/inner.js @@ -222,21 +222,19 @@ define([ ]; var onModeChanged = function (mode) { - // TODO - return; - var $codeMirror = $iframe.find('.CodeMirror'); + var $codeMirror = $('.CodeMirror'); window.clearTimeout(APP.previewTo); $codeMirror.addClass('transition'); APP.previewTo = window.setTimeout(function () { $codeMirror.removeClass('transition'); }, 500); - if (mediaTagModes.indexOf(mode) !== -1) { + /*if (mediaTagModes.indexOf(mode) !== -1) { APP.$mediaTagButton.show(); - } else { APP.$mediaTagButton.hide(); } + } else { APP.$mediaTagButton.hide(); }*/// TODO if (mode === "markdown") { APP.$previewButton.show(); - Cryptpad.getPadAttribute('previewMode', function (e, data) { + common.getPadAttribute('previewMode', function (e, data) { if (e) { return void console.error(e); } if (data !== false) { $previewContainer.show(); @@ -323,6 +321,45 @@ define([ var $forgetPad = common.createButton('forget', true, {}, forgetCb); $rightside.append($forgetPad); + var $previewButton = APP.$previewButton = common.createButton(null, true); + $previewButton.removeClass('fa-question').addClass('fa-eye'); + $previewButton.attr('title', Messages.previewButtonTitle); + $previewButton.click(function () { + var $codeMirror = $('.CodeMirror'); + window.clearTimeout(APP.previewTo); + $codeMirror.addClass('transition'); + APP.previewTo = window.setTimeout(function () { + $codeMirror.removeClass('transition'); + }, 500); + if (CodeMirror.highlightMode !== 'markdown') { + $previewContainer.show(); + } + $previewContainer.toggle(); + if ($previewContainer.is(':visible')) { + forceDrawPreview(); + $codeMirror.removeClass('fullPage'); + $previewButton.addClass('active'); + common.setPadAttribute('previewMode', true, function (e) { + if (e) { return console.log(e); } + }); + } else { + $codeMirror.addClass('fullPage'); + $previewButton.removeClass('active'); + common.setPadAttribute('previewMode', false, function (e) { + if (e) { return console.log(e); } + }); + } + }); + $rightside.append($previewButton); + + if (!readOnly) { + CodeMirror.configureTheme(function () { + CodeMirror.configureLanguage(null, onModeChanged); + }); + } + else { + CodeMirror.configureTheme(); + } // TODO return; @@ -345,45 +382,6 @@ define([ Cryptpad.createFileDialog(fileDialogCfg); }).appendTo($rightside); - var $previewButton = APP.$previewButton = Cryptpad.createButton(null, true); - $previewButton.removeClass('fa-question').addClass('fa-eye'); - $previewButton.attr('title', Messages.previewButtonTitle); - $previewButton.click(function () { - var $codeMirror = $iframe.find('.CodeMirror'); - window.clearTimeout(APP.previewTo); - $codeMirror.addClass('transition'); - APP.previewTo = window.setTimeout(function () { - $codeMirror.removeClass('transition'); - }, 500); - if (CodeMirror.highlightMode !== 'markdown') { - $previewContainer.show(); - } - $previewContainer.toggle(); - if ($previewContainer.is(':visible')) { - forceDrawPreview(); - $codeMirror.removeClass('fullPage'); - Cryptpad.setPadAttribute('previewMode', true, function (e) { - if (e) { return console.log(e); } - }); - $previewButton.addClass('active'); - } else { - $codeMirror.addClass('fullPage'); - $previewButton.removeClass('active'); - Cryptpad.setPadAttribute('previewMode', false, function (e) { - if (e) { return console.log(e); } - }); - } - }); - $rightside.append($previewButton); - - if (!readOnly) { - CodeMirror.configureTheme(function () { - CodeMirror.configureLanguage(null, onModeChanged); - }); - } - else { - CodeMirror.configureTheme(); - } }; config.onReady = function (info) { @@ -439,14 +437,13 @@ define([ } -/* TODO RPC - Cryptpad.getPadAttribute('previewMode', function (e, data) { + common.getPadAttribute('previewMode', function (e, data) { if (e) { return void console.error(e); } if (data === false && APP.$previewButton) { APP.$previewButton.click(); } }); -*/ + /* // add the splitter diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index e96e19b0f..a355734de 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -200,6 +200,21 @@ define([ network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', secret.channel, secret.keys.validateKey])); }); + sframeChan.on('Q_GET_PAD_ATTRIBUTE', function (data, cb) { + Cryptpad.getPadAttribute(data.key, function (e, data) { + cb({ + error: e, + data: data + }); + }); + }); + sframeChan.on('Q_SET_PAD_ATTRIBUTE', function (data, cb) { + Cryptpad.setPadAttribute(data.key, data.value, function (e) { + cb({error:e}); + }); + }); + + CpNfOuter.start({ sframeChan: sframeChan, channel: secret.channel, diff --git a/www/common/sframe-common.js b/www/common/sframe-common.js index 5e50209b6..6beb1e83d 100644 --- a/www/common/sframe-common.js +++ b/www/common/sframe-common.js @@ -107,6 +107,22 @@ define([ ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb); }; + funcs.getPadAttribute = function (key, cb) { + ctx.sframeChan.query('Q_GET_PAD_ATTRIBUTE', { + key: key + }, function (err, res) { + cb (err || res.error, res.data); + }); + }; + funcs.setPadAttribute = function (key, value, cb) { + ctx.sframeChan.query('Q_SET_PAD_ATTRIBUTE', { + key: key, + value: value + }, function (err, data) { + cb(); + }); + }; + // Friends var pendingFriends = []; funcs.getPendingFriends = function () { diff --git a/www/common/sframe-protocol.js b/www/common/sframe-protocol.js index 747827316..1db4c01a8 100644 --- a/www/common/sframe-protocol.js +++ b/www/common/sframe-protocol.js @@ -84,4 +84,8 @@ define({ // Send the new settings to the inner iframe when they are changed in the proxy 'EV_SETTINGS_UPDATE': true, + + // Get and set pad attributes stored in the drive from the inner iframe + 'Q_GET_PAD_ATTRIBUTE': true, + 'Q_SET_PAD_ATTRIBUTE': true, }); diff --git a/www/common/userObject.js b/www/common/userObject.js index 2d9f0680d..6eab74bc3 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -146,6 +146,7 @@ define([ if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); } var data = getFileData(id); data[attr] = value; + cb(null); }; // PATHS