diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-14 00:06:58 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-14 00:06:58 +0200 |
commit | 9ffa462111b1d5b4c954464416fdc8daf69c9d3f (patch) | |
tree | b38e046662d4ae31d5b611166264e4d68500736a /theme/javascript/core/progress.js | |
parent | 1bbef540157b513d3e336325a3d636885e15357e (diff) | |
download | gitbook-9ffa462111b1d5b4c954464416fdc8daf69c9d3f.zip gitbook-9ffa462111b1d5b4c954464416fdc8daf69c9d3f.tar.gz gitbook-9ffa462111b1d5b4c954464416fdc8daf69c9d3f.tar.bz2 |
Add base from clarity theme from @Nijikokun
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 { |