1 (function($){$(function(){
4 function hide_menu_boxes() {
5 /* Closes any open menu boxes. */
6 $("#menu .active").each(function() {
7 $(this).removeClass("active");
8 $("#" + $(this).attr("data-box")).hide();
9 if ($(this).hasClass('dropdown')) {
10 $($(this).attr('href')).slideUp('fast');
13 $("#box-underlay").hide();
16 function release_menu() {
17 /* Exits the menu. It only really disappears on small screens. */
19 $("body").removeClass("menu-showed");
23 $('#menu-toggle-on').click(function(e) {
26 /* Just stop hiding the menu. This way, after narrowing the browser,
27 * menu will still disappear normally. */
28 body.removeClass("menu-hidden");
29 /* Menu still not visible? Really open it then. */
30 if (!$("#menu").is(":visible")) {
31 body.addClass("menu-showed");
33 _paq.push(['trackEvent', 'html', 'menu-on']);
37 $('#menu-toggle-off').click(function(e) {
39 /* Just release the menu. This way, after widening the browser,
40 * menu will still appear normally. */
42 /* Menu still visible after releasing it? Really hide it then. */
43 if ($("#menu").is(":visible")) {
44 $("body").addClass("menu-hidden");
46 _paq.push(['trackEvent', 'html', 'menu-off']);
50 /* Exit menu by clicking anywhere else. */
51 $("#box-underlay").click(release_menu);
54 /* Toggle hidden box on click. */
55 $("#menu a").each(function() {
56 var boxid = $(this).attr("data-box");
58 $("#" + boxid).hide();
60 $(this).click(function(e) {
62 var showing = $(this).hasClass("active");
65 $("body").addClass("menu-showed");
66 $(this).addClass("active");
67 $("#box-underlay").show();
68 $("#" + boxid).show();
71 _paq.push(['trackEvent', 'html', boxid]);
73 else if ($(this).hasClass('dropdown')) {
74 $(this).click(function(e) {
76 var showing = $(this).hasClass("active");
79 $("body").addClass("menu-showed");
80 $("#sponsors:not(:hidden)").fadeOut();
81 $(this).addClass("active");
82 $($(this).attr('href')).slideDown('fast');
86 else if (!$(this).hasClass('button')) {
87 $(this).click(release_menu);
92 /* Show menu item for other versions of text.
93 * It's only present if there are any. */
94 $("#menu-other").show();
97 /* Load other version of text. */
98 $(".display-other").click(function(e) {
102 $("#other-text").show();
103 $("body").addClass('with-other-text');
105 $.ajax($(this).attr('data-other'), {
106 success: function(text) {
107 $("#other-text-body").html(text);
108 $("#other-text-waiter").hide();
109 $("#other-text-body").show();
110 loaded_text($("#other-text-body"));
113 _paq.push(['trackEvent', 'html', 'other-text']);
117 /* Remove other version of text. */
118 $(".other-text-close").click(function(e) {
121 $("#other-text").hide();
122 $("body").removeClass('with-other-text');
123 $("#other-text-body").html("");
124 _paq.push(['trackEvent', 'html', 'other-text-close']);
128 /* Release menu after clicking inside TOC. */
129 $("#toc a").click(function(){
131 _paq.push(['trackEvent', 'html', 'toc-item']);
135 if ($('#nota_red').length > 0) {
136 $("#menu-nota_red").show();
139 /* Show themes menu item, if there are any. */
140 if ($('#themes li').length > 0) {
141 $("#menu-themes").show();
144 function loaded_text(text) {
145 /* Attach events to elements inside book texts here.
146 * This way they'll work for the other text when it's loaded. */
148 $(".theme-begin", text).click(function(e) {
150 if ($(this).css("overflow") == "hidden" || $(this).hasClass('showing')) {
151 $(this).toggleClass("showing");
156 loaded_text("#book-text");