From 2ef4af02cb495cda441f80fbc432f8aa277d17d1 Mon Sep 17 00:00:00 2001 From: Hauke D Date: Wed, 10 Oct 2018 13:45:23 +0200 Subject: [PATCH] Refactored code for file editing --- web/democode/perleditor.html | 79 ++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/web/democode/perleditor.html b/web/democode/perleditor.html index c9fea0f..dfd86f8 100644 --- a/web/democode/perleditor.html +++ b/web/democode/perleditor.html @@ -165,10 +165,27 @@ function fetchUrl(url,cm) { // fetch the contents of a URL into a CodeMirror ins }); } -function fileRename () { - var div = $(this); - var newname = prompt("Please choose a new filename:",div.text()); - if (newname) div.text(newname); +function makeCodeWithFn (fn,targ,ro,nodel) { + var div = $('
',{class:"codewithfn"}); + //TODO: the "delete" and "rename" functions should probably be styled better + if (!nodel) { + $('
',{class:"fakelink",style:"float:right;",text:"delete"}) + .appendTo(div).click(function () { + if (confirm("Are you sure you want to remove this file?")) + div.remove() }); + } + $('
',{class:"filename",text:fn}) + .appendTo(div).click(function () { + var filename = $(this); + var newname = prompt("Please choose a new filename:", filename.text()); + if (newname) filename.text(newname); + }); + div.append( $('
',{style:"clear:both;"}) ); + var ta = $(' -
- -
+