udemy-go-web-1/static/admin/js/template.js

96 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

(function($) {
'use strict';
$(function() {
var body = $('body');
var contentWrapper = $('.content-wrapper');
var scroller = $('.container-scroller');
var footer = $('.footer');
var sidebar = $('.sidebar');
//Add active class to nav-link based on url dynamically
//Active class can be hard coded directly in html file also as required
function addActiveClass(element) {
if (current === "") {
//for root url
if (element.attr('href').indexOf("index.html") !== -1) {
element.parents('.nav-item').last().addClass('active');
if (element.parents('.sub-menu').length) {
element.closest('.collapse').addClass('show');
element.addClass('active');
}
}
} else {
//for other url
if (element.attr('href').indexOf(current) !== -1) {
element.parents('.nav-item').last().addClass('active');
if (element.parents('.sub-menu').length) {
element.closest('.collapse').addClass('show');
element.addClass('active');
}
if (element.parents('.submenu-item').length) {
element.addClass('active');
}
}
}
}
var current = location.pathname.split("/").slice(-1)[0].replace(/^\/|\/$/g, '');
$('.nav li a', sidebar).each(function() {
var $this = $(this);
addActiveClass($this);
})
//Close other submenu in sidebar on opening any
sidebar.on('show.bs.collapse', '.collapse', function() {
sidebar.find('.collapse.show').collapse('hide');
});
//Change sidebar
$('[data-toggle="minimize"]').on("click", function() {
body.toggleClass('sidebar-icon-only');
});
//checkbox and radios
$(".form-check label,.form-radio label").append('<i class="input-helper"></i>');
});
// focus input when clicking on search icon
$('#navbar-search-icon').click(function() {
$("#navbar-search-input").focus();
});
if ($.cookie('royal-free-banner')!="true") {
document.querySelector('#proBanner').classList.add('d-flex');
document.querySelector('.navbar').classList.remove('fixed-top');
}
else {
document.querySelector('#proBanner').classList.add('d-none');
document.querySelector('.navbar').classList.add('fixed-top');
}
if ($( ".navbar" ).hasClass( "fixed-top" )) {
document.querySelector('.page-body-wrapper').classList.remove('pt-0');
document.querySelector('.navbar').classList.remove('pt-5');
}
else {
document.querySelector('.page-body-wrapper').classList.add('pt-0');
document.querySelector('.navbar').classList.add('pt-5');
document.querySelector('.navbar').classList.add('mt-3');
}
document.querySelector('#bannerClose').addEventListener('click',function() {
document.querySelector('#proBanner').classList.add('d-none');
document.querySelector('#proBanner').classList.remove('d-flex');
document.querySelector('.navbar').classList.remove('pt-5');
document.querySelector('.navbar').classList.add('fixed-top');
document.querySelector('.page-body-wrapper').classList.add('proBanner-padding-top');
document.querySelector('.navbar').classList.remove('mt-3');
var date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
$.cookie('royal-free-banner', "true", { expires: date });
});
})(jQuery);