diff --git a/customize.dist/translations/messages.fr.js b/customize.dist/translations/messages.fr.js index 4c5ba9fc9..e4e6befbd 100644 --- a/customize.dist/translations/messages.fr.js +++ b/customize.dist/translations/messages.fr.js @@ -132,6 +132,11 @@ define(function () { out.printCSS = "Personnaliser l'apparence (CSS):"; out.printTransition = "Activer les animations de transition"; + out.filePickerButton = "Intégrer un fichier"; + out.filePicker_close = "Fermer"; + out.filePicker_description = "Choisissez un fichier de votre CryptDrive pour l'intégrer"; + out.filePicker_filter = "Filtrez les fichiers par leur nom"; + out.slideOptionsTitle = "Personnaliser la présentation"; out.slideOptionsButton = "Enregistrer (Entrée)"; diff --git a/customize.dist/translations/messages.js b/customize.dist/translations/messages.js index ceade6204..16bc6aff4 100644 --- a/customize.dist/translations/messages.js +++ b/customize.dist/translations/messages.js @@ -134,6 +134,11 @@ define(function () { out.printCSS = "Custom style rules (CSS):"; out.printTransition = "Enable transition animations"; + out.filePickerButton = "Embed a file"; + out.filePicker_close = "Close"; + out.filePicker_description = "Choose a file from your CryptDrive to embed it"; + out.filePicker_filter = "Filter files by name"; + out.slideOptionsTitle = "Customize your slides"; out.slideOptionsButton = "Save (enter)"; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 49d756168..eec76cc6c 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -131,6 +131,11 @@ define([ return store.getProxy().proxy; } }; + common.getFO = function () { + if (store && store.getProxy()) { + return store.getProxy().fo; + } + }; var getNetwork = common.getNetwork = function () { if (store) { if (store.getProxy() && store.getProxy().info) { @@ -644,6 +649,23 @@ define([ }); }; + common.getUserFilesList = function () { + var store = common.getStore(); + var proxy = store.getProxy(); + var fo = proxy.fo; + var hashes = []; + var list = fo.getFiles().filter(function (id) { + var href = fo.getFileData(id).href; + var parsed = parsePadUrl(href); + if ((parsed.type === 'file' || parsed.type === 'media') + && hashes.indexOf(parsed.hash) === -1) { + hashes.push(parsed.hash); + return true; + } + }); + return list; + }; + var getUserChannelList = common.getUserChannelList = function () { var store = common.getStore(); var proxy = store.getProxy(); diff --git a/www/slide/main.js b/www/slide/main.js index 8a4522f30..50efb8b2c 100644 --- a/www/slide/main.js +++ b/www/slide/main.js @@ -196,6 +196,61 @@ define([ } }; + var createFileDialog = function () { + var $body = $iframe.find('body'); + var $block = $body.find('#fileDialog'); + if (!$block.length) { + $block = $('
').text(Messages.filePicker_description); + $block.append($description); + var $filter = $('
').appendTo($block); + var $container = $('', {'class': 'fileContainer'}).appendTo($block); + var updateContainer = function () { + $container.html(''); + var filter = $filter.find('.filter').val().trim(); + var list = Cryptpad.getUserFilesList(); + var fo = Cryptpad.getFO(); + list.forEach(function (id) { + var data = fo.getFileData(id); + var name = fo.getTitle(id); + if (filter && name.toLowerCase().indexOf(filter.toLowerCase()) === -1) { + return; + } + var $span = $('', {'class': 'element'}).appendTo($container); + var $inner = $('').text(name); + $span.append($inner).click(function () { + var cleanName = name.replace(/[\[\]]/g, ''); + var text = '!['+cleanName+']('+data.href+')'; + editor.replaceSelection(text); + $block.hide(); + console.log(data.href); + }); + }); + }; + var to; + $('', { + type: 'text', + 'class': 'filter', + 'placeholder': Messages.filePicker_filter + }).appendTo($filter).on('keypress', function () { + if (to) { window.clearTimeout(to); } + to = window.setTimeout(updateContainer, 300); + }); + updateContainer(); + $body.keydown(function (e) { + if (e.which === 27) { $block.hide(); } + }); + $block.show(); + }; + var createPrintDialog = function () { var slideOptionsTmp = { title: false, @@ -357,6 +412,14 @@ define([ var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb); $rightside.append($forgetPad); + $('