-
Notifications
You must be signed in to change notification settings - Fork 1
/
functionality.js
170 lines (148 loc) · 5.77 KB
/
functionality.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
// Constants
const NOT_FOUND = -1;
/***********************************
* SIDEBAR ************************************************************************************************************************************************************************************
**********************************/
bodyElement = $("body");
$mainElement = $("main");
bodyLayoutClass = $("body").attr("class"); /* bodyLayout */
if (bodyLayoutClass.indexOf("basic-sidebar-left") !== NOT_FOUND) {
$sidebar = $(".sidebar-left");
$side = "left";
$openSign = ">";
$closeSign = "<";
$sidebarToggleButton = $(".btn-sidebar-left");
} else if (bodyLayoutClass.indexOf("basic-sidebar-right") !== NOT_FOUND) {
$sidebar = $(".sidebar-right");
$side = "right";
$openSign = "<";
$closeSign = ">";
$sidebarToggleButton = $(".btn-sidebar-right");
}
if (bodyLayoutClass.indexOf("basic-sidebar") !== NOT_FOUND) {
distanceTop = $mainElement.position().top;
if (bodyElement.width() < 481) {
$sidebar.css($side, 0);
$sidebar.css("top",distanceTop);
}
$(document).ready(function() {
$sidebarToggleButton.css("top", distanceTop + 40);
/*Configuração do aspeto inicial*/
if ($mainElement.width() < 780) {
$sidebar.toggle();
$sidebarToggleButton.closing();
} else {
$sidebarToggleButton.opening();
}
/*Configuração da utilização do button*/
$sidebarToggleButton.click(function() {
$sidebar.toggle("fast", function() {
if ($sidebar.css("display") === "none") {
$sidebarToggleButton.closing();
} else {
$sidebarToggleButton.opening();
}
});
});
});
/*Configuração da alteração de tamanho da janela*/
$(window).resize(function() {
if ($sidebar.css("display") === "grid") {
if ($mainElement.width() < 780) {
$sidebar.css($side, 0);
$sidebar.css("top",distanceTop);
$sidebar.hide();
$sidebarToggleButton.closing();
}
updateButtonWidth();
}
});
}
function updateButtonWidth() {
$sidebarToggleButton.css($side, $sidebar.innerWidth());
}
$.fn.closing = function() {
this.css($side, 0);
this.text($openSign);
this.attr("aria-pressed", "true");
$sidebar.attr("aria-expanded", "false");
};
$.fn.opening = function() {
this.css($side, $sidebar.innerWidth());
this.text($closeSign);
this.attr("aria-pressed", "false");
$sidebar.attr("aria-expanded", "true");
};
/***********************************
* HORIZONTAL-NAVBAR ************************************************************************************************************************************************************************************
**********************************/
$links = $("header.head > nav > ul.links-hover");
$navElement = $(".head > nav");
$toggleButton = $("#toggle");
let mobileMaxWidth = ($links.width() + $('ul.brand > li').width()) * 1.1;
$toggleButton.click(function() {
$links.toggle();
if ($links.css("display") === "none") {
$links.attr("aria-expanded", "false");
$toggleButton.attr("aria-pressed", "true");
} else {
$links.attr("aria-expanded", "true");
$toggleButton.attr("aria-pressed", "false");
}
});
$(document).ready(function() {
//navbar responsive
if (bodyElement.width() > mobileMaxWidth) {
$toggleButton.hide().attr("aria-pressed", "false");
} else {
$links.hide().attr("aria-expanded", "false");
$navElement.switchClass("flexRow", "flexCol");
$links.switchClass("flexEnd", "flexStart");
$links.switchClass("flexRow", "flexCol");
}
});
$(window).resize(function() {
if (bodyElement.width() <= mobileMaxWidth) {
$toggleButton.show().attr("aria-pressed", "false");
$links.hide().attr("aria-expanded", "true");
$navElement.switchClass("flexRow", "flexCol");
$links.switchClass("flexEnd", "flexStart");
$links.switchClass("flexRow", "flexCol");
} else {
$toggleButton.hide().attr("aria-pressed", "true");
$links.show().attr("aria-expanded", "false");
$navElement.switchClass("flexCol", "flexRow");
$links.switchClass("flexStart", "flexEnd");
$links.switchClass("flexCol", "flexRow");
}
});
$.fn.switchClass = function(previous, next) {
this.removeClass(previous).addClass(next);
};
/***********************************
* FILL CLASS ************************************************************************************************************************************************************************************
**********************************/
height = $(window).height() - ($("body").height() - $mainElement.innerHeight());
$(".fill").css("min-height", height);
/***********************************
* CONTRAST CLASS ************************************************************************************************************************************************************************************
**********************************/
$(".contrast").click(function() {
$("html").toggleClass("contrast-vars");// todo trocar $("html") por var
});
/***********************************
* MAGNIFY CLASS ************************************************************************************************************************************************************************************
**********************************/
const root = document.querySelector("html");
let fontSize = null;
$(".plus, .minus").click(function() {
fontSize = $("p").css('font-size');
fontSize = parseFloat(fontSize);
($(this).hasClass("plus")) ? fontSize += 1 : fontSize -= 1 ;
root.style.setProperty("--font-size", fontSize + "px");
if (bodyLayoutClass.indexOf("basic") === NOT_FOUND) {
for(let i = 0; i < 300; i += 10) {
setTimeout(function(){updateButtonWidth();}, i);
}
}
});