/* * Document : main.js * Author : pixelcave * Description: Custom scripts and plugin initializations */ /* var url = window.location.pathname; var filename = url.substring(url.lastIndexOf('/')+1); $('a[href*="'+filename+'"]').addClass('active'); */ var webApp = function() { /* Cache variables of some often used jquery objects */ var body = $('body'); var header = $('header'); // Used for sidebar functionality, check handleSidebars() var sLToggle = $('#sidebar-left-toggle'); var sRToggle = $('#sidebar-right-toggle'); var sLScroll = $('.sidebar-left-scroll'); var sRScroll = $('.sidebar-right-scroll'); // 50 is the height of .sidebar-search and .user-info in pixels var sScrollHeight = $(window).height() - 51; /* Initialization UI Code */ var uiInit = function() { // Add opacity to the header when scrolling (you can comment/remove the following line if you prefer a solid header) $(window).scroll(function() { if ($(this).scrollTop() > 60) { header.addClass('add-opacity'); } else { header.removeClass('add-opacity'); } }); // Initialize tabs $('[data-toggle="tabs"] a, .enable-tabs a').click(function(e){ e.preventDefault(); $(this).tab('show'); }); // Initialize Tooltips $('[data-toggle="tooltip"], .enable-tooltip').tooltip({container: 'body', animation: false}); // Initialize Popovers $('[data-toggle="popover"], .enable-popover').popover({container: 'body', animation: false}); // Initialize single image lightbox $('[data-toggle="lightbox-image"]').magnificPopup({type: 'image', image: {titleSrc: 'title'}}); // Initialize image gallery lightbox $('[data-toggle="lightbox-gallery"]').magnificPopup({ delegate: 'a.gallery-link', type: 'image', gallery: { enabled: true, navigateByImgClick: true, arrowMarkup: '', tPrev: 'Previous', tNext: 'Next', tCounter: '%curr% of %total%' }, image: {titleSrc: 'title'} }); // Initialize Elastic $('textarea.textarea-elastic').elastic(); // Initialize Editor $('.textarea-editor').wysihtml5(); // Initialize Chosen $('.select-chosen').chosen(); // Initialize Datepicker $('.input-datepicker, .input-daterange').datepicker(); // Initialize Timepicker $('.input-timepicker').timepicker({minuteStep: 1,showSeconds: true,showMeridian: true}); $('.input-timepicker24').timepicker({minuteStep: 1,showSeconds: true,showMeridian: false}); /* Easy Pie Chart */ $('.pie-chart').easyPieChart({ barColor: '#f39c12', trackColor: '#eeeeee', scaleColor: false, lineWidth: 3, size: $(this).data('size'), animate: 1200 }); }; /* Sidebar Navigation functionality */ var handleNav = function() { // Animation Speed, change the values for different results var upSpeed = 250; var downSpeed = 300; // Get all vital links var allTopLinks = $('.sidebar-nav a'); var menuLinks = $('.menu-link'); // Initialize number idicators on menu links menuLinks.each(function(n, e){ $(e).append('' + $(e).next('ul').find('a').not('.submenu-link').length + ''); }); // Icon animation on hover -> Find more animations in plugin.css allTopLinks .mouseenter(function(){ $('i', this).addClass('animation-expandOpen'); }) .mouseleave(function(){ $('i', this).removeClass('animation-expandOpen'); }); // Primary Accordion functionality menuLinks.click(function() { var link = $(this); if (link.parent().hasClass('active') !== true) { if (link.hasClass('open')) { link.removeClass('open').next().slideUp(upSpeed); } else { $('.menu-link.open').removeClass('open').next().slideUp(upSpeed); link.addClass('open').next().slideDown(downSpeed); } } return false; }); }; /* Handle Sidebars, show/hide sidebars */ var handleSidebars = function(mode) { if (mode === 'init') { // Init Sidebar Scrolling sLScroll.add(sRScroll).slimScroll({ height: sScrollHeight, color: '#fff', size: '3px', touchScrollStep: 750 }); $(window).resize(function(){ handleSidebars('resize-scroll'); }); $(window).bind('orientationchange', handleSidebars('resize-scroll')); // Init Left Sidebar sLToggle.click(function(){ handleSidebars('toggle-left'); }); $('#sidebar-left') .mouseenter(function(){ handleSidebars('open-left'); }) .mouseleave(function(){ handleSidebars('close-left'); }); // Init Right Sidebar sRToggle.click(function(){ handleSidebars('toggle-right'); }); $('#sidebar-right') .mouseenter(function(){ handleSidebars('open-right'); }) .mouseleave(function(){ handleSidebars('close-right'); }); // Init Swipe Functionality $('.sidebars-swipe').swipe({ swipeRight: function(event, direction, distance, duration, fingerCount) { if (body.hasClass('sidebar-right-open')) { handleSidebars('close-right'); } else { handleSidebars('open-left'); } }, swipeLeft: function(event, direction, distance, duration, fingerCount) { if (body.hasClass('sidebar-left-open')) { handleSidebars('close-left'); } else { handleSidebars('open-right'); } } }); } else if (mode === 'resize-scroll') { // Resize Scroll Height // 50 is the height of .sidebar-search and .user-info in pixels sLScroll.add(sRScroll).css('height', $(window).height() - 51); } else if (mode === 'open-left') { // Open Left Sidebar body.removeClass('sidebar-right-open').addClass('sidebar-left-open'); sLToggle.parent('li').addClass('active'); sRToggle.parent('li').removeClass('active'); } else if (mode === 'close-left') { // Close Left Sidebar body.removeClass('sidebar-left-open'); sLToggle.parent('li').removeClass('active'); sLToggle.blur(); } else if (mode === 'toggle-left') { // Toggle Left Sidebar body.removeClass('sidebar-right-open').toggleClass('sidebar-left-open'); sLToggle.parent('li').toggleClass('active'); sRToggle.parent('li').removeClass('active'); } else if (mode === 'open-right') { // Open Right Sidebar body.removeClass('sidebar-left-open').addClass('sidebar-right-open'); sRToggle.parent('li').addClass('active'); sLToggle.parent('li').removeClass('active'); } else if (mode === 'close-right') { // Close Right Sidebar body.removeClass('sidebar-right-open'); sRToggle.parent('li').removeClass('active'); } else if (mode === 'toggle-right') { // Toggle Left Sidebar body.removeClass('sidebar-left-open').toggleClass('sidebar-right-open'); sRToggle.parent('li').toggleClass('active'); sLToggle.parent('li').removeClass('active'); } }; /* Scroll to top functionality */ var scrollToTop = function() { // Get link var link = $('#to-top'); $(window).scroll(function() { // If the user scrolled a bit (150 pixels) show the link if ($(this).scrollTop() > 150) { link.fadeIn(100); } else { link.fadeOut(100); } }); // On click get to top link.click(function() { $('html, body').animate({scrollTop: 0}, 200); return false; }); }; /* Input placeholder for older browsers */ var oldiePlaceholder = function() { // Check if placeholder feature is supported by the browser if (!Modernizr.input.placeholder) { // If not, add the functionality $('[placeholder]').focus(function() { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); input.removeClass('ph'); } }).blur(function() { var input = $(this); if (input.val() === '' || input.val() === input.attr('placeholder')) { input.addClass('ph'); input.val(input.attr('placeholder')); } }).blur().parents('form').submit(function() { $(this).find('[placeholder]').each(function() { var input = $(this); if (input.val() === input.attr('placeholder')) { input.val(''); } }); }); } }; /* Datatables Bootstrap integration */ var dtIntegration = function() { // Set the defaults for DataTables initialization $.extend(true, $.fn.dataTable.defaults, { "sDom": "<'row'<'col-md-6'l><'col-md-6'f>r>t<'row'<'col-md-5'i><'col-md-7'p>>", "sPaginationType": "bootstrap", "oLanguage": { "sLengthMenu": "_MENU_", "sSearch": "