/
script.js
82 lines (77 loc) · 3.33 KB
/
script.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
jQuery.noConflict();
(function($) {
$(document).ready(function() {
/* turns on specific styling when main nav items are less than the width of the header otherwise it defaults to mediaquery multiline styling */
function toggleNavigationClassByWidth(){
var primaryNavigation = $('.primary').first();
var mainNavigation = $(primaryNavigation).find('ul').first();
if(primaryNavigation.outerWidth() > mainNavigation.outerWidth()) {
mainNavigation.addClass("standard-nav"); //if the nav ul fits within its container the standard styling is applied
}
else {
mainNavigation.removeClass("standard-nav");
}
}
var resizeTimer; //constantly checks for the size of the browser window so correct style is applied.
$(window).resize(function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(toggleNavigationClassByWidth, 100);
}).load(function(){
clearTimeout(resizeTimer);
resizeTimer = setTimeout(toggleNavigationClassByWidth, 100);
});
/* show/hide search form when window width less than 700px */
$('span.search-dropdown-icon').on('click',function() {
if ($(window).width() < 700) { // checks for width of window - if it is less than 700px
if ($('div.search-bar').is(":hidden")){ //checks if ul#nav is hidden
$('div.search-bar').slideDown('fast'); // slides the Search bar down
$('div.search-bar form').fadeIn(500); // Fades the Search form in
return false;
} else {
$('div.search-bar').slideUp('fast'); // slides the Search bar up
$('div.search-bar form').hide(); // Fades the Search form out
return false;
}
}
});
/* show/hide main nav menu when window width less than 700px */
$('span.nav-open-button').on('click',function() {
if ($(window).width() < 700) { // checks for width of window - if it is less than 700px
if ($('ul#nav').is(":hidden")){ //checks if ul#nav is hidden
$('ul#nav').slideDown('fast'); // slides the nav menu down
$('header span.menu-bubble-arrow').show(); // shows the nav menu arrow
return false;
} else {
$('ul#nav').slideUp('fast'); // slides the nav menu up
$('header span.menu-bubble-arrow').removeAttr("style"); // hides the nav menu arrow
return false;
}
}
});
/* clears any inline styles when window is resized above 700px */
$(window).resize(function () {
if ($(this).width() >= 700) {
$('div.search-bar').removeAttr("style");
$('ul#nav').removeAttr("style");
$('div.search-bar form').removeAttr("style");
$('span.search-bubble-arrow').removeAttr("style");
}
});
/* removes text from search form on focus and replaces it on unfocus - if text is entered then it does not get replaced with default on unfocus */
$('#SearchForm_SearchForm_Search').each(function() {
var default_value = this.value;
$(this).focus(function() {
if(this.value == default_value) {
this.value = '';
}
});
$(this).blur(function() {
if(this.value == '') {
this.value = default_value;
}
});
});
});
}(jQuery));