From d85bc736b7ff3c7482dcc68a4d3127a874049cfe Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 14:43:01 +0100 Subject: [PATCH 1/9] Added Save and Load functions I was interested in saving my consoles, then loading them later. I got tired of copy and paste to/from files. --- index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 9f3a838f..8fb4b512 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 + From 8e92784adcd828dc491d582693a2cd2d079877c0 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 14:45:02 +0100 Subject: [PATCH 2/9] Added Save and Load functions I was interested in saving my consoles, then loading them later. I got tired of copy and paste to/from files. --- index.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 9f3a838f..8fb4b512 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 + From e76b36aac333118021371abdcf0af58ecfd36990 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 15:26:04 +0100 Subject: [PATCH 3/9] changed load/save style --- styles.css | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/styles.css b/styles.css index 632d64a1..f14b6f4e 100644 --- a/styles.css +++ b/styles.css @@ -31,6 +31,13 @@ input { font-size: 2em; } +.f { + 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 +} From c032079884089c9bc61a00cbdaeb13c251f5ed64 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 15:27:42 +0100 Subject: [PATCH 4/9] Added Save and Load to Javascript Functions I copied the reset and created load/save. --- php-console.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/php-console.js b/php-console.js index 80e7be54..ae1be487 100644 --- a/php-console.js +++ b/php-console.js @@ -181,6 +181,54 @@ e.preventDefault(); }); } + + //Save + if (window.localStorage) { + $('.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"; + if (window.webkitURL != null) + { + // Chrome allows the link to be clicked + // without actually adding it to the DOM. + downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); + } + else + { + // Firefox requires the link to be added to the DOM + // before it can be clicked. + downloadLink.href = window.URL.createObjectURL(textFileAsBlob); + downloadLink.onclick = destroyClickedElement; + downloadLink.style.display = "none"; + document.body.appendChild(downloadLink); + } + + downloadLink.click(); + }); + } + + //Load + if (window.localStorage) { + $('.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; + //document.getElementById("inputTextToSave").value = textFromFileLoaded; + editor.getSession().setValue(textFromFileLoaded); + localStorage.setItem('phpCode',textFromFileLoaded); + }; + fileReader.readAsText(fileToLoad, "UTF-8"); + }); + } + // commands editor.commands.addCommand({ From 222ba27b8078a2895cd9e4b94896686d0cb7fd9e Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 16:31:05 +0100 Subject: [PATCH 5/9] Revert "Added Save and Load functions" From bfe9a27e72e625c302fbd3f2b1398c48a911e8de Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 23:51:01 +0100 Subject: [PATCH 6/9] changing class name per request --- index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 8fb4b512..d82643c8 100644 --- a/index.php +++ b/index.php @@ -169,9 +169,9 @@ function runCode($__source_code, $__bootstrap_file) Reset - "> + "> Save - + Load From d3d62c2b30a076d2ac169f703910a972439a0d50 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 23:51:43 +0100 Subject: [PATCH 7/9] changing class name per request --- styles.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/styles.css b/styles.css index f14b6f4e..10ea028a 100644 --- a/styles.css +++ b/styles.css @@ -31,7 +31,7 @@ input { font-size: 2em; } -.f { +.ls-input { width: auto; display: inline; margin: 0px auto; From 0162e8d60b6c578e1439bf1324ff7c329e7e6257 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Fri, 10 Jul 2015 23:52:49 +0100 Subject: [PATCH 8/9] removed commented code per request --- php-console.js | 1 - 1 file changed, 1 deletion(-) diff --git a/php-console.js b/php-console.js index ae1be487..e4b37514 100644 --- a/php-console.js +++ b/php-console.js @@ -221,7 +221,6 @@ fileReader.onload = function(fileLoadedEvent) { var textFromFileLoaded = fileLoadedEvent.target.result; - //document.getElementById("inputTextToSave").value = textFromFileLoaded; editor.getSession().setValue(textFromFileLoaded); localStorage.setItem('phpCode',textFromFileLoaded); }; From 11818838670bbf4a8d71ef1f00911b66d3f9a131 Mon Sep 17 00:00:00 2001 From: lowrykun Date: Mon, 13 Jul 2015 13:38:53 -0600 Subject: [PATCH 9/9] php-console.js changes that were recommended. Sorry - I was travelling while you guys were talking about this. I removed the local storage requirement and gave credit to the original author. I tested and it works on Chrome and Firefox. Both browsers use the same codepath. I also tested Safari and note that the console doesn't work (the top panels don't show up. I doubt that's related to my change, but thought I would mention it.) --- php-console.js | 72 +++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/php-console.js b/php-console.js index e4b37514..dd6fec83 100644 --- a/php-console.js +++ b/php-console.js @@ -183,50 +183,38 @@ } //Save - if (window.localStorage) { - $('.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"; - if (window.webkitURL != null) - { - // Chrome allows the link to be clicked - // without actually adding it to the DOM. - downloadLink.href = window.webkitURL.createObjectURL(textFileAsBlob); - } - else - { - // Firefox requires the link to be added to the DOM - // before it can be clicked. - downloadLink.href = window.URL.createObjectURL(textFileAsBlob); - downloadLink.onclick = destroyClickedElement; - downloadLink.style.display = "none"; - document.body.appendChild(downloadLink); - } - - downloadLink.click(); - }); - } + // 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 - if (window.localStorage) { - $('.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"); - }); - } + $('.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