Save sidebar state

This commit is contained in:
Samy Pessé
2014-04-01 13:26:04 -07:00
parent 86cf2d9d9d
commit b93f67c84a
7 changed files with 64 additions and 8 deletions
+4 -6
View File
@@ -3,16 +3,14 @@ require([
"core/state",
"core/exercise",
"core/progress",
], function($, _state, exercise, progress){
"core/sidebar"
], function($, _state, exercise, progress, sidebar){
$(document).ready(function() {
var state = _state();
var $book = state.$book;
// Toggle summary
$book.find(".book-header .toggle-summary").click(function(e) {
e.preventDefault();
$book.toggleClass("with-summary");
});
// Init sidebar
sidebar.init();
// Star and watch count
$.getJSON("https://api.github.com/repos/"+state.githubId)
+41
View File
@@ -0,0 +1,41 @@
define([
"utils/storage",
"utils/platform",
"core/state"
], function(storage, platform, state) {
// Toggle sidebar with or withour animation
var toggleSidebar = function(_state, animation) {
if (animation == null) animation = true;
var $book = state().$book;
$book.toggleClass("without-animation", !animation);
$book.toggleClass("with-summary", _state);
storage.set("sidebar", isOpen());
};
// Return true if sidebar is open
var isOpen = function() {
return state().$book.hasClass("with-summary");
};
// Prepare sidebar: state and toggle button
var init = function() {
var $book = state().$book;
// Toggle summary
$book.find(".book-header .toggle-summary").click(function(e) {
e.preventDefault();
toggleSidebar();
});
// Init last state if not mobile and not homepage
if (!isOpen()) toggleSidebar(platform.isMobile ? false : storage.get("sidebar", false), false);
};
return {
init: init,
toggle: toggleSidebar
}
});
+5
View File
@@ -0,0 +1,5 @@
define([], function() {
return {
isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
};
});
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+6
View File
@@ -46,4 +46,10 @@
}
}
}
&.without-animation {
.book-body {
.transition(none) !important;
}
}
}
+6
View File
@@ -90,4 +90,10 @@
left: 0px;
}
}
&.without-animation {
.book-summary {
.transition(none) !important;
}
}
}