diff --git a/public/js/lib/coursewares/coursewaresJSFramework_0.0.5.js b/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js similarity index 77% rename from public/js/lib/coursewares/coursewaresJSFramework_0.0.5.js rename to public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js index 2183c226d7..f11f202086 100644 --- a/public/js/lib/coursewares/coursewaresJSFramework_0.0.5.js +++ b/public/js/lib/coursewares/coursewaresJSFramework_0.0.6.js @@ -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; if (attempts) { @@ -71,15 +131,15 @@ var editorValue; var challengeSeed = challengeSeed || null; var tests = tests || []; + var allSeeds = ''; (function() { challengeSeed.forEach(function(elem) { - allSeeds += elem + '\n'; + allSeeds += elem + '\n'; }); })(); -editorValue = allSeeds; - +editorValue = (localBonfire.isAlive())? localBonfire.getEditorValue() : allSeeds; myCodeMirror.setValue(editorValue); diff --git a/seed/challenges/basic-bonfires.json b/seed/challenges/basic-bonfires.json index df4b6bc16c..08c797f58c 100644 --- a/seed/challenges/basic-bonfires.json +++ b/seed/challenges/basic-bonfires.json @@ -853,7 +853,7 @@ "difficulty": "2.03", "description": [ "Perform a search and replace on the sentence using the arguments provided and return the new sentence.", - "First argument is the sentence the perform the search and replace on.", + "First argument is the sentence to perform the search and replace on.", "Second argument is the word that you will be replacing (before).", "Third argument is what you will be replacing the second argument with (after).", "NOTE: Preserve the case of the original word when you are replacing it. For example if you mean to replace the word 'Book' with the word 'dog', it should be replaced as 'Dog'", @@ -990,7 +990,8 @@ "expect(fearNotLetter('yz')).to.be.undefined;" ], "MDNlinks": [ - "String.charCodeAt()" + "String.charCodeAt()", + "String.fromCharCode()" ], "challengeType": 5, "nameCn": "", diff --git a/server/views/coursewares/showBonfire.jade b/server/views/coursewares/showBonfire.jade index d18abe290e..8ca3e962e1 100644 --- a/server/views/coursewares/showBonfire.jade +++ b/server/views/coursewares/showBonfire.jade @@ -84,7 +84,7 @@ block content label.negative-10.btn.btn-primary.btn-block#submitButton i.fa.fa-play |   Run code (ctrl + enter) - + #resetButton.btn.btn-danger.btn-big.btn-block(data-toggle='modal', data-target='#reset-modal', data-backdrop='true') Reset Code if (user && user.sentSlackInvite) .button-spacer .btn-group.input-group.btn-group-justified