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 5e6de0e413..a339037b0e 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_data/challenges/basic-bonfires.json b/seed_data/challenges/basic-bonfires.json index 3773c4da22..6033a8937e 100644 --- a/seed_data/challenges/basic-bonfires.json +++ b/seed_data/challenges/basic-bonfires.json @@ -832,7 +832,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'", @@ -966,7 +966,8 @@ "expect(fearNotLetter('yz')).to.be.undefined;" ], "MDNlinks": [ - "String.charCodeAt()" + "String.charCodeAt()", + "String.fromCharCode()" ], "challengeType": 5, "nameCn": "", diff --git a/views/coursewares/showBonfire.jade b/views/coursewares/showBonfire.jade index 4270e5975a..4fd79ffc88 100644 --- a/views/coursewares/showBonfire.jade +++ b/views/coursewares/showBonfire.jade @@ -90,7 +90,10 @@ block content alert(type='danger') span.ion-close-circled | Username not found - #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) + #submitButton.btn.btn-primary.btn-big.btn-block Run code (ctrl + enter) + .button-spacer + #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