Skip to content
Prev Previous commit
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.)
  • Loading branch information
lowrykun committed Jul 13, 2015
commit 11818838670bbf4a8d71ef1f00911b66d3f9a131
72 changes: 30 additions & 42 deletions php-console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down