-
Notifications
You must be signed in to change notification settings - Fork 14
Add localStorage #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add localStorage #80
Changes from 4 commits
801e4cb
5a33ce6
d9237d0
a9f0e29
aa26578
f6f0ead
5469208
7b7dfe2
d400e6c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -148,6 +148,8 @@ | |
exercise.idle = false; | ||
connection.sendMessage('userBack', {}); | ||
} | ||
// Save the editor content in the local storage | ||
$window.localStorage.setItem("editor." + exercise.id + "." + editor.getOption("mode"), editor.getValue()); | ||
startIdleLoop(); | ||
} | ||
|
||
|
@@ -157,6 +159,13 @@ | |
exercise.editor.on('change', resetIdleLoop); | ||
resizeCodeMirror(); | ||
}; | ||
|
||
|
||
function loadEditorContent() { | ||
var editorValue = $window.localStorage.getItem("editor." + exercise.id + "." + editor.getOption("mode")); | ||
if (editorValue != null) | ||
editor.setValue(editorValue); | ||
} | ||
|
||
function getExercise() { | ||
var args = { | ||
|
@@ -212,6 +221,8 @@ | |
exercise.id = data.id; | ||
exercise.name = data.id.split('.').pop(); | ||
|
||
loadEditorContent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be removed, since the value of the editor is overriden a few lines later by |
||
|
||
navigation.setInlesson(true); | ||
navigation.setCurrentPageTitle(exercise.lessonName + ' / ' + exercise.name); | ||
|
||
|
@@ -468,8 +479,8 @@ | |
exercise.resultType = null; | ||
exercise.result = ''; | ||
exercise.logs = ''; | ||
|
||
exercisesList.setCurrentLessonID(exercise.lessonID); | ||
|
||
} | ||
|
||
function updateInstructions(instructions, api) { | ||
|
@@ -793,6 +804,7 @@ | |
break; | ||
} | ||
} | ||
loadEditorContent(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
function toggleAPI() { | ||
|
@@ -848,4 +860,4 @@ | |
} | ||
return buffer; | ||
} | ||
})(); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's one of the common best practices to use
===
and!==
instead of==
and!=
to prevent type coercion during comparison.For more details about type coercion and why we want to avoid it, you can check this link: http://blog.jeremymartin.name/2008/03/understanding-loose-typing-in.html