Added "add", "delete", and "rename" of files

master
Hauke D 7 years ago
parent 457f54d5ad
commit aa2cf82a03

@ -34,10 +34,10 @@ If not, see http://perldoc.perl.org/index-licence.html
<iframe name="perlrunner" sandbox="allow-scripts" <iframe name="perlrunner" sandbox="allow-scripts"
src="perlrunner.html" style="display:none;"></iframe> src="perlrunner.html" style="display:none;"></iframe>
<iframe id="perl1" sandbox="allow-scripts" <iframe id="perl1" sandbox="allow-scripts allow-modals"
style="border:1px solid black;width:100%;height:8em;"></iframe> style="border:1px solid black;width:100%;max-width:50em;height:8em;"></iframe>
<iframe id="perl2" sandbox="allow-scripts" <iframe id="perl2" sandbox="allow-scripts allow-modals"
style="border:1px solid black;width:100%;height:40em;"></iframe> style="border:1px solid black;width:100%;max-width:50em;height:40em;"></iframe>
<script> <script>
document.getElementById('perl1').src = document.getElementById('perl1').src =
"perleditor.html#" + encodeURIComponent(JSON.stringify( { "perleditor.html#" + encodeURIComponent(JSON.stringify( {

@ -2,7 +2,7 @@
body { body {
margin: 0.4em; margin: 0.4em;
} }
.text { .text,.fakelink {
font-family: Calibri, Ubuntu, "Droid Sans", Tahoma, Arial, Helvetica, sans-serif; font-family: Calibri, Ubuntu, "Droid Sans", Tahoma, Arial, Helvetica, sans-serif;
} }
pre,textarea,code,.code,.filename,.CodeMirror { pre,textarea,code,.code,.filename,.CodeMirror {
@ -20,6 +20,12 @@ pre {
max-height: 12em; max-height: 12em;
} }
.fakelink {
color: darkblue;
cursor: pointer;
font-size: 0.9em;
}
#runnerstate { #runnerstate {
margin-top: 0.1em; margin-top: 0.1em;
margin-bottom: 0.3em; margin-bottom: 0.3em;

@ -165,6 +165,12 @@ 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 setupOutputFile (fn, text) { function setupOutputFile (fn, text) {
var found = $('div.outputs>.filename') var found = $('div.outputs>.filename')
.filter(function(){ return $(this).text() == fn }); .filter(function(){ return $(this).text() == fn });
@ -175,7 +181,13 @@ function setupOutputFile (fn, text) {
} }
else { else {
var div = $('<div/>',{class:"codewithfn outputs"}); var div = $('<div/>',{class:"codewithfn outputs"});
div.append( $('<div/>',{class:"filename",text:fn}) ); //TODO: the "delete" and "rename" functions should probably be styled better
$('<div/>',{class:"fakelink",style:"float:right;",text:"delete"})
.appendTo(div).click(function () {
if (confirm("Are you sure you want to remove this file?"))
div.remove() });
div.append( $('<div/>',{class:"filename",text:fn}).click(fileRename) );
div.append( $('<div/>',{style:"clear:both;"}) );
var ta = $('<textarea/>').appendTo(div); var ta = $('<textarea/>').appendTo(div);
$('#outputhere').before(div); $('#outputhere').before(div);
cm = makeCM(ta,1,1); cm = makeCM(ta,1,1);
@ -203,7 +215,12 @@ function setupInputFile (inp) {
} }
} }
var div = $('<div/>',{class:"codewithfn inputs"}); var div = $('<div/>',{class:"codewithfn inputs"});
div.append( $('<div/>',{class:"filename",text:fn}) ); $('<div/>',{class:"fakelink",style:"float:right;",text:"delete"})
.appendTo(div).click(function () {
if (confirm("Are you sure you want to remove this file?"))
div.remove() });
div.append( $('<div/>',{class:"filename",text:fn}).click(fileRename) );
div.append( $('<div/>',{style:"clear:both;"}) );
var ta = $('<textarea/>').appendTo(div); var ta = $('<textarea/>').appendTo(div);
$('#inputhere').before(div); $('#inputhere').before(div);
var cm = makeCM(ta,1,0); var cm = makeCM(ta,1,0);
@ -245,6 +262,16 @@ $(function () {
var hashdata = window.location.hash.substr(1); var hashdata = window.location.hash.substr(1);
var hash = hashdata.length>0 ? JSON.parse(decodeURIComponent(hashdata)) : {}; var hash = hashdata.length>0 ? JSON.parse(decodeURIComponent(hashdata)) : {};
$('#addinput').click(function () {
var fn = prompt("Please choose a filename for the new input file:");
if (fn) setupInputFile( {fn:fn} );
});
$('#addoutput').click(function () {
var fn = prompt("Please choose a filename for the new output file:");
if (fn) setupOutputFile( fn );
});
$('#script>.filename').click(fileRename);
// script // script
if ( hash["script"] || hash["script_url"] ) { if ( hash["script"] || hash["script_url"] ) {
var scriptdiv = $('#script'); var scriptdiv = $('#script');
@ -317,7 +344,9 @@ $(function () {
</head> </head>
<body> <body>
<div id="inputhere" style="display:none;"></div> <div id="inputhere" style="text-align:right;">
<span id="addinput" class="fakelink">Add Input File</span>
</div>
<div id="script" class="codewithfn" style="display:none;"> <div id="script" class="codewithfn" style="display:none;">
<div class="filename">script.pl</div> <div class="filename">script.pl</div>
@ -347,7 +376,9 @@ $(function () {
<textarea></textarea> <textarea></textarea>
</div> </div>
<div id="outputhere" style="display:none;"></div> <div id="outputhere" style="text-align:right;">
<span id="addoutput" class="fakelink">Add Output File</span>
</div>
</body> </body>
</html> </html>

Loading…
Cancel
Save