silverstripe-simple/javascript/script.js

83 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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));