From 66d81429bdff87bc2a6ed86e9b14c7d8e9b54433 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 3 Aug 2017 11:47:54 +0200 Subject: [PATCH] integrate file embed into code editor --- www/code/code.less | 1 + www/code/main.js | 34 ++++++++++++++++++++++++++++++++ www/common/file-dialog.less | 39 +++++++++++++++++++++++++++++++++++++ www/slide/slide.less | 38 +----------------------------------- 4 files changed, 75 insertions(+), 37 deletions(-) create mode 100644 www/common/file-dialog.less diff --git a/www/code/code.less b/www/code/code.less index f90e1a15b..6c620fff8 100644 --- a/www/code/code.less +++ b/www/code/code.less @@ -1,6 +1,7 @@ @import "/customize/src/less/variables.less"; @import "/customize/src/less/mixins.less"; @import "/common/markdown.less"; +@import "/common/file-dialog.less"; html, body{ height: 100%; diff --git a/www/code/main.js b/www/code/main.js index 1b6cb8997..db358018d 100644 --- a/www/code/main.js +++ b/www/code/main.js @@ -147,6 +147,17 @@ define([ } }; + var mediaTagModes = [ + 'markdown', + 'html', + 'htmlembedded', + 'htmlmixed', + 'index.html', + 'php', + 'velocity', + 'xml', + ]; + var onModeChanged = function (mode) { var $codeMirror = $iframe.find('.CodeMirror'); window.clearTimeout(APP.previewTo); @@ -154,6 +165,10 @@ define([ APP.previewTo = window.setTimeout(function () { $codeMirror.removeClass('transition'); }, 500); + if (mediaTagModes.indexOf(mode) !== -1) { + APP.$mediaTagButton.show(); + } else { APP.$mediaTagButton.hide(); } + if (mode === "markdown") { APP.$previewButton.show(); Cryptpad.getPadAttribute('previewMode', function (e, data) { @@ -253,6 +268,25 @@ define([ var $forgetPad = Cryptpad.createButton('forget', true, {}, forgetCb); $rightside.append($forgetPad); + 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 = ''; + editor.replaceSelection(mt); + }, + data: APP + }; + APP.$mediaTagButton = $('