Change norm of core/state

This commit is contained in:
Samy Pessé
2014-04-06 16:10:25 -07:00
parent ff52a2317b
commit 607b45f172
7 changed files with 21399 additions and 25 deletions
+1 -2
View File
@@ -10,9 +10,8 @@ require([
"core/progress",
"core/sidebar",
"core/search"
], function($, storage, analytic, sharing, _state, keyboard, exercise, progress, sidebar, search){
], function($, storage, analytic, sharing, state, keyboard, exercise, progress, sidebar, search){
$(document).ready(function() {
var state = _state();
var $book = state.$book;
// Initialize storage
+1 -1
View File
@@ -38,7 +38,7 @@ define([
// Prepare all exercise
var init = function() {
state().$book.find("section.exercise").each(function() {
state.$book.find("section.exercise").each(function() {
prepareExercise($(this));
});
};
+1 -1
View File
@@ -6,7 +6,7 @@ define([
], function(_, $, storage, state) {
// Get current level
var getCurrentLevel = function() {
return state().level;
return state.level;
};
// Return all levels
+16 -12
View File
@@ -4,15 +4,17 @@ define([
"core/state",
"core/search"
], function(storage, platform, state, search) {
var $summary = state.$book.find(".book-summary");
var $searchInput = $summary.find(".book-search input")
// Toggle sidebar with or withour animation
var toggleSidebar = function(_state, animation) {
if (state != null && isOpen() == _state) return;
if (animation == null) animation = true;
var $book = state().$book;
$book.toggleClass("without-animation", !animation);
$book.toggleClass("with-summary", _state);
state.$book.toggleClass("without-animation", !animation);
state.$book.toggleClass("with-summary", _state);
storage.set("sidebar", isOpen());
};
@@ -21,29 +23,31 @@ define([
var toggleSearch = function(_state) {
if (state != null && isSearchOpen() == _state) return;
var $summary = state().$book.find(".book-summary");
$summary.toggleClass("with-search", _state);
// If search bar is open: focus input
if (isSearchOpen()) $summary.find(".book-search input").focus();
if (isSearchOpen()) {
$searchInput.focus();
} else {
}
};
// Return true if sidebar is open
var isOpen = function() {
return state().$book.hasClass("with-summary");
return state.$book.hasClass("with-summary");
};
// Return true if search bar is open
var isSearchOpen = function() {
return state().$book.find(".book-summary").hasClass("with-search");
return $summary.hasClass("with-search");
};
// Prepare sidebar: state and toggle button
var init = function() {
var $book = state().$book;
// Toggle summary
$book.find(".book-header .toggle-summary").click(function(e) {
state.$book.find(".book-header .toggle-summary").click(function(e) {
e.preventDefault();
toggleSidebar();
});
@@ -54,12 +58,12 @@ define([
}
// Toggle search
$book.find(".book-header .toggle-search").click(function(e) {
state.$book.find(".book-header .toggle-search").click(function(e) {
e.preventDefault();
toggleSearch();
});
$book.find(".book-summary .book-search input").keyup(function(e) {
$searchInput.keyup(function(e) {
var key = (e.keyCode ? e.keyCode : e.which);
var q = $(this).val();
+5 -7
View File
@@ -1,14 +1,12 @@
define([
"jQuery"
], function() {
return function() {
var $book = $(".book");
var $book = $(".book");
return {
'$book': $book,
return {
'$book': $book,
'githubId': $book.data("github"),
'level': $book.data("level")
};
'githubId': $book.data("github"),
'level': $book.data("level")
};
});