-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbehaviour.js
95 lines (76 loc) · 2.55 KB
/
behaviour.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
/*
* It looks like jQuery but it's Cash 💰
* You'll find the documentation on GitHub: https://github.com/fabiospampinato/cash#readme
*
* Thanks to Stephan M. for helping me out with JS
*/
/*
* Helper Functions
* - find an attribute
*/
$.fn.hasAttr = function (name) {
return this.attr(name) !== undefined;
};
// https://stackoverflow.com/questions/26203453/jquery-generate-unique-ids
function Generator() {}
Generator.prototype.rand = Math.floor(Math.random() * 26) + Date.now();
Generator.prototype.getId = function() {
return this.rand++;
};
var idGen = new Generator();
/* TODO: Convert skipt links to function
$.fn.dynamicSkiplinks = function (name) {
//
};
*/
// Skip link function
$(function () {
// Basics
$('html').removeClass('no-js');
// DEBUG
//if(window.location.href.includes('github')) {
if (document.location.href.indexOf('github') === -1) {
$('#design-01').attr('checked', true);
// $('#design-02').attr('checked', true);
// $('#design-03').attr('checked', true);
}
/*
* Dynamic Skip Links
* looks for specific elements and built a list (select)
*/
$('legend,h1,h2')
.attr('tabindex', '-1')
.removeAttr('title')
.each(function () {
var elementName = $(this).get(0).tagName.toLowerCase();
var getElementAriaLabel = $(this).attr('aria-label');
var getElementText = $(this).text();
var noContent = 'No label';
if ($(this).hasAttr('aria-label')) {
var elementAriaLabel = getElementAriaLabel;
} else {
var elementText = getElementText;
}
if ($(this).hasAttr('id')) {
// console.log("true");
} else {
var elementUniqueId = idGen.getId();
$(this).attr('id', elementUniqueId);
$('#js-nav-skip-links').append(
'<li><a href="#' + elementUniqueId + '">Go to ' + (typeof elementAriaLabel !== 'undefined' ? elementAriaLabel : (elementText != '' ? elementText : noContent)) + " (" + elementName + ")" + "</a></li>"
);
}
});
/*
* Design options
* optional styles based on checkboxes
*/
$('.design-option').on('change', function() {
var elementId = this.id;
if(this.checked) {
$('body').addClass(elementId);
} else {
$('body').removeClass(elementId);
}
});
});