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:
@ -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();
|
||||
|
Reference in New Issue
Block a user