(function($) { "use strict"; /** * debouncing function from John Hann * http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/ */ var debounce = function (func, threshold, execAsap) { var timeout; return function debounced () { var obj = this, args = arguments; function delayed () { if (!execAsap) func.apply(obj, args); timeout = null; }; if (timeout) clearTimeout(timeout); else if (execAsap) func.apply(obj, args); timeout = setTimeout(delayed, threshold || 100); }; }; /** * Register smartresize plugin */ $.fn['smartresize'] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger('smartresize'); }; /** * Initialize masonry layout with blog style * and mosaic style * * @return void */ var init_layout = function () { var blog_layout = $('.blog-masonry'), mosaic_layout = $('.masonry'), init_blog_layout = function () { blog_layout.masonry({ itemSelector : '.item', }); }, init_mosaic_layout = function () { mosaic_layout.masonry({ itemSelector: 'article.item', isResizeBound: false, isInitLayout: false }); }; // Initialize blog layout if (blog_layout.size() != 0) { $(window).on('load', init_blog_layout); } if (mosaic_layout.size() != 0) { var refresh_layout = function () { $('article.item', mosaic_layout).each(function () { $(this).height($(this).width()); $('.tm-content-inner', this).height($(this).width()); }); mosaic_layout.masonry('layout'); } $(window).on('load', init_mosaic_layout); $(window).on('load', refresh_layout); $(window).smartresize(refresh_layout); } }; /** * Initialize sticky navigator * * @return void */ var init_sticky_nav = function () { var nav = $('.tm-sticky-menu'); if (nav.size() != 0) { var offset_top = nav.offset().top, nav_height = nav.height(), place_holder = $('
', { height: nav_height }); // Inject place holder for the nav place_holder.hide() nav.after(place_holder); $(window).on('load scroll', function () { if ($(window).scrollTop() > offset_top) { nav.addClass('tm-fixed'); place_holder.show(); } else { place_holder.hide(); nav.removeClass('tm-fixed'); } }); $(window).smartresize(function () { offset_top = nav.offset().top; }); } }; var init_portfolio = function () { var grid = $('#tm-portfolio .tm-content-isotope'), filters = $('#tm-portfolio .tm-filter a'), active = $('#tm-portfolio .tm-filter a.selected'); if (grid.size() != 0) { $(window).on('load', function () { grid.isotope({ filter: '*', animationOptions: { duration: 750, easing: 'linear', queue: false, } }); filters.on('click', function (e) { e.preventDefault(); // Trigger isotope to filter data grid.isotope({ filter: $(this).attr('data-filter') }); // Remove current active class active.removeClass('selected'); // Assign active object to clicked element active = $(this); active.addClass('selected'); }); }); } }; var init_switch_buttons = function () { var buttons = $('a.button-switch'); buttons.on('click',function(e) { buttons.removeClass('active'); $(this).addClass('active'); if ($(this).hasClass('grid')) { $('#tm-blog') .removeClass('tm-blog-style-list') .addClass('tm-blog-style-grid'); } else if($(this).hasClass('list')) { $('#tm-blog') .removeClass('tm-blog-style-grid') .addClass('tm-blog-style-list'); } }); }; var init_tabs = function () { $('.tm-tabs > ul a').on('click', function (e) { e.preventDefault(); var elm = $(this), parent = elm.closest('.tm-tabs'), tab_page = $(elm.attr('href'), parent); parent.find('> ul a').removeClass('selected'); parent.find('.tab-content').hide(); elm.addClass('selected'); tab_page.fadeIn(); }); $('.tm-tabs > ul li:first-child a').trigger('click'); }; var init_accordions = function () { var acc_wrapper = $('.tm-accordion'); if (acc_wrapper.length > 0) { $('.tm-accordion .accordion-container').hide(); $.each(acc_wrapper, function(index, item){ $(this).find($('.accordion-title')).first().addClass('active').next().show(); }); $('.accordion-title').on('click', function(e) { if( $(this).next().is(':hidden') ) { $(this).parent().find($('.active')).removeClass('active').next().slideUp(300); $(this).toggleClass('active').next().slideDown(300); } e.preventDefault(); }); } }; var init_progress_bar = function () { $(".tm-progress-bar-inner").each(function() { $(this).data("origWidth", ($(this).width() / $(this).parent().width()) * 100) .width(0) .animate({ width: $(this).data("origWidth") + "%" }, 1200); }); }; var init_animate_scroll = function () { $(window).on('load scroll', function () { $('.setanimate').each(function() { this.getBoundingClientRect().top < $(window).height() ? $(this).addClass('visible') : $(this).removeClass('visible'); }); }); }; var init_countdown = function () { var simple_style = function (data) { $(this.el).html( + this.leadingZeros(data.years, 4) + " years" + this.leadingZeros(data.days, 3) + " days" + this.leadingZeros(data.hours, 2) + " hrs" + this.leadingZeros(data.min, 2) + " min" + this.leadingZeros(data.sec, 2) + " sec"); }, boxed_style = function (data) { $(this.el).html("