diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-27 18:05:13 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-27 18:05:13 +0200 |
commit | 54f530c7c36105698958908272e79935a56bf25f (patch) | |
tree | 7d01ad53a8013595461e5128b4b5140317df0f3e /theme/javascript | |
parent | ca94055adf2d0519105b587116d5d56b559a2c3a (diff) | |
parent | 9fdc5da22da283f8c3a76760194bf2f61a8cebd4 (diff) | |
download | gitbook-54f530c7c36105698958908272e79935a56bf25f.zip gitbook-54f530c7c36105698958908272e79935a56bf25f.tar.gz gitbook-54f530c7c36105698958908272e79935a56bf25f.tar.bz2 |
Merge pull request #171 from GitbookIO/feature/offlineCache
Improve pages loading
Diffstat (limited to 'theme/javascript')
-rw-r--r-- | theme/javascript/core/loading.js | 18 | ||||
-rwxr-xr-x | theme/javascript/core/navigation.js | 9 | ||||
-rwxr-xr-x | theme/javascript/gitbook.js | 6 | ||||
-rw-r--r-- | theme/javascript/utils/appcache.js | 15 |
4 files changed, 43 insertions, 5 deletions
diff --git a/theme/javascript/core/loading.js b/theme/javascript/core/loading.js new file mode 100644 index 0000000..193531f --- /dev/null +++ b/theme/javascript/core/loading.js @@ -0,0 +1,18 @@ +define([ + "jQuery" +], function($) { + var showLoading = function(p) { + var $book = $(".book"); + + $book.addClass("is-loading"); + p.always(function() { + $book.removeClass("is-loading"); + }); + + return p; + }; + + return { + show: showLoading + }; +});
\ No newline at end of file diff --git a/theme/javascript/core/navigation.js b/theme/javascript/core/navigation.js index d8dc8b9..e614392 100755 --- a/theme/javascript/core/navigation.js +++ b/theme/javascript/core/navigation.js @@ -6,8 +6,9 @@ define([ "core/search", "core/progress", "core/exercise", - "core/quiz" -], function($, path, events, state, search, progress, exercises, quiz) { + "core/quiz", + "core/loading" +], function($, path, events, state, search, progress, exercises, quiz, loading) { var prev, next; var githubCountStars, githubCountWatch; @@ -23,7 +24,7 @@ define([ return } - return $.get(url) + return loading.show($.get(url) .done(function (html) { // Push url to history if (push) history.pushState({ path: url }, null, url); @@ -59,7 +60,7 @@ define([ }) .fail(function (e) { location.href = relativeUrl; - }); + })); }; var updateGitHubCounts = function() { diff --git a/theme/javascript/gitbook.js b/theme/javascript/gitbook.js index 7dcb8d7..cb222da 100755 --- a/theme/javascript/gitbook.js +++ b/theme/javascript/gitbook.js @@ -2,6 +2,7 @@ define([ "jQuery", "utils/storage", "utils/sharing", + "utils/appcache", "core/events", "core/font-settings", @@ -11,7 +12,7 @@ define([ "core/progress", "core/sidebar", "core/search" -], function($, storage, sharing, events, fontSettings, state, keyboard, navigation, progress, sidebar, search){ +], function($, storage, appCache, sharing, events, fontSettings, state, keyboard, navigation, progress, sidebar, search){ var start = function(config) { var $book; $book = state.$book; @@ -30,6 +31,9 @@ define([ // Init keyboard keyboard.init(); + // Init appcache + appCache.init(); + // Bind sharing button sharing.init(); diff --git a/theme/javascript/utils/appcache.js b/theme/javascript/utils/appcache.js new file mode 100644 index 0000000..e813ab0 --- /dev/null +++ b/theme/javascript/utils/appcache.js @@ -0,0 +1,15 @@ +define([], function() { + var isAvailable = (typeof applicationCache !== "undefined"); + + var init = function() { + if (!isAvailable) return; + + window.applicationCache.addEventListener('updateready', function() { + window.location.reload(); + }, false); + }; + + return { + init: init + }; +});
\ No newline at end of file |