This repository has been archived by the owner on Dec 24, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
210 lines (154 loc) · 4.56 KB
/
main.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
Hyperspace by HTML5 UP
html5up.net | @ajlkn
Free for personal and commercial use under the CCA 3.0 license (html5up.net/license)
*/
(function($) {
skel.breakpoints({
xlarge: '(max-width: 1680px)',
large: '(max-width: 1280px)',
medium: '(max-width: 980px)',
small: '(max-width: 736px)',
xsmall: '(max-width: 480px)'
});
$(function() {
var $window = $(window),
$body = $('body'),
$sidebar = $('#sidebar');
// Hack: Enable IE flexbox workarounds.
if (skel.vars.IEVersion < 12)
$body.addClass('is-ie');
// Disable animations/transitions until the page has loaded.
if (skel.canUse('transition'))
$body.addClass('is-loading');
$window.on('load', function() {
window.setTimeout(function() {
$body.removeClass('is-loading');
}, 100);
});
// Forms.
// Fix: Placeholder polyfill.
$('form').placeholder();
// Hack: Activate non-input submits.
$('form').on('click', '.submit', function(event) {
// Stop propagation, default.
event.stopPropagation();
event.preventDefault();
// Submit form.
$(this).parents('form').submit();
});
// Prioritize "important" elements on medium.
skel.on('+medium -medium', function() {
$.prioritize(
'.important\\28 medium\\29',
skel.breakpoint('medium').active
);
});
// Sidebar.
if ($sidebar.length > 0) {
var $sidebar_a = $sidebar.find('a');
$sidebar_a
.addClass('scrolly')
.on('click', function() {
var $this = $(this);
// External link? Bail.
if ($this.attr('href').charAt(0) != '#')
return;
// Deactivate all links.
$sidebar_a.removeClass('active');
// Activate link *and* lock it (so Scrollex doesn't try to activate other links as we're scrolling to this one's section).
$this
.addClass('active')
.addClass('active-locked');
})
.each(function() {
var $this = $(this),
id = $this.attr('href'),
$section = $(id);
// No section for this link? Bail.
if ($section.length < 1)
return;
// Scrollex.
$section.scrollex({
mode: 'middle',
top: '-20vh',
bottom: '-20vh',
initialize: function() {
// Deactivate section.
if (skel.canUse('transition'))
$section.addClass('inactive');
},
enter: function() {
// Activate section.
$section.removeClass('inactive');
// No locked links? Deactivate all links and activate this section's one.
if ($sidebar_a.filter('.active-locked').length == 0) {
$sidebar_a.removeClass('active');
$this.addClass('active');
}
// Otherwise, if this section's link is the one that's locked, unlock it.
else if ($this.hasClass('active-locked'))
$this.removeClass('active-locked');
}
});
});
}
// Scrolly.
$('.scrolly').scrolly({
speed: 1000,
offset: function() {
// If <=large, >small, and sidebar is present, use its height as the offset.
if (skel.breakpoint('large').active
&& !skel.breakpoint('small').active
&& $sidebar.length > 0)
return $sidebar.height();
return 0;
}
});
// Spotlights.
$('.spotlights > section')
.scrollex({
mode: 'middle',
top: '-10vh',
bottom: '-10vh',
initialize: function() {
// Deactivate section.
if (skel.canUse('transition'))
$(this).addClass('inactive');
},
enter: function() {
// Activate section.
$(this).removeClass('inactive');
}
})
.each(function() {
var $this = $(this),
$image = $this.find('.image'),
$img = $image.find('img'),
x;
// Assign image.
$image.css('background-image', 'url(' + $img.attr('src') + ')');
// Set background position.
if (x = $img.data('position'))
$image.css('background-position', x);
// Hide <img>.
$img.hide();
});
// Features.
if (skel.canUse('transition'))
$('.features')
.scrollex({
mode: 'middle',
top: '-20vh',
bottom: '-20vh',
initialize: function() {
// Deactivate section.
$(this).addClass('inactive');
},
enter: function() {
// Activate section.
$(this).removeClass('inactive');
}
});
});
})(jQuery);