-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
78 lines (65 loc) · 2.36 KB
/
scripts.js
File metadata and controls
78 lines (65 loc) · 2.36 KB
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
/* Description: Custom JS file */
(function($) {
"use strict";
/* Navbar Scripts */
// jQuery to collapse the navbar on scroll
$(window).on('scroll load', function() {
if ($(".navbar").offset().top > 60) {
$(".fixed-top").addClass("top-nav-collapse");
} else {
$(".fixed-top").removeClass("top-nav-collapse");
}
});
// jQuery for page scrolling feature - requires jQuery Easing plugin
$(function() {
$(document).on('click', 'a.page-scroll', function(event) {
var $anchor = $(this);
$('html, body').stop().animate({
scrollTop: $($anchor.attr('href')).offset().top
}, 600, 'easeInOutExpo');
event.preventDefault();
});
});
// offcanvas script from Bootstrap + added element to close menu on click in small viewport
$('[data-toggle="offcanvas"], .navbar-nav li a:not(.dropdown-toggle').on('click', function () {
$('.offcanvas-collapse').toggleClass('open')
})
// hover in desktop mode
function toggleDropdown (e) {
const _d = $(e.target).closest('.dropdown'),
_m = $('.dropdown-menu', _d);
setTimeout(function(){
const shouldOpen = e.type !== 'click' && _d.is(':hover');
_m.toggleClass('show', shouldOpen);
_d.toggleClass('show', shouldOpen);
$('[data-toggle="dropdown"]', _d).attr('aria-expanded', shouldOpen);
}, e.type === 'mouseleave' ? 300 : 0);
}
$('body')
.on('mouseenter mouseleave','.dropdown',toggleDropdown)
.on('click', '.dropdown-menu a', toggleDropdown);
/* Move Form Fields Label When User Types */
// for input and textarea fields
$("input, textarea").keyup(function(){
if ($(this).val() != '') {
$(this).addClass('notEmpty');
} else {
$(this).removeClass('notEmpty');
}
});
/* Back To Top Button */
// create the back to top button
$('body').prepend('<a href="body" class="back-to-top page-scroll">Back to Top</a>');
var amountScrolled = 700;
$(window).scroll(function() {
if ($(window).scrollTop() > amountScrolled) {
$('a.back-to-top').fadeIn('500');
} else {
$('a.back-to-top').fadeOut('500');
}
});
/* Removes Long Focus On Buttons */
$(".button, a, button").mouseup(function() {
$(this).blur();
});
})(jQuery);