Add previewMode settings to code2

pull/1/head
yflory 7 years ago
parent 0d008aaa2e
commit b8971cdc23

@ -222,21 +222,19 @@ define([
]; ];
var onModeChanged = function (mode) { var onModeChanged = function (mode) {
// TODO var $codeMirror = $('.CodeMirror');
return;
var $codeMirror = $iframe.find('.CodeMirror');
window.clearTimeout(APP.previewTo); window.clearTimeout(APP.previewTo);
$codeMirror.addClass('transition'); $codeMirror.addClass('transition');
APP.previewTo = window.setTimeout(function () { APP.previewTo = window.setTimeout(function () {
$codeMirror.removeClass('transition'); $codeMirror.removeClass('transition');
}, 500); }, 500);
if (mediaTagModes.indexOf(mode) !== -1) { /*if (mediaTagModes.indexOf(mode) !== -1) {
APP.$mediaTagButton.show(); APP.$mediaTagButton.show();
} else { APP.$mediaTagButton.hide(); } } else { APP.$mediaTagButton.hide(); }*/// TODO
if (mode === "markdown") { if (mode === "markdown") {
APP.$previewButton.show(); APP.$previewButton.show();
Cryptpad.getPadAttribute('previewMode', function (e, data) { common.getPadAttribute('previewMode', function (e, data) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
if (data !== false) { if (data !== false) {
$previewContainer.show(); $previewContainer.show();
@ -323,33 +321,11 @@ define([
var $forgetPad = common.createButton('forget', true, {}, forgetCb); var $forgetPad = common.createButton('forget', true, {}, forgetCb);
$rightside.append($forgetPad); $rightside.append($forgetPad);
// TODO var $previewButton = APP.$previewButton = common.createButton(null, true);
return;
var fileDialogCfg = {
$body: $iframe.find('body'),
onSelect: function (href) {
var parsed = Cryptpad.parsePadUrl(href);
var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel);
var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName;
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + parsed.hashData.key + '"></media-tag>';
editor.replaceSelection(mt);
},
data: APP
};
APP.$mediaTagButton = $('<button>', {
title: Messages.filePickerButton,
'class': 'rightside-button fa fa-picture-o',
style: 'font-size: 17px'
}).click(function () {
Cryptpad.createFileDialog(fileDialogCfg);
}).appendTo($rightside);
var $previewButton = APP.$previewButton = Cryptpad.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);
$previewButton.click(function () { $previewButton.click(function () {
var $codeMirror = $iframe.find('.CodeMirror'); var $codeMirror = $('.CodeMirror');
window.clearTimeout(APP.previewTo); window.clearTimeout(APP.previewTo);
$codeMirror.addClass('transition'); $codeMirror.addClass('transition');
APP.previewTo = window.setTimeout(function () { APP.previewTo = window.setTimeout(function () {
@ -362,14 +338,14 @@ define([
if ($previewContainer.is(':visible')) { if ($previewContainer.is(':visible')) {
forceDrawPreview(); forceDrawPreview();
$codeMirror.removeClass('fullPage'); $codeMirror.removeClass('fullPage');
Cryptpad.setPadAttribute('previewMode', true, function (e) { $previewButton.addClass('active');
common.setPadAttribute('previewMode', true, function (e) {
if (e) { return console.log(e); } if (e) { return console.log(e); }
}); });
$previewButton.addClass('active');
} else { } else {
$codeMirror.addClass('fullPage'); $codeMirror.addClass('fullPage');
$previewButton.removeClass('active'); $previewButton.removeClass('active');
Cryptpad.setPadAttribute('previewMode', false, function (e) { common.setPadAttribute('previewMode', false, function (e) {
if (e) { return console.log(e); } if (e) { return console.log(e); }
}); });
} }
@ -384,6 +360,28 @@ define([
else { else {
CodeMirror.configureTheme(); CodeMirror.configureTheme();
} }
// TODO
return;
var fileDialogCfg = {
$body: $iframe.find('body'),
onSelect: function (href) {
var parsed = Cryptpad.parsePadUrl(href);
var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel);
var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName;
var mt = '<media-tag src="' + src + '" data-crypto-key="cryptpad:' + parsed.hashData.key + '"></media-tag>';
editor.replaceSelection(mt);
},
data: APP
};
APP.$mediaTagButton = $('<button>', {
title: Messages.filePickerButton,
'class': 'rightside-button fa fa-picture-o',
style: 'font-size: 17px'
}).click(function () {
Cryptpad.createFileDialog(fileDialogCfg);
}).appendTo($rightside);
}; };
config.onReady = function (info) { config.onReady = function (info) {
@ -439,14 +437,13 @@ define([
} }
/* TODO RPC common.getPadAttribute('previewMode', function (e, data) {
Cryptpad.getPadAttribute('previewMode', function (e, data) {
if (e) { return void console.error(e); } if (e) { return void console.error(e); }
if (data === false && APP.$previewButton) { if (data === false && APP.$previewButton) {
APP.$previewButton.click(); APP.$previewButton.click();
} }
}); });
*/
/* /*
// add the splitter // add the splitter

@ -200,6 +200,21 @@ define([
network.sendto(hkn, JSON.stringify(['GET_FULL_HISTORY', secret.channel, secret.keys.validateKey])); 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({ CpNfOuter.start({
sframeChan: sframeChan, sframeChan: sframeChan,
channel: secret.channel, channel: secret.channel,

@ -107,6 +107,22 @@ define([
ctx.sframeChan.query('Q_GET_FULL_HISTORY', null, cb); 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 // Friends
var pendingFriends = []; var pendingFriends = [];
funcs.getPendingFriends = function () { funcs.getPendingFriends = function () {

@ -84,4 +84,8 @@ define({
// Send the new settings to the inner iframe when they are changed in the proxy // Send the new settings to the inner iframe when they are changed in the proxy
'EV_SETTINGS_UPDATE': true, '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,
}); });

@ -146,6 +146,7 @@ define([
if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); } if (!attr || !attr.trim()) { return void cb("E_INVAL_ATTR"); }
var data = getFileData(id); var data = getFileData(id);
data[attr] = value; data[attr] = value;
cb(null);
}; };
// PATHS // PATHS

Loading…
Cancel
Save