(function($) { "use strict"; jQuery(document).ready(function($){ //Custom amaaaze scripts /* Init functions */ revealPosts(); /* variable declarations */ var last_scroll = 0; /* carousel functions */ $(document).on('click', '.amaaaze-carousel-thumb', function(){ var id = $("#" + $(this).attr("id")); $(id).on('slid.bs.carousel', function(){ amaaaze_get_bs_thumbs( id ); }); }); $(document).on('mouseenter', '.amaaaze-carousel-thumb', function(){ var id = $("#" + $(this).attr("id")); amaaaze_get_bs_thumbs( id ); }); function amaaaze_get_bs_thumbs( id ){ var nextThumb = $(id).find('.item.active').find('.next-image-preview').data('image'); var prevThumb = $(id).find('.item.active').find('.prev-image-preview').data('image'); $(id).find('.carousel-control.right').find('.thumbnail-container').css({ 'background-image' : 'url('+nextThumb+')' }); $(id).find('.carousel-control.left').find('.thumbnail-container').css({ 'background-image' : 'url('+prevThumb+')' }); } /* Scroll functions */ $(window).scroll( function(){ var scroll = $(window).scrollTop(); if( Math.abs( scroll - last_scroll ) > $(window).height()*0.1 ){ last_scroll = scroll; $('.page-limit').each(function( index ){ // var pathname = window.location.pathname; // Returns path only // var url = window.location.href; // Returns full URL if( isVisible( $(this) ) ){ //var ssss = $(this).attr("data-url")+$(this).attr("data-page"); history.replaceState( null, null, $(this).attr("data-page") ); return(false); } }); } }); // pre loader $(window).on('load', function () { $('#preloader').fadeOut('slow',function(){ $(this).remove(); }); }); /* Helper Functions */ function revealPosts() { $('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="popover"]').popover(); var posts = $('article:not(.reveal)'); var i = 0; setInterval(function(){ if( i >= posts.length ) return false; var el = posts[i]; $(el).addClass('reveal').find('.amaaaze-carousel-thumb').carousel(); i++; }, 200); } function isVisible( element ){ var scroll_pos = $(window).scrollTop(); var window_height = $(window).height(); var el_top = $(element).offset().top; var el_height = $(element).height(); var el_bottom = el_top + el_height; return ( ( el_bottom - el_height*0.25 > scroll_pos ) && ( el_top < ( scroll_pos+0.5*window_height ) ) ); } /* Sidebar functions */ $(document).on('click', '.js-toggleSidebar', function(){ $('.amaaaze-sidebar').toggleClass('sidebar-closed'); $('.sidebar-overlay').fadeToggle( 320 ); }); $(document).on('click', '.top-toggleSidebar', function(){ $('.home-sidebar').toggleClass('topsidebar-closed'); $('.home-overlay').fadeToggle( 320 ); }); function fixButtonHeights() { var heights = new Array(); // Loop to get all element heights $('.amaaaze-blog-colums .post').each(function() { // Need to let sizes be whatever they want so no overflow on resize $(this).css('min-height', '0'); $(this).css('max-height', 'none'); $(this).css('height', 'auto'); // Then add size (no units) to array heights.push($(this).height()); }); // Find max height of all elements var max = Math.max.apply( Math, heights ); // Set all heights to max height $('.amaaaze-blog-colums .post').each(function() { $(this).css('height', max + 'px'); // Note: IF box-sizing is border-box, would need to manually add border and padding to height (or tallest element will overflow by amount of vertical border + vertical padding) }); } $(window).load(function() { // Fix heights on page load fixButtonHeights(); // Fix heights on window resize $(window).resize(function() { // Needs to be a timeout function so it doesn't fire every ms of resize setTimeout(function() { fixButtonHeights(); }, 120); }); }); /* Theme customizing functions */ // Back to top $('#back-to-top').on('click', function(){ $("html, body").animate({scrollTop: 0}, 600); return false; }); // Search expand in header $(".search-expand").hide(); $(document).on('click', '.toggle-search', function(){ $('.search-expand').slideToggle( 320 ); }); // Affix height $(".nav_wrapper").height($(".header-container").height()); // Change target to _blank to _self for portfolio $(".tlp-portfolio-item .tlp-item .tlp-overlay a").attr("target", "_self"); // Menu hover $('ul.navbar-menu li.dropdown').hover(function() { $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeIn(200); }, function() { $(this).find('.dropdown-menu').stop(true, true).delay(200).fadeOut(200); }); // Close button $('.close_button').click(function() { $('.search-expand').toggle("slide"); }); }); })(jQuery);