Skip to content

Commit

Permalink
fix sidebar hover when initially pinned
Browse files Browse the repository at this point in the history
  • Loading branch information
azouaoui-med committed Jun 10, 2020
1 parent 9067d30 commit 3ab0d7b
Showing 1 changed file with 92 additions and 77 deletions.
169 changes: 92 additions & 77 deletions src/js/main.js
Original file line number Diff line number Diff line change
@@ -1,89 +1,104 @@
jQuery(function ($) {
// Dropdown menu
$('.sidebar-dropdown > a').click(function () {
$('.sidebar-submenu').slideUp(200);
if ($(this).parent().hasClass('active')) {
$('.sidebar-dropdown').removeClass('active');
$(this).parent().removeClass('active');
} else {
$('.sidebar-dropdown').removeClass('active');
$(this).next('.sidebar-submenu').slideDown(200);
$(this).parent().addClass('active');
}
});

// Dropdown menu
$(".sidebar-dropdown > a").click(function () {
$(".sidebar-submenu").slideUp(200);
if ($(this).parent().hasClass("active")) {
$(".sidebar-dropdown").removeClass("active");
$(this).parent().removeClass("active");
} else {
$(".sidebar-dropdown").removeClass("active");
$(this).next(".sidebar-submenu").slideDown(200);
$(this).parent().addClass("active");
}
//toggle sidebar
$('#toggle-sidebar').click(function () {
$('.page-wrapper').toggleClass('toggled');
});

});

//toggle sidebar
$("#toggle-sidebar").click(function () {
$(".page-wrapper").toggleClass("toggled");
});
//Pin sidebar
$("#pin-sidebar").click(function () {
if ($(".page-wrapper").hasClass("pinned")) {
// unpin sidebar when hovered
$(".page-wrapper").removeClass("pinned");
$("#sidebar").unbind( "hover");
} else {
$(".page-wrapper").addClass("pinned");
$("#sidebar").hover(
function () {
console.log("mouseenter");
$(".page-wrapper").addClass("sidebar-hovered");
},
function () {
console.log("mouseout");
$(".page-wrapper").removeClass("sidebar-hovered");
}
)
// bind hover if pinned is initially enabled
if ($('.page-wrapper').hasClass('pinned')) {
$('#sidebar').hover(
function () {
console.log('mouseenter');
$('.page-wrapper').addClass('sidebar-hovered');
},
function () {
console.log('mouseout');
$('.page-wrapper').removeClass('sidebar-hovered');
}
);
}

//Pin sidebar
$('#pin-sidebar').click(function () {
if ($('.page-wrapper').hasClass('pinned')) {
// unpin sidebar when hovered
$('.page-wrapper').removeClass('pinned');
$('#sidebar').unbind('hover');
} else {
$('.page-wrapper').addClass('pinned');
$('#sidebar').hover(
function () {
console.log('mouseenter');
$('.page-wrapper').addClass('sidebar-hovered');
},
function () {
console.log('mouseout');
$('.page-wrapper').removeClass('sidebar-hovered');
}
});
);
}
});

//toggle sidebar overlay
$('#overlay').click(function () {
$('.page-wrapper').toggleClass('toggled');
});

//toggle sidebar overlay
$("#overlay").click(function () {
$(".page-wrapper").toggleClass("toggled");
});
//switch between themes
var themes =
'default-theme legacy-theme chiller-theme ice-theme cool-theme light-theme';
$('[data-theme]').click(function () {
$('[data-theme]').removeClass('selected');
$(this).addClass('selected');
$('.page-wrapper').removeClass(themes);
$('.page-wrapper').addClass($(this).attr('data-theme'));
});

//switch between themes
var themes = "default-theme legacy-theme chiller-theme ice-theme cool-theme light-theme";
$('[data-theme]').click(function () {
$('[data-theme]').removeClass("selected");
$(this).addClass("selected");
$('.page-wrapper').removeClass(themes);
$('.page-wrapper').addClass($(this).attr('data-theme'));
});
// switch between background images
var bgs = 'bg1 bg2 bg3 bg4';
$('[data-bg]').click(function () {
$('[data-bg]').removeClass('selected');
$(this).addClass('selected');
$('.page-wrapper').removeClass(bgs);
$('.page-wrapper').addClass($(this).attr('data-bg'));
});

// switch between background images
var bgs = "bg1 bg2 bg3 bg4";
$('[data-bg]').click(function () {
$('[data-bg]').removeClass("selected");
$(this).addClass("selected");
$('.page-wrapper').removeClass(bgs);
$('.page-wrapper').addClass($(this).attr('data-bg'));
});
// toggle background image
$('#toggle-bg').change(function (e) {
e.preventDefault();
$('.page-wrapper').toggleClass('sidebar-bg');
});

// toggle background image
$("#toggle-bg").change(function (e) {
e.preventDefault();
$('.page-wrapper').toggleClass("sidebar-bg");
});
// toggle border radius
$('#toggle-border-radius').change(function (e) {
e.preventDefault();
$('.page-wrapper').toggleClass('boder-radius-on');
});

// toggle border radius
$("#toggle-border-radius").change(function (e) {
e.preventDefault();
$('.page-wrapper').toggleClass("boder-radius-on");
//custom scroll bar is only used on desktop
if (
!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(
navigator.userAgent
)
) {
$('.sidebar-content').mCustomScrollbar({
axis: 'y',
autoHideScrollbar: true,
scrollInertia: 300,
});

//custom scroll bar is only used on desktop
if (!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
$(".sidebar-content").mCustomScrollbar({
axis: "y",
autoHideScrollbar: true,
scrollInertia: 300
});
$(".sidebar-content").addClass("desktop");

}
});
$('.sidebar-content').addClass('desktop');
}
});

0 comments on commit 3ab0d7b

Please sign in to comment.