1. Migrated /slide/ to use framework

2. Fixed CSS not being applied on /slide/
3. Minor changes to /code/ to reuse code which is also used on /slide/
pull/1/head
Caleb James DeLisle 7 years ago
parent 1e5bc5da14
commit fa6938baa8

@ -166,6 +166,7 @@ define(function () {
out.slideOptionsText = "Options"; out.slideOptionsText = "Options";
out.slideOptionsTitle = "Customize your slides"; out.slideOptionsTitle = "Customize your slides";
out.slideOptionsButton = "Save (enter)"; out.slideOptionsButton = "Save (enter)";
out.slide_invalidLess = "Invalid custom style";
out.languageButton = "Language"; out.languageButton = "Language";
out.languageButtonTitle = "Select the language to use for the syntax highlighting"; out.languageButtonTitle = "Select the language to use for the syntax highlighting";

@ -51,8 +51,6 @@ define([
window.CodeMirror = CMeditor; window.CodeMirror = CMeditor;
var Messages = Cryptpad.Messages; var Messages = Cryptpad.Messages;
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
var MEDIA_TAG_MODES = Object.freeze([ var MEDIA_TAG_MODES = Object.freeze([
'markdown', 'markdown',
'html', 'html',
@ -142,7 +140,6 @@ define([
framework.onReady(function () { framework.onReady(function () {
// add the splitter // add the splitter
if ($('.cp-splitter').length) { return; }
var splitter = $('<div>', { var splitter = $('<div>', {
'class': 'cp-splitter' 'class': 'cp-splitter'
}).appendTo($previewContainer); }).appendTo($previewContainer);
@ -266,23 +263,19 @@ define([
//// ////
framework.onContentUpdate(function (newContent) { framework.onContentUpdate(function (newContent) {
var oldDoc = canonicalize(CodeMirror.$textarea.val()); CodeMirror.contentUpdate(newContent);
var remoteDoc = newContent.content;
var highlightMode = newContent.highlightMode; var highlightMode = newContent.highlightMode;
if (highlightMode && highlightMode !== CodeMirror.highlightMode) { if (highlightMode && highlightMode !== CodeMirror.highlightMode) {
CodeMirror.setMode(highlightMode, evModeChange.fire); CodeMirror.setMode(highlightMode, evModeChange.fire);
} }
CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
previewPane.draw(); previewPane.draw();
}); });
framework.setContentGetter(function () { framework.setContentGetter(function () {
editor.save(); var content = CodeMirror.getContent();
content.highlightMode = CodeMirror.highlightMode;
previewPane.draw(); previewPane.draw();
return { return content;
content: canonicalize(CodeMirror.$textarea.val()),
highlightMode: CodeMirror.highlightMode
};
}); });
framework.onEditableChange(function () { framework.onEditableChange(function () {

@ -376,7 +376,9 @@ define([
}).nThen(function () { }).nThen(function () {
title = common.createTitle({ getHeadingText: titleRecommender }, onLocal); title = common.createTitle({
getHeadingText: function () { return titleRecommender(); }
}, onLocal);
var configTb = { var configTb = {
displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'], displayed: ['userlist', 'title', 'useradmin', 'spinner', 'newpad', 'share', 'limit'],
title: title.getTitleConfig(), title: title.getTitleConfig(),

@ -3,9 +3,10 @@ define([
'/common/modes.js', '/common/modes.js',
'/common/themes.js', '/common/themes.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/bower_components/textpatcher/TextPatcher.js',
'/bower_components/file-saver/FileSaver.min.js' '/bower_components/file-saver/FileSaver.min.js'
], function ($, Modes, Themes, Cryptpad) { ], function ($, Modes, Themes, Cryptpad, TextPatcher) {
var saveAs = window.saveAs; var saveAs = window.saveAs;
var module = {}; var module = {};
@ -305,6 +306,42 @@ define([
editor.scrollTo(scroll.left, scroll.top); editor.scrollTo(scroll.left, scroll.top);
}; };
/////
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
exp.contentUpdate = function (newContent) {
var oldDoc = canonicalize($textarea.val());
var remoteDoc = newContent.content;
exp.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
};
exp.getContent = function () {
editor.save();
return { content: canonicalize($textarea.val()) };
};
exp.mkFileManager = function (framework) {
var fmConfig = {
dropArea: $('.CodeMirror'),
body: $('body'),
onUploaded: function (ev, data) {
//var cursor = editor.getCursor();
//var cleanName = data.name.replace(/[\[\]]/g, '');
//var text = '!['+cleanName+']('+data.url+')';
var parsed = Cryptpad.parsePadUrl(data.url);
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);
}
};
framework._.sfCommon.createFileManager(fmConfig);
};
return exp; return exp;
}; };

@ -324,3 +324,6 @@ p {
min-width:0; min-width:0;
} }
pre.cp-slide-css-error {
color: white;
}

@ -5,7 +5,7 @@
<meta content="text/html; charset=utf-8" http-equiv="content-type"/> <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="referrer" content="no-referrer" /> <meta name="referrer" content="no-referrer" />
<script async data-bootload="main.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script> <script async data-bootload="/common/sframe-app-outer.js" data-main="/common/boot.js?ver=1.0" src="/bower_components/requirejs/require.js?ver=2.3.5"></script>
<style> <style>
html, body { html, body {
margin: 0px; margin: 0px;

@ -1,19 +1,12 @@
define([ define([
'jquery', 'jquery',
'/bower_components/chainpad-crypto/crypto.js',
'/bower_components/textpatcher/TextPatcher.js',
'/common/toolbar3.js',
'json.sortify', 'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js', '/common/cryptpad-common.js',
'/common/cryptget.js',
'/common/diffMarked.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/common/sframe-common.js', '/common/sframe-common.js',
'/api/config',
'/common/common-realtime.js',
'/slide/slide.js', '/slide/slide.js',
'/common/sframe-app-framework.js',
'/common/common-util.js',
'cm/lib/codemirror', 'cm/lib/codemirror',
'css!/bower_components/bootstrap/dist/css/bootstrap.min.css', 'css!/bower_components/bootstrap/dist/css/bootstrap.min.css',
@ -48,150 +41,84 @@ define([
], function ( ], function (
$, $,
Crypto,
TextPatcher,
Toolbar,
JSONSortify, JSONSortify,
JsonOT,
Cryptpad, Cryptpad,
Cryptget,
DiffMd,
nThen, nThen,
SFCommon, SFCommon,
ApiConfig,
CommonRealtime,
Slide, Slide,
Framework,
Util,
CMeditor) CMeditor)
{ {
window.CodeMirror = CMeditor; window.CodeMirror = CMeditor;
var Messages = Cryptpad.Messages; var Messages = Cryptpad.Messages;
var APP = window.APP = {
Cryptpad: Cryptpad,
};
var SLIDE_BACKCOLOR_ID = "cp-app-slide-toolbar-backcolor"; var SLIDE_BACKCOLOR_ID = "cp-app-slide-toolbar-backcolor";
var SLIDE_COLOR_ID = "cp-app-slide-toolbar-color"; var SLIDE_COLOR_ID = "cp-app-slide-toolbar-color";
var stringify = function (obj) { var mkLess = function (less) {
return JSONSortify(obj); return (
'#cp-app-slide-print .cp-app-slide-frame, ' +
'#cp-app-slide-modal #cp-app-slide-modal-content .cp-app-slide-frame {\r\n' +
less +
'\r\n}'
);
}; };
var toolbar; var mkSlidePreviewPane = function (framework, $contentContainer) {
var isPresentMode; var $previewButton = framework._.sfCommon.createButton(null, true);
$previewButton.removeClass('fa-question').addClass('fa-eye');
var onConnectError = function () { $previewButton.attr('title', Messages.previewButtonTitle);
Cryptpad.errorLoadingScreen(Messages.websocketError); $previewButton.click(function () {
}; var $c = $contentContainer;
if ($c.hasClass('cp-app-slide-preview')) {
var andThen = function (editor, CodeMirror, common) { framework._.sfCommon.setPadAttribute('previewMode', false, function (e) {
var readOnly = false; if (e) { return console.log(e); }
var cpNfInner; });
var metadataMgr; $previewButton.removeClass('cp-toolbar-button-active');
var $bar = $('#cme_toolbox'); return void $c.removeClass('cp-app-slide-preview');
var isHistoryMode = false;
var setEditable = APP.setEditable = function (bool) {
if (readOnly && bool) { return; }
editor.setOption('readOnly', !bool);
};
var Title;
var config = {
readOnly: readOnly,
transformFunction: JsonOT.validate,
// cryptpad debug logging (default is 1)
// logLevel: 0,
validateContent: function (content) {
try {
JSON.parse(content);
return true;
} catch (e) {
console.log("Failed to parse, rejecting patch");
return false;
}
}
};
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
var setHistory = function (bool, update) {
isHistoryMode = bool;
setEditable(!bool);
if (!bool && update) {
config.onRemote();
}
};
var $contentContainer = $('#cp-app-slide-editor');
var $modal = $('#cp-app-slide-modal');
var $content = $('#cp-app-slide-modal-content');
var $print = $('#cp-app-slide-print');
var slideOptions = {};
var initialState = Messages.slideInitialState;
var textColor;
var backColor;
$content.click(function (e) {
if (!e.target) { return; }
var $t = $(e.target);
if ($t.is('a') || $t.parents('a').length) {
e.preventDefault();
var $a = $t.is('a') ? $t : $t.parents('a').first();
var href = $a.attr('href');
window.open(href);
} }
framework._.sfCommon.setPadAttribute('previewMode', true, function (e) {
if (e) { return console.log(e); }
});
$c.addClass('cp-app-slide-preview');
$previewButton.addClass('cp-toolbar-button-active');
Slide.updateFontSize();
}); });
framework._.toolbar.$rightside.append($previewButton);
Slide.setModal(common, $modal, $content, slideOptions, initialState); framework._.sfCommon.getPadAttribute('previewMode', function (e, data) {
if (e) { return void console.error(e); }
var enterPresentationMode = function (shouldLog) { if (data !== false && $previewButton) {
Slide.show(true, editor.getValue()); $previewButton.click();
if (shouldLog) {
Cryptpad.log(Messages.presentSuccess);
} }
}; });
};
if (isPresentMode) {
enterPresentationMode(true);
}
CommonRealtime.onInfiniteSpinner(function () { setEditable(false); });
setEditable(false);
var initializing = true;
var stringifyInner = function (textValue) {
var obj = {
content: textValue,
metadata: metadataMgr.getMetadataLazy()
};
// stringify the json and send it into chainpad
return stringify(obj);
};
var onLocal = config.onLocal = function () {
if (initializing) { return; }
if (isHistoryMode) { return; }
if (readOnly) { return; }
editor.save();
var textValue = canonicalize(CodeMirror.$textarea.val());
var shjson = stringifyInner(textValue);
APP.patchText(shjson);
Slide.update(textValue);
if (APP.realtime.getUserDoc() !== shjson) { var mkPrintButton = function (framework, editor, $content, $print, $toolbarDrawer) {
console.error("realtime.getUserDoc() !== shjson"); var $printButton = $('<button>', {
} title: Messages.printButtonTitle,
}; 'class': 'cp-toolbar-rightside-button fa fa-print',
style: 'font-size: 17px'
}).click(function () {
Slide.update(editor.getValue(), true);
$print.html($content.html());
// TODO use translation key
Cryptpad.confirm("Are you sure you want to print?", function (yes) {
if (yes) {
window.focus();
window.print();
}
}, {ok: Messages.printButton});
framework.feedback('PRINT_SLIDES');
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.printText));
$toolbarDrawer.append($printButton);
};
var mkSlideOptionsButton = function (framework, slideOptions, $toolbarDrawer) {
var metadataMgr = framework._.cpNfInner.metadataMgr;
var updateSlideOptions = function (newOpt) { var updateSlideOptions = function (newOpt) {
if (stringify(newOpt) !== stringify(slideOptions)) { if (JSONSortify(newOpt) !== JSONSortify(slideOptions)) {
$.extend(slideOptions, newOpt); $.extend(slideOptions, newOpt);
// TODO: manage realtime + cursor in the "options" modal ?? // TODO: manage realtime + cursor in the "options" modal ??
Slide.updateOptions(); Slide.updateOptions();
@ -202,38 +129,16 @@ define([
var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata())); var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata()));
metadata.slideOptions = slideOptions; metadata.slideOptions = slideOptions;
metadataMgr.updateMetadata(metadata); metadataMgr.updateMetadata(metadata);
onLocal(); framework.localChange();
}; };
var updateColors = function (text, back) { var createPrintDialog = function (invalidStyle) {
if (text) {
textColor = text;
$modal.css('color', text);
$modal.css('border-color', text);
$('#' + SLIDE_COLOR_ID).css('color', text);
}
if (back) {
backColor = back;
$modal.css('background-color', back);
$('#' + SLIDE_BACKCOLOR_ID).css('color', back);
}
};
var updateLocalColors = function (text, back) {
updateColors(text, back);
var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata()));
if (backColor) { metadata.backColor = backColor; }
if (textColor) { metadata.color = textColor; }
metadataMgr.updateMetadata(metadata);
onLocal();
console.log(metadataMgr.getMetadata());
};
var createPrintDialog = function () {
var slideOptionsTmp = { var slideOptionsTmp = {
title: false, title: false,
slide: false, slide: false,
date: false, date: false,
transition: true, transition: true,
style: '' style: '',
styleLess: ''
}; };
$.extend(slideOptionsTmp, slideOptions); $.extend(slideOptionsTmp, slideOptions);
@ -299,14 +204,45 @@ define([
.on('keydown keyup', function (e) { .on('keydown keyup', function (e) {
e.stopPropagation(); e.stopPropagation();
}); });
$textarea.val(slideOptionsTmp.style); $textarea.val(invalidStyle || slideOptionsTmp.styleLess || slideOptionsTmp.style);
window.setTimeout(function () { $textarea.focus(); }, 0); window.setTimeout(function () { $textarea.focus(); }, 0);
var h; require(['/bower_components/less/dist/less.min.js'], function () { });
var parseLess = function (less, cb) {
require(['/bower_components/less/dist/less.min.js'], function (Less) {
Less.render(less, {}, function(err, css) {
if (err) { return void cb(err); }
cb(undefined, css.css);
}, window.less);
});
};
var h;
var todo = function () { var todo = function () {
slideOptionsTmp.style = $textarea.val(); if ($textarea.val() !== slideOptionsTmp.styleLess) {
updateLocalOptions(slideOptionsTmp); var less = slideOptionsTmp.styleLess = $textarea.val();
slideOptionsTmp.style = '';
parseLess(mkLess(less), function (err, css) {
if (err) {
console.log(err);
Cryptpad.alert(
'<strong>' + Messages.slide_invalidLess + '</strong>' +
'<br>' +
'<pre class="cp-slide-css-error">' + Util.fixHTML(
'Line: ' + (err.line - 1) + '\n' +
err.extract[err.line - 1] + '\n' +
new Array(err.column+1).join(' ') +
'^--- ' + err.message
) + '</pre>'
/*Messages.slide_badLess*/, function () {
$('body').append(createPrintDialog(less));
}, true);
} else {
slideOptionsTmp.style = css;
updateLocalOptions(slideOptionsTmp);
}
});
}
$container.remove(); $container.remove();
Cryptpad.stopListening(h); Cryptpad.stopListening(h);
}; };
@ -324,270 +260,190 @@ define([
return $container; return $container;
}; };
config.onInit = function (info) { var $slideOptions = $('<button>', {
readOnly = metadataMgr.getPrivateData().readOnly; title: Messages.slideOptionsTitle,
'class': 'cp-toolbar-rightside-button fa fa-cog',
var titleCfg = { getHeadingText: CodeMirror.getHeadingText }; style: 'font-size: 17px'
Title = common.createTitle(titleCfg, config.onLocal); }).click(function () {
Slide.setTitle(Title); $('body').append(createPrintDialog());
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.slideOptionsText));
var configTb = { $toolbarDrawer.append($slideOptions);
displayed: ['title', 'useradmin', 'spinner', 'share', 'userlist', 'newpad', 'limit'],
title: Title.getTitleConfig(), metadataMgr.onChange(function () {
metadataMgr: metadataMgr, var md = metadataMgr.getMetadata();
readOnly: readOnly, if (md.slideOptions) {
ifrw: window, updateLocalOptions(md.slideOptions);
realtime: info.realtime,
common: Cryptpad,
sfCommon: common,
$container: $bar,
$contentContainer: $contentContainer
};
toolbar = APP.toolbar = Toolbar.create(configTb);
Title.setToolbar(toolbar);
CodeMirror.init(config.onLocal, Title, toolbar);
var $rightside = toolbar.$rightside;
var $drawer = toolbar.$drawer;
/* add a history button */
var histConfig = {
onLocal: config.onLocal,
onRemote: config.onRemote,
setHistory: setHistory,
applyVal: function (val) {
var remoteDoc = JSON.parse(val || '{}').content;
editor.setValue(remoteDoc || '');
editor.save();
},
$toolbar: $bar
};
var $hist = common.createButton('history', true, {histConfig: histConfig});
$drawer.append($hist);
/* save as template */
if (!metadataMgr.getPrivateData().isTemplate) {
var templateObj = {
rt: info.realtime,
getTitle: function () { return metadataMgr.getMetadata().title; }
};
var $templateButton = common.createButton('template', true, templateObj);
$rightside.append($templateButton);
} }
});
};
/* add an export button */ var mkColorConfiguration = function (framework, $modal) {
var $export = common.createButton('export', true, {}, CodeMirror.exportText); var textColor;
$drawer.append($export); var backColor;
var metadataMgr = framework._.cpNfInner.metadataMgr;
if (!readOnly) { var updateColors = function (text, back) {
/* add an import button */ if (text) {
var $import = common.createButton('import', true, {}, CodeMirror.importText); textColor = text;
$drawer.append($import); $modal.css('color', text);
$modal.css('border-color', text);
$('#' + SLIDE_COLOR_ID).css('color', text);
} }
if (back) {
backColor = back;
$modal.css('background-color', back);
$('#' + SLIDE_BACKCOLOR_ID).css('color', back);
}
};
var updateLocalColors = function (text, back) {
updateColors(text, back);
var metadata = JSON.parse(JSON.stringify(metadataMgr.getMetadata()));
if (backColor) { metadata.backColor = backColor; }
if (textColor) { metadata.color = textColor; }
metadataMgr.updateMetadata(metadata);
framework.localChange();
console.log(metadataMgr.getMetadata());
};
/* add a forget button */ var $back = $('<button>', {
var forgetCb = function (err) { id: SLIDE_BACKCOLOR_ID,
if (err) { return; } 'class': 'fa fa-square cp-toolbar-rightside-button',
setEditable(false); 'style': 'font-family: FontAwesome; color: #000;',
}; title: Messages.backgroundButtonTitle
var $forgetPad = common.createButton('forget', true, {}, forgetCb); });
$rightside.append($forgetPad); var $text = $('<button>', {
id: SLIDE_COLOR_ID,
var $previewButton = APP.$previewButton = common.createButton(null, true); 'class': 'fa fa-i-cursor cp-toolbar-rightside-button',
$previewButton.removeClass('fa-question').addClass('fa-eye'); 'style': 'font-family: FontAwesome; font-weight: bold; color: #fff;',
$previewButton.attr('title', Messages.previewButtonTitle); title: Messages.colorButtonTitle
$previewButton.click(function () { });
var $c = $contentContainer; var $testColor = $('<input>', { type: 'color', value: '!' });
if ($c.hasClass('cp-app-slide-preview')) { var $check = $("#cp-app-slide-colorpicker");
common.setPadAttribute('previewMode', false, function (e) { if ($testColor.attr('type') !== "color" || $testColor.val() === '!') { return; }
if (e) { return console.log(e); }
}); var $backgroundPicker = $('<input>', { type: 'color', value: backColor })
$previewButton.removeClass('cp-toolbar-button-active'); .css({ display: 'none', })
return void $c.removeClass('cp-app-slide-preview'); .on('change', function() { updateLocalColors(undefined, this.value); });
} $check.append($backgroundPicker);
common.setPadAttribute('previewMode', true, function (e) { $back.on('click', function() {
if (e) { return console.log(e); } $backgroundPicker.val(backColor);
}); $backgroundPicker.click();
$c.addClass('cp-app-slide-preview'); });
$previewButton.addClass('cp-toolbar-button-active');
Slide.updateFontSize();
});
$rightside.append($previewButton);
var $printButton = $('<button>', {
title: Messages.printButtonTitle,
'class': 'cp-toolbar-rightside-button fa fa-print',
style: 'font-size: 17px'
}).click(function () {
Slide.update(editor.getValue(), true);
$print.html($content.html());
// TODO use translation key
Cryptpad.confirm("Are you sure you want to print?", function (yes) {
if (yes) {
window.focus();
window.print();
}
}, {ok: Messages.printButton});
common.feedback('PRINT_SLIDES');
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.printText));
$drawer.append($printButton);
var $slideOptions = $('<button>', {
title: Messages.slideOptionsTitle,
'class': 'cp-toolbar-rightside-button fa fa-cog',
style: 'font-size: 17px'
}).click(function () {
$('body').append(createPrintDialog());
}).append($('<span>', {'class': 'cp-toolbar-drawer-element'}).text(Messages.slideOptionsText));
$drawer.append($slideOptions);
var $present = common.createButton('present', true)
.click(function () {
enterPresentationMode(true);
});
$rightside.append($present);
var configureColors = function () {
var $back = $('<button>', {
id: SLIDE_BACKCOLOR_ID,
'class': 'fa fa-square cp-toolbar-rightside-button',
'style': 'font-family: FontAwesome; color: #000;',
title: Messages.backgroundButtonTitle
});
var $text = $('<button>', {
id: SLIDE_COLOR_ID,
'class': 'fa fa-i-cursor cp-toolbar-rightside-button',
'style': 'font-family: FontAwesome; font-weight: bold; color: #fff;',
title: Messages.colorButtonTitle
});
var $testColor = $('<input>', { type: 'color', value: '!' });
var $check = $("#cp-app-slide-colorpicker");
if ($testColor.attr('type') !== "color" || $testColor.val() === '!') { return; }
$back.on('click', function() {
var $picker = $('<input>', { type: 'color', value: backColor })
.css({ display: 'none', })
.on('change', function() {
updateLocalColors(undefined, this.value);
$check.html('');
});
$check.append($picker);
setTimeout(function() {
$picker.click();
}, 0);
});
$text.on('click', function() {
var $picker = $('<input>', { type: 'color', value: textColor })
.css({ display: 'none', })
.on('change', function() {
updateLocalColors(this.value, undefined);
$check.html('');
});
$check.append($picker);
setTimeout(function() {
$picker.click();
}, 0);
});
$rightside.append($back).append($text); var $foregroundPicker = $('<input>', { type: 'color', value: textColor })
}; .css({ display: 'none', })
configureColors(); .on('change', function() { updateLocalColors(this.value, undefined); });
$check.append($foregroundPicker);
$text.on('click', function() {
$foregroundPicker.val(textColor);
$foregroundPicker.click();
});
CodeMirror.configureTheme(); framework._.toolbar.$rightside.append($back).append($text);
if (!readOnly) { metadataMgr.onChange(function () {
var fileDialogCfg = { var md = metadataMgr.getMetadata();
onSelect: function (data) { if (md.color || md.backColor) {
if (data.type === 'file') { updateLocalColors(md.color, md.backColor);
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
editor.replaceSelection(mt);
return;
}
}
};
common.initFilePicker(fileDialogCfg);
APP.$mediaTagButton = $('<button>', {
title: Messages.filePickerButton,
'class': 'cp-toolbar-rightside-button fa fa-picture-o',
style: 'font-size: 17px'
}).click(function () {
var pickerCfg = {
types: ['file'],
where: ['root']
};
common.openFilePicker(pickerCfg);
}).appendTo($rightside);
var $tags = common.createButton('hashtag', true);
$rightside.append($tags);
} }
});
};
metadataMgr.onChange(function () { var mkFilePicker = function (framework, editor) {
var md = metadataMgr.getMetadata(); var fileDialogCfg = {
if (md.color || md.backColor) { onSelect: function (data) {
updateLocalColors(md.color, md.backColor); if (data.type === 'file') {
} var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
if (md.slideOptions) { editor.replaceSelection(mt);
updateLocalOptions(md.slideOptions); return;
} }
}); }
}; };
framework._.sfCommon.initFilePicker(fileDialogCfg);
$('<button>', {
title: Messages.filePickerButton,
'class': 'cp-toolbar-rightside-button fa fa-picture-o',
style: 'font-size: 17px'
}).click(function () {
var pickerCfg = {
types: ['file'],
where: ['root']
};
framework._.sfCommon.openFilePicker(pickerCfg);
}).appendTo(framework._.toolbar.$rightside);
config.onReady = function (info) { var $tags = framework._.sfCommon.createButton('hashtag', true);
console.log('onready'); framework._.toolbar.$rightside.append($tags);
if (APP.realtime !== info.realtime) { };
var realtime = APP.realtime = info.realtime;
APP.patchText = TextPatcher.create({
realtime: realtime,
//logging: true
});
}
var userDoc = APP.realtime.getUserDoc(); /////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
var isNew = false;
if (userDoc === "" || userDoc === "{}") { isNew = true; }
var newDoc = ""; var andThen2 = function (editor, CodeMirror, framework, isPresentMode) {
if (userDoc !== "") {
var hjson = JSON.parse(userDoc);
if (hjson && hjson.metadata) { var $contentContainer = $('#cp-app-slide-editor');
metadataMgr.updateMetadata(hjson.metadata); var $modal = $('#cp-app-slide-modal');
} var $content = $('#cp-app-slide-modal-content');
if (typeof (hjson) !== 'object' || Array.isArray(hjson) || var $print = $('#cp-app-slide-print');
(hjson.metadata && typeof(hjson.metadata.type) !== 'undefined' && var slideOptions = {};
hjson.metadata.type !== 'slide')) {
var errorText = Messages.typeError;
Cryptpad.errorLoadingScreen(errorText);
throw new Error(errorText);
}
newDoc = hjson.content; var $toolbarDrawer = framework._.toolbar.$drawer;
if (hjson.highlightMode) { $content.click(function (e) {
CodeMirror.setMode(hjson.highlightMode); if (!e.target) { return; }
} var $t = $(e.target);
} else { if ($t.is('a') || $t.parents('a').length) {
Title.updateTitle(Cryptpad.initialName || Title.defaultTitle); e.preventDefault();
var $a = $t.is('a') ? $t : $t.parents('a').first();
var href = $a.attr('href');
window.open(href);
} }
});
if (!CodeMirror.highlightMode) { Slide.setModal(framework._.sfCommon, $modal, $content, slideOptions, Messages.slideInitialState);
CodeMirror.setMode('markdown'); mkPrintButton(framework, editor, $content, $print, $toolbarDrawer);
} mkSlideOptionsButton(framework, slideOptions, $toolbarDrawer);
mkColorConfiguration(framework, $modal);
mkFilePicker(framework, editor);
mkSlidePreviewPane(framework, $contentContainer);
editor.setValue(newDoc || initialState); CodeMirror.configureTheme();
if (Cryptpad.initialName && Title.isDefaultTitle()) { var enterPresentationMode = function (shouldLog) {
Title.updateTitle(Cryptpad.initialName); Slide.show(true, editor.getValue());
if (shouldLog) {
Cryptpad.log(Messages.presentSuccess);
} }
};
common.getPadAttribute('previewMode', function (e, data) { if (isPresentMode) { enterPresentationMode(true); }
if (e) { return void console.error(e); }
if (data !== false && APP.$previewButton) { framework.onContentUpdate(function (newContent) {
APP.$previewButton.click(); CodeMirror.contentUpdate(newContent);
} Slide.update(newContent.content);
}); });
framework.setContentGetter(function () {
console.log(framework._.title.title);
var content = CodeMirror.getContent();
Slide.update(content.content);
return content;
});
framework.onEditableChange(function () {
editor.setOption('readOnly', framework.isLocked() || framework.isReadOnly());
});
framework.setTitleRecommender(function () {
console.log('titleRecommender');
return CodeMirror.getHeadingText();
});
framework.onReady(function (/*newPad*/) {
CodeMirror.setMode('markdown', function () { });
Slide.onChange(function (o, n, l) { Slide.onChange(function (o, n, l) {
var slideNumber = ''; var slideNumber = '';
if (n !== null) { if (n !== null) {
@ -595,153 +451,58 @@ define([
slideNumber = ' (' + (++n) + '/' + l + ')'; slideNumber = ' (' + (++n) + '/' + l + ')';
} }
} }
common.setTabTitle('{title}' + slideNumber); framework._.sfCommon.setTabTitle('{title}' + slideNumber);
}); });
setEditable(!readOnly);
initializing = false;
onLocal(); // push local state to avoid parse errors later.
Slide.update(editor.getValue()); Slide.update(editor.getValue());
Cryptpad.removeLoadingScreen(); });
if (readOnly) {
config.onRemote();
return;
}
if (isNew) {
common.openTemplatePicker();
}
var fmConfig = {
dropArea: $('.CodeMirror'),
body: $('body'),
onUploaded: function (ev, data) {
var parsed = Cryptpad.parsePadUrl(data.url);
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);
}
};
APP.FM = common.createFileManager(fmConfig);
};
config.onRemote = function () {
if (initializing) { return; }
if (isHistoryMode) { return; }
var oldDoc = canonicalize(CodeMirror.$textarea.val());
var shjson = APP.realtime.getUserDoc();
var hjson = JSON.parse(shjson);
var remoteDoc = hjson.content;
if (hjson.metadata) {
metadataMgr.updateMetadata(hjson.metadata);
}
var highlightMode = hjson.highlightMode;
if (highlightMode && highlightMode !== APP.highlightMode) {
CodeMirror.setMode(highlightMode);
}
CodeMirror.setValueAndCursor(oldDoc, remoteDoc, TextPatcher);
if (!readOnly) {
var textValue = canonicalize(CodeMirror.$textarea.val());
var shjson2 = stringifyInner(textValue);
if (shjson2 !== shjson) {
console.error("shjson2 !== shjson");
TextPatcher.log(shjson, TextPatcher.diff(shjson, shjson2));
APP.patchText(shjson2);
}
}
Slide.update(remoteDoc);
if (oldDoc !== remoteDoc) { common.notify(); }
};
config.onAbort = function () {
// inform of network disconnect
setEditable(false);
toolbar.failed();
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
};
config.onConnectionChange = function (info) {
setEditable(info.state);
//toolbar.failed();
if (info.state) {
initializing = true;
//toolbar.reconnecting(info.myId);
Cryptpad.findOKButton().click();
} else {
Cryptpad.alert(Messages.common_connectionLost, undefined, true);
}
};
config.onError = onConnectError; framework.onDefaultContentNeeded(function () {
CodeMirror.contentUpdate({ content: Messages.slideInitialState });
});
cpNfInner = common.startRealtime(config); Slide.setTitle(framework._.title);
metadataMgr = cpNfInner.metadataMgr;
cpNfInner.onInfiniteSpinner(function () { framework._.toolbar.$rightside.append(
setEditable(false); framework._.sfCommon.createButton('present', true).click(function () {
Cryptpad.confirm(Messages.realtime_unrecoverableError, function (yes) { enterPresentationMode(true);
if (!yes) { return; } })
common.gotoURL(); );
});
});
editor.on('change', onLocal); editor.on('change', framework.localChange);
Cryptpad.onLogout(function () { setEditable(false); }); framework.start();
}; };
var CMEDITOR_CHECK_INTERVAL = 100;
var cmEditorAvailable = function (cb) {
var intr;
var check = function () {
if (window.CodeMirror) {
clearTimeout(intr);
cb(window.CodeMirror);
}
};
intr = setInterval(function () {
console.log("CodeMirror was not defined. Trying again in %sms", CMEDITOR_CHECK_INTERVAL);
check();
}, CMEDITOR_CHECK_INTERVAL);
check();
};
var main = function () { var main = function () {
var CM;
var CodeMirror; var CodeMirror;
var editor; var editor;
var common; var common;
var framework;
nThen(function (waitFor) { nThen(function (waitFor) {
cmEditorAvailable(waitFor(function (cm) {
CM = cm; Framework.create({
})); toolbarContainer: '#cme_toolbox',
$(waitFor(function () { contentContainer: '#cp-app-slide-editor'
Cryptpad.addLoadingScreen(); }, waitFor(function (fw) { framework = fw; }));
}));
SFCommon.create(waitFor(function (c) { APP.common = common = c; })); nThen(function (waitFor) {
$(waitFor());
// TODO(cjd): This is crap but we cannot bring up codemirror until after
// the CryptPad Common is up and we can't bring up framework
// without codemirror.
SFCommon.create(waitFor(function (c) { common = c; }));
}).nThen(function () {
CodeMirror = common.initCodeMirrorApp(null, CMeditor);
$('.CodeMirror').addClass('fullPage');
editor = CodeMirror.editor;
}).nThen(waitFor());
}).nThen(function (waitFor) {
common.getSframeChannel().onReady(waitFor());
}).nThen(function (/*waitFor*/) { }).nThen(function (/*waitFor*/) {
CodeMirror = common.initCodeMirrorApp(null, CM); common.isPresentUrl(function (err, val) {
$('.CodeMirror').addClass('fullPage'); andThen2(editor, CodeMirror, framework, val);
editor = CodeMirror.editor;
Cryptpad.onError(function (info) {
if (info && info.type === "store") {
onConnectError();
}
});
common.getSframeChannel().onReady(function () {
common.isPresentUrl(function (err, val) {
isPresentMode = val;
andThen(editor, CodeMirror, common);
});
}); });
}); });
}; };

@ -1,41 +0,0 @@
// Load #1, load as little as possible because we are in a race to get the loading screen up.
define([
'/bower_components/nthen/index.js',
'/api/config',
'jquery',
'/common/requireconfig.js',
'/common/sframe-common-outer.js'
], function (nThen, ApiConfig, $, RequireConfig, SFCommonO) {
var requireConfig = RequireConfig();
// Loaded in load #2
nThen(function (waitFor) {
$(waitFor());
}).nThen(function (waitFor) {
var req = {
cfg: requireConfig,
req: [ '/common/loading.js' ],
pfx: window.location.origin
};
window.rc = requireConfig;
window.apiconf = ApiConfig;
$('#sbox-iframe').attr('src',
ApiConfig.httpSafeOrigin + '/slide/inner.html?' + requireConfig.urlArgs +
'#' + encodeURIComponent(JSON.stringify(req)));
// This is a cheap trick to avoid loading sframe-channel in parallel with the
// loading screen setup.
var done = waitFor();
var onMsg = function (msg) {
var data = JSON.parse(msg.data);
if (data.q !== 'READY') { return; }
window.removeEventListener('message', onMsg);
var _done = done;
done = function () { };
_done();
};
window.addEventListener('message', onMsg);
}).nThen(function (/*waitFor*/) {
SFCommonO.start();
});
});

@ -58,12 +58,6 @@ define([
// $print.css('font-size', (20*9/16)+'vw'); // $print.css('font-size', (20*9/16)+'vw');
}; };
var fixCSS = function (css) {
var append = '.cp #cp-app-slide-print .cp-app-slide-frame ';
var append2 = '.cp div#cp-app-slide-modal #cp-app-slide-modal-content .cp-app-slide-frame ';
return css.replace(/(\n*)([^\n}]+)\s*\{/g, '$1' + append + '$2,' + append2 + '$2 {');
};
var goTo = Slide.goTo = function (i) { var goTo = Slide.goTo = function (i) {
i = i || 0; i = i || 0;
Slide.index = i; Slide.index = i;
@ -87,8 +81,8 @@ define([
var length = getNumberOfSlides(); var length = getNumberOfSlides();
$modal.find('style.cp-app-slide-style').remove(); $modal.find('style.cp-app-slide-style').remove();
if (options.style && Slide.shown) { if (options.style) {
$modal.prepend($('<style>', {'class': 'cp-app-slide-style'}).text(fixCSS(options.style))); $modal.prepend($('<style>', {'class': 'cp-app-slide-style'}).text(options.style));
} }
$content.find('.cp-app-slide-frame').each(function (i, el) { $content.find('.cp-app-slide-frame').each(function (i, el) {
if (options.slide) { if (options.slide) {

Loading…
Cancel
Save