Skip to content

Commit b89829c

Browse files
committed
global.js wrap in IIFE
1 parent 4781ffb commit b89829c

File tree

1 file changed

+57
-55
lines changed

1 file changed

+57
-55
lines changed

webroot/js/global.js

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,72 @@
1-
$(document).ready(setNav);
2-
$(window).resize(setNav);
1+
(function () {
2+
$(document).ready(setNav);
3+
$(window).resize(setNav);
34

4-
function setNav() {
5-
if ($("button.hamburger").is(":visible")) {
6-
$("nav.mainNav").hide(); // Mobile View
7-
} else {
8-
$("nav.mainNav").show(); // Desktop View
5+
function setNav() {
6+
if ($("button.hamburger").is(":visible")) {
7+
$("nav.mainNav").hide(); // Mobile View
8+
} else {
9+
$("nav.mainNav").show(); // Desktop View
10+
}
911
}
10-
}
1112

12-
$("button.hamburger").on("click", function () {
13-
var mainNav = $("nav.mainNav");
14-
if (mainNav.is(":visible")) {
15-
mainNav.fadeOut(100);
16-
} else {
17-
mainNav.fadeIn(100);
18-
}
19-
});
13+
$("button.hamburger").on("click", function () {
14+
var mainNav = $("nav.mainNav");
15+
if (mainNav.is(":visible")) {
16+
mainNav.fadeOut(100);
17+
} else {
18+
mainNav.fadeIn(100);
19+
}
20+
});
2021

21-
$(window).click(function (e) {
22-
if (
23-
!$(e.target).parent().hasClass("hamburger") &&
24-
$("button.hamburger").is(":visible")
25-
) {
26-
$("nav.mainNav").fadeOut(100);
27-
}
28-
});
22+
$(window).click(function (e) {
23+
if (
24+
!$(e.target).parent().hasClass("hamburger") &&
25+
$("button.hamburger").is(":visible")
26+
) {
27+
$("nav.mainNav").fadeOut(100);
28+
}
29+
});
2930

30-
// Functions to set nav links as active. Sub links can activate parents by naming files with same prefix, for example: documentation.php and documentation_view.php activate the same link
31-
var url = location.pathname;
32-
if (url.lastIndexOf(".") >= 0) {
33-
url = url.substring(0, url.lastIndexOf("."));
34-
}
31+
// Functions to set nav links as active. Sub links can activate parents by naming files with same prefix, for example: documentation.php and documentation_view.php activate the same link
32+
var url = location.pathname;
33+
if (url.lastIndexOf(".") >= 0) {
34+
url = url.substring(0, url.lastIndexOf("."));
35+
}
3536

36-
if (url.lastIndexOf("/") >= 0) {
37-
url = url.substring(url.lastIndexOf("/") + 1);
38-
}
37+
if (url.lastIndexOf("/") >= 0) {
38+
url = url.substring(url.lastIndexOf("/") + 1);
39+
}
3940

40-
$("nav.mainNav a").each(function () {
41-
var href = $(this).attr("href");
41+
$("nav.mainNav a").each(function () {
42+
var href = $(this).attr("href");
4243

43-
if (href.lastIndexOf(".") >= 0) {
44-
href = href.substring(0, href.lastIndexOf("."));
45-
}
44+
if (href.lastIndexOf(".") >= 0) {
45+
href = href.substring(0, href.lastIndexOf("."));
46+
}
4647

47-
if (href.lastIndexOf("/") >= 0) {
48-
href = href.substring(href.lastIndexOf("/") + 1);
49-
}
48+
if (href.lastIndexOf("/") >= 0) {
49+
href = href.substring(href.lastIndexOf("/") + 1);
50+
}
5051

51-
if (url.indexOf(href) == 0) {
52-
$(this).addClass("active");
53-
}
54-
});
52+
if (url.indexOf(href) == 0) {
53+
$(this).addClass("active");
54+
}
55+
});
5556

56-
/**
57-
* btnDropdown Click Events
58-
*/
59-
$("div.btnDropdown > button").click(function () {
60-
$("div.btnDropdown > div").toggle();
61-
});
57+
/**
58+
* btnDropdown Click Events
59+
*/
60+
$("div.btnDropdown > button").click(function () {
61+
$("div.btnDropdown > div").toggle();
62+
});
6263

63-
$(window).click(function (e) {
64-
if (!e.target.matches("div.btnDropdown > button")) {
65-
$("div.btnDropdown > div").hide();
66-
}
67-
});
64+
$(window).click(function (e) {
65+
if (!e.target.matches("div.btnDropdown > button")) {
66+
$("div.btnDropdown > div").hide();
67+
}
68+
});
69+
})();
6870

6971
function downloadFile(text, filename) {
7072
var element = document.createElement("a");

0 commit comments

Comments
 (0)