diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:36:12 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-14 16:36:12 +0200 |
commit | 5848f5db51fb9258ff55dc93010b2c862abeec0a (patch) | |
tree | d12c06a056e30bf42e144f5e52643cee86243ece /theme/javascript/core/progress.js | |
parent | 1bbef540157b513d3e336325a3d636885e15357e (diff) | |
parent | 9f1ba8483b3484391ca1cf5b3ed6005d97e0693b (diff) | |
download | gitbook-5848f5db51fb9258ff55dc93010b2c862abeec0a.zip gitbook-5848f5db51fb9258ff55dc93010b2c862abeec0a.tar.gz gitbook-5848f5db51fb9258ff55dc93010b2c862abeec0a.tar.bz2 |
Merge pull request #88 from GitbookIO/feature/clarity
Feature/clarity
Diffstat (limited to 'theme/javascript/core/progress.js')
-rwxr-xr-x[-rw-r--r--] | theme/javascript/core/progress.js | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/theme/javascript/core/progress.js b/theme/javascript/core/progress.js index d074cae..a409a11 100644..100755 --- a/theme/javascript/core/progress.js +++ b/theme/javascript/core/progress.js @@ -10,15 +10,16 @@ define([ }; // Return all levels - var getLevels = function() { + var getLevels = function () { var levels = $(".book-summary li[data-level]"); + return _.map(levels, function(level) { return $(level).data("level").toString(); }); }; // Return a map chapter -> number (timestamp) - var getProgress = function() { + var getProgress = function () { // Current level var progress = storage.get("progress", {}); @@ -33,27 +34,33 @@ define([ }; // Change value of progress for a level - var markProgress = function(level, state) { - if (state == null) state = true; - + var markProgress = function (level, state) { var progress = getProgress(); - progress[level] = state? Date.now() : 0; + + if (state == null) { + state = true; + } + + progress[level] = state + ? Date.now() + : 0; storage.set("progress", progress); }; // Show progress - var showProgress = function() { - // Update progress + var showProgress = function () { var progress = getProgress(); var $summary = $(".book-summary"); - _.each(progress, function(value, level) { + _.each(progress, function (value, level) { $summary.find("li[data-level='"+level+"']").toggleClass("done", value > 0); }); - // Mark current progress - markProgress(getCurrentLevel(), true); + // Mark current progress if we have not already + if (!progress[getCurrentLevel()]) { + markProgress(getCurrentLevel(), true); + } }; return { |