/* * King Composer * * URI KingComposer.com * * Copyright king-theme.com * * */ var kc_front = ( function($){ jQuery.extend( jQuery.easing, { easeInOutQuart: function (x, t, b, c, d) { if ((t/=d/2) < 1) return c/2*t*t*t*t + b; return -c/2 * ((t-=2)*t*t*t - 2) + b; }, }); var $window = $(window); var windowHeight = $window.height(); $window.resize(function() { windowHeight = $window.height(); kc_front.row_action(true); }); $.fn.kc_parallax = function() { var $this = $(this), el_top; $this.each(function() { el_top = $this.offset().top; }); function update() { var pos = $window.scrollTop(); $this.each(function() { var $el = $(this), top = $el.offset().top, height = $el.outerHeight(true); if (top + height < pos || top > pos + windowHeight || $this.data('kc-parallax') !== true ) return; $this.css('backgroundPosition', "50% " + Math.round((el_top - pos) * 0.4) + "px"); }) } $window.on('scroll resize', update).trigger('update'); }; $.fn.viewportChecker = function(useroptions){ // Define options and extend with user var options = { classToAdd: 'visible', offset: 100, callbackFunction: function(elem){} }; $.extend(options, useroptions); // Cache the given element and height of the browser var $elem = this, windowHeight = $(window).height(); this.checkElements = function(){ // Set some vars to check with var scrollElem = ((navigator.userAgent.toLowerCase().indexOf('webkit') != -1) ? window : 'html'), viewportTop = $(scrollElem).scrollTop(), viewportBottom = (viewportTop + windowHeight); $elem.each(function(){ var $obj = $(this); // If class already exists; quit if ( $obj.hasClass(options.classToAdd) && options.classToAdd != '' ){ return; } // define the top position of the element and include the offset which makes is appear earlier or later var elemTop = Math.round( $obj.offset().top ) + options.offset, elemBottom = elemTop + ($obj.height()); // Add class if in viewport if ((elemTop < viewportBottom) && (elemBottom > viewportTop) && this.done != true){ $obj.addClass(options.classToAdd); // Do the callback function. Callback wil send the jQuery object as parameter options.callbackFunction($obj); } }); }; // Run checkelements on load and scroll $(window).scroll(this.checkElements); this.checkElements(); // On resize change the height var $(window).resize(function(e){ windowHeight = e.currentTarget.innerHeight; }); }; $( document ).ready(function($){ // load js when document is ready kc_front.init($); }); return { win_height : 0, win_width : 0, body : $('body'), init : function(){ $('section[data-kc-parallax="true"]').each(function(){ $(this).kc_parallax(); }); this.accordion(); this.tabs(); this.youtube_row_background.init(); if( window.location.href.indexOf('#') > -1 ){ $('a[href="#'+window.location.href.split('#')[1]+'"]').trigger('click'); } $('.kc_button').add('.kc_tooltip').kcTooltip(); $('.kc-close-but').on( 'click', function(){ $(this).parent().parent().hide('slow',function(){$(this).remove();}); }); this.google_maps(); this.blog.masonry(); this.image_gallery.masonry(); this.carousel_images(); this.carousel_post(); this.countdown_timer(); this.piechar.init(); this.progress_bar.run(); this.ajax_action(); this.pretty_photo(); this.tooltips(); this.image_fade(); this.smooth_scroll(); this.animate(); this.row_action(true); }, refresh: function( el ){ setTimeout( function( el){ kc_front.piechar.update( el ); kc_front.progress_bar.update( el ); kc_front.image_gallery.masonry( el ); if($('.kc_video_play').length > 0){ kc_video_play.refresh( el ); } }, 100, el ); }, viewport : function( st ) { var d = document; if (d.compatMode === 'BackCompat') { if (st == 'height') return d.body.clientHeight; else return d.body.clientWidth } else { if (st == 'height') return d.documentElement.clientHeight; else return d.documentElement.clientWidth } }, row_action : function( force ) { var d = document; [].forEach.call(d.querySelectorAll('section[data-kc-fullwidth]'), function(el) { var kc_clfw = d.querySelectorAll('.kc_clfw')[0], rect; if(typeof kc_clfw === 'undefined') return; rect = kc_clfw.getBoundingClientRect(); el.style.left = (-rect.left) + 'px'; if (el.getAttribute('data-kc-fullwidth') == 'row') { el.style.paddingLeft = rect.left + 'px'; el.style.paddingRight = (kc_front.viewport('width') - rect.width - rect.left) + 'px'; el.style.width = rect.width + 'px' } else { el.style.paddingLeft = '0px'; el.style.width = kc_front.viewport('width') + 'px' } if (el.nextElementSibling !== null && el.nextElementSibling.tagName == 'SCRIPT') { if (el.nextElementSibling.innerHTML == 'kc_front.row_action(true);') { el.parentNode.removeChild(el.nextElementSibling) } } }) }, google_maps: function( wrp ){ $('.kc_google_maps').each( function(){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); var $_this = $( this ); if( $_this.data('wheel') == 'disable'){ $_this.click(function () { $_this.find('iframe').css("pointer-events", "auto"); }); $_this.mouseleave(function() { $_this.find('iframe').css("pointer-events", "none"); }); } $_this.find('.close').on('click', function(){ $_this.find('.map_popup_contact_form').toggleClass( "hidden" ); $_this.find('.show_contact_form').fadeIn('slow'); }); $_this.find('.show_contact_form').on('click', function(){ $_this.find('.map_popup_contact_form').toggleClass( "hidden" ); $_this.find('.show_contact_form').fadeOut('slow'); }); }); }, accordion: function( wrp ){ $('.kc_accordion_wrapper').each(function(){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); var active = $(this).data('tab-active')!==undefined?($(this).data('tab-active')-1):0; if ($(this).data('closeall') == true) active = '100000'; $ (this).find('>div.kc_accordion_section>h3.kc_accordion_header>a, >div.kc_accordion_section>h3.kc_accordion_header>.ui-accordion-header-icon') .off('click') .on('click', function(e) { var wrp = $(this).closest('.kc_accordion_wrapper'), section = $(this).closest('.kc_accordion_section'), allowopenall = (true === wrp.data('allowopenall')) ? true : false, closeall = (true === wrp.data('closeall')) ? true : false, changed = section.find('>h3.kc_accordion_header').hasClass('ui-state-active'), clickitself = false; if( allowopenall === false ){ if (!section.find('>h3.kc_accordion_header').hasClass('ui-state-active')) { wrp.find( '>.kc_accordion_section>.kc_accordion_content' ).slideUp(); wrp.find('>.kc_accordion_section>h3.kc_accordion_header').removeClass('ui-state-active'); wrp.find('>.kc_accordion_section.kc-section-active').removeClass('kc-section-active'); section.find('>.kc_accordion_content').stop().slideDown( 'normal', function(){ $(this).css({height:''}) } ); section.find('>h3.kc_accordion_header').addClass('ui-state-active'); section.addClass('kc-section-active'); }else{ wrp.find( '>.kc_accordion_section>.kc_accordion_content' ).slideUp(); wrp.find('>.kc_accordion_section>h3.kc_accordion_header').removeClass('ui-state-active'); wrp.find('>.kc_accordion_section>.kc-section-active').removeClass('kc-section-active'); section.removeClass('kc-section-active'); } }else{ if( section.find('>h3.kc_accordion_header').hasClass('ui-state-active') ){ section.find('>.kc_accordion_content').stop().slideUp(); section.find('>h3.kc_accordion_header').removeClass('ui-state-active'); section.removeClass('kc-section-active'); }else{ section.find('>.kc_accordion_content').stop().slideDown( 'normal', function(){ $(this).css({height:''}) } ); section.find('>h3.kc_accordion_header').addClass('ui-state-active'); section.addClass('kc-section-active'); } } if( changed != section.find('>h3.kc_accordion_header').hasClass('ui-state-active') ) kc_front.refresh( section.find('>.kc_accordion_content') ); e.preventDefault(); var index = $(this).closest('.kc_accordion_section'); index = index.parent().find('>.kc_accordion_section').index( index.get(0) ); $(this).closest('.kc_accordion_wrapper').data({'tab-active':(index+1)}); }).eq(active).trigger('click'); }); }, tabs: function( wrp ){ $('.kc_tabs > .kc_wrapper').each( function( index ){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); var $_this = $(this), tab_group = $_this.parent('.kc_tabs.group'), tab_event = ('yes' === tab_group.data('open-on-mouseover')) ? 'mouseover' : 'click', effect_option = ('yes' === tab_group.data('effect-option')) ? true : false, active_section = parseInt( tab_group.data('tab-active') )-1; $( this ).find('>.ui-tabs-nav>li') .off('click') .on( 'click', function(e){ e.preventDefault(); } ) .off( tab_event ) .on( tab_event, function(e){ if( $(this).hasClass('ui-tabs-active') ){ e.preventDefault(); return; } var labels = $(this).closest('.kc_tabs_nav,.ui-tabs-nav').find('>li'), index = labels.index( this ), tab_list = $(this).closest('.kc_wrapper').find('>.kc_tab'), new_panel = tab_list.eq( index ); labels.removeClass('ui-tabs-active'); $(this).addClass('ui-tabs-active'); tab_list.removeClass('ui-tabs-body-active').removeClass('kc-section-active'); new_panel.addClass('ui-tabs-body-active').addClass('kc-section-active'); if( effect_option === true) new_panel.css({'opacity':0}).animate({opacity:1}); e.preventDefault(); $(this).closest('.kc_tabs').data({'tab-active':(index+1)}); }).eq( active_section ).trigger( tab_event ); }); $('.kc_tabs.kc-tabs-slider').each(function(){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); $( this ).find('.kc-tabs-slider-nav li').each(function( index ){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); $( this ).on( 'click', index, function( e ){ $(this).parent().find('.kc-title-active').removeClass('kc-title-active'); $(this).addClass('kc-title-active'); console.log(e.data); $(this).closest('.kc-tabs-slider').find('.owl-carousel').trigger('owl.goTo', e.data); e.preventDefault(); $(this).closest('.kc_tabs').data({'active':e.data}); }); if( index === 0 ) $( this ).addClass('kc-title-active'); }); }); kc_front.owl_slider(); }, counterup : function (){ $('.counterup').each(function( index ){ if( $(this).data('loaded') === true ) return; else $(this).data({ 'loaded' : true }); $(this).counterUp({ delay: 100, time: 2000 }); }); }, youtube_row_background: { init: function(){ $( '.kc_row, .kc_column' ).each( function () { var $row = $( this ), youtubeUrl, youtubeId; if ( $row.data( 'kc-video-bg' ) ) { youtubeUrl = $row.data( 'kc-video-bg' ); youtubeId = kc_front.youtube_row_background.getID( youtubeUrl ); if ( youtubeId ) { $row.find( '.kc_wrap-video-bg' ).remove(); kc_front.youtube_row_background.add( $row, youtubeId ); } } else { $row.find( '.kc_wrap-video-bg' ).remove(); } } ); }, getID: function ( url ) { if ( 'undefined' === typeof(url) ) { return false; } var id = url.match( /(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/ ); if ( null !== id ) { return id[ 1 ]; } return false; }, add: function( $obj, youtubeId, counter ) { if( YT === undefined ) return; if ( 'undefined' === typeof( YT.Player ) ) { counter = 'undefined' === typeof( counter ) ? 0 : counter; if ( counter > 100 ) { console.warn( 'Too many attempts to load YouTube api' ); return; } setTimeout( function () { kc_front.youtube_row_background.add( $obj, youtubeId, counter++ ); }, 100 ); return; } var player, $container = $obj.prepend( '