|
@@ -6,6 +6,7 @@ var SideBarPopup = require('./popup');
|
|
|
require('perfect-scrollbar/jquery')($);
|
|
|
require('browsernizr/test/touchevents');
|
|
|
require('browsernizr');
|
|
|
+require('jquery.cookie');
|
|
|
|
|
|
var SideBar = function($sidebar) {
|
|
|
this.$sidebar = $sidebar;
|
|
@@ -18,15 +19,57 @@ SideBar.prototype = {
|
|
|
}
|
|
|
},
|
|
|
initSideBarToggle: function() {
|
|
|
- $('.sidebar-toggle').on('click', function(e) {
|
|
|
+ var toggle = function (e) {
|
|
|
e.preventDefault();
|
|
|
+ this.sideBarToggle();
|
|
|
+ };
|
|
|
|
|
|
+ $('.sidebar-toggle, #branding-menu').on('click', toggle.bind(this));
|
|
|
+ $(document.body).on('click', '.sidebar-backdrop', toggle.bind(this));
|
|
|
+ },
|
|
|
+ sideBarToggle: function() {
|
|
|
+ var $dependent = $('.sidebar-dependent');
|
|
|
+ var open = !$dependent.hasClass('sidebar-opened') && !$(document.body).hasClass('menu-pinned');
|
|
|
+
|
|
|
+ $(document.body).toggleClass('non-scrollable', open).removeClass('menu-pinned');
|
|
|
+ $dependent.toggleClass('sidebar-opened', open);
|
|
|
+
|
|
|
+ this.storePinStatus(false);
|
|
|
+ this.toggleBackdrop(open);
|
|
|
+ },
|
|
|
+ toggleBackdrop: function(open) {
|
|
|
+ if (open) {
|
|
|
+ var backdrop = $('<div/>', {class: 'sidebar-backdrop'});
|
|
|
+ $(document.body).append(backdrop);
|
|
|
+ backdrop.animate({opacity: 0.5}, 300);
|
|
|
+ } else {
|
|
|
+ $('.sidebar-backdrop').animate({opacity: 0}, 300, function () {
|
|
|
+ $(this).remove();
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ initPinSideBar: function($sidebar) {
|
|
|
+ $sidebar.on('click', '#branding-pin', (function () {
|
|
|
var $dependent = $('.sidebar-dependent');
|
|
|
- var open = !$dependent.hasClass('sidebar-opened');
|
|
|
|
|
|
- $(document.body).toggleClass('non-scrollable', open);
|
|
|
- $dependent.toggleClass('sidebar-opened', open);
|
|
|
- });
|
|
|
+ if ($(document.body).hasClass('menu-pinned')) {
|
|
|
+ $dependent.removeClass('sidebar-opened');
|
|
|
+ $(document.body).removeClass('menu-pinned');
|
|
|
+ this.storePinStatus(false);
|
|
|
+ } else {
|
|
|
+ this.storePinStatus(true);
|
|
|
+ $(document.body).addClass('menu-pinned').removeClass('non-scrollable');
|
|
|
+ }
|
|
|
+
|
|
|
+ this.toggleBackdrop(false);
|
|
|
+
|
|
|
+ setTimeout(function() {
|
|
|
+ $(window).trigger('resize');
|
|
|
+ }, 500);
|
|
|
+ }).bind(this));
|
|
|
+ },
|
|
|
+ storePinStatus: function(status) {
|
|
|
+ $.cookie('sidebar_pinned', status, { expires: 365, path: '/' });
|
|
|
},
|
|
|
run: function() {
|
|
|
var $sidebar = this.$sidebar;
|
|
@@ -38,6 +81,7 @@ SideBar.prototype = {
|
|
|
try {
|
|
|
this.initScrollBars($sidebar);
|
|
|
this.initSideBarToggle();
|
|
|
+ this.initPinSideBar($sidebar);
|
|
|
} catch (e) {
|
|
|
console.error(e, e.stack);
|
|
|
}
|
|
@@ -51,3 +95,5 @@ $(document).ready(function() {
|
|
|
new SideBar($(this)).run();
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+module.exports = new SideBar();
|