2017: Add 'Expand All' in /program.
[libreplanet-static.git] / 2017 / includes / program_js.html
CommitLineData
97a8abce 1<!-- start html templates -->
2<script id="details-menu-up-glyph" type="text/x-generic-html-template">
3 <span class="glyphicon glyphicon-menu-up" style="margin-left: 5px;"
4 aria-hidden="true"></span>
5</script>
6<script id="details-menu-down-glyph" type="text/x-generic-html-template">
7 <span class="glyphicon glyphicon-menu-down" style="margin-left: 5px;"
8 aria-hidden="true"></span>
9</script>
10<!-- end html templates -->
11
fcf95e6d 12<script>
97a8abce 13 $('.collapse').removeClass('in');
14
15 $(window).ready(function() {
16 init_toggle_all();
17
18 $('.session-desc')
19 .on('show.bs.collapse', function() {
20 var id = $(this).attr('id');
21 // find corresponding "Details"/"Collapse details" button.
22 var btn = $('[data-target="#'+ id + '"]');
23 var glyph = $('#details-menu-up-glyph').text();
24 $(btn).text('Collapse details');
25 $(glyph).appendTo(btn);
26 });
27
28 $('.session-desc')
29 .on('hide.bs.collapse', function() {
30 var id = $(this).attr('id');
31 // find corresponding "Details"/"Collapse details" button.
32 var btn = $('[data-target="#'+ id + '"]');
33 var glyph = $('#details-menu-down-glyph').text();
34 $(btn).text('Show details');
35 $(glyph).appendTo(btn);
36 });
37 });
38
39 $(window).resize(function() {
40 reinit_toggle_all();
41 });
42
43 $(window).scroll(function() {
44 position_toggle_all();
45 });
46
47 function init_toggle_all(reinit=false) {
48 var id = '.program-session-details-toggle-all button';
49 // on click init.
50 if (!reinit)
51 toggle_all_click_init();
52
53 // positioning.
54 window.toggle_all_pos = $(id).offset();
55 position_toggle_all();
56 }
57
58 function reinit_toggle_all() {
59 // make position static to know the real position of toggle all.
60 toggle_all_static();
61 init_toggle_all(true);
62 }
63
64 function toggle_all_fixed() {
65 $('.program-session-details-toggle-all button').addClass('fixed');
66 }
67
68 function toggle_all_static() {
69 $('.program-session-details-toggle-all button').removeClass('fixed');
70 }
71
72 function position_toggle_all() {
73 var toggle_all_btn = '.program-session-details-toggle-all button';
74 var t_pos = window.toggle_all_pos;
75 var w_top = $(window).scrollTop();
76
77 if(w_top > t_pos.top)
78 toggle_all_fixed();
79 else
80 toggle_all_static();
81
82 }
83
84 function toggle_all_click_init() {
85 var toggle_all_btn = '.program-session-details-toggle-all button';
86 var details_btn = '.program-session-room-details button';
87
88 // initially everything is collapsed.
89 window.toggle_all = {
90 'collapsed': true,
91 'clicked': false,
92 };
93
94 $(toggle_all_btn).click(function() {
95
96 if (window.toggle_all.collapsed) {
97 $('.collapse').collapse('show');
98 window.toggle_all.collapsed = false;
99 } else {
100 $('.collapse').collapse('hide');
101 window.toggle_all.collapsed = true;
102 }
103
104 // set toggle all clicked.
105 window.toggle_all.clicked = true;
106 });
107
108 $('.collapse').on('shown.bs.collapse', function() {
109 update_toggle_all_text('Collapse all');
110 });
111
112 $('.collapse').on('hidden.bs.collapse', function() {
113 update_toggle_all_text('Expand all');
114 });
115 }
116
117 function update_toggle_all_text(txt) {
118 var toggle_all_btn = '.program-session-details-toggle-all button';
119
120 // update text only when toggle all is clicked.
121 if (window.toggle_all.clicked)
122 $(toggle_all_btn).text(txt);
123
124 // reset toggle clicked
125 window.toggle_all.clicked = false;
126 }
fcf95e6d 127</script>
128
129<script type="text/javascript">
130 $(".program-link").addClass("active");
131</script>