// Set jQuery to NoConflict Mode jQuery.noConflict(); ;(function( $, window, document, undefined ){ "use strict"; var $window = $(window); var $document = $(document); var $body = $('body'); /* ============================================================================= Custom Extensions ============================================================================= */ /*////////////////////////////////////// // Photo Proofing //////////////////////////////////////*/ $.fn.vwPhotoProofing = function() { this.each( function( i, el ) { var $approveButton = $( el ); var $postBox = $approveButton.parents( '.vw-gallery__item' ); if ( 'approved' == $approveButton.data( 'proofing' ) ) { $postBox.addClass( 'vw-approved' ); } $approveButton.on( 'click', function( e ) { e.preventDefault(); e.stopPropagation(); var $this = $( this ); $postBox.addClass( 'vw-approving' ); $.ajax( { type: "GET", url: vw_main_js.ajaxurl, cache: false, data: { action: 'kepler_photo_proofing', method: $this.data( 'proofing' ) == 'approved'? 'reject': 'approve', galleryid: $this.data( 'galleryid' ), photoid: $this.data( 'photoid' ), _wpnonce: $( '#vw_photo_proofing_nonce' ).val(), }, success: function( data ) { $postBox.removeClass( 'vw-approving' ); if ( $this.data( 'proofing' ) == 'approved' ) { $this.data( 'proofing', 'rejected' ); $postBox.removeClass( 'vw-approved' ); } else { $this.data( 'proofing', 'approved' ); $postBox.addClass( 'vw-approved' ); } }, } ); } ); } ); $( '.vw-proofing-filter__approved' ).on( 'click', function ( e ) { e.preventDefault(); e.stopPropagation(); var $this = $( this ); $this.parent().find( 'a:not( .vw-button--white )' ).addClass( 'vw-button--white' ); $this.removeClass( 'vw-button--white' ); $('.vw-gallery__item' ).hide().filter( '.vw-approved' ).fadeIn( 500 ); } ); $( '.vw-proofing-filter__rejected' ).on( 'click', function ( e ) { e.preventDefault(); e.stopPropagation(); var $this = $( this ); $this.parent().find( 'a:not( .vw-button--white )' ).addClass( 'vw-button--white' ); $this.removeClass( 'vw-button--white' ); $('.vw-gallery__item' ).hide().filter( ':not(.vw-approved)' ).fadeIn( 500 ); } ); $( '.vw-proofing-filter__all' ).on( 'click', function ( e ) { e.preventDefault(); e.stopPropagation(); var $this = $( this ); $this.parent().find( 'a:not( .vw-button--white )' ).addClass( 'vw-button--white' ); $this.removeClass( 'vw-button--white' ); $('.vw-gallery__item' ).hide().fadeIn( 500 ); } ); }; /*////////////////////////////////////// // Category Filter //////////////////////////////////////*/ $.fn.vwCategoryFilter = function() { this.each( function( i, el ) { var $categories = $( el ); var $filters = $categories.find( 'a' ); $filters.each( function( i, el ) { var $button = $( el ); $button.on( 'click', function( e ) { e.preventDefault(); e.stopPropagation(); $button.parent().find( 'a:not( .vw-button--white )' ).addClass( 'vw-button--white' ); $button.removeClass( 'vw-button--white' ); var slug = $button.data( 'slug' ); Waypoint.refreshAll(); if ( 'all' == slug ) { $('.vw-portfolios .vw-flex-grid__item' ).hide().finish().fadeIn( 500 ); } else { $('.vw-portfolios .vw-flex-grid__item' ).hide().finish().filter( '[data-slugs~='+slug+']' ).fadeIn( 500 ); } } ); } ); } ); }; /*////////////////////////////////////// // Title Parallax //////////////////////////////////////*/ $.fn.vwTitleParallax = function() { var t = $(window).scrollTop() , i = $( this ) , n = i.parent().height(); if ( i.length ) { // console.log( {t: t, i: i, 'offsettop': i.parent().offset().top, 'total': t-i.parent().offset().top}); t -= i.parent().offset().top; if ( t < 0 ) t = 0; i.css( { // transform: 'translateY('+( 0.4 * t + "px")+')', transform: 'translate3d( 0,'+( 0.4 * t + "px")+',0)', // top: .4 * t + "px", opacity: 1 - 1 / (n / t) } ); } } /*////////////////////////////////////// // Title Area Background //////////////////////////////////////*/ $.fn.vwTitleAreaBackground = function( options ) { if ( ! vw_main_js.hasOwnProperty( 'vw_backstretch_images' ) ) { return; } if ( $.fn.vegas ) { var $target = $( '.vw-title-area' ); var $background = $target.find( '.vw-title-area__background' ); if ( $target.length == 0 ) return; // var height = $(window).height() - $('.vw-top-bar').height() - $('.vw-site-header').height() - 60; var resize_handle = function() { $target.find( '.vw-title-area__inner' ).css( 'height', $target.height()+'px' ); }; resize_handle(); $window.resize( resize_handle ); var slides = []; $.each( vw_main_js.vw_backstretch_images, function( i, el ) { var src = { src: el }; if ( vw_main_js.vw_backstretch_video ) { src.video = { src: [ vw_main_js.vw_backstretch_video ], loop: true, mute: true }; } slides.push( src ); } ); $background.vegas( { autoplay: true, timer: false, 'transition': vw_main_js.vw_backstretch_opt_transition, 'transitionDuration': vw_main_js.vw_backstretch_opt_fade, delay: vw_main_js.vw_backstretch_opt_duration, slides: slides, animation: vw_main_js.vw_backstretch_opt_animation, } ); $target.addClass( 'vw-title-area--has-bg' ); // Captions var $captions = $('
', { class: 'vw-title-area__captions' } ); $.each( vw_main_js.vw_backstretch_captions, function( i, caption ) { $captions.append( $('', { class: 'vw-title-area__caption vw-caption', text: caption } ) ); } ); $target.append( $captions ); // Locations var $locations = $('', { class: 'vw-title-area__locations' } ); $.each( vw_main_js.vw_backstretch_locations, function( i, location ) { $locations.append( $('', { class: 'vw-title-area__location', html: location } ) ); } ); $target.append( $locations ); // Show info $target.on( 'vegaswalk', function ( e, index, slideSettings ) { $target.find( '.vw-title-area__caption' ) .removeClass( 'visible' ) .eq( index ).addClass( 'visible' ); $target.find( '.vw-title-area__location' ) .removeClass( 'visible' ) .eq( index ).addClass( 'visible' ); // console.log("Slide index " + index + " image " + slideSettings.src); }); // Navigation if ( slides.length > 1 ) { $target.find( '.vw-title-area__nav' ).removeClass( 'hidden' ); } $target.find( '.vw-title-area__nav-button--next' ).on( 'click', function( e ) { e.preventDefault(); e.stopPropagation(); $background.vegas("next"); } ); $target.find( '.vw-title-area__nav-button--prev' ).on( 'click', function( e ) { e.preventDefault(); e.stopPropagation(); $background.vegas("previous"); } ); } } /*////////////////////////////////////// // Visible/Invisible On Scrolling //////////////////////////////////////*/ $.fn.vwScroller = function( options ) { var default_options = { delay: 500, /* Milliseconds */ position: 0.7, /* Multiplier for document height */ visibleClass: '', invisibleClass: '', } var isVisible = false; var $document = $(document); var $window = $(window); options = $.extend( default_options, options ); var observer = $.proxy( function () { var isInViewPort = $document.scrollTop() > ( ( $document.height() - $window.height() ) * options.position ); if ( ! isVisible && isInViewPort ) { onVisible(); } else if ( isVisible && ! isInViewPort ) { onInvisible(); } }, this ); var onVisible = $.proxy( function () { isVisible = true; /* Add visible class */ if ( options.visibleClass ) { this.addClass( options.visibleClass ); } /* Remove invisible class */ if ( options.invisibleClass ) { this.removeClass( options.invisibleClass ); } }, this ); var onInvisible = $.proxy( function () { isVisible = false; /* Remove visible class */ if ( options.visibleClass ) { this.removeClass( options.visibleClass ); } /* Add invisible class */ if ( options.invisibleClass ) { this.addClass( options.invisibleClass ); } }, this ); /* Start observe*/ setInterval( observer, options.delay ); return this; } /*////////////////////////////////////// // InView //////////////////////////////////////*/ $.fn.vwInView = function() { var itemQueue = []; var delay = 70; var queueTimer; function processItemQueue() { if (queueTimer) return; // We're already processing the queue queueTimer = window.setInterval(function () { if (itemQueue.length) { var $img = $(itemQueue.shift()); if ( ! $img.hasClass( 'vw-inview--visible' ) ) { $img.addClass('vw-inview--visible'); } processItemQueue(); } else { window.clearInterval(queueTimer); queueTimer = null; } }, delay); } if ( ! $body.hasClass( 'vw-disable-inview' ) ) { this.waypoint( function() { itemQueue.push(this.element); processItemQueue(); },{ offset: '98%' } ); } } /*////////////////////////////////////// // Custom Tiled Gallery //////////////////////////////////////*/ $.fn.vwCustomTiledGallery = function() { this.each( function( i, el ) { var $gallery = $( el ); var layout = $gallery.attr( 'data-gallery-layout' ); if ( ! ( parseInt( layout, 10 ) > 0 ) ) { layout = '213'; // Default layout } layout = layout.split(''); var columnLayout = []; for (var i in layout ) { var columnCount = parseInt( layout[i], 10 ); var columnWidth = 100.0 / columnCount; for ( var j = 1; j <= columnCount; j++ ) { columnLayout.push( columnWidth ); } } $gallery.find( '> figure' ).each( function( i, el ) { var $el = $( el ); var layoutIndex = i % columnLayout.length; $el.css( 'width', columnLayout[ layoutIndex ] - 1 + '%' ); } ); } ); } /*////////////////////////////////////// // Fixed Tabular //////////////////////////////////////*/ $.fn.vwFixedTab = function() { this.each( function( i, el ) { var $this = $( el ); var $tabs = $this.find( '.vw-fixed-tab-title' ); var $contents = $this.find( '.vw-fixed-tab-content' ); $tabs.each( function( i, el ) { $( el ).on( 'click', function( e ) { e.preventDefault(); // Manage tabs $this.find( '.vw-fixed-tab-title.is-active' ).removeClass( 'is-active' ); $( this ).addClass( 'is-active' ); // Manage contents $this.find( '.vw-fixed-tab-content.is-active' ).hide(); $contents.eq( i ).show().addClass('is-active'); $( document ).trigger( 'vw_content_height_changed' ); } ) } ); } ); } /*////////////////////////////////////// // Post Share Link //////////////////////////////////////*/ $.fn.vwShareLink = function() { this.on( 'click', function( e ) { var $this = $( this ); var url = $this.attr( 'href' ); var width = $this.data( 'width' ); var height = $this.data( 'height' ); var leftPosition, topPosition; //Allow for borders. leftPosition = (window.screen.width / 2) - ((width / 2) + 10); //Allow for title and status bars. topPosition = (window.screen.height / 2) - ((height / 2) + 50); var windowFeatures = "status=no,height=" + height + ",width=" + width + ",resizable=yes,left=" + leftPosition + ",top=" + topPosition + ",screenX=" + leftPosition + ",screenY=" + topPosition + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no"; window.open( url,'sharer', windowFeatures ); return false; } ); }; /*////////////////////////////////////// // Ajax Pagination //////////////////////////////////////*/ $.fn.vwPaginationAjax = function() { function bind_click_event( $placeholder ) { var $link = $placeholder.find( '.vw-pagination a' ); $link.on( 'click', _on_click ); // Auto loading for infinite scrolling $placeholder.find( '.vw-pagination--infinite-auto .vw-pagination__load-more' ).waypoint({ handler: function( direction ) { $link.click(); }, offset: '90%', }); } var _on_click = function( e ) { var $this = $( this ); var link = $this.attr( 'href' ); var $viewport = $('html, body'); var $container = $this.closest( '.vw-content-main, .vw-post-shortcode, .vwspc-section' ); var container_id = $container.attr( 'id' ); if( ! container_id ) { console.log( 'AJAX Pagination: No container',$container ); return; } else { e.preventDefault(); // prevent default linking } if ( $container.hasClass( 'vwspc-section' ) ) { var placeholder = '#'+container_id+' .vwspc-section-content'; var $post_container = $container.find( '.vwspc-section-content .vw-loop' ); var $controls = $container.find( '.vwspc-section-content .vw-loop > *, .vwspc-section-content .vw-pagination' ); } else { // hasClass( 'vw-post-shortcode' ) var placeholder = '#'+container_id; var $post_container = $container.find( '.vw-loop' ); var $controls = $container.find( '.vw-loop > *, .vw-pagination' ); } var $placeholder = $( placeholder ); var is_append_items = $this.parents( '.vw-pagination' ).hasClass( 'vw-pagination--append-items' ); var $preloader = $('