Guest User

Untitled

a guest
May 21st, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // GLOBAL VARIABLE
  2. // set it to false by default
  3. var isMobile = false;
  4.  
  5.  
  6. var detectMobile = function(){
  7.     var MIN_SCREEN_WIDTH = 767;
  8.     var $window = $(window);
  9.  
  10.     if($window.width() < MIN_SCREEN_WIDTH){
  11.         return true;
  12.     }else{
  13.         return false;
  14.     }
  15. };
  16.  
  17.  
  18. var mobileSpecialSauce = function(){
  19.          $('li.nav-header span').hide();    
  20.         //$('ul.sub-nav').hide();
  21.         $('.side-nav li.nav-header').prepend("<span class='plus collapse-symb'>[+] </span><span class='minus collapse-symb'>[-] </span>");
  22.  
  23.         $('.side-nav li.nav-header').on('click.mobile', function() {
  24.             $(this).next('ul.sub-nav').slideToggle();
  25.  
  26.            $(this).children('span').toggle();
  27.         });
  28.    
  29.  
  30. };
  31.  
  32.  
  33.  
  34.  
  35.  
  36. // update variable on load
  37. isMobile = detectMobile();
  38.  
  39. // onload run special sauce
  40. if(isMobile){
  41.     mobileSpecialSauce();
  42.  
  43. }
  44.  
  45.  
  46. // update variable if window is resized
  47. $(window).on('resize',function(){
  48.         isMobile = detectMobile();
  49.     if(isMobile){
  50.      mobileSpecialSauce();
  51.     }
  52. });
Advertisement
Add Comment
Please, Sign In to add comment