blueprint-jekyll-theme 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +12 -0
- data/_includes/bp-agencyhead.html +134 -0
- data/_includes/bp-footer.html +104 -0
- data/_includes/bp-masthead.html +12 -0
- data/_includes/bp-search-box.html +12 -0
- data/_includes/display-media.html +22 -0
- data/_includes/head.html +24 -0
- data/_includes/header-breadcrumb.html +36 -0
- data/_includes/homepage/hero.html +46 -0
- data/_includes/homepage/media-homepage.html +98 -0
- data/_includes/links-baseurl.html +6 -0
- data/_includes/main-scripts.html +19 -0
- data/_includes/post.json +6 -0
- data/_includes/sublinks-baseurl.html +6 -0
- data/_layouts/contact-us.html +113 -0
- data/_layouts/default.html +15 -0
- data/_layouts/homepage.html +28 -0
- data/_layouts/media.html +192 -0
- data/_layouts/page-with-sideNav.html +124 -0
- data/_layouts/page.html +4 -0
- data/_layouts/post.html +37 -0
- data/_layouts/privacy.html +26 -0
- data/_layouts/search.html +40 -0
- data/_layouts/terms-of-use.html +26 -0
- data/_layouts/who-we-are.html +84 -0
- data/assets/img/career/stories/INTERN_serena.jpg +0 -0
- data/assets/img/career/stories/TAP_Sharlene.jpg +0 -0
- data/assets/img/career/stories/TAP_kaiwen.jpg +0 -0
- data/assets/img/career/stories/TAP_weijian.jpg +0 -0
- data/assets/img/facebook.png +0 -0
- data/assets/img/favicon.ico +0 -0
- data/assets/img/home/hero-banner-2.png +0 -0
- data/assets/img/home/hero-banner.png +0 -0
- data/assets/img/instagram.png +0 -0
- data/assets/img/logo_govtech.png +0 -0
- data/assets/img/logo_govtech.svg +44 -0
- data/assets/img/logo_hlb.svg +1 -0
- data/assets/img/post/pdf-icon.svg +7 -0
- data/assets/img/twitter.png +0 -0
- data/assets/img/what-we-do/application-development.svg +8 -0
- data/assets/img/what-we-do/cybersecurity.svg +7 -0
- data/assets/img/what-we-do/data-science.svg +11 -0
- data/assets/img/what-we-do/digitalisation-guide.svg +14 -0
- data/assets/img/what-we-do/geospatial.svg +7 -0
- data/assets/img/what-we-do/government-ict.svg +7 -0
- data/assets/img/what-we-do/sensors-iot.svg +9 -0
- data/assets/img/what-we-do/web-standards.svg +8 -0
- data/assets/img/youtube.png +0 -0
- data/assets/js/build-index.js +54 -0
- data/assets/js/cancel-notification.js +5 -0
- data/assets/js/common.js +383 -0
- data/assets/js/home.js +53 -0
- data/assets/js/jquery.sticky-sidebar.js +749 -0
- data/assets/js/lunr.min.js +1 -0
- data/assets/js/owl.carousel.js +3275 -0
- data/assets/js/search.js +167 -0
- data/assets/js/sideNav-offset.js +8 -0
- data/assets/js/worker.js +19 -0
- data/assets/posts.json +33 -0
- metadata +145 -0
data/assets/js/common.js
ADDED
@@ -0,0 +1,383 @@
|
|
1
|
+
var BLUEPRINT;
|
2
|
+
|
3
|
+
if (typeof BLUEPRINT !== "object") {
|
4
|
+
BLUEPRINT = {};
|
5
|
+
}
|
6
|
+
|
7
|
+
(function() {
|
8
|
+
var hashCode;
|
9
|
+
BLUEPRINT.hide = function(el) {
|
10
|
+
var display;
|
11
|
+
display = BLUEPRINT.isVisible(el);
|
12
|
+
if (display) {
|
13
|
+
el.style.display = 'none';
|
14
|
+
}
|
15
|
+
};
|
16
|
+
BLUEPRINT.show = function(el) {
|
17
|
+
var display;
|
18
|
+
display = BLUEPRINT.isVisible(el);
|
19
|
+
if (!display) {
|
20
|
+
el.style.display = 'block';
|
21
|
+
}
|
22
|
+
};
|
23
|
+
BLUEPRINT.toggle = function(el) {
|
24
|
+
var display;
|
25
|
+
display = BLUEPRINT.isVisible(el);
|
26
|
+
if (!display) {
|
27
|
+
el.style.display = 'block';
|
28
|
+
} else {
|
29
|
+
el.style.display = 'none';
|
30
|
+
}
|
31
|
+
};
|
32
|
+
BLUEPRINT.getElements = function(name) {
|
33
|
+
return document.querySelectorAll('[data-blueprint="' + name + '"]');
|
34
|
+
};
|
35
|
+
BLUEPRINT.isVisible = function(el) {
|
36
|
+
var display;
|
37
|
+
if (window.getComputedStyle) {
|
38
|
+
display = getComputedStyle(el, null).display;
|
39
|
+
} else {
|
40
|
+
display = el.currentStyle.display;
|
41
|
+
}
|
42
|
+
return display !== 'none';
|
43
|
+
};
|
44
|
+
BLUEPRINT.hasClass = function(el, className) {
|
45
|
+
if (el.classList) {
|
46
|
+
return el.classList.contains(className);
|
47
|
+
} else {
|
48
|
+
return new RegExp('\\b' + className + '\\b').test(el.className);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
BLUEPRINT.addClass = function(el, className) {
|
52
|
+
if (el.classList) {
|
53
|
+
return el.classList.add(className);
|
54
|
+
} else if (!BLUEPRINT.hasClass(el, className)) {
|
55
|
+
return el.className += ' ' + className;
|
56
|
+
}
|
57
|
+
};
|
58
|
+
BLUEPRINT.removeClass = function(el, className) {
|
59
|
+
if (el.classList) {
|
60
|
+
return el.classList.remove(className);
|
61
|
+
} else {
|
62
|
+
return el.className = el.className.replace(new RegExp('\\b' + className + '\\b', 'g'), '');
|
63
|
+
}
|
64
|
+
};
|
65
|
+
BLUEPRINT.parseOptions = function(el) {
|
66
|
+
var j, len, option, options, opts;
|
67
|
+
opts = {};
|
68
|
+
options = el.getAttribute('data-options');
|
69
|
+
options = (options || '').replace(/\s/g, '').split(';');
|
70
|
+
for (j = 0, len = options.length; j < len; j++) {
|
71
|
+
option = options[j];
|
72
|
+
if (option) {
|
73
|
+
option = option.split(':');
|
74
|
+
opts[option[0]] = option[1];
|
75
|
+
}
|
76
|
+
}
|
77
|
+
return opts;
|
78
|
+
};
|
79
|
+
BLUEPRINT.click = function(el, handler) {
|
80
|
+
if (!el.eventListener) {
|
81
|
+
el.eventListener = true;
|
82
|
+
return el.addEventListener('click', handler);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
BLUEPRINT.unclick = function(el, handler) {
|
86
|
+
if (el.eventListener) {
|
87
|
+
el.eventListener = false;
|
88
|
+
return el.removeEventListener('click', handler);
|
89
|
+
}
|
90
|
+
};
|
91
|
+
if (document.readyState !== 'loading') {
|
92
|
+
BLUEPRINT.isReady = true;
|
93
|
+
return;
|
94
|
+
} else if (document.addEventListener) {
|
95
|
+
document.addEventListener('DOMContentLoaded', function() {
|
96
|
+
BLUEPRINT.isReady = true;
|
97
|
+
});
|
98
|
+
} else {
|
99
|
+
document.attachEvent('onreadystatechange', function() {
|
100
|
+
if (document.readyState === 'complete') {
|
101
|
+
BLUEPRINT.isReady = true;
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
return hashCode = function(str) {
|
106
|
+
var hash, i, j, len, s;
|
107
|
+
hash = 0;
|
108
|
+
for (i = j = 0, len = str.length; j < len; i = ++j) {
|
109
|
+
s = str[i];
|
110
|
+
hash = ~~(((hash << 5) - hash) + str.charCodeAt(i));
|
111
|
+
}
|
112
|
+
return hash;
|
113
|
+
};
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
})();
|
118
|
+
;var i, j, len, len1, list, lists, menu, menuElems, options, subMenu;
|
119
|
+
|
120
|
+
BLUEPRINT.toggleMenu = function(el, options) {
|
121
|
+
BLUEPRINT.collapseMenu(el, 'hide');
|
122
|
+
BLUEPRINT.click(el, function(e) {
|
123
|
+
var active, actives, i, len;
|
124
|
+
e.preventDefault();
|
125
|
+
e.stopPropagation();
|
126
|
+
if (options.single) {
|
127
|
+
actives = menu.querySelectorAll('.is-active');
|
128
|
+
for (i = 0, len = actives.length; i < len; i++) {
|
129
|
+
active = actives[i];
|
130
|
+
if (active !== e.target) {
|
131
|
+
BLUEPRINT.removeClass(active, 'is-active');
|
132
|
+
if (active.nextElementSibling.nodeName === 'UL') {
|
133
|
+
BLUEPRINT.hide(active.nextElementSibling);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
}
|
137
|
+
}
|
138
|
+
BLUEPRINT.collapseMenu(e.target, 'toggle');
|
139
|
+
});
|
140
|
+
};
|
141
|
+
|
142
|
+
BLUEPRINT.collapseMenu = function(el, status) {
|
143
|
+
var smenu;
|
144
|
+
smenu = el.nextElementSibling;
|
145
|
+
if (status === 'show') {
|
146
|
+
BLUEPRINT.show(smenu);
|
147
|
+
if (BLUEPRINT.isVisible(smenu)) {
|
148
|
+
return BLUEPRINT.addClass(el, 'is-active');
|
149
|
+
}
|
150
|
+
} else if (status === 'hide') {
|
151
|
+
BLUEPRINT.hide(smenu);
|
152
|
+
if (!BLUEPRINT.isVisible(smenu)) {
|
153
|
+
return BLUEPRINT.removeClass(el, 'is-active');
|
154
|
+
}
|
155
|
+
} else if (status === 'toggle') {
|
156
|
+
BLUEPRINT.toggle(smenu);
|
157
|
+
if (BLUEPRINT.isVisible(smenu)) {
|
158
|
+
return BLUEPRINT.addClass(el, 'is-active');
|
159
|
+
} else {
|
160
|
+
return BLUEPRINT.removeClass(el, 'is-active');
|
161
|
+
}
|
162
|
+
}
|
163
|
+
};
|
164
|
+
|
165
|
+
if (!BLUEPRINT.isReady) {
|
166
|
+
menuElems = BLUEPRINT.getElements('menu');
|
167
|
+
if (menuElems && menuElems.length > 0) {
|
168
|
+
for (i = 0, len = menuElems.length; i < len; i++) {
|
169
|
+
menu = menuElems[i];
|
170
|
+
options = BLUEPRINT.parseOptions(menu);
|
171
|
+
lists = menu.querySelectorAll('.bp-menu-list');
|
172
|
+
for (j = 0, len1 = lists.length; j < len1; j++) {
|
173
|
+
list = lists[j];
|
174
|
+
subMenu = list.querySelector('ul');
|
175
|
+
if (subMenu) {
|
176
|
+
BLUEPRINT.toggleMenu(subMenu.previousElementSibling, options);
|
177
|
+
}
|
178
|
+
}
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
;var i, len, modal, modals, options;
|
184
|
+
|
185
|
+
BLUEPRINT.toggleModal = function(el, options) {
|
186
|
+
if (!options.target) {
|
187
|
+
throw new Error('Found [BLUEPRINT-MODAL] but there is no target defined!');
|
188
|
+
}
|
189
|
+
el.addEventListener('click', function(e) {
|
190
|
+
|
191
|
+
var backdrop, closeBtn, closeModal, modal;
|
192
|
+
e.preventDefault();
|
193
|
+
e.stopPropagation();
|
194
|
+
modal = document.getElementById(options.target);
|
195
|
+
backdrop = modal.querySelector('.bp-modal-background');
|
196
|
+
closeBtn = modal.querySelector('.bp-modal-close');
|
197
|
+
closeModal = function() {
|
198
|
+
if (BLUEPRINT.hasClass(modal, 'is-active')) {
|
199
|
+
BLUEPRINT.removeClass(modal, 'is-active');
|
200
|
+
return BLUEPRINT.unclick(this, closeModal);
|
201
|
+
}
|
202
|
+
};
|
203
|
+
if (options.closeByBackdrop === void 0 || options.closeByBackdrop) {
|
204
|
+
BLUEPRINT.click(backdrop, closeModal);
|
205
|
+
}
|
206
|
+
if (options.closeByButton === void 0 || options.closeByButton) {
|
207
|
+
BLUEPRINT.click(closeBtn, closeModal);
|
208
|
+
}
|
209
|
+
BLUEPRINT.addClass(modal, 'is-active');
|
210
|
+
});
|
211
|
+
};
|
212
|
+
|
213
|
+
if (!BLUEPRINT.isReady) {
|
214
|
+
modals = BLUEPRINT.getElements('bp-modal');
|
215
|
+
if (modals && modals.length > 0) {
|
216
|
+
for (i = 0, len = modals.length; i < len; i++) {
|
217
|
+
modal = modals[i];
|
218
|
+
options = BLUEPRINT.parseOptions(modal);
|
219
|
+
BLUEPRINT.toggleModal(modal, options);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
}
|
223
|
+
;var i, len, notification, notifications, options;
|
224
|
+
|
225
|
+
BLUEPRINT.notification = function(el, status, options) {
|
226
|
+
var deleteBtn, deleteNotification;
|
227
|
+
if (options.deletable === void 0 || options.deletable !== false) {
|
228
|
+
deleteBtn = el.querySelector('.delete');
|
229
|
+
deleteNotification = function(e) {
|
230
|
+
e.preventDefault();
|
231
|
+
e.stopPropagation();
|
232
|
+
el.parentNode.removeChild(el);
|
233
|
+
};
|
234
|
+
}
|
235
|
+
if (status === 'show') {
|
236
|
+
BLUEPRINT.removeClass(el, 'is-hidden');
|
237
|
+
BLUEPRINT.click(deleteBtn, deleteNotification);
|
238
|
+
} else if (status === 'hide') {
|
239
|
+
BLUEPRINT.addClass(el, 'is-hidden');
|
240
|
+
} else if (status === 'toggle') {
|
241
|
+
if (BLUEPRINT.isVisible(el)) {
|
242
|
+
BLUEPRINT.notification(el, 'hide', options);
|
243
|
+
} else {
|
244
|
+
BLUEPRINT.notification(el, 'show', options);
|
245
|
+
}
|
246
|
+
return;
|
247
|
+
}
|
248
|
+
};
|
249
|
+
|
250
|
+
if (!BLUEPRINT.isReady) {
|
251
|
+
notifications = BLUEPRINT.getElements('notification');
|
252
|
+
if (notifications && notifications.length > 0) {
|
253
|
+
for (i = 0, len = notifications.length; i < len; i++) {
|
254
|
+
notification = notifications[i];
|
255
|
+
options = BLUEPRINT.parseOptions(notification);
|
256
|
+
BLUEPRINT.notification(notification, 'hide', options);
|
257
|
+
}
|
258
|
+
}
|
259
|
+
}
|
260
|
+
;var i, j, len, len1, tab, tabs, target, targets;
|
261
|
+
|
262
|
+
BLUEPRINT.toggleTab = function(el) {
|
263
|
+
var i, l, len, links;
|
264
|
+
links = el.target.parentNode.parentNode;
|
265
|
+
links = links.querySelectorAll('li');
|
266
|
+
for (i = 0, len = links.length; i < len; i++) {
|
267
|
+
l = links[i];
|
268
|
+
BLUEPRINT.removeClass(l, 'is-active');
|
269
|
+
BLUEPRINT.hide(document.querySelector(l.firstChild.getAttribute('data-tab')));
|
270
|
+
}
|
271
|
+
BLUEPRINT.addClass(el.target.parentNode, 'is-active');
|
272
|
+
BLUEPRINT.show(document.querySelector(el.target.getAttribute('data-tab')));
|
273
|
+
};
|
274
|
+
|
275
|
+
if (!BLUEPRINT.isReady) {
|
276
|
+
tabs = BLUEPRINT.getElements('tabs');
|
277
|
+
if (tabs && tabs.length > 0) {
|
278
|
+
for (i = 0, len = tabs.length; i < len; i++) {
|
279
|
+
tab = tabs[i];
|
280
|
+
targets = tab.querySelectorAll('[data-tab]');
|
281
|
+
for (j = 0, len1 = targets.length; j < len1; j++) {
|
282
|
+
target = targets[j];
|
283
|
+
tab = document.querySelector(target.getAttribute('data-tab'));
|
284
|
+
if (BLUEPRINT.hasClass(target.parentNode, 'is-active') === false) {
|
285
|
+
BLUEPRINT.hide(tab);
|
286
|
+
}
|
287
|
+
BLUEPRINT.click(target, BLUEPRINT.toggleTab);
|
288
|
+
}
|
289
|
+
}
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
// Get all "navbar-burger" elements
|
294
|
+
var $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0);
|
295
|
+
|
296
|
+
// Check if there are any navbar burgers
|
297
|
+
if ($navbarBurgers.length > 0) {
|
298
|
+
|
299
|
+
// Add a click event on each of them
|
300
|
+
$navbarBurgers.forEach(function ($el) {
|
301
|
+
$el.addEventListener('click', function () {
|
302
|
+
|
303
|
+
// Get the target from the "data-target" attribute
|
304
|
+
var target = $el.dataset.target;
|
305
|
+
var $target = document.getElementById(target);
|
306
|
+
|
307
|
+
// Toggle the class on both the "navbar-burger" and the "navbar-menu"
|
308
|
+
$el.classList.toggle('is-active');
|
309
|
+
$target.classList.toggle('is-active');
|
310
|
+
|
311
|
+
});
|
312
|
+
});
|
313
|
+
}
|
314
|
+
|
315
|
+
// // Searchbar Activate
|
316
|
+
// var $searchActivate = document.getElementById('search-activate');
|
317
|
+
// var $searchDeactivate = document.getElementById('search-deactivate');
|
318
|
+
// var $searchBar = document.getElementById('search-bar');
|
319
|
+
// BLUEPRINT.hide($searchDeactivate);
|
320
|
+
// BLUEPRINT.hide($searchBar);
|
321
|
+
// BLUEPRINT.show($searchActivate);
|
322
|
+
//
|
323
|
+
// $searchActivate.addEventListener('click', function (event){
|
324
|
+
// BLUEPRINT.toggle($searchDeactivate);
|
325
|
+
// BLUEPRINT.toggle($searchBar);
|
326
|
+
// BLUEPRINT.toggle($searchActivate);
|
327
|
+
// });
|
328
|
+
//
|
329
|
+
// $searchDeactivate.addEventListener('click', function (event){
|
330
|
+
// BLUEPRINT.toggle($searchDeactivate);
|
331
|
+
// BLUEPRINT.toggle($searchBar);
|
332
|
+
// BLUEPRINT.toggle($searchActivate);
|
333
|
+
// });
|
334
|
+
|
335
|
+
// Dropdowns
|
336
|
+
var $dropdowns = getAll('.bp-dropdown:not(.is-hoverable)');
|
337
|
+
|
338
|
+
if ($dropdowns.length > 0) {
|
339
|
+
$dropdowns.forEach(function ($el) {
|
340
|
+
$el.addEventListener('click', function (event) {
|
341
|
+
event.stopPropagation();
|
342
|
+
$el.classList.toggle('is-active');
|
343
|
+
});
|
344
|
+
});
|
345
|
+
|
346
|
+
document.addEventListener('click', function (event) {
|
347
|
+
closeDropdowns();
|
348
|
+
});
|
349
|
+
}
|
350
|
+
|
351
|
+
function closeDropdowns() {
|
352
|
+
$dropdowns.forEach(function ($el) {
|
353
|
+
$el.classList.remove('is-active');
|
354
|
+
});
|
355
|
+
}
|
356
|
+
|
357
|
+
// Close dropdowns if ESC pressed
|
358
|
+
document.addEventListener('keydown', function (event) {
|
359
|
+
var e = event || window.event;
|
360
|
+
if (e.keyCode === 27) {
|
361
|
+
closeDropdowns();
|
362
|
+
}
|
363
|
+
});
|
364
|
+
|
365
|
+
// Functions
|
366
|
+
function getAll(selector) {
|
367
|
+
return Array.prototype.slice.call(document.querySelectorAll(selector), 0);
|
368
|
+
}
|
369
|
+
|
370
|
+
$(document).ready(function(){
|
371
|
+
var masthead_container = $('.masthead-container');
|
372
|
+
var searchToggle = $('#search-activate');
|
373
|
+
var searchIcon = $('#search-activate span');
|
374
|
+
var searchBar = $('.search-bar');
|
375
|
+
var searchBar_input = $('.search-bar input');
|
376
|
+
searchToggle.on('click',function(e){
|
377
|
+
e.preventDefault();
|
378
|
+
searchIcon.toggleClass('bp-icon-search').toggleClass('bp-icon-cross');;
|
379
|
+
searchBar.toggleClass('hide');
|
380
|
+
searchBar_input.focus().val('');
|
381
|
+
masthead_container.toggleClass('is-opened');
|
382
|
+
});
|
383
|
+
});
|
data/assets/js/home.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
$( document ).ready(function() {
|
2
|
+
|
3
|
+
var carousel_setting = {
|
4
|
+
loop:true,
|
5
|
+
autoplay:true,
|
6
|
+
autoplayTimeout:7000,
|
7
|
+
margin:0,
|
8
|
+
nav:false,
|
9
|
+
mouseDrag:false,
|
10
|
+
items: 1,
|
11
|
+
dots:true,
|
12
|
+
animateOut: 'fadeOut',
|
13
|
+
responsive : {
|
14
|
+
// breakpoint from 0 up
|
15
|
+
0 : {
|
16
|
+
dots : true,
|
17
|
+
mouseDrag:true
|
18
|
+
},
|
19
|
+
|
20
|
+
// breakpoint from 768 up
|
21
|
+
768 : {
|
22
|
+
dots : false
|
23
|
+
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
};
|
28
|
+
|
29
|
+
var programme_carousel = $('.programme-carousel');
|
30
|
+
var programme_nav_left = $('.carousel-nav-container.programme-nav .carousel-nav.left');
|
31
|
+
var programme_nav_right = $('.carousel-nav-container.programme-nav .carousel-nav.right');
|
32
|
+
|
33
|
+
var career_carousel = $('.career-carousel');
|
34
|
+
var career_nav_left = $('.carousel-nav-container.career-nav .carousel-nav.left');
|
35
|
+
var career_nav_right = $('.carousel-nav-container.career-nav .carousel-nav.right');
|
36
|
+
|
37
|
+
programme_carousel.owlCarousel(carousel_setting);
|
38
|
+
programme_nav_left.click(function(){
|
39
|
+
programme_carousel.trigger('prev.owl.carousel',[1000])
|
40
|
+
});
|
41
|
+
programme_nav_right.click(function(){
|
42
|
+
programme_carousel.trigger('next.owl.carousel',[1000])
|
43
|
+
});
|
44
|
+
|
45
|
+
career_carousel.owlCarousel(carousel_setting);
|
46
|
+
career_nav_left.click(function(){
|
47
|
+
career_carousel.trigger('prev.owl.carousel',[1000])
|
48
|
+
});
|
49
|
+
career_nav_right.click(function(){
|
50
|
+
career_carousel.trigger('next.owl.carousel',[1000])
|
51
|
+
});
|
52
|
+
|
53
|
+
});
|
@@ -0,0 +1,749 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
4
|
+
(global.StickySidebar = factory());
|
5
|
+
}(this, (function () { 'use strict';
|
6
|
+
|
7
|
+
var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
function unwrapExports (x) {
|
12
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
13
|
+
}
|
14
|
+
|
15
|
+
function createCommonjsModule(fn, module) {
|
16
|
+
return module = { exports: {} }, fn(module, module.exports), module.exports;
|
17
|
+
}
|
18
|
+
|
19
|
+
var stickySidebar = createCommonjsModule(function (module, exports) {
|
20
|
+
(function (global, factory) {
|
21
|
+
if (typeof undefined === "function" && undefined.amd) {
|
22
|
+
undefined(['exports'], factory);
|
23
|
+
} else {
|
24
|
+
factory(exports);
|
25
|
+
}
|
26
|
+
})(commonjsGlobal, function (exports) {
|
27
|
+
Object.defineProperty(exports, "__esModule", {
|
28
|
+
value: true
|
29
|
+
});
|
30
|
+
|
31
|
+
function _classCallCheck(instance, Constructor) {
|
32
|
+
if (!(instance instanceof Constructor)) {
|
33
|
+
throw new TypeError("Cannot call a class as a function");
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
var _createClass = function () {
|
38
|
+
function defineProperties(target, props) {
|
39
|
+
for (var i = 0; i < props.length; i++) {
|
40
|
+
var descriptor = props[i];
|
41
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
42
|
+
descriptor.configurable = true;
|
43
|
+
if ("value" in descriptor) descriptor.writable = true;
|
44
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
return function (Constructor, protoProps, staticProps) {
|
49
|
+
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
50
|
+
if (staticProps) defineProperties(Constructor, staticProps);
|
51
|
+
return Constructor;
|
52
|
+
};
|
53
|
+
}();
|
54
|
+
|
55
|
+
/**
|
56
|
+
* Sticky Sidebar JavaScript Plugin.
|
57
|
+
* @version 3.3.4
|
58
|
+
* @author Ahmed Bouhuolia <a.bouhuolia@gmail.com>
|
59
|
+
* @license The MIT License (MIT)
|
60
|
+
*/
|
61
|
+
var StickySidebar = function () {
|
62
|
+
|
63
|
+
// ---------------------------------
|
64
|
+
// # Define Constants
|
65
|
+
// ---------------------------------
|
66
|
+
//
|
67
|
+
var EVENT_KEY = '.stickySidebar';
|
68
|
+
var DEFAULTS = {
|
69
|
+
/**
|
70
|
+
* Additional top spacing of the element when it becomes sticky.
|
71
|
+
* @type {Numeric|Function}
|
72
|
+
*/
|
73
|
+
topSpacing: 0,
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Additional bottom spacing of the element when it becomes sticky.
|
77
|
+
* @type {Numeric|Function}
|
78
|
+
*/
|
79
|
+
bottomSpacing: 0,
|
80
|
+
|
81
|
+
/**
|
82
|
+
* Container sidebar selector to know what the beginning and end of sticky element.
|
83
|
+
* @type {String|False}
|
84
|
+
*/
|
85
|
+
containerSelector: false,
|
86
|
+
|
87
|
+
/**
|
88
|
+
* Inner wrapper selector.
|
89
|
+
* @type {String}
|
90
|
+
*/
|
91
|
+
innerWrapperSelector: '.inner-wrapper-sticky',
|
92
|
+
|
93
|
+
/**
|
94
|
+
* The name of CSS class to apply to elements when they have become stuck.
|
95
|
+
* @type {String|False}
|
96
|
+
*/
|
97
|
+
stickyClass: 'is-affixed',
|
98
|
+
|
99
|
+
/**
|
100
|
+
* Detect when sidebar and its container change height so re-calculate their dimensions.
|
101
|
+
* @type {Boolean}
|
102
|
+
*/
|
103
|
+
resizeSensor: true,
|
104
|
+
|
105
|
+
/**
|
106
|
+
* The sidebar returns to its normal position if its width below this value.
|
107
|
+
* @type {Numeric}
|
108
|
+
*/
|
109
|
+
minWidth: false
|
110
|
+
};
|
111
|
+
|
112
|
+
// ---------------------------------
|
113
|
+
// # Class Definition
|
114
|
+
// ---------------------------------
|
115
|
+
//
|
116
|
+
/**
|
117
|
+
* Sticky Sidebar Class.
|
118
|
+
* @public
|
119
|
+
*/
|
120
|
+
|
121
|
+
var StickySidebar = function () {
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Sticky Sidebar Constructor.
|
125
|
+
* @constructor
|
126
|
+
* @param {HTMLElement|String} sidebar - The sidebar element or sidebar selector.
|
127
|
+
* @param {Object} options - The options of sticky sidebar.
|
128
|
+
*/
|
129
|
+
function StickySidebar(sidebar) {
|
130
|
+
var _this = this;
|
131
|
+
|
132
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
133
|
+
|
134
|
+
_classCallCheck(this, StickySidebar);
|
135
|
+
|
136
|
+
this.options = StickySidebar.extend(DEFAULTS, options);
|
137
|
+
|
138
|
+
// Sidebar element query if there's no one, throw error.
|
139
|
+
this.sidebar = 'string' === typeof sidebar ? document.querySelector(sidebar) : sidebar;
|
140
|
+
if ('undefined' === typeof this.sidebar) throw new Error("There is no specific sidebar element.");
|
141
|
+
|
142
|
+
this.sidebarInner = false;
|
143
|
+
this.container = this.sidebar.parentElement;
|
144
|
+
|
145
|
+
// Current Affix Type of sidebar element.
|
146
|
+
this.affixedType = 'STATIC';
|
147
|
+
this.direction = 'down';
|
148
|
+
this.support = {
|
149
|
+
transform: false,
|
150
|
+
transform3d: false
|
151
|
+
};
|
152
|
+
|
153
|
+
this._initialized = false;
|
154
|
+
this._reStyle = false;
|
155
|
+
this._breakpoint = false;
|
156
|
+
|
157
|
+
// Dimensions of sidebar, container and screen viewport.
|
158
|
+
this.dimensions = {
|
159
|
+
translateY: 0,
|
160
|
+
maxTranslateY: 0,
|
161
|
+
topSpacing: 0,
|
162
|
+
lastTopSpacing: 0,
|
163
|
+
bottomSpacing: 0,
|
164
|
+
lastBottomSpacing: 0,
|
165
|
+
sidebarHeight: 0,
|
166
|
+
sidebarWidth: 0,
|
167
|
+
containerTop: 0,
|
168
|
+
containerHeight: 0,
|
169
|
+
viewportHeight: 0,
|
170
|
+
viewportTop: 0,
|
171
|
+
lastViewportTop: 0
|
172
|
+
};
|
173
|
+
|
174
|
+
// Bind event handlers for referencability.
|
175
|
+
['handleEvent'].forEach(function (method) {
|
176
|
+
_this[method] = _this[method].bind(_this);
|
177
|
+
});
|
178
|
+
|
179
|
+
// Initialize sticky sidebar for first time.
|
180
|
+
this.initialize();
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Initializes the sticky sidebar by adding inner wrapper, define its container,
|
185
|
+
* min-width breakpoint, calculating dimensions, adding helper classes and inline style.
|
186
|
+
* @private
|
187
|
+
*/
|
188
|
+
|
189
|
+
|
190
|
+
_createClass(StickySidebar, [{
|
191
|
+
key: 'initialize',
|
192
|
+
value: function initialize() {
|
193
|
+
var _this2 = this;
|
194
|
+
|
195
|
+
this._setSupportFeatures();
|
196
|
+
|
197
|
+
// Get sticky sidebar inner wrapper, if not found, will create one.
|
198
|
+
if (this.options.innerWrapperSelector) {
|
199
|
+
this.sidebarInner = this.sidebar.querySelector(this.options.innerWrapperSelector);
|
200
|
+
|
201
|
+
if (null === this.sidebarInner) this.sidebarInner = false;
|
202
|
+
}
|
203
|
+
|
204
|
+
if (!this.sidebarInner) {
|
205
|
+
var wrapper = document.createElement('div');
|
206
|
+
wrapper.setAttribute('class', 'inner-wrapper-sticky');
|
207
|
+
this.sidebar.appendChild(wrapper);
|
208
|
+
|
209
|
+
while (this.sidebar.firstChild != wrapper) {
|
210
|
+
wrapper.appendChild(this.sidebar.firstChild);
|
211
|
+
}this.sidebarInner = this.sidebar.querySelector('.inner-wrapper-sticky');
|
212
|
+
}
|
213
|
+
|
214
|
+
// Container wrapper of the sidebar.
|
215
|
+
if (this.options.containerSelector) {
|
216
|
+
var containers = document.querySelectorAll(this.options.containerSelector);
|
217
|
+
containers = Array.prototype.slice.call(containers);
|
218
|
+
|
219
|
+
containers.forEach(function (container, item) {
|
220
|
+
if (!container.contains(_this2.sidebar)) return;
|
221
|
+
_this2.container = container;
|
222
|
+
});
|
223
|
+
|
224
|
+
if (!containers.length) throw new Error("The container does not contains on the sidebar.");
|
225
|
+
}
|
226
|
+
|
227
|
+
// If top/bottom spacing is not function parse value to integer.
|
228
|
+
if ('function' !== typeof this.options.topSpacing) this.options.topSpacing = parseInt(this.options.topSpacing) || 0;
|
229
|
+
|
230
|
+
if ('function' !== typeof this.options.bottomSpacing) this.options.bottomSpacing = parseInt(this.options.bottomSpacing) || 0;
|
231
|
+
|
232
|
+
// Breakdown sticky sidebar if screen width below `options.minWidth`.
|
233
|
+
this._widthBreakpoint();
|
234
|
+
|
235
|
+
// Calculate dimensions of sidebar, container and viewport.
|
236
|
+
this.calcDimensions();
|
237
|
+
|
238
|
+
// Affix sidebar in proper position.
|
239
|
+
this.stickyPosition();
|
240
|
+
|
241
|
+
// Bind all events.
|
242
|
+
this.bindEvents();
|
243
|
+
|
244
|
+
// Inform other properties the sticky sidebar is initialized.
|
245
|
+
this._initialized = true;
|
246
|
+
}
|
247
|
+
}, {
|
248
|
+
key: 'bindEvents',
|
249
|
+
value: function bindEvents() {
|
250
|
+
window.addEventListener('resize', this, { passive: true, capture: false });
|
251
|
+
window.addEventListener('scroll', this, { passive: true, capture: false });
|
252
|
+
|
253
|
+
this.sidebar.addEventListener('update' + EVENT_KEY, this);
|
254
|
+
|
255
|
+
if (this.options.resizeSensor && 'undefined' !== typeof ResizeSensor) {
|
256
|
+
new ResizeSensor(this.sidebarInner, this.handleEvent);
|
257
|
+
new ResizeSensor(this.container, this.handleEvent);
|
258
|
+
}
|
259
|
+
}
|
260
|
+
}, {
|
261
|
+
key: 'handleEvent',
|
262
|
+
value: function handleEvent(event) {
|
263
|
+
this.updateSticky(event);
|
264
|
+
}
|
265
|
+
}, {
|
266
|
+
key: 'calcDimensions',
|
267
|
+
value: function calcDimensions() {
|
268
|
+
if (this._breakpoint) return;
|
269
|
+
var dims = this.dimensions;
|
270
|
+
|
271
|
+
// Container of sticky sidebar dimensions.
|
272
|
+
dims.containerTop = StickySidebar.offsetRelative(this.container).top;
|
273
|
+
dims.containerHeight = this.container.clientHeight;
|
274
|
+
dims.containerBottom = dims.containerTop + dims.containerHeight;
|
275
|
+
|
276
|
+
// Sidebar dimensions.
|
277
|
+
dims.sidebarHeight = this.sidebarInner.offsetHeight;
|
278
|
+
dims.sidebarWidth = this.sidebarInner.offsetWidth;
|
279
|
+
|
280
|
+
// Screen viewport dimensions.
|
281
|
+
dims.viewportHeight = window.innerHeight;
|
282
|
+
|
283
|
+
// Maximum sidebar translate Y.
|
284
|
+
dims.maxTranslateY = dims.containerHeight - dims.sidebarHeight;
|
285
|
+
|
286
|
+
this._calcDimensionsWithScroll();
|
287
|
+
}
|
288
|
+
}, {
|
289
|
+
key: '_calcDimensionsWithScroll',
|
290
|
+
value: function _calcDimensionsWithScroll() {
|
291
|
+
var dims = this.dimensions;
|
292
|
+
|
293
|
+
dims.sidebarLeft = StickySidebar.offsetRelative(this.sidebar).left;
|
294
|
+
|
295
|
+
dims.viewportTop = document.documentElement.scrollTop || document.body.scrollTop;
|
296
|
+
dims.viewportBottom = dims.viewportTop + dims.viewportHeight;
|
297
|
+
dims.viewportLeft = document.documentElement.scrollLeft || document.body.scrollLeft;
|
298
|
+
|
299
|
+
dims.topSpacing = this.options.topSpacing;
|
300
|
+
dims.bottomSpacing = this.options.bottomSpacing;
|
301
|
+
|
302
|
+
if ('function' === typeof dims.topSpacing) dims.topSpacing = parseInt(dims.topSpacing(this.sidebar)) || 0;
|
303
|
+
|
304
|
+
if ('function' === typeof dims.bottomSpacing) dims.bottomSpacing = parseInt(dims.bottomSpacing(this.sidebar)) || 0;
|
305
|
+
|
306
|
+
if ('VIEWPORT-TOP' === this.affixedType) {
|
307
|
+
// Adjust translate Y in the case decrease top spacing value.
|
308
|
+
if (dims.topSpacing < dims.lastTopSpacing) {
|
309
|
+
dims.translateY += dims.lastTopSpacing - dims.topSpacing;
|
310
|
+
this._reStyle = true;
|
311
|
+
}
|
312
|
+
} else if ('VIEWPORT-BOTTOM' === this.affixedType) {
|
313
|
+
// Adjust translate Y in the case decrease bottom spacing value.
|
314
|
+
if (dims.bottomSpacing < dims.lastBottomSpacing) {
|
315
|
+
dims.translateY += dims.lastBottomSpacing - dims.bottomSpacing;
|
316
|
+
this._reStyle = true;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
dims.lastTopSpacing = dims.topSpacing;
|
321
|
+
dims.lastBottomSpacing = dims.bottomSpacing;
|
322
|
+
}
|
323
|
+
}, {
|
324
|
+
key: 'isSidebarFitsViewport',
|
325
|
+
value: function isSidebarFitsViewport() {
|
326
|
+
var dims = this.dimensions;
|
327
|
+
var offset = this.scrollDirection === 'down' ? dims.lastBottomSpacing : dims.lastTopSpacing;
|
328
|
+
return this.dimensions.sidebarHeight + offset < this.dimensions.viewportHeight;
|
329
|
+
}
|
330
|
+
}, {
|
331
|
+
key: 'observeScrollDir',
|
332
|
+
value: function observeScrollDir() {
|
333
|
+
var dims = this.dimensions;
|
334
|
+
if (dims.lastViewportTop === dims.viewportTop) return;
|
335
|
+
|
336
|
+
var furthest = 'down' === this.direction ? Math.min : Math.max;
|
337
|
+
|
338
|
+
// If the browser is scrolling not in the same direction.
|
339
|
+
if (dims.viewportTop === furthest(dims.viewportTop, dims.lastViewportTop)) this.direction = 'down' === this.direction ? 'up' : 'down';
|
340
|
+
}
|
341
|
+
}, {
|
342
|
+
key: 'getAffixType',
|
343
|
+
value: function getAffixType() {
|
344
|
+
this._calcDimensionsWithScroll();
|
345
|
+
var dims = this.dimensions;
|
346
|
+
var colliderTop = dims.viewportTop + dims.topSpacing;
|
347
|
+
var affixType = this.affixedType;
|
348
|
+
|
349
|
+
if (colliderTop <= dims.containerTop || dims.containerHeight <= dims.sidebarHeight) {
|
350
|
+
dims.translateY = 0;
|
351
|
+
affixType = 'STATIC';
|
352
|
+
} else {
|
353
|
+
affixType = 'up' === this.direction ? this._getAffixTypeScrollingUp() : this._getAffixTypeScrollingDown();
|
354
|
+
}
|
355
|
+
|
356
|
+
// Make sure the translate Y is not bigger than container height.
|
357
|
+
dims.translateY = Math.max(0, dims.translateY);
|
358
|
+
dims.translateY = Math.min(dims.containerHeight, dims.translateY);
|
359
|
+
dims.translateY = Math.round(dims.translateY);
|
360
|
+
|
361
|
+
dims.lastViewportTop = dims.viewportTop;
|
362
|
+
return affixType;
|
363
|
+
}
|
364
|
+
}, {
|
365
|
+
key: '_getAffixTypeScrollingDown',
|
366
|
+
value: function _getAffixTypeScrollingDown() {
|
367
|
+
var dims = this.dimensions;
|
368
|
+
var sidebarBottom = dims.sidebarHeight + dims.containerTop;
|
369
|
+
var colliderTop = dims.viewportTop + dims.topSpacing;
|
370
|
+
var colliderBottom = dims.viewportBottom - dims.bottomSpacing;
|
371
|
+
var affixType = this.affixedType;
|
372
|
+
|
373
|
+
if (this.isSidebarFitsViewport()) {
|
374
|
+
if (dims.sidebarHeight + colliderTop >= dims.containerBottom) {
|
375
|
+
dims.translateY = dims.containerBottom - sidebarBottom;
|
376
|
+
affixType = 'CONTAINER-BOTTOM';
|
377
|
+
} else if (colliderTop >= dims.containerTop) {
|
378
|
+
dims.translateY = colliderTop - dims.containerTop;
|
379
|
+
affixType = 'VIEWPORT-TOP';
|
380
|
+
}
|
381
|
+
} else {
|
382
|
+
if (dims.containerBottom <= colliderBottom) {
|
383
|
+
dims.translateY = dims.containerBottom - sidebarBottom;
|
384
|
+
affixType = 'CONTAINER-BOTTOM';
|
385
|
+
} else if (sidebarBottom + dims.translateY <= colliderBottom) {
|
386
|
+
dims.translateY = colliderBottom - sidebarBottom;
|
387
|
+
affixType = 'VIEWPORT-BOTTOM';
|
388
|
+
} else if (dims.containerTop + dims.translateY <= colliderTop && 0 !== dims.translateY && dims.maxTranslateY !== dims.translateY) {
|
389
|
+
affixType = 'VIEWPORT-UNBOTTOM';
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
return affixType;
|
394
|
+
}
|
395
|
+
}, {
|
396
|
+
key: '_getAffixTypeScrollingUp',
|
397
|
+
value: function _getAffixTypeScrollingUp() {
|
398
|
+
var dims = this.dimensions;
|
399
|
+
var sidebarBottom = dims.sidebarHeight + dims.containerTop;
|
400
|
+
var colliderTop = dims.viewportTop + dims.topSpacing;
|
401
|
+
var colliderBottom = dims.viewportBottom - dims.bottomSpacing;
|
402
|
+
var affixType = this.affixedType;
|
403
|
+
|
404
|
+
if (colliderTop <= dims.translateY + dims.containerTop) {
|
405
|
+
dims.translateY = colliderTop - dims.containerTop;
|
406
|
+
affixType = 'VIEWPORT-TOP';
|
407
|
+
} else if (dims.containerBottom <= colliderBottom) {
|
408
|
+
dims.translateY = dims.containerBottom - sidebarBottom;
|
409
|
+
affixType = 'CONTAINER-BOTTOM';
|
410
|
+
} else if (!this.isSidebarFitsViewport()) {
|
411
|
+
|
412
|
+
if (dims.containerTop <= colliderTop && 0 !== dims.translateY && dims.maxTranslateY !== dims.translateY) {
|
413
|
+
affixType = 'VIEWPORT-UNBOTTOM';
|
414
|
+
}
|
415
|
+
}
|
416
|
+
|
417
|
+
return affixType;
|
418
|
+
}
|
419
|
+
}, {
|
420
|
+
key: '_getStyle',
|
421
|
+
value: function _getStyle(affixType) {
|
422
|
+
if ('undefined' === typeof affixType) return;
|
423
|
+
|
424
|
+
var style = { inner: {}, outer: {} };
|
425
|
+
var dims = this.dimensions;
|
426
|
+
|
427
|
+
switch (affixType) {
|
428
|
+
case 'VIEWPORT-TOP':
|
429
|
+
style.inner = { position: 'fixed', top: dims.topSpacing,
|
430
|
+
left: dims.sidebarLeft - dims.viewportLeft, width: dims.sidebarWidth };
|
431
|
+
break;
|
432
|
+
case 'VIEWPORT-BOTTOM':
|
433
|
+
style.inner = { position: 'fixed', top: 'auto', left: dims.sidebarLeft,
|
434
|
+
bottom: dims.bottomSpacing, width: dims.sidebarWidth };
|
435
|
+
break;
|
436
|
+
case 'CONTAINER-BOTTOM':
|
437
|
+
case 'VIEWPORT-UNBOTTOM':
|
438
|
+
var translate = this._getTranslate(0, dims.translateY + 'px');
|
439
|
+
|
440
|
+
if (translate) style.inner = { transform: translate };else style.inner = { position: 'absolute', top: dims.translateY, width: dims.sidebarWidth };
|
441
|
+
break;
|
442
|
+
}
|
443
|
+
|
444
|
+
switch (affixType) {
|
445
|
+
case 'VIEWPORT-TOP':
|
446
|
+
case 'VIEWPORT-BOTTOM':
|
447
|
+
case 'VIEWPORT-UNBOTTOM':
|
448
|
+
case 'CONTAINER-BOTTOM':
|
449
|
+
style.outer = { height: dims.sidebarHeight, position: 'relative' };
|
450
|
+
break;
|
451
|
+
}
|
452
|
+
|
453
|
+
style.outer = StickySidebar.extend({ height: '', position: '' }, style.outer);
|
454
|
+
style.inner = StickySidebar.extend({ position: 'relative', top: '', left: '',
|
455
|
+
bottom: '', width: '', transform: '' }, style.inner);
|
456
|
+
|
457
|
+
return style;
|
458
|
+
}
|
459
|
+
}, {
|
460
|
+
key: 'stickyPosition',
|
461
|
+
value: function stickyPosition(force) {
|
462
|
+
if (this._breakpoint) return;
|
463
|
+
|
464
|
+
force = this._reStyle || force || false;
|
465
|
+
|
466
|
+
var offsetTop = this.options.topSpacing;
|
467
|
+
var offsetBottom = this.options.bottomSpacing;
|
468
|
+
|
469
|
+
var affixType = this.getAffixType();
|
470
|
+
var style = this._getStyle(affixType);
|
471
|
+
|
472
|
+
if ((this.affixedType != affixType || force) && affixType) {
|
473
|
+
var affixEvent = 'affix.' + affixType.toLowerCase().replace('viewport-', '') + EVENT_KEY;
|
474
|
+
StickySidebar.eventTrigger(this.sidebar, affixEvent);
|
475
|
+
|
476
|
+
if ('STATIC' === affixType) StickySidebar.removeClass(this.sidebar, this.options.stickyClass);else StickySidebar.addClass(this.sidebar, this.options.stickyClass);
|
477
|
+
|
478
|
+
for (var key in style.outer) {
|
479
|
+
var unit = 'number' === typeof style.outer[key] ? 'px' : '';
|
480
|
+
this.sidebar.style[key] = style.outer[key] + unit;
|
481
|
+
}
|
482
|
+
|
483
|
+
for (var _key in style.inner) {
|
484
|
+
var _unit = 'number' === typeof style.inner[_key] ? 'px' : '';
|
485
|
+
this.sidebarInner.style[_key] = style.inner[_key] + _unit;
|
486
|
+
}
|
487
|
+
|
488
|
+
var affixedEvent = 'affixed.' + affixType.toLowerCase().replace('viewport-', '') + EVENT_KEY;
|
489
|
+
StickySidebar.eventTrigger(this.sidebar, affixedEvent);
|
490
|
+
} else {
|
491
|
+
if (this._initialized) this.sidebarInner.style.left = style.inner.left;
|
492
|
+
}
|
493
|
+
|
494
|
+
this.affixedType = affixType;
|
495
|
+
}
|
496
|
+
}, {
|
497
|
+
key: '_widthBreakpoint',
|
498
|
+
value: function _widthBreakpoint() {
|
499
|
+
|
500
|
+
if (window.innerWidth <= this.options.minWidth) {
|
501
|
+
this._breakpoint = true;
|
502
|
+
this.affixedType = 'STATIC';
|
503
|
+
|
504
|
+
this.sidebar.removeAttribute('style');
|
505
|
+
StickySidebar.removeClass(this.sidebar, this.options.stickyClass);
|
506
|
+
this.sidebarInner.removeAttribute('style');
|
507
|
+
} else {
|
508
|
+
this._breakpoint = false;
|
509
|
+
}
|
510
|
+
}
|
511
|
+
}, {
|
512
|
+
key: 'updateSticky',
|
513
|
+
value: function updateSticky() {
|
514
|
+
var _this3 = this;
|
515
|
+
|
516
|
+
var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
517
|
+
|
518
|
+
if (this._running) return;
|
519
|
+
this._running = true;
|
520
|
+
|
521
|
+
(function (eventType) {
|
522
|
+
requestAnimationFrame(function () {
|
523
|
+
switch (eventType) {
|
524
|
+
// When browser is scrolling and re-calculate just dimensions
|
525
|
+
// within scroll.
|
526
|
+
case 'scroll':
|
527
|
+
_this3._calcDimensionsWithScroll();
|
528
|
+
_this3.observeScrollDir();
|
529
|
+
_this3.stickyPosition();
|
530
|
+
break;
|
531
|
+
|
532
|
+
// When browser is resizing or there's no event, observe width
|
533
|
+
// breakpoint and re-calculate dimensions.
|
534
|
+
case 'resize':
|
535
|
+
default:
|
536
|
+
_this3._widthBreakpoint();
|
537
|
+
_this3.calcDimensions();
|
538
|
+
_this3.stickyPosition(true);
|
539
|
+
break;
|
540
|
+
}
|
541
|
+
_this3._running = false;
|
542
|
+
});
|
543
|
+
})(event.type);
|
544
|
+
}
|
545
|
+
}, {
|
546
|
+
key: '_setSupportFeatures',
|
547
|
+
value: function _setSupportFeatures() {
|
548
|
+
var support = this.support;
|
549
|
+
|
550
|
+
support.transform = StickySidebar.supportTransform();
|
551
|
+
support.transform3d = StickySidebar.supportTransform(true);
|
552
|
+
}
|
553
|
+
}, {
|
554
|
+
key: '_getTranslate',
|
555
|
+
value: function _getTranslate() {
|
556
|
+
var y = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
557
|
+
var x = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
558
|
+
var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
559
|
+
|
560
|
+
if (this.support.transform3d) return 'translate3d(' + y + ', ' + x + ', ' + z + ')';else if (this.support.translate) return 'translate(' + y + ', ' + x + ')';else return false;
|
561
|
+
}
|
562
|
+
}, {
|
563
|
+
key: 'destroy',
|
564
|
+
value: function destroy() {
|
565
|
+
window.removeEventListener('resize', this, { capture: false });
|
566
|
+
window.removeEventListener('scroll', this, { capture: false });
|
567
|
+
|
568
|
+
this.sidebar.classList.remove(this.options.stickyClass);
|
569
|
+
this.sidebar.style.minHeight = '';
|
570
|
+
|
571
|
+
this.sidebar.removeEventListener('update' + EVENT_KEY, this);
|
572
|
+
|
573
|
+
var styleReset = { inner: {}, outer: {} };
|
574
|
+
|
575
|
+
styleReset.inner = { position: '', top: '', left: '', bottom: '', width: '', transform: '' };
|
576
|
+
styleReset.outer = { height: '', position: '' };
|
577
|
+
|
578
|
+
for (var key in styleReset.outer) {
|
579
|
+
this.sidebar.style[key] = styleReset.outer[key];
|
580
|
+
}for (var _key2 in styleReset.inner) {
|
581
|
+
this.sidebarInner.style[_key2] = styleReset.inner[_key2];
|
582
|
+
}if (this.options.resizeSensor && 'undefined' !== typeof ResizeSensor) {
|
583
|
+
ResizeSensor.detach(this.sidebarInner, this.handleEvent);
|
584
|
+
ResizeSensor.detach(this.container, this.handleEvent);
|
585
|
+
}
|
586
|
+
}
|
587
|
+
}], [{
|
588
|
+
key: 'supportTransform',
|
589
|
+
value: function supportTransform(transform3d) {
|
590
|
+
var result = false,
|
591
|
+
property = transform3d ? 'perspective' : 'transform',
|
592
|
+
upper = property.charAt(0).toUpperCase() + property.slice(1),
|
593
|
+
prefixes = ['Webkit', 'Moz', 'O', 'ms'],
|
594
|
+
support = document.createElement('support'),
|
595
|
+
style = support.style;
|
596
|
+
|
597
|
+
(property + ' ' + prefixes.join(upper + ' ') + upper).split(' ').forEach(function (property, i) {
|
598
|
+
if (style[property] !== undefined) {
|
599
|
+
result = property;
|
600
|
+
return false;
|
601
|
+
}
|
602
|
+
});
|
603
|
+
return result;
|
604
|
+
}
|
605
|
+
}, {
|
606
|
+
key: 'eventTrigger',
|
607
|
+
value: function eventTrigger(element, eventName, data) {
|
608
|
+
try {
|
609
|
+
var event = new CustomEvent(eventName, { detail: data });
|
610
|
+
} catch (e) {
|
611
|
+
var event = document.createEvent('CustomEvent');
|
612
|
+
event.initCustomEvent(eventName, true, true, data);
|
613
|
+
}
|
614
|
+
element.dispatchEvent(event);
|
615
|
+
}
|
616
|
+
}, {
|
617
|
+
key: 'extend',
|
618
|
+
value: function extend(defaults, options) {
|
619
|
+
var results = {};
|
620
|
+
for (var key in defaults) {
|
621
|
+
if ('undefined' !== typeof options[key]) results[key] = options[key];else results[key] = defaults[key];
|
622
|
+
}
|
623
|
+
return results;
|
624
|
+
}
|
625
|
+
}, {
|
626
|
+
key: 'offsetRelative',
|
627
|
+
value: function offsetRelative(element) {
|
628
|
+
var result = { left: 0, top: 0 };
|
629
|
+
|
630
|
+
do {
|
631
|
+
var offsetTop = element.offsetTop;
|
632
|
+
var offsetLeft = element.offsetLeft;
|
633
|
+
|
634
|
+
if (!isNaN(offsetTop)) result.top += offsetTop;
|
635
|
+
|
636
|
+
if (!isNaN(offsetLeft)) result.left += offsetLeft;
|
637
|
+
|
638
|
+
element = 'BODY' === element.tagName ? element.parentElement : element.offsetParent;
|
639
|
+
} while (element);
|
640
|
+
return result;
|
641
|
+
}
|
642
|
+
}, {
|
643
|
+
key: 'addClass',
|
644
|
+
value: function addClass(element, className) {
|
645
|
+
if (!StickySidebar.hasClass(element, className)) {
|
646
|
+
if (element.classList) element.classList.add(className);else element.className += ' ' + className;
|
647
|
+
}
|
648
|
+
}
|
649
|
+
}, {
|
650
|
+
key: 'removeClass',
|
651
|
+
value: function removeClass(element, className) {
|
652
|
+
if (StickySidebar.hasClass(element, className)) {
|
653
|
+
if (element.classList) element.classList.remove(className);else element.className = element.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
|
654
|
+
}
|
655
|
+
}
|
656
|
+
}, {
|
657
|
+
key: 'hasClass',
|
658
|
+
value: function hasClass(element, className) {
|
659
|
+
if (element.classList) return element.classList.contains(className);else return new RegExp('(^| )' + className + '( |$)', 'gi').test(element.className);
|
660
|
+
}
|
661
|
+
}, {
|
662
|
+
key: 'defaults',
|
663
|
+
get: function () {
|
664
|
+
return DEFAULTS;
|
665
|
+
}
|
666
|
+
}]);
|
667
|
+
|
668
|
+
return StickySidebar;
|
669
|
+
}();
|
670
|
+
|
671
|
+
return StickySidebar;
|
672
|
+
}();
|
673
|
+
|
674
|
+
exports.default = StickySidebar;
|
675
|
+
|
676
|
+
|
677
|
+
// Global
|
678
|
+
// -------------------------
|
679
|
+
window.StickySidebar = StickySidebar;
|
680
|
+
});
|
681
|
+
});
|
682
|
+
|
683
|
+
unwrapExports(stickySidebar);
|
684
|
+
|
685
|
+
var jquery_stickySidebar = createCommonjsModule(function (module, exports) {
|
686
|
+
(function (global, factory) {
|
687
|
+
if (typeof undefined === "function" && undefined.amd) {
|
688
|
+
undefined(['./sticky-sidebar'], factory);
|
689
|
+
} else {
|
690
|
+
factory(stickySidebar);
|
691
|
+
}
|
692
|
+
})(commonjsGlobal, function (_stickySidebar) {
|
693
|
+
var _stickySidebar2 = _interopRequireDefault(_stickySidebar);
|
694
|
+
|
695
|
+
function _interopRequireDefault(obj) {
|
696
|
+
return obj && obj.__esModule ? obj : {
|
697
|
+
default: obj
|
698
|
+
};
|
699
|
+
}
|
700
|
+
|
701
|
+
(function () {
|
702
|
+
if ('undefined' === typeof window) return;
|
703
|
+
|
704
|
+
var plugin = window.$ || window.jQuery || window.Zepto;
|
705
|
+
var DATA_NAMESPACE = 'stickySidebar';
|
706
|
+
|
707
|
+
// Make sure the site has jquery or zepto plugin.
|
708
|
+
if (plugin) {
|
709
|
+
var _jQueryPlugin = function (config) {
|
710
|
+
return this.each(function () {
|
711
|
+
var $this = plugin(this),
|
712
|
+
data = plugin(this).data(DATA_NAMESPACE);
|
713
|
+
|
714
|
+
if (!data) {
|
715
|
+
data = new _stickySidebar2.default(this, typeof config == 'object' && config);
|
716
|
+
$this.data(DATA_NAMESPACE, data);
|
717
|
+
}
|
718
|
+
|
719
|
+
if ('string' === typeof config) {
|
720
|
+
if (data[config] === undefined && ['destroy', 'updateSticky'].indexOf(config) === -1) throw new Error('No method named "' + config + '"');
|
721
|
+
|
722
|
+
data[config]();
|
723
|
+
}
|
724
|
+
});
|
725
|
+
};
|
726
|
+
|
727
|
+
plugin.fn.stickySidebar = _jQueryPlugin;
|
728
|
+
plugin.fn.stickySidebar.Constructor = _stickySidebar2.default;
|
729
|
+
|
730
|
+
var old = plugin.fn.stickySidebar;
|
731
|
+
|
732
|
+
/**
|
733
|
+
* Sticky Sidebar No Conflict.
|
734
|
+
*/
|
735
|
+
plugin.fn.stickySidebar.noConflict = function () {
|
736
|
+
plugin.fn.stickySidebar = old;
|
737
|
+
return this;
|
738
|
+
};
|
739
|
+
}
|
740
|
+
})();
|
741
|
+
});
|
742
|
+
});
|
743
|
+
|
744
|
+
var jquery_stickySidebar$1 = unwrapExports(jquery_stickySidebar);
|
745
|
+
|
746
|
+
return jquery_stickySidebar$1;
|
747
|
+
|
748
|
+
})));
|
749
|
+
|