From 067eff8ebaaf7b05ef8514bc051c72f1f80ddc82 Mon Sep 17 00:00:00 2001 From: zeripath Date: Mon, 20 Apr 2020 11:32:44 +0100 Subject: [PATCH] Ensure that relative paths in edit preview work (#11143) Fix #10131 Signed-off-by: Andrew Thornton Co-authored-by: Lauris BH --- web_src/js/index.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index 2bf34a956..ed747765a 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -64,10 +64,16 @@ function initEditPreviewTab($form) { previewFileModes = $previewTab.data('preview-file-modes').split(','); $previewTab.on('click', function () { const $this = $(this); + let context = `{$this.data('context')}/`; + const treePathEl = $form.find('input#tree_path'); + if (treePathEl.length > 0) { + context += treePathEl.val(); + } + context = context.substring(0, context.lastIndexOf('/')); $.post($this.data('url'), { _csrf: csrf, mode: 'gfm', - context: $this.data('context'), + context, text: $form.find(`.tab.segment[data-tab="${$tabMenu.data('write')}"] textarea`).val() }, (data) => { const $previewPanel = $form.find(`.tab.segment[data-tab="${$tabMenu.data('preview')}"]`);