Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // GLOBAL VARIABLE
- // set it to false by default
- var isMobile = false;
- var detectMobile = function(){
- var MIN_SCREEN_WIDTH = 767;
- var $window = $(window);
- if($window.width() < MIN_SCREEN_WIDTH){
- return true;
- }else{
- return false;
- }
- };
- var mobileSpecialSauce = function(){
- $('li.nav-header span').hide();
- //$('ul.sub-nav').hide();
- $('.side-nav li.nav-header').prepend("<span class='plus collapse-symb'>[+] </span><span class='minus collapse-symb'>[-] </span>");
- $('.side-nav li.nav-header').on('click.mobile', function() {
- $(this).next('ul.sub-nav').slideToggle();
- $(this).children('span').toggle();
- });
- };
- // update variable on load
- isMobile = detectMobile();
- // onload run special sauce
- if(isMobile){
- mobileSpecialSauce();
- }
- // update variable if window is resized
- $(window).on('resize',function(){
- isMobile = detectMobile();
- if(isMobile){
- mobileSpecialSauce();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment