-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathmain.js
74 lines (64 loc) · 2.57 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
$(document).ready(function () {
$(window).scroll(function () {
if ($(this).scrollTop() > 500) {
$('#back-to-top').fadeIn();
} else {
$('#back-to-top').fadeOut();
}
});
patchAssetIntoDom('/assets/logos/cc/logomark.svg');
patchAssetIntoDom('/assets/logos/products/open_source.svg');
// Check for click events on the navbar burger icon
$(".navbar-burger").click(function() {
// Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu"
$(".navbar-burger").toggleClass("is-active");
$(".navbar-menu").toggleClass("is-active");
});
$(".navbar-item.has-dropdown").click(function() {
if ($(".navbar-burger").is(':visible')) {
$(this).toggleClass("is-active");
}
});
$(".navbar-item > .navbar-link").click(function(e) {
if ($(".navbar-burger").is(':visible')) {
e.preventDefault();
}
});
$(window).resize(function() {
if (!$(".navbar-burger").is(':visible') && $(".navbar-item.has-dropdown.is-active").length) {
$(".navbar-item.has-dropdown.is-active").removeClass('is-active');
}
});
// Internal Navigation for table of contents and table of progress component
let hash = window.location.hash;
if (hash.length > 0) {
$('.menu-list').find('a[href=\"' + hash + '\"]').addClass('is-active');
$('.step').find('a[href=\"' + hash + '\"]').find('.number').addClass('is-active');
}
$(window).on('hashchange', function() {
let hash = window.location.hash;
$('.menu-list a[href*="#"]').closest('a').removeClass('is-active');
$('.menu-list').find('a[href=\"' + hash + '\"]').addClass('is-active');
$('.step a[href*="#"]').closest('a').find('.number').removeClass('is-active');
$('.step').find('a[href=\"' + hash + '\"]').find('.number').addClass('is-active');
});
});
const getFullyQualifiedUrl = (path, version) => {
let baseUrl = "https://unpkg.com/@creativecommons/vocabulary"
if (version) {
baseUrl = `${baseUrl}@${version}`
}
return `${baseUrl}/${path}`
}
const patchAssetIntoDom = (asset, version = null) => {
const ajax = new XMLHttpRequest();
ajax.open("GET", getFullyQualifiedUrl(asset, version), true);
ajax.onload = () => {
var div = document.createElement("div");
// Render SVG in the page
div.innerHTML = ajax.responseText;
div.style.display = 'none';
document.body.insertBefore(div, document.body.childNodes[0]);
}
ajax.send();
}