Update and rename coursewaresJSFramework_0.0.5.js to coursewaresJSFramework_0.0.6.js

Added auto save(to local storage) for any progress. It will set the IDE text to whatever the user last saw within 24 hours. 
The auto save happens every 1.5 seconds _after_ someone lifts a key.
This commit is contained in:
Andrew Cay
2015-06-15 22:47:17 -07:00
parent 76a800f575
commit a53114e7b6

View File

@ -40,6 +40,66 @@ editor.setOption("extraKeys", {
}); });
/*
Local Storage Update System By Andrew Cay(Resto)
localBonfire: singleton object that contains properties and methods related to
dealing with the localStorage system.
The keys work off of the variable challenge_name to make unique identifiers per bonfire
Two extra functionalities:
Added anonymous version checking system incase of future updates to the system
Added keyup listener to editor(myCodeMirror) so the last update has been saved to storage
*/
var localBonfire = {
version: 0.01,
keyVersion:"saveVersion",
keyStamp: challenge_Name + 'Stamp',
keyValue: challenge_Name + 'Val',
stampExpireTime: (1000 *60) *60 *24,
updateWait: 1500,// 1.5 seconds
updateTimeoutId: null
};
localBonfire.getEditorValue = function(){
return localStorage.getItem(localBonfire.keyValue);
};
localBonfire.getStampTime = function(){
//localstorage always saves as strings.
return Number.parseInt( localStorage.getItem(localBonfire.keyStamp) );
};
localBonfire.isAlive = function(){// returns true if IDE was edited within expire time
return ( Date.now() - localBonfire.getStampTime() < localBonfire.stampExpireTime );
};
localBonfire.updateStorage = function(){
if(typeof(Storage) !== undefined) {
var stamp = Date.now(),
value = editor.getValue();
localStorage.setItem(localBonfire.keyValue, value);
localStorage.setItem(localBonfire.keyStamp, stamp);
} else {
if( debugging ){
console.log('no web storage');
}
}
localBonfire.updateTimeoutId = null;
console.log('updated!');
};
// ANONYMOUS 1 TIME UPDATE VERSION
(function(){
var savedVersion = localStorage.getItem('saveVersion');
if( savedVersion === null ){
localStorage.setItem(localBonfire.keyVersion, localBonfire.version);//just write current version
}else{
//do checking if not current version
if( savedVersion !== localBonfire.version ){
//update version
}
}
})();
editor.on('keyup', function(codMir, event){
window.clearTimeout(localBonfire.updateTimeoutId);
localBonfire.updateTimeoutId = window.setTimeout(localBonfire.updateStorage, localBonfire.updateWait);
});
var attempts = 0; var attempts = 0;
if (attempts) { if (attempts) {
@ -71,6 +131,7 @@ var editorValue;
var challengeSeed = challengeSeed || null; var challengeSeed = challengeSeed || null;
var tests = tests || []; var tests = tests || [];
var allSeeds = ''; var allSeeds = '';
(function() { (function() {
challengeSeed.forEach(function(elem) { challengeSeed.forEach(function(elem) {
@ -78,8 +139,7 @@ var allSeeds = '';
}); });
})(); })();
editorValue = allSeeds; editorValue = (localBonfire.isAlive())? localBonfire.getEditorValue() : allSeeds;
myCodeMirror.setValue(editorValue); myCodeMirror.setValue(editorValue);