implemented autosave, save button is now hidden. there is a label to show the last save timestamp. Code is saved on browser close.

This commit is contained in:
Ralf Teusner
2015-08-12 17:38:34 +02:00
parent e49f0dc063
commit b4527aef50
6 changed files with 49 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ $(function() {
var FILENAME_URL_PLACEHOLDER = '{filename}';
var SUCCESSFULL_PERCENTAGE = 90;
var THEME = 'ace/theme/textmate';
var AUTOSAVE_INTERVAL = 15 * 1000;
var editors = [];
var active_file = undefined;
@@ -317,6 +318,23 @@ $(function() {
$('button i.fa-spin').hide();
};
var autosaveTimer;
var autosaveLabel = $("#autosave-label span");
var resetSaveTimer = function(){
clearTimeout(autosaveTimer);
autosaveTimer = setTimeout(autosave, AUTOSAVE_INTERVAL);
};
var autosave = function(){
var date = new Date();
autosaveLabel.parent().css("visibility", "visible");
autosaveLabel.text(date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds());
autosaveLabel.text(date.toLocaleTimeString());
autosaveTimer = null;
createSubmission($('#autosave'), null);
}
var initializeEditors = function() {
$('.editor').each(function(index, element) {
var editor = ace.edit(element);
@@ -326,6 +344,12 @@ $(function() {
});
}
// listener for autosave
editor.getSession().on("change", function (deltaObject) {
resetSaveTimer();
});
var document = editor.getSession().getDocument();
// insert pre-existing code into editor. we have to use insertLines, otherwise the deltas are not properly added
var file_id = $(element).data('file-id');
@@ -983,6 +1007,13 @@ $(function() {
}
}
$(window).on("beforeunload", function() {
if(autosaveTimer){
autosave();
}
})
if ($('#editor').isPresent()) {
if (isBrowserSupported()) {
initializeCodePilot();

View File

@@ -31,7 +31,7 @@ button i.fa-spin {
#editor-buttons {
background-color: #008CBA;
margin-top: 1em;
margin-top: 0;
width: 100%;
button {
@@ -39,7 +39,7 @@ button i.fa-spin {
}
button, .btn-group {
width: 25%;
width: 33.33333%;
}
.btn-group {
@@ -80,3 +80,11 @@ button i.fa-spin {
#results {
display: none;
}
#autosave-label{
visibility: hidden;
height: 1.6em;
text-align: right;
color: #777;
font-size: 0.8em;
}