(function($) { 'use strict'; $(document).ready(function($){ var windowWidth = $(window).width(); /*----------------------------------------------------------------------------------- SUPERFISH -----------------------------------------------------------------------------------*/ if( windowWidth < 1024 ) { $('.thmlv-header-menu').superfish({ animation: {height:'show'}, animationOut: {height: 'hide'}, }); $('.thmlv-header-menu-scroll').superfish({ animation: {height:'show'}, animationOut: {height: 'hide'}, }); $(this).toggleClass('sf-js-enabled'); } else { $('.thmlv-header-menu').superfish(); $('.thmlv-header-menu-scroll').superfish(); $(window).bind('scroll',scrollMenu); $('.thmlv-scroll-header').show(); } $("#thmlv-menu-icon").on("click", function(e){ e.preventDefault(); $(".thmlv-menu-mobile").slideToggle(); }); $(window).resize(function(){ if( $(window).width() > 1024 ) { $(".thmlv-menu-mobile").removeAttr( 'style' ); $(window).bind('scroll',scrollMenu); $('.thmlv-scroll-header').show(); } else { $(window).unbind('scroll',scrollMenu); $('.thmlv-scroll-header').hide(); } }); /*----------------------------------------------------------------------------------- SEARCH FORM -----------------------------------------------------------------------------------*/ $.fn.setCursorPosition = function(position){ if(this.lengh == 0) return this; return $(this).setSelection(position, position); } $.fn.setSelection = function(selectionStart, selectionEnd) { if(this.lengh == 0) return this; var input = this[0]; if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd('character', selectionEnd); range.moveStart('character', selectionStart); range.select(); } else if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } return this; } var placeholder = $('.thmlv-searchform input[type=text]').attr('data-placeholder'); $('.thmlv-link-fadein').click(function(e){ e.preventDefault(); $(this).fadeOut(500, function() { $('.thmlv-link-fadein').not(this).show(); $('.thmlv-searchform').hide(); $('#thmlv-overlay-search').fadeIn(500); $(this).siblings('.thmlv-searchform').fadeIn(500, function() { $(this).children('input[type=text]').focus(); if($('.thmlv-searchform input[type=text]').attr('value') == placeholder){ $('.thmlv-searchform input[type=text]').setCursorPosition(0); } $(this).children('input[type=text]').keydown(function(){ if($(this).attr('value') == placeholder){ $(this).attr('value', ''); } }); $(this).children('input[type=text]').keyup(function(){ if($(this).attr('value') == ''){ $(this).attr('value', placeholder); $(this).setCursorPosition(0); } }); }); return false; }); }); $('#thmlv-overlay-search').click(function(){ $('#thmlv-overlay-search').fadeOut(500); $('.thmlv-searchform').each(function() { $(this).fadeOut(500, function() { $(this).siblings('.thmlv-link-fadein').fadeIn(500); }); }); return false; }); $(document).keyup(function(e){ if (e.keyCode == 27) { $('#thmlv-overlay-search').fadeOut(500); $('.thmlv-searchform').each(function() { $(this).fadeOut(500, function() { $(this).siblings('.thmlv-link-fadein').fadeIn(500); }); }); }; }); /*----------------------------------------------------------------------------------- ISOTOPE -----------------------------------------------------------------------------------*/ var $container = [$('#thmlv-isotope')]; //Run to initialise column sizes //Load masonry when images all loaded $.each($container, function() { $.each($(this), function() { var $current = $(this); if(!$current.parents('.thmlv-no-isotope').length) { $current.imagesLoaded( function(){ $('#thmlv-loading').hide(); $current.delay(100).animate({ 'opacity' : 1 },300,'easeOutSine'); $current.isotope({ // options layoutMode : 'perfectMasonry', perfectMasonry: { columnWidth: 240, rowHeight: 320, liquid: true, minCols: 1, maxCols: 10, } }); }); } }); }); $(window).smartresize(function(){ $.each($container, function() { $.each($(this), function() { var $current = $(this); if(!$current.parents('.thmlv-no-isotope').length) { $current.isotope('reLayout'); } }); }); }); $('.type-portfolio.isotope-item').each(function() { $(this).appear(function() { $(this).delay(100).animate({ 'opacity' : 1 },300,'easeOutSine'); }); }); /*----------------------------------------------------------------------------------- PORTFOLIO HOVER -----------------------------------------------------------------------------------*/ $(".portfolioSmall").mouseenter(function() { var currHeight = ($(this).find(".thmlv-overlay").height()); $(this).find(".thmlv-overlay").stop().animate({top: '+'+currHeight},500,"easeInOutExpo"); }).mouseleave(function() { $(this).find(".thmlv-overlay").stop().animate({top: 0},500,"easeInOutExpo"); }); $(".portfolioMedium").mouseenter(function() { var currWidth = ($(this).find(".thmlv-overlay").width()); $(this).find(".thmlv-overlay").stop().animate({right: '+'+currWidth},500,"easeInOutExpo"); }).mouseleave(function() { $(this).find(".thmlv-overlay").stop().animate({right: 0},500,"easeInOutExpo"); }); $(".portfolioBig").mouseenter(function() { var currHeight = ($(this).find(".thmlv-overlay").height()) / 2; $(this).find(".thmlv-overlay").stop().animate({top: '+'+currHeight},500,"easeInOutExpo"); }).mouseleave(function() { $(this).find(".thmlv-overlay").stop().animate({top: 0},500,"easeInOutExpo"); }); $(".portfolioTall").mouseenter(function() { var currHeight = ($(this).find(".thmlv-overlay").height()) / 2; $(this).find(".thmlv-overlay").stop().animate({top: '+'+currHeight},500,"easeInOutExpo"); }).mouseleave(function() { $(this).find(".thmlv-overlay").stop().animate({top: 0},500,"easeInOutExpo"); }); $(".portfolioLong").mouseenter(function() { var currWidth = ($(this).find(".thmlv-overlay").width()); $(this).find(".thmlv-overlay").stop().animate({right: '+'+currWidth},500,"easeInOutExpo"); }).mouseleave(function() { $(this).find(".thmlv-overlay").stop().animate({right: 0},500,"easeInOutExpo"); }); /*----------------------------------------------------------------------------------- SECONDARY MENU -----------------------------------------------------------------------------------*/ function scrollMenu() { var scroll = $(window).scrollTop(); if (scroll >= 800) { $('body').removeClass('thmlv-hide-banner').addClass("thmlv-show-banner"); } else { $('body').removeClass("thmlv-show-banner").addClass('thmlv-hide-banner'); } } /*----------------------------------------------------------------------------------- CYRCLE GALLERY -----------------------------------------------------------------------------------*/ $('.thmlv-cycle-slideshow').imagesLoaded(function(){ $('.thmlv-cycle-slideshow ul').cycle({ autoHeight: 'container', fx: 'sparksHorz', slides: '> li', speed: 500, timeout: 0, log: false, centerHorz: true, updateView: 1, swipe: true, next: '#thmlv-cycle-next', prev: '#thmlv-cycle-prev' }); }); $('.thmlv-cycle-slideshow ul').on('cycle-initialized', function() { $('.thmlv-cycle-slideshow').fadeIn('slow'); }); /*----------------------------------------------------------------------------------- TOOLTIPSTER -----------------------------------------------------------------------------------*/ $('.tooltip').tooltipster(); /*----------------------------------------------------------------------------------- NAVIGATION -----------------------------------------------------------------------------------*/ $('.thmlv-prev-post-link').hover(function() { $(this).closest('.thmlv-arrow-nav').find('h1').fadeIn("fast"); }, function() { $(this).closest('.thmlv-arrow-nav').find('h1').fadeOut("fast"); }); /*----------------------------------------------------------------------------------- FIT VIDEOS -----------------------------------------------------------------------------------*/ $(".thmlv-video-embed").fitVids(); /*----------------------------------------------------------------------------------- LOVE-IT -----------------------------------------------------------------------------------*/ $('a.love-it').on('click', function() { var postid = $(this).data('post-id'); var lovenonce = thmlv_script_vars.loveNonce; if($.cookie('loved-' + postid)) { return false; } $.ajax({ type: 'POST', url: thmlv_script_vars.wpDir+'/wp-admin/admin-ajax.php', data: { action: 'thmlv_process_love', itemid: postid, loveitnonce: lovenonce }, success: function(data, textStatus, XMLHttpRequest) { if($('#post-' + postid).length == 0) { var count = $('.thmlv-love-it-counter').text(); $('.thmlv-love-it-counter').text(parseInt(count) + 1); } else { var count = $('#post-' + postid + ' .thmlv-love-it-counter').text(); $('#post-' + postid + ' .thmlv-love-it-counter').text(parseInt(count) + 1); } $(this).parent().find('a.love-it').addClass('loved'); $.cookie('loved-' + postid, 'yes', { expires: 1 }); }, error: function(MLHttpRequest, textStatus, errorThrown){ /*$(".love-it-mex").empty(); $(".love-it-mex").text('Sorry, there was a problem processing your request.').fadeTo(500, 1, function() { $(".love-it-mex").delay(2000).fadeTo(500,0); });*/ } }); return false; }); /*----------------------------------------------------------------------------------- STUFF -----------------------------------------------------------------------------------*/ $('.thmlv-header-menu').delay(200).animate({ 'opacity' : 1 },500,'easeOutSine'); $('#thmlv-arrow-up').click(function(){ $("html, body").animate({ scrollTop: 0 }, 600); return false; }); $('.page-template-thmlv-page-blog-timeline-php .col.span_5').each(function() { $(this).appear(function() { $(this).delay(200).animate({ 'opacity' : 1 },500,'easeOutSine'); }); }); $('#thmlv-super-footer .container').each(function() { $(this).appear(function() { $(this).delay(200).animate({ 'opacity' : 1 },500,'easeOutSine'); }); }); $('#thmlv-footer-widget-area .span_3, #thmlv-footer-widget-area .span_4').each(function() { $(this).appear(function() { $(this).find('.widget').delay(500).animate({ 'opacity' : 1 },300,'easeOutSine'); }); }); }); } (jQuery))