/* -----------------------------------------------------------------------------
* Document ready
* -------------------------------------------------------------------------- */
;(function( $, window, document, undefined ){
"use strict";
/*//////////////////////////////////////
// Visible/Invisible On Scrolling
//////////////////////////////////////*/
$.fn.vwScroller = function( options ) {
var default_options = {
delay: 500, /* Milliseconds */
position: 0.7, /* Multiplier for document height */
visibleClass: '',
invisibleClass: '',
autoplay: false,
}
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;
}
/*//////////////////////////////////////
// AJAX Pagination
//////////////////////////////////////*/
$.fn.vwPaginationAjax = function() {
function progressiveAnimate(items, reverse) {
var i = 0;
if (reverse) {
items = $(items.get().reverse());
}
items.each(function(){
var $this = $(this);
if (reverse) {
$this.stop().delay( i + '').fadeTo(150, 0);
} else {
$this.stop().delay( i + '').fadeTo(150, 1);
}
i = i + 100;
});
}
function bind_click_event( $placeholder ) {
var $link = $placeholder.find( 'a' );
$link.click( _on_click );
}
var _on_click = function( e ) {
e.preventDefault(); // prevent default linking
var $this = $( this );
var link = $this.attr( 'href' );
var $container = $this.closest( '.vwpc-section' );
var container_id = $container.attr( 'id' );
var is_infinite_scrolling = $this.hasClass( 'vw-load-more' );
if( ! container_id ) {
console.log( 'AJAX Pagination Error: No container' );
}
if ( $container.hasClass( 'vwpc-section' ) ) {
var placeholder = '#'+container_id;
var $post_container = $container.find( '.post-box-list' );
var $controls = $container.find( '#pagination' );
} else { // hasClass( 'vw-post-shortcode' )
var placeholder = '#'+container_id;
var $post_container = $container.find( '.vw-post-loop' );
var $controls = $container.find( '.vw-post-loop > *, .vw-page-navigation' );
}
var $placeholder = $( placeholder );
if ( is_infinite_scrolling ) { // For infinite scrolling
$placeholder.find( '.vw-load-more' ).fadeOut( function() {
$(this).remove();
$placeholder.find( '#pagination' ).append( '
' );
});
$placeholder.find( '.vw-pagination-load-more' ).css( 'opacity', 0 );
$( '' ).load( link + ' ' + placeholder, function( response, status, xhr ) {
if( status == 'success' ) {
var new_items = $( this ).find( '.vw-isotope.post-box-list > *' );
// Insert items
$placeholder.find( '.vw-isotope.post-box-list' ).append( new_items );
$placeholder.find( '.vw-isotope' ).isotope( 'appended', new_items );
$placeholder.find( '.vw-isotope' ).vwIsotope();
// Update pagination
var $new_pagination = $( this ).find( '.vw-load-more' );
$placeholder.find( '.vw-infinite-loading-icon' ).remove();
$placeholder.find( '#pagination' ).append( $new_pagination );
bind_click_event( $placeholder.find( '#pagination.vw-pagination--infinite-more' ) );
}
if( status == 'error' ) {
console.log( 'AJAX Pagination Error: '+xhr.status+': '+xhr.statusText );
}
} )
}
}
bind_click_event( $( this ) );
}
$.fn.vwIsotope = function() {
if ( $.fn.isotope ) {
var $isotope_list = $( this );
$isotope_list.imagesLoaded( function () {
$isotope_list.isotope();
$( window ).resize( function() {
$isotope_list.isotope( 'layout' );
} );
});
}
};
$( document ).ready( function ($) {
// Add swipe box into gallery
$(".swipebox, .custom-gallery a, iv[id^=attachment_] a[href$=jpg], div[id^=attachment_] a[href$=jpeg], div[id^=attachment_] a[href$=png], .post-content a[href$=jpg], .post-content a[href$=png], .post-content a[href$=jpeg]").each( function( i, el ) {
var $this = $( el );
if ( ! $this.attr( 'title' ) ) {
$this.attr( 'title', $this.find( 'img' ).attr( 'alt' ) );
}
}).swipebox();
// Wordpress gallery grid
$( '.custom-gallery' ).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 + '%' );
} );
} );
// Ajax pagination
if ( $.fn.vwPaginationAjax ) {
$( '#pagination.vw-pagination--infinite-more' ).vwPaginationAjax();
}
// Fit images
$( '.vw-imgliquid' ).imgLiquid();
// Show circle graph for review box
$(".dial").knob();
// Instant search
$(".instant-search-icon").instant_search();
// Sticky top bar
$(".top-bar").sticky();
// carouFredSel
$(".top-posts .top-posts-inner").carouFredSel({
auto: true,
swipe: true,
mousewheel: true,
align: 'left',
width: '100%',
items: {
start: -1,
width: 'auto',
visible: function( visibleItems ) {
var viewportWidth = document.documentElement.clientWidth;
/* md device */ if ( viewportWidth >= 992 ) return 4;
/* sm device */if ( viewportWidth >= 768 ) return 3;
return 2;
},
},
scroll: {
items: 1,
easing: "quadratic",
duration: 500,
pauseOnHover: true,
onAfter: function() {
$.force_appear();
}
},
prev: ".carousel-nav-prev",
next: ".carousel-nav-next",
onCreate: function( data ) {
var $this = $(this)
setTimeout( function() {
$this.trigger("slideTo", 0);
}, 250 );
}
});
$(window).resize(function() {
$(".top-posts .top-posts-inner").trigger('configuration', ['debug', false, true]);
});
/*//////////////////////////////////////
// More articles
//////////////////////////////////////*/
if ( $.fn.vwScroller ) {
var $more_articles = $('.vw-more-articles');
$more_articles.vwScroller( { visibleClass: 'vw-more-articles--visible' } )
$more_articles.find( '.vw-more-articles__close-button' ).click( function() {
$more_articles.hide();
} );
}
// -----------------------------------------------------------------------------
// Mobile navigation
//
var $body = $('body');
$('#open-mobile-nav').click( function( e ) {
$body.toggleClass('mobile-nav-open');
$( 'body,html' ).scrollTop( 0 );
return false;
} );
var defaultWindowWidth = $(window).width();
$(window).resize(function() {
if ( defaultWindowWidth != $(window).width() ) {
$body.removeClass('mobile-nav-open');
}
});
var $mobile_nav = $('#mobile-nav-wrapper');
var $clone_main_nav = $('#main-nav-wrapper').children().clone();
$clone_main_nav.find( '.sub-posts' ).remove();
$clone_main_nav = $clone_main_nav.removeAttr('id').removeClass('main-nav').addClass('mobile-nav');
var $clone_top_nav = $('#top-nav-wrapper').children().clone();
$clone_top_nav.find( '.sub-posts' ).remove();
$clone_top_nav = $clone_top_nav.removeAttr('id').removeClass('top-nav').addClass('mobile-nav');
$mobile_nav.append( $clone_main_nav, $( '
' ), $clone_top_nav );
// -----------------------------------------------------------------------------
// Navigation Sub-menu
//
$( '.main-nav .menu-item' ).hover(
function() {
$( '> .sub-menu' , this )
.stop( true, true )
.fadeIn( { duration: 250 } );
}, function() {
$( '> .sub-menu' , this )
.stop( true, true )
.fadeOut( { duration: 250 } );
} );
// -----------------------------------------------------------------------------
// Fitvids - keep video ratio
//
$( '.post-audio-wrapper, .post-video-wrapper, .flxmap-container, .comment-body, .post-content, #footer' ).fitVids( { customSelector: "iframe[src*='maps.google.']", ignore: '.vw-ignore-fitvids' });
// -----------------------------------------------------------------------------
// Isotope - Mansonry grid
//
// var $isotope_list = $('.vw-isotope');
// $isotope_list.imagesLoaded( function () {
// var options = {};
// if ( $( 'body' ).hasClass( 'rtl' ) ) {
// options.isOriginLeft = false;
// }
// $isotope_list.isotope( options );
// $(window).resize(function() {
// $isotope_list.isotope('layout');
// });
// });
$('.vw-isotope').vwIsotope();
// -----------------------------------------------------------------------------
// Back to top
//
$( '.back-to-top' ).click( function() {
$( 'body,html' ).animate( { scrollTop: 0 } );
return false;
} );
// -----------------------------------------------------------------------------
// Appear
//
$( 'body.site-enable-post-box-effects .post-box.animated-content' ).data( 'appear-top-offset', 100 ).on( 'appear', function( event, $all_appeared_elements ) {
$all_appeared_elements.removeClass( 'animated-content' ).addClass( 'appeared' );
} ).appear( { force_process: false } );
if ( $( 'html' ).hasClass( 'no-touch' ) ) {
$( document ).scrollTop( 1 );
}
} );
})( jQuery, window , document );
/**
* No-touch detection
*/
if (!("ontouchstart" in document.documentElement)){
document.documentElement.className += " no-touch";
}