Merge branch 'obrazy' into rwd
[wolnelektury.git] / apps / wolnelektury_core / 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     });
10     $("#box-underlay").hide();
11 }
12
13 function release_menu() {
14     /* Exits the menu. It only really disappears on small screens. */
15     hide_menu_boxes();
16     $("body").removeClass("menu-showed");
17 }
18
19 /* Show menu */
20 $('#menu-toggle-on').click(function(e) {
21     e.preventDefault();
22     var body = $("body");
23     /* Just stop hiding the menu. This way, after narrowing the browser,
24      * menu will still disappear normally. */
25     body.removeClass("menu-hidden");
26     /* Menu still not visible? Really open it then. */
27     if (!$("#menu").is(":visible")) {
28         body.addClass("menu-showed");
29     }
30 });
31
32 /* Hide menu */
33 $('#menu-toggle-off').click(function(e) {
34     e.preventDefault();
35     /* Just release the menu. This way, after widening the browser,
36      * menu will still appear normally. */
37     release_menu();
38     /* Menu still visible after releasing it? Really hide it then. */
39     if ($("#menu").is(":visible")) {
40         $("body").addClass("menu-hidden");
41     }
42 });
43
44
45 /* Exit menu by clicking anywhere else. */
46 $("#box-underlay").click(release_menu);
47
48
49 /* Toggle hidden box on click. */
50 $("#menu a").each(function() {
51     var boxid = $(this).attr("data-box");
52     if (boxid) {
53         $("#" + $(this).attr("data-box")).hide();
54
55         $(this).click(function(e) {
56             e.preventDefault();
57             var showing = $(this).hasClass("active");
58             hide_menu_boxes();
59             if (!showing) {
60                 $("body").addClass("menu-showed");
61                 $(this).addClass("active");
62                 $("#box-underlay").show();
63                 $("#" + $(this).attr("data-box")).show();
64             }
65         });
66     }
67     else {
68         $(this).click(release_menu);
69     }
70 });
71
72
73 /* Show menu item for other versions of text. 
74  * It's only present if there are any. */
75 $("#menu-other").show();
76
77
78 /* Load other version of text. */
79 $(".display-other").click(function(e) {
80     e.preventDefault();
81     release_menu();
82
83     $("#other-text").show();
84     $("body").addClass('with-other-text');
85
86     $.ajax($(this).attr('data-other'), {
87         success: function(text) {
88             $("#other-text-body").html(text);
89             $("#other-text-waiter").hide();
90             $("#other-text-body").show();
91             loaded_text($("#other-text-body"));
92         }
93     });
94 });
95
96
97 /* Remove other version of text. */
98 $(".other-text-close").click(function(e) {
99     release_menu();
100     e.preventDefault();
101     $("#other-text").hide();
102     $("body").removeClass('with-other-text');
103     $("#other-text-body").html("");
104 });
105
106
107 /* Release menu after clicking inside TOC. */
108 $("#toc a").click(release_menu);
109
110
111 if ($('#nota_red').length > 0) {
112     $("#menu-nota_red").show();
113 }
114
115 /* Show themes menu item, if there are any. */
116 if ($('#themes li').length > 0) {
117     $("#menu-themes").show();
118 }
119
120 function loaded_text(text) {
121     /* Attach events to elements inside book texts here.
122      * This way they'll work for the other text when it's loaded. */
123
124     $(".theme-begin", text).click(function(e) {
125         e.preventDefault();
126         if ($(this).css("overflow") == "hidden" || $(this).hasClass('showing')) {
127             $(this).toggleClass("showing");
128         }
129     });
130
131 }
132 loaded_text("#book-text");
133
134
135 })})(jQuery);