Standardize media-tag embedder and make media tags always absolute URL, Standardize import/export logic for codemirror apps, fix arrow key navigation in presentation fullscreen mode before first click.
This commit is contained in:
parent
94d2f4472b
commit
d6570ad9f2
@ -204,6 +204,20 @@ define([
|
|||||||
updateIndentSettings();
|
updateIndentSettings();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var mkFilePicker = function (framework, editor, evModeChange) {
|
||||||
|
evModeChange.reg(function (mode) {
|
||||||
|
if (MEDIA_TAG_MODES.indexOf(mode) !== -1) {
|
||||||
|
// Embedding is endabled
|
||||||
|
framework.setMediaTagEmbedder(function (mt) {
|
||||||
|
editor.replaceSelection($(mt)[0].outerHTML);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Embedding is disabled
|
||||||
|
framework.setMediaTagEmbedder();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -211,7 +225,6 @@ define([
|
|||||||
|
|
||||||
var andThen2 = function (editor, CodeMirror, framework) {
|
var andThen2 = function (editor, CodeMirror, framework) {
|
||||||
|
|
||||||
var $toolbarContainer = $('#cme_toolbox');
|
|
||||||
var common = framework._.sfCommon;
|
var common = framework._.sfCommon;
|
||||||
|
|
||||||
var previewPane = mkPreviewPane(editor, CodeMirror, framework);
|
var previewPane = mkPreviewPane(editor, CodeMirror, framework);
|
||||||
@ -220,37 +233,7 @@ define([
|
|||||||
|
|
||||||
mkIndentSettings(editor, framework._.cpNfInner.metadataMgr);
|
mkIndentSettings(editor, framework._.cpNfInner.metadataMgr);
|
||||||
CodeMirror.init(framework.localChange, framework._.title, framework._.toolbar);
|
CodeMirror.init(framework.localChange, framework._.title, framework._.toolbar);
|
||||||
|
mkFilePicker(framework, editor, evModeChange);
|
||||||
if (!framework.isReadOnly()) {
|
|
||||||
var fileDialogCfg = {
|
|
||||||
onSelect: function (data) {
|
|
||||||
if (data.type === 'file') {
|
|
||||||
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
|
||||||
editor.replaceSelection(mt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
common.initFilePicker(fileDialogCfg);
|
|
||||||
var $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(framework._.toolbar.$rightside);
|
|
||||||
evModeChange.reg(function (mode) {
|
|
||||||
if (MEDIA_TAG_MODES.indexOf(mode) !== -1) {
|
|
||||||
$($mediaTagButton).show();
|
|
||||||
} else {
|
|
||||||
$($mediaTagButton).hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!framework.isReadOnly()) {
|
if (!framework.isReadOnly()) {
|
||||||
CodeMirror.configureTheme(function () {
|
CodeMirror.configureTheme(function () {
|
||||||
@ -311,37 +294,8 @@ define([
|
|||||||
editor.setValue(Messages.codeInitialState);
|
editor.setValue(Messages.codeInitialState);
|
||||||
});
|
});
|
||||||
|
|
||||||
framework.setFileExporter(
|
framework.setFileExporter(CodeMirror.getContentExtension, CodeMirror.fileExporter);
|
||||||
function () {
|
framework.setFileImporter({}, CodeMirror.fileImporter);
|
||||||
return (Modes.extensionOf(CodeMirror.highlightMode) || '.txt').slice(1);
|
|
||||||
},
|
|
||||||
function () {
|
|
||||||
return new Blob([ editor.getValue() ], { type: 'text/plain;charset=utf-8' });
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
framework.setFileImporter({}, function (content, file) {
|
|
||||||
var mime = CodeMirror.findModeByMIME(file.type);
|
|
||||||
var mode;
|
|
||||||
if (!mime) {
|
|
||||||
var ext = /.+\.([^.]+)$/.exec(file.name);
|
|
||||||
if (ext[1]) {
|
|
||||||
mode = CMeditor.findModeByExtension(ext[1]);
|
|
||||||
mode = mode && mode.mode || null;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mode = mime && mime.mode || null;
|
|
||||||
}
|
|
||||||
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
|
||||||
CodeMirror.setMode(mode);
|
|
||||||
$toolbarContainer.find('#language-mode').val(mode);
|
|
||||||
} else {
|
|
||||||
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
|
||||||
CodeMirror.setMode('text');
|
|
||||||
$toolbarContainer.find('#language-mode').val('text');
|
|
||||||
}
|
|
||||||
return content;
|
|
||||||
});
|
|
||||||
|
|
||||||
framework.setNormalizer(function (c) {
|
framework.setNormalizer(function (c) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -52,6 +52,9 @@ define([
|
|||||||
|
|
||||||
var evStart = Util.mkEvent(true);
|
var evStart = Util.mkEvent(true);
|
||||||
|
|
||||||
|
var mediaTagEmbedder;
|
||||||
|
var $embedButton;
|
||||||
|
|
||||||
var common;
|
var common;
|
||||||
var cpNfInner;
|
var cpNfInner;
|
||||||
var textPatcher;
|
var textPatcher;
|
||||||
@ -302,6 +305,42 @@ define([
|
|||||||
common.feedback(action, force);
|
common.feedback(action, force);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var createFilePicker = function () {
|
||||||
|
common.initFilePicker({
|
||||||
|
onSelect: function (data) {
|
||||||
|
if (data.type !== 'file') {
|
||||||
|
console.log("Unexpected data type picked " + data.type);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mediaTagEmbedder) { console.log('mediaTagEmbedder missing'); return; }
|
||||||
|
if (data.type !== 'file') { console.log('unhandled embed type ' + data.type); return; }
|
||||||
|
var privateDat = cpNfInner.metadataMgr.getPrivateData();
|
||||||
|
var origin = privateDat.fileHost || privateDat.origin;
|
||||||
|
var src = origin + data.src;
|
||||||
|
mediaTagEmbedder($('<media-tag src="' + src +
|
||||||
|
'" data-crypto-key="cryptpad:' + data.key + '"></media-tag>'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$embedButton = $('<button>', {
|
||||||
|
title: Messages.filePickerButton,
|
||||||
|
'class': 'cp-toolbar-rightside-button fa fa-picture-o',
|
||||||
|
style: 'font-size: 17px'
|
||||||
|
}).click(function () {
|
||||||
|
common.openFilePicker({
|
||||||
|
types: ['file'],
|
||||||
|
where: ['root']
|
||||||
|
});
|
||||||
|
}).appendTo(toolbar.$rightside).hide();
|
||||||
|
};
|
||||||
|
var setMediaTagEmbedder = function (mte) {
|
||||||
|
if (!mte || readOnly) {
|
||||||
|
$embedButton.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$embedButton.show();
|
||||||
|
mediaTagEmbedder = mte;
|
||||||
|
};
|
||||||
|
|
||||||
nThen(function (waitFor) {
|
nThen(function (waitFor) {
|
||||||
Cryptpad.addLoadingScreen();
|
Cryptpad.addLoadingScreen();
|
||||||
SFCommon.create(waitFor(function (c) { common = c; }));
|
SFCommon.create(waitFor(function (c) { common = c; }));
|
||||||
@ -424,6 +463,8 @@ define([
|
|||||||
var $tags = common.createButton('hashtag', true);
|
var $tags = common.createButton('hashtag', true);
|
||||||
toolbar.$rightside.append($tags);
|
toolbar.$rightside.append($tags);
|
||||||
|
|
||||||
|
createFilePicker();
|
||||||
|
|
||||||
cb(Object.freeze({
|
cb(Object.freeze({
|
||||||
// Register an event to be informed of a content update coming from remote
|
// Register an event to be informed of a content update coming from remote
|
||||||
// This event will pass you the object.
|
// This event will pass you the object.
|
||||||
@ -475,6 +516,12 @@ define([
|
|||||||
// such as removing extra fields.
|
// such as removing extra fields.
|
||||||
setNormalizer: function (n) { normalize0 = n; },
|
setNormalizer: function (n) { normalize0 = n; },
|
||||||
|
|
||||||
|
// Set a function which should take a jquery element which is a media tag and place
|
||||||
|
// it in the document. If this is not called then there will be no embed button,
|
||||||
|
// if this is called a second time with a null function, it will remove the embed
|
||||||
|
// button from the toolbar.
|
||||||
|
setMediaTagEmbedder: setMediaTagEmbedder,
|
||||||
|
|
||||||
// Call the CryptPad feedback API.
|
// Call the CryptPad feedback API.
|
||||||
feedback: feedback,
|
feedback: feedback,
|
||||||
|
|
||||||
|
|||||||
@ -211,26 +211,18 @@ define([
|
|||||||
Common.getAttribute(themeKey, todo);
|
Common.getAttribute(themeKey, todo);
|
||||||
};
|
};
|
||||||
|
|
||||||
exp.exportText = function () {
|
exp.getContentExtension = function () {
|
||||||
var text = editor.getValue();
|
console.log(Modes.extensionOf(exp.highlightMode));
|
||||||
|
console.log(exp.highlightMode);
|
||||||
var ext = Modes.extensionOf(exp.highlightMode);
|
return (Modes.extensionOf(exp.highlightMode) || '.txt').slice(1);
|
||||||
|
|
||||||
var title = Cryptpad.fixFileName(Title ? Title.suggestTitle('cryptpad') : "?") + (ext || '.txt');
|
|
||||||
|
|
||||||
Cryptpad.prompt(Messages.exportPrompt, title, function (filename) {
|
|
||||||
if (filename === null) { return; }
|
|
||||||
var blob = new Blob([text], {
|
|
||||||
type: 'text/plain;charset=utf-8'
|
|
||||||
});
|
|
||||||
saveAs(blob, filename);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
exp.importText = function (content, file) {
|
exp.fileExporter = function () {
|
||||||
var $bar = $('#cme_toolbox');
|
return new Blob([ editor.getValue() ], { type: 'text/plain;charset=utf-8' });
|
||||||
var mode;
|
};
|
||||||
|
exp.fileImporter = function (content, file) {
|
||||||
|
var $toolbarContainer = $('#cme_toolbox');
|
||||||
var mime = CodeMirror.findModeByMIME(file.type);
|
var mime = CodeMirror.findModeByMIME(file.type);
|
||||||
|
var mode;
|
||||||
if (!mime) {
|
if (!mime) {
|
||||||
var ext = /.+\.([^.]+)$/.exec(file.name);
|
var ext = /.+\.([^.]+)$/.exec(file.name);
|
||||||
if (ext[1]) {
|
if (ext[1]) {
|
||||||
@ -240,18 +232,15 @@ define([
|
|||||||
} else {
|
} else {
|
||||||
mode = mime && mime.mode || null;
|
mode = mime && mime.mode || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
if (mode && Modes.list.some(function (o) { return o.mode === mode; })) {
|
||||||
setMode(mode);
|
exp.setMode(mode);
|
||||||
$bar.find('#language-mode').val(mode);
|
$toolbarContainer.find('#language-mode').val(mode);
|
||||||
} else {
|
} else {
|
||||||
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
console.log("Couldn't find a suitable highlighting mode: %s", mode);
|
||||||
setMode('text');
|
exp.setMode('text');
|
||||||
$bar.find('#language-mode').val('text');
|
$toolbarContainer.find('#language-mode').val('text');
|
||||||
}
|
}
|
||||||
|
return { content: content };
|
||||||
editor.setValue(content);
|
|
||||||
onLocal();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var cursorToPos = function(cursor, oldText) {
|
var cursorToPos = function(cursor, oldText) {
|
||||||
|
|||||||
@ -363,35 +363,11 @@ define([
|
|||||||
if (href) { ifrWindow.open(bounceHref, '_blank'); }
|
if (href) { ifrWindow.open(bounceHref, '_blank'); }
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!framework.isReadOnly()) {
|
framework.setMediaTagEmbedder(function ($mt) {
|
||||||
framework.onEditableChange(function () {
|
$mt.attr('contenteditable', 'false');
|
||||||
var locked = framework.isLocked();
|
$mt.attr('tabindex', '1');
|
||||||
$(inner).css({ 'background-color': ((locked) ? '#aaa' : '') });
|
editor.insertElement(new window.CKEDITOR.dom.element($mt[0]));
|
||||||
inner.setAttribute('contenteditable', !locked);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
var fileDialogCfg = {
|
|
||||||
onSelect: function (data) {
|
|
||||||
if (data.type === 'file') {
|
|
||||||
var mt = '<media-tag contenteditable="false" src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '" tabindex="1"></media-tag>';
|
|
||||||
editor.insertElement(window.CKEDITOR.dom.element.createFromHtml(mt));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
framework._.sfCommon.initFilePicker(fileDialogCfg);
|
|
||||||
window.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']
|
|
||||||
};
|
|
||||||
framework._.sfCommon.openFilePicker(pickerCfg);
|
|
||||||
}).appendTo(framework._.toolbar.$rightside);
|
|
||||||
}
|
|
||||||
|
|
||||||
framework.setTitleRecommender(function () {
|
framework.setTitleRecommender(function () {
|
||||||
var text;
|
var text;
|
||||||
|
|||||||
@ -241,6 +241,8 @@ define([
|
|||||||
updateLocalOptions(slideOptionsTmp);
|
updateLocalOptions(slideOptionsTmp);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
updateLocalOptions(slideOptionsTmp);
|
||||||
}
|
}
|
||||||
$container.remove();
|
$container.remove();
|
||||||
Cryptpad.stopListening(h);
|
Cryptpad.stopListening(h);
|
||||||
@ -348,32 +350,24 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
var mkFilePicker = function (framework, editor) {
|
var mkFilePicker = function (framework, editor) {
|
||||||
var fileDialogCfg = {
|
framework.setMediaTagEmbedder(function (mt) {
|
||||||
onSelect: function (data) {
|
editor.replaceSelection($(mt)[0].outerHTML);
|
||||||
if (data.type === 'file') {
|
});
|
||||||
var mt = '<media-tag src="' + data.src + '" data-crypto-key="cryptpad:' + data.key + '"></media-tag>';
|
|
||||||
editor.replaceSelection(mt);
|
|
||||||
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);
|
|
||||||
|
|
||||||
var $tags = framework._.sfCommon.createButton('hashtag', true);
|
|
||||||
framework._.toolbar.$rightside.append($tags);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var activateLinks = function ($content) {
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@ -390,17 +384,7 @@ define([
|
|||||||
|
|
||||||
var $toolbarDrawer = framework._.toolbar.$drawer;
|
var $toolbarDrawer = framework._.toolbar.$drawer;
|
||||||
|
|
||||||
$content.click(function (e) {
|
activateLinks($content);
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Slide.setModal(framework._.sfCommon, $modal, $content, slideOptions, Messages.slideInitialState);
|
Slide.setModal(framework._.sfCommon, $modal, $content, slideOptions, Messages.slideInitialState);
|
||||||
mkPrintButton(framework, editor, $content, $print, $toolbarDrawer);
|
mkPrintButton(framework, editor, $content, $print, $toolbarDrawer);
|
||||||
mkSlideOptionsButton(framework, slideOptions, $toolbarDrawer);
|
mkSlideOptionsButton(framework, slideOptions, $toolbarDrawer);
|
||||||
@ -410,10 +394,6 @@ define([
|
|||||||
|
|
||||||
CodeMirror.configureTheme();
|
CodeMirror.configureTheme();
|
||||||
|
|
||||||
var enterPresentationMode = function () { Slide.show(true, editor.getValue()); };
|
|
||||||
|
|
||||||
if (isPresentMode) { enterPresentationMode(); }
|
|
||||||
|
|
||||||
framework.onContentUpdate(function (newContent) {
|
framework.onContentUpdate(function (newContent) {
|
||||||
CodeMirror.contentUpdate(newContent);
|
CodeMirror.contentUpdate(newContent);
|
||||||
Slide.update(newContent.content);
|
Slide.update(newContent.content);
|
||||||
@ -455,12 +435,17 @@ define([
|
|||||||
|
|
||||||
Slide.setTitle(framework._.title);
|
Slide.setTitle(framework._.title);
|
||||||
|
|
||||||
|
var enterPresentationMode = function () { Slide.show(true, editor.getValue()); };
|
||||||
framework._.toolbar.$rightside.append(
|
framework._.toolbar.$rightside.append(
|
||||||
framework._.sfCommon.createButton('present', true).click(enterPresentationMode)
|
framework._.sfCommon.createButton('present', true).click(enterPresentationMode)
|
||||||
);
|
);
|
||||||
|
if (isPresentMode) { enterPresentationMode(); }
|
||||||
|
|
||||||
editor.on('change', framework.localChange);
|
editor.on('change', framework.localChange);
|
||||||
|
|
||||||
|
framework.setFileExporter(CodeMirror.getContentExtension, CodeMirror.fileExporter);
|
||||||
|
framework.setFileImporter({}, CodeMirror.fileImporter);
|
||||||
|
|
||||||
framework.start();
|
framework.start();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -115,7 +115,10 @@ define([
|
|||||||
Slide.update(content);
|
Slide.update(content);
|
||||||
Slide.draw(Slide.index);
|
Slide.draw(Slide.index);
|
||||||
$modal.addClass('cp-app-slide-shown');
|
$modal.addClass('cp-app-slide-shown');
|
||||||
|
|
||||||
|
$('textarea').blur();
|
||||||
$(ifrw).focus();
|
$(ifrw).focus();
|
||||||
|
|
||||||
change(null, Slide.index);
|
change(null, Slide.index);
|
||||||
Common.setPresentUrl(true);
|
Common.setPresentUrl(true);
|
||||||
$('.cp-app-slide-present-button').hide();
|
$('.cp-app-slide-present-button').hide();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user