github.com/kardianos/nomad@v0.1.3-0.20151022182107-b13df73ee850/website/source/assets/javascripts/app/Sidebar.js (about)

     1  (function(){
     2  
     3  Sidebar = Base.extend({
     4  
     5  	$body: null,
     6  	$overlay: null,
     7  	$sidebar: null,
     8  	$sidebarHeader: null,
     9  	$sidebarImg: null,
    10  	$toggleButton: null,
    11  
    12  	constructor: function(){
    13  		this.$body = $('body');
    14  		this.$overlay = $('.sidebar-overlay');
    15      	this.$sidebar = $('#sidebar');
    16      	this.$sidebarHeader = $('#sidebar .sidebar-header');
    17      	this.$toggleButton = $('.navbar-toggle');
    18  
    19      	this.sidebarImg = this.$sidebarHeader.css('background-image');
    20  
    21  		this.addEventListeners();
    22  	},
    23  
    24  	addEventListeners: function(){
    25  		var _this = this;
    26  
    27  	    _this.$toggleButton.on('click', function() {
    28  	        _this.$sidebar.toggleClass('open');
    29  	        if ((_this.$sidebar.hasClass('sidebar-fixed-left') || _this.$sidebar.hasClass('sidebar-fixed-right')) && _this.$sidebar.hasClass('open')) {
    30  	            _this.$overlay.addClass('active');
    31  	            _this.$body.css('overflow', 'hidden');
    32  	        } else {
    33  	            _this.$overlay.removeClass('active');
    34  	            _this.$body.css('overflow', 'auto');
    35  	        }
    36  
    37  	        return false;
    38  	    });
    39  
    40  	    _this.$overlay.on('click', function() {
    41  	        $(this).removeClass('active');
    42  	        _this.$body.css('overflow', 'auto');
    43  	        _this.$sidebar.removeClass('open');
    44  	    });
    45  	}
    46  
    47  });
    48  
    49  window.Sidebar = Sidebar;
    50  
    51  })();