diff --git a/index.php b/index.php index 9f3a838f..d82643c8 100644 --- a/index.php +++ b/index.php @@ -169,6 +169,10 @@ function runCode($__source_code, $__bootstrap_file) Reset + "> + Save + + Load @@ -203,4 +207,4 @@ function runCode($__source_code, $__bootstrap_file) - \ No newline at end of file + diff --git a/php-console.js b/php-console.js index 80e7be54..dd6fec83 100644 --- a/php-console.js +++ b/php-console.js @@ -181,6 +181,41 @@ e.preventDefault(); }); } + + //Save + // Load and Save functions copied from: + // https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/ + + $('.statusbar .save').on('click', function (e) { + var textToWrite = editor.getSession().getValue(); + var textFileAsBlob = new Blob([textToWrite], {type:'text/plain'}); + var fileNameToSaveAs = document.getElementById("inputFileNameToSaveAs").value; + var downloadLink = document.createElement("a"); + downloadLink.download = fileNameToSaveAs; + downloadLink.innerHTML = "Download File"; + downloadLink.href = window.URL.createObjectURL(textFileAsBlob); + downloadLink.style.display = "none"; + document.body.appendChild(downloadLink); + } + + downloadLink.click(); + }); + + + //Load + $('.statusbar .load').on('click', function (e) { + var fileToLoad = document.getElementById("fileToLoad").files[0]; + + var fileReader = new FileReader(); + fileReader.onload = function(fileLoadedEvent) + { + var textFromFileLoaded = fileLoadedEvent.target.result; + editor.getSession().setValue(textFromFileLoaded); + localStorage.setItem('phpCode',textFromFileLoaded); + }; + fileReader.readAsText(fileToLoad, "UTF-8"); + }); + // commands editor.commands.addCommand({ diff --git a/styles.css b/styles.css index 632d64a1..10ea028a 100644 --- a/styles.css +++ b/styles.css @@ -31,6 +31,13 @@ input { font-size: 2em; } +.ls-input { + width: auto; + display: inline; + margin: 0px auto; + font-size: 10px; +} + a { color: #88f; } @@ -149,4 +156,4 @@ a { float: right; clear: right; width: 350px; -} \ No newline at end of file +}