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 function insertOtherText(text) {
99 let lang = tree.attr('lang') || 'pl';
104 let cursor = $(".main-text-body #book-text").children().first();
105 // wstawiamy przed kursorem
107 tree.children().each((i, e) => {
110 if ($e.hasClass('anchor')) return;
111 if ($e.hasClass('numeracja')) return;
112 if ($e.attr('id') == 'toc') return;
113 if ($e.attr('id') == 'nota_red') return;
114 if ($e.attr('id') == 'themes') return;
115 if ($e.attr('name') && $e.attr('name').startsWith('sec')) return;
117 if ($e.hasClass('target')) {
118 let target = $e.attr('name');
120 while (lastTarget != target) {
121 let nc = cursor.next();
126 lastTarget = cursor.attr('name');
130 let nc = cursor.next();
135 lastTarget = cursor.attr('name');
136 if (lastTarget) break;
140 let d = $('<div class="other">');
141 d.attr('lang', lang);
143 d.insertBefore(cursor);
148 /* Load other version of text. */
149 $(".display-other").click(function(e) {
153 $(".other").remove();
154 $("body").addClass('with-other-text');
156 $.ajax($(this).attr('data-other'), {
157 success: function(text) {
158 insertOtherText(text);
159 $("#other-text-waiter").hide();
160 loaded_text($(".other"));
163 _paq.push(['trackEvent', 'html', 'other-text']);
170 /* Remove other version of text. */
171 $(".other-text-close").click(function(e) {
174 $(".other").remove();
175 $("body").removeClass('with-other-text');
176 _paq.push(['trackEvent', 'html', 'other-text-close']);
180 /* Release menu after clicking inside TOC. */
181 $("#toc a").click(function(){
183 _paq.push(['trackEvent', 'html', 'toc-item']);
187 if ($('#nota_red').length > 0) {
188 $("#menu-nota_red").show();
191 /* Show themes menu item, if there are any. */
192 if ($('#themes li').length > 0) {
193 $("#menu-themes").show();
196 function loaded_text(text) {
197 /* Attach events to elements inside book texts here.
198 * This way they'll work for the other text when it's loaded. */
200 $(".theme-begin", text).click(function(e) {
202 if ($(this).css("overflow") == "hidden" || $(this).hasClass('showing')) {
203 $(this).toggleClass("showing");
208 loaded_text("#book-text");