Use CodeMirror in /slide #2

Fix title errors in the slide app caused by the present mode
This commit is contained in:
yflory 2016-10-03 14:21:39 +02:00
parent 8c33218ceb
commit 391728ee6d
9 changed files with 98 additions and 33 deletions

View file

@ -79,7 +79,7 @@ define(['/customize/languageSelector.js',
'---',
'\n',
'# How to use\n',
'1. Write your slides content using the markdown syntax\n',
'1. Write your slides content using markdown syntax\n',
'2. Separate your slides with ---\n',
'3. Click on the "Play" button to see the result'
].join('');

View file

@ -67,6 +67,8 @@ define(function () {
out.presentButton = 'PRÉSENTER';
out.presentButtonTitle = "Entrer en mode présentation";
out.presentSuccess = 'Appuyer sur Échap pour quitter le mode présentation';
out.sourceButton = 'VOIR LA SOURCE';
out.sourceButtonTitle = "Quitter le mode présentation";
out.commitButton = 'VALIDER';

View file

@ -68,6 +68,8 @@ define(function () {
out.presentButton = 'PRESENT';
out.presentButtonTitle = "Enter presentation mode";
out.presentSuccess = 'Hit ESC to exit presentation mode';
out.sourceButton = 'VIEW SOURCE';
out.sourceButtonTitle = "Leave presentation mode";
out.commitButton = 'COMMIT';

View file

@ -9,8 +9,8 @@ define([
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/code/modes.js',
'/code/themes.js',
'/common/modes.js',
'/common/themes.js',
'/common/visible.js',
'/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js',
@ -80,7 +80,7 @@ define([
editor.setValue(Messages.codeInitialState); // HERE
var setTheme = module.setTheme = (function () {
var path = './theme/';
var path = '/common/theme/';
var $head = $(ifrw.document.head);

View file

@ -661,11 +661,18 @@ define([
case 'present':
button = $('<button>', {
title: Messages.presentButton + '\n' + Messages.presentButtonTitle,
'class': "fa fa-play-circle",
'class': "fa fa-play-circle cryptpad-present-button", // class used in slide.js
style: 'font:'+size+' FontAwesome'
});
break;
default:
case 'source':
button = $('<button>', {
title: Messages.sourceButton + '\n' + Messages.sourceButtonTitle,
'class': "fa fa-stop-circle cryptpad-source-button", // class used in slide.js
style: 'font:'+size+' FontAwesome'
});
break;
default:
button = $('<button>', {
'class': "fa fa-question",
style: 'font:'+size+' FontAwesome'

View file

@ -32,6 +32,10 @@
padding:0;
overflow:hidden;
}
#pad-iframe.fullscreen {
top: 0px;
height: 100% !important;
}
</style>
</head>
<body>

View file

@ -72,7 +72,7 @@
#modal.shown {
display: block;
position: fixed;
top: 25px;
top: 0px;
left: 0px;
z-index: 100;
background-color: black;

View file

@ -9,8 +9,8 @@ define([
'json.sortify',
'/bower_components/chainpad-json-validator/json-ot.js',
'/common/cryptpad-common.js',
'/code/modes.js',
'/code/themes.js',
'/common/modes.js',
'/common/themes.js',
'/common/visible.js',
'/common/notify.js',
'/slide/slide.js',
@ -38,15 +38,26 @@ define([
return JSONSortify(obj);
};
var setTabTitle = function () {
var slideNumber = '';
if (Slide.index && Slide.content.length) {
slideNumber = ' (' + Slide.index + '/' + Slide.content.length + ')';
}
document.title = APP.title + slideNumber;
};
$(function () {
var toolbar;
var secret = Cryptpad.getSecrets();
var readOnly = secret.keys && !secret.keys.editKeyStr;
Slide.readOnly = readOnly;
if (!secret.keys) {
secret.keys = secret.key;
}
var presentMode = Slide.isPresentURL();
var andThen = function (CMeditor) {
var CodeMirror = module.CodeMirror = CMeditor;
CodeMirror.modeURL = "/bower_components/codemirror/mode/%N/%N.js";
@ -85,7 +96,7 @@ define([
editor.setValue(Messages.slideInitialState); // HERE
var setTheme = module.setTheme = (function () {
var path = './theme/';
var path = '/common/theme/';
var $head = $(ifrw.document.head);
@ -116,7 +127,7 @@ define([
var $modal = $pad.contents().find('#modal');
var $content = $pad.contents().find('#content');
Slide.setModal($modal, $content);
Slide.setModal($modal, $content, $pad);
var enterPresentationMode = function (shouldLog) {
Slide.show(true, $textarea.val());
@ -124,9 +135,12 @@ define([
Cryptpad.log(Messages.presentSuccess);
}
};
var leavePresentationMode = function () {
Slide.show(false);
};
if (readOnly) {
enterPresentationMode(false);
if (presentMode) {
enterPresentationMode(true);
}
var setEditable = module.setEditable = function (bool) {
@ -180,7 +194,7 @@ define([
// append the userlist to the hyperjson structure
obj.metadata = {
users: userList,
title: document.title
title: APP.title
};
// stringify the json and send it into chainpad
@ -244,10 +258,10 @@ define([
var parsed = Cryptpad.parsePadUrl(window.location.href);
var name = Cryptpad.getDefaultName(parsed, []);
if (document.title.slice(0, name.length) === name) {
return getHeadingText() || document.title;
if (APP.title.slice(0, name.length) === name) {
return getHeadingText() || APP.title;
} else {
return document.title || getHeadingText() || name;
return APP.title || getHeadingText() || name;
}
};
@ -358,7 +372,8 @@ define([
console.log(err);
return;
}
document.title = APP.title = title;
APP.title = title;
setTabTitle();
onLocal();
});
});
@ -379,7 +394,8 @@ define([
return;
}
var parsed = Cryptpad.parsePadUrl(href);
document.title = APP.title = Cryptpad.getDefaultName(parsed, []);
APP.title = Cryptpad.getDefaultName(parsed, []);
setTabTitle();
});
});
});
@ -390,7 +406,7 @@ define([
var $links = Cryptpad.createButton('readonly', true)
.click(function () {
var baseUrl = window.location.origin + window.location.pathname + '#';
var url = baseUrl + viewHash;
var url = baseUrl + viewHash + '/present';
var content = '<b>' + Messages.readonlyUrl + '</b><br><a href="' + url + '" target="_blank" rel="noopener noreferrer">' + url + '</a><br>';
Cryptpad.alert(content);
});
@ -398,11 +414,21 @@ define([
}
var $present = Cryptpad.createButton('present', true)
.click(function () {
.click(function () {
enterPresentationMode(true);
});
if (presentMode) {
$present.hide();
}
$rightside.append($present);
var $leavePresent = Cryptpad.createButton('source', true)
.click(leavePresentationMode);
if (!presentMode) {
$leavePresent.hide();
}
$rightside.append($leavePresent);
$language = $('<span>', {
'style': "margin-right: 10px;"
}).text(Messages.type.slide + " (Markdown)");
@ -441,12 +467,14 @@ define([
});
};
if (!readOnly) {
configureTheme();
configureTheme();
if (presentMode) {
$('#top-bar').hide();
}
// set the hash
if (!readOnly) {
if (!window.location.hash || window.location.hash === '#') {
window.location.hash = editHash;
}
@ -468,15 +496,17 @@ define([
};
var updateTitle = function (newTitle) {
if (newTitle === document.title) { return; }
if (newTitle === APP.title) { return; }
// Change the title now, and set it back to the old value if there is an error
var oldTitle = document.title;
document.title = newTitle;
var oldTitle = APP.title;
APP.title = newTitle;
setTabTitle();
Cryptpad.setPadTitle(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
APP.title = oldTitle;
setTabTitle();
return;
}
});
@ -655,7 +685,7 @@ define([
content: localDoc,
metadata: {
users: userList,
title: document.title
title: APP.title
},
highlightMode: highlightMode,
};

View file

@ -17,9 +17,11 @@ define([
var ifrw = $('#pad-iframe')[0].contentWindow;
var $modal;
var $content;
Slide.setModal = function ($m, $c) {
var $pad;
Slide.setModal = function ($m, $c, $p) {
$modal = Slide.$modal = $m;
$content = Slide.$content = $c;
$pad = Slide.$pad = $p;
};
Slide.onChange = function (f) {
@ -110,16 +112,36 @@ define([
change(Slide.lastIndex, Slide.index);
};
var isPresentURL = Slide.isPresentURL = function () {
var hash = window.location.hash;
// Present mode has /present at the end of the hash
var urlLastFragment = hash.slice(hash.lastIndexOf('/')+1);
return urlLastFragment === "present";
};
var show = Slide.show = function (bool, content) {
Slide.shown = bool;
if (bool) {
Slide.update(content);
Slide.draw(Slide.index);
$modal.addClass('shown');
$(ifrw).focus();
change(null, Slide.index);
if (!isPresentURL()) {
window.location.hash += '/present';
}
$pad.contents().find('.cryptpad-present-button').hide();
$pad.contents().find('.cryptpad-source-button').show();
$pad.addClass('fullscreen');
$('.top-bar').hide();
return;
}
window.location.hash = window.location.hash.replace(/\/present$/, '');
change(Slide.index, null);
$pad.contents().find('.cryptpad-present-button').show();
$pad.contents().find('.cryptpad-source-button').hide();
$pad.removeClass('fullscreen');
$('.top-bar').show();
$modal.removeClass('shown');
};
@ -161,9 +183,7 @@ define([
Slide.right();
break;
case 27: // esc
if (!Slide.readOnly) {
show(false);
}
show(false);
break;
default:
console.log(e.which);