forked from michalwiglasz/obed.michalwiglasz.cz
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathscript.js
45 lines (39 loc) · 1.3 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$(function() {
var headings = $('h1');
var headingHeight = headings.outerHeight();
var picker = $('<i id="panel-picker" class="fa fa-bars">').css({
height: headingHeight,
lineHeight: headingHeight + "px",
width: headingHeight,
});
document.body.appendChild(picker[0]);
var pickerMenu = $('<ul id="panel-picker-menu">').css({
top: headingHeight,
display: "none",
});
headings.each(function(index) {
var me = $(this);
var target = document.getElementById("d-" + me.attr('id'));
var item = $('<li>').text(me.text());
item.data('target', target);
item.attr('class', me.attr('class'));
item.click(function() {
pickerMenu[0].scrollTop = 0;
pickerMenu.hide();
$(this).data('target').scrollIntoView({ behavior: "smooth" });
})
pickerMenu.append(item);
});
document.body.appendChild(pickerMenu[0]);
picker.click(function() {
pickerMenu[0].scrollTop = 0;
pickerMenu.toggle("fast");
})
$(document).click(function(event) {
if(!$(event.target).closest('#panel-picker').length) {
if($('#panel-picker-menu').is(":visible")) {
$('#panel-picker-menu').hide();
}
}
});
});