-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
executable file
·130 lines (114 loc) · 3.71 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* day/night toggle */
function tpl_toggleLight() {
if (DokuCookie.getValue('dark')==1)
{
DokuCookie.setValue('dark','0');
jQuery('body').toggleClass('dark');
return false;
}
else
{
DokuCookie.setValue('dark','1');
jQuery('body').toggleClass('dark');
return false;
}
}
(function($) {
var fadeOption = {duration: 1};
var device_class = ''; // not yet known
var device_classes = 'mobile wide desktop tablet phone';
var resizeTimer;
function toggleLeft() {
$('#nav_bg').show('fade', fadeOption);
$('#dokuwiki__nav').show();
}
function toggleRight() {
$('#sidebar_bg').show('fade', fadeOption);
$('#dokuwiki__aside').show();
}
function preventParentWheel(e) {
var curScrollPos = $(this).scrollTop();
var scrollableDist = $(this).prop('scrollHeight') - $(this).outerHeight();
var wheelEvent = e.originalEvent;
var dY = wheelEvent.deltaY;
if (dY < 0 && curScrollPos <= 0) {
return false;
}
if (dY > 0 && curScrollPos >= scrollableDist) {
return false;
}
}
function checkWidth() {
// the z-index in mobile.css is (mis-)used purely for detecting the screen mode here
var screen_mode = jQuery('#screen__mode').css('z-index') + '';
// determine our device pattern
// TODO: consider moving into dokuwiki core
switch (screen_mode) {
case '1':
if (device_class.match(/phone/)) return;
device_class = 'mobile phone';
$('#dokuwiki__aside').hide();
break;
case '2':
if (device_class.match(/tablet/)) return;
device_class = 'mobile tablet';
$('#dokuwiki__aside').hide();
break;
case '3':
if (device_class.match(/desktop/)) return;
device_class = 'desktop';
$('#dokuwiki__aside').show();
break;
default:
if (device_class.match(/wide/)) return;
$('#dokuwiki__aside').show();
device_class = 'wide';
}
jQuery('html').removeClass(device_classes).addClass(device_class);
}
function bindEvents() {
$('.sidebar').on('wheel scroll', preventParentWheel);
$('.btn_left').click(function() {
toggleLeft();
});
$('.btn_right').click(function() {
toggleRight();
});
$('#sidebar_bg').click(function() {
$(this).hide('fade', fadeOption);
if (device_class.match(/mobile/))
$('#dokuwiki__aside').hide();
});
$('#nav_bg').click(function() {
$(this).hide('fade', fadeOption);
$('#dokuwiki__nav').hide();
jQuery('.btn_left i').removeClass('fa-spin');
});
$('.btn_search').click(function() {
$('div.search').toggle();
$('div.search').find('input.edit').focus();
});
jQuery(window).bind('resize',
function(){
if (resizeTimer) clearTimeout(resizeTimer);
resizeTimer = setTimeout(checkWidth,200);
});
}
function initUI() {
// Move TOC
if ($('#dokuwiki__content h2').length > 0) {
$('#dw__toc').insertBefore($('#dokuwiki__content h2:first'));
} else {
$('#dw__toc').insertAfter($('#dokuwiki__content h1:first').next('.level1'));
}
// Anchor link should be shifted by header pixel
$(window).on("hashchange", function () {
window.scrollTo(window.scrollX, window.scrollY - 48);
});
}
$(function() {
initUI();
checkWidth();
bindEvents();
});
})(jQuery);