forked from openhab/openhab-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
115 lines (98 loc) · 3.38 KB
/
init.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
var LANDING_PAGE_HERO_HEIGHT = 550 - 64;
$(function() {
window.isSmall = $(window).width() <= 600;
window.pathArray = window.location.pathname.split('/');
window.onLandingPage = 0;
initEffects();
initSideNav();
initStickyHeader();
});
function initEffects() {
// Pipes Slide & Custom Parallax
$('#hero .img-wrapper').slideDown();
function parallaxScroll() {
var scrolledY = $(window).scrollTop();
$('#hero .img-wrapper').css('bottom', '-' + ((scrolledY * 0.1)) + 'px');
}
if (!window.isSmall) {
$(window).bind('scroll', function(e) {
parallaxScroll();
});
}
// Slide In Top Level Menu
$(".button-collapse").sideNav();
// Generel Parallax Effect
$('.parallax').parallax();
// Striped Tables
$('section#documentation table').not('.bordered').addClass('striped');
// Linkable Headers
$('section#documentation h2, section#documentation h3, section#documentation h4, section#documentation h5').click(function(event) {
var id = $(event.target).attr('id');
window.location.hash = id;
});
}
function initStickyHeader() {
var stickyHeaderPosition = !window.onLandingPage ? 1 : LANDING_PAGE_HERO_HEIGHT;
$(window).scroll(function() {
if ($(this).scrollTop() > stickyHeaderPosition) {
$('#header').addClass("sticky");
$('#header').addClass("z-depth-1");
} else {
$('#header').removeClass("sticky");
$('#header').removeClass("z-depth-1");
}
});
}
function initSideNav() {
var linkUrl = getLinkUrl();
$('section ul.nav a').each(function(index, element) {
if ($(element).attr('href').indexOf(linkUrl) != -1) {
$(element).closest('li').addClass('active');
$(element).closest('li').parents('li').addClass('active open');
$(element).parents('ul').slideDown();
}
if ($(element).closest('li').children('ul').length > 0) {
$(element).addClass('has-submenu');
// Accordion
/*
$(element).click(function(event) {
event.stopPropagation();
$('section#documentation ul.nav ul').slideUp();
$(element).closest('li').children('ul').slideDown();
return false;
});
*/
}
});
var sideNavMobileSection = (linkUrl.indexOf('/developer') == 0) ? 'developer' : (linkUrl.indexOf('/tutorials') == 0) ? 'tutorials' : 'user';
$('section ul.nav').clone().appendTo('#side-nav-mobile-' + sideNavMobileSection);
// Sticky SideNav
if (!window.onLandingPage) {
var isSmall = $(window).width() <= 600;
if (!isSmall) {
// $('section ul.nav').sticky({topSpacing: 100});
}
$(window).resize(function() {
var isSmall = $(window).width() <= 600;
if (isSmall) {
// $('section ul.nav').unstick();
} else {
// $('section ul.nav').sticky({topSpacing: 100});
}
});
}
}
function getLinkUrl() {
var linkUrl = '';
for (i = 1; i < pathArray.length; i++) {
var pathSegment = pathArray[i];
if (pathSegment != '') {
linkUrl += "/" + pathSegment;
}
}
if (!linkUrl.endsWith('.html')) {
return linkUrl + "/index.html";
} else {
return linkUrl;
}
}