remove the banner
[wolnelektury.git] / src / wolnelektury / static / js / book_text / menu.js
1 (function($){$(function(){
2
3
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');
11         }
12     });
13     $("#box-underlay").hide();
14 }
15
16 function release_menu() {
17     /* Exits the menu. It only really disappears on small screens. */
18     hide_menu_boxes();
19     $("body").removeClass("menu-showed");
20 }
21
22 /* Show menu */
23 $('#menu-toggle-on').click(function(e) {
24     e.preventDefault();
25     var body = $("body");
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");
32     }
33     _paq.push(['trackEvent', 'html', 'menu-on']);
34 });
35
36 /* Hide menu */
37 $('#menu-toggle-off').click(function(e) {
38     e.preventDefault();
39     /* Just release the menu. This way, after widening the browser,
40      * menu will still appear normally. */
41     release_menu();
42     /* Menu still visible after releasing it? Really hide it then. */
43     if ($("#menu").is(":visible")) {
44         $("body").addClass("menu-hidden");
45     }
46     _paq.push(['trackEvent', 'html', 'menu-off']);
47 });
48
49
50 /* Exit menu by clicking anywhere else. */
51 $("#box-underlay").click(release_menu);
52
53
54 /* Toggle hidden box on click. */
55 $("#menu a").each(function() {
56     var boxid = $(this).attr("data-box");
57     if (boxid) {
58         $("#" + boxid).hide();
59
60         $(this).click(function(e) {
61             e.preventDefault();
62             var showing = $(this).hasClass("active");
63             hide_menu_boxes();
64             if (!showing) {
65                 $("body").addClass("menu-showed");
66                 $(this).addClass("active");
67                 $("#box-underlay").show();
68                 $("#" + boxid).show();
69             }
70         });
71         _paq.push(['trackEvent', 'html', boxid]);
72     }
73     else if ($(this).hasClass('dropdown')) {
74         $(this).click(function(e) {
75             e.preventDefault();
76             var showing = $(this).hasClass("active");
77             hide_menu_boxes();
78             if (!showing) {
79                 $("body").addClass("menu-showed");
80                 $("#sponsors:not(:hidden)").fadeOut();
81                 $(this).addClass("active");
82                 $($(this).attr('href')).slideDown('fast');
83             }
84         });
85     }
86     else if (!$(this).hasClass('button')) {
87         $(this).click(release_menu);
88     }
89 });
90
91
92 /* Show menu item for other versions of text. 
93  * It's only present if there are any. */
94 $("#menu-other").show();
95
96
97 /* Load other version of text. */
98 $(".display-other").click(function(e) {
99     e.preventDefault();
100     release_menu();
101
102     $("#other-text").show();
103     $("body").addClass('with-other-text');
104
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"));
111         }
112     });
113     _paq.push(['trackEvent', 'html', 'other-text']);
114 });
115
116
117 /* Remove other version of text. */
118 $(".other-text-close").click(function(e) {
119     release_menu();
120     e.preventDefault();
121     $("#other-text").hide();
122     $("body").removeClass('with-other-text');
123     $("#other-text-body").html("");
124     _paq.push(['trackEvent', 'html', 'other-text-close']);
125 });
126
127
128 /* Release menu after clicking inside TOC. */
129     $("#toc a").click(function(){
130         release_menu();
131         _paq.push(['trackEvent', 'html', 'toc-item']);
132     });
133
134
135 if ($('#nota_red').length > 0) {
136     $("#menu-nota_red").show();
137 }
138
139 /* Show themes menu item, if there are any. */
140 if ($('#themes li').length > 0) {
141     $("#menu-themes").show();
142 }
143
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. */
147
148     $(".theme-begin", text).click(function(e) {
149         e.preventDefault();
150         if ($(this).css("overflow") == "hidden" || $(this).hasClass('showing')) {
151             $(this).toggleClass("showing");
152         }
153     });
154
155 }
156 loaded_text("#book-text");
157
158
159 })})(jQuery);