Last active
March 31, 2016 18:16
-
-
Save Deviad/13d01ddf40157957d7495a894e932ca6 to your computer and use it in GitHub Desktop.
jQuery with Modular OOP design pattern (it's a working example)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Custom = { | |
showHideSearch: function(boolVal) { | |
var onOff = boolVal; | |
if (onOff == 'on') { | |
jQuery(function() { | |
jQuery('#search-icon').click(function() { | |
var jtheinputselector = jQuery('input#search'); | |
if (!jtheinputselector.hasClass('active')) { | |
jQuery('#top-menu > #md-menu').css({ | |
'z-index': '10' | |
}); | |
jQuery('#search-container').css({ | |
'z-index': '11' | |
}); | |
jtheinputselector.addClass('active').css({ | |
'visibility': 'visible', | |
'opacity': '1', | |
'margin-left': '-5%', | |
'width': '100%', | |
'transition': 'opacity 1s linear, margin-left 1s, width 1s, visibility 1s' | |
}); | |
} else if (jtheinputselector.hasClass('active')) { | |
jQuery('#top-menu > #md-menu').css({ | |
'z-index': '11' | |
}); | |
jQuery('#search-container').css({ | |
'z-index': '10' | |
}); | |
jtheinputselector.removeClass('active').css({ | |
'visibility': 'hidden', | |
'opacity': '0', | |
'margin-left': '92%', | |
'width': '0', | |
'transition': 'opacity 1s linear, margin-left 1s, width 1s, visibility 1s' | |
}); | |
} | |
}); | |
}); | |
console.log("on"); | |
} else if (onOff == 'off' || onOff === undefined) { | |
// jQuery(function(){}); | |
console.log("off"); | |
jQuery(function() { | |
var jtheinputselector = jQuery('input#search'); | |
jtheinputselector.css({ | |
'visibility': 'visible', | |
'opacity': '1', | |
'margin-left': '-5%', | |
'width': '100%' | |
}); | |
jQuery('#top-menu > #md-menu').css({ | |
'z-index': '10' | |
}); | |
jQuery('#search-container').css({ | |
'z-index': '11' | |
}); | |
}); | |
} | |
}, | |
showHideMobileMenu: function() { | |
jQuery(function() { | |
var jtarget = jQuery('nav#top-menu'); | |
var jselector = jQuery('#mob-menu-btn'); | |
jselector.click(function() { | |
if (!jtarget.hasClass('mobile-active')) { | |
jtarget.addClass('mobile-active').css({ | |
'height': '450px', | |
'z-index': '10', | |
'transition': 'height .2s linear' | |
}); | |
} else if (jtarget.hasClass('mobile-active')) { | |
// jtarget.removeClass('active').css({'height': '44px', 'transition': 'height 1s'}); | |
jtarget.removeClass('mobile-active').css({ | |
'height': '44px', | |
'transition': 'height .2s linear' | |
}); | |
} | |
}); | |
jQuery(window).resize(function() { | |
var jtarget = jQuery('nav#top-menu'); | |
if (jQuery(window).width() >= 768 && jtarget.hasClass('mobile-active')) { | |
jtarget.removeClass('mobile-active').css({ | |
'height': '44px', | |
'transition': 'height 0s linear' | |
}); | |
} | |
}); | |
}); | |
}, | |
overflowAlert: function() { | |
var docWidth = document.documentElement.offsetWidth; | |
[].forEach.call(document.querySelectorAll('*'), function(el) { | |
if (el.offsetWidth > docWidth) { | |
console.log(el); | |
} | |
}); | |
}, | |
footerHeight: function() { | |
function thisHeight() { | |
return jQuery(this).height(); | |
} | |
function setFooterHeight() { | |
if (jQuery(window).width() > 1200) { | |
jQuery(".footer-bg").height(function() { | |
return Math.max.apply(Math, jQuery(this).find('span').map(thisHeight)); | |
}); | |
jQuery('.footer-bg > span').css({ | |
"top": "50%", | |
"transform": "translateY(-50%)" | |
}); | |
} else if (jQuery(window).width() <= 1200) { | |
jQuery(".footer-bg").css("height", ""); | |
jQuery('.footer-bg > span').css({ | |
"top": "", | |
"transform": "" | |
}); | |
} | |
} | |
jQuery(function() { | |
setFooterHeight(); | |
jQuery(window).resize(setFooterHeight); | |
}); | |
} | |
}; | |
Custom.footerHeight(); | |
Custom.showHideSearch('on'); | |
Custom.showHideMobileMenu(); | |
Custom.overflowAlert(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment