(function($){
"use strict";
var WITHEMES=WITHEMES||{};
var isMobile={
Android: function(){
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function(){
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function(){
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function(){
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function(){
return navigator.userAgent.match(/IEMobile/i);
},
any: function(){
return (isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows());
}};
WITHEMES.tipsy=function(){
if($().tipsy){
$('.top-social.with-tooltip ul li').tipsy({
gravity:'n',
fade:true,
});
$('.footer-social.with-tooltip ul li').tipsy({
gravity:'s',
fade:true,
opacity:1,
});
$('.hastip').tipsy({
gravity:'s',
opacity:1,
fade:true,
});
};};
WITHEMES.zoom=function(){
};
WITHEMES.fitvids=function(){
if($().fitVids){
$('.media-container, .post-content').fitVids();
}};
WITHEMES.scrollup=function(){
$(window).scroll(function(){
if($(this).scrollTop() > 600){
$('#scrollup').fadeIn();
}else{
$('#scrollup').fadeOut();
}});
$('.scrollup').click(function(){
$("html, body").animate({ scrollTop: 0 }, 1000 , 'easeInOutExpo');
return false;
});
};
WITHEMES.top_search=function(){
$('.top-search .button').on('click',function(){
var $this=$(this);
var offset=$this.offset();
if(offset.left < 220 ) $('.hidden-search').css({marginRight: - 220 + offset.left + 'px' });
$('.hidden-search').toggle();
});
$(document).on('click',function(e){
var currentTarget=$(e.target).closest(".top-search");
if(currentTarget.length==0){
$('.hidden-search').hide();
}});
}
WITHEMES.superfish=function(){
if($().superfish){
var sf=$('#wi-mainnav > .menu');
sf.superfish({
animation:{opacity:'show',height:'show'},
speed:'fast',
disableHI:!$('#wi-mainnav').data('hover-intent'),
cssArrows:true,
onInit:function(){
$(this).find('.sf-with-ul').append('<u class="indicator"><u></u></u>');
},
});
if(matchMedia('only screen and (max-width: 979px)').matches){
sf.superfish('destroy');
}
$(window).resize(function(){
if(matchMedia('only screen and (max-width: 979px)').matches){
sf.superfish('destroy');
}else{
sf.superfish({
animation:{opacity:'show',height:'show'},
speed:'fast',
disableHI:!$('#wi-mainnav').data('hover-intent'),
cssArrows:true
});
}});
}}
WITHEMES.sticky_header=function(){
var ele=$('.enable-sticky-header #wi-header');
var header_height=ele.height();
ele.parent().css({height:header_height + 'px'});
$(window).scroll(function (){
var from_top=$(this).scrollTop();
var adminbar_height=$('#wpadminbar').height();
var topbar_height=$('#wi-topbar').height();
if(from_top > (adminbar_height + topbar_height)){
ele.addClass('is-sticky');
}else{
ele.removeClass('is-sticky');
}});
}
WITHEMES.parallax=function(){
var iOS=(navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true:false);
if(iOS){
$('#wi-titlebar.style-1.enable-parallax').css({backgroundAttachment:'scroll'});
}else{
$('#wi-titlebar.style-1.enable-parallax').css({backgroundAttachment:'fixed'});
}
if($().parallax&&isMobile.any()==null){
$('#wi-titlebar.style-1.enable-parallax').parallax();
}};
WITHEMES.sidenav=function(){
var sidebarTopMargin=$('#wpadminbar').height() + 20;
if($('body').hasClass('enable-sticky-header')){
sidebarTopMargin +=60;
}
var footerSelector;
if($('#comments.comments-area').length)
footerSelector='#comments.comments-area';
else
footerSelector='#footer-container';
var iOS=(navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true:false);
if(isMobile.any()==null){
if($().stickySidebar){
$('.side-nav-slide').stickySidebar({
contentSelector:'#post-content',
headerSelector:'#wi-header',
navSelector:'#titlebar-container',
footerSelector:footerSelector,
sidebarTopMargin:sidebarTopMargin,
footerThreshold:100
});
}
$('.side-nav-slide').css({width:$('#secondary').width() + 'px'});
$(window).resize(function(){
$('.side-nav-slide').css({width:$('#secondary').width() + 'px'});
});
}
$('.side-nav-slide ul li a, .btn-scroll').on('click',function(e){
var $this=$(this);
if($(this).closest('.side-nav-slide').length > 0){
$('.side-nav-slide ul li').removeClass('active');
$(this).parent().addClass('active');
}
var href=$(this).data('href');
if(href=='') href=$(this).attr('href');
var hash;
if(href!='') hash=href.split('#')[1];
if(hash){
if($('#'+hash).length > 0){
e.preventDefault();
var offset_top=$('#'+hash).offset().top - sidebarTopMargin + 10;
if($this.closest('.wi-page').hasClass('side-nav-scroll-style-easing')){
$('html,body').animate({ scrollTop: offset_top}, 800 ,'easeInOutExpo');
}else{
$('html,body').animate({ scrollTop: offset_top}, 500 ,'');
}}
}});
var lastid,	scroll_items=$(".side-nav-slide").find('a').map(function (){
var href=$(this).data('href');
if(href=='') href=$(this).attr("href");
var hash;
if(href) hash=href.split('#')[1];
if(hash){
if($('#' + hash).length > 0) return $('#' + hash);
}});
$(window).scroll(function (){
var from_top=$(this).scrollTop() + 100;
if($('body').hasClass('enable-sticky-header')){
from_top +=60;
}
var cur=scroll_items.map(function (){
if($(this).offset().top < from_top) return this
});
cur=cur[cur.length - 1];
var id=(cur&&cur.length) ? cur[0].id:'';
if(lastid!==id){
lastid=id;
$('.side-nav-slide ul li a').each(function(){
var href=$(this).data('href');
if(!href) href=$(this).attr('href');
var hash;
if(href) hash=href.split('#')[1];
if(hash==id){
$(this).parent().addClass("active");
}else{
$(this).parent().removeClass("active");
}});
}});
};
WITHEMES.colorbox=function(){
if($().colorbox){
$('.wi-colorbox').colorbox({
transition:'none',
speed:300,
maxWidth:'90%',
maxHeight:'90%',
returnFocus:false,
});
$('.gallery').each(function(index){
var id=($(this).attr('id')) ? $(this).attr('id'):'gallery-' + index;
$(this).
find('.gallery-item').
find('a[href$=".gif"], a[href$=".jpg"], a[href$=".png"], a[href$=".bmp"]').
has('img').
colorbox({
transition:'elastic',
speed:300,
maxWidth:'90%',
maxHeight:'90%',
rel:id,
returnFocus:false,
});
});
$('.wi-single .post-thumbnail a').has('img').colorbox({
transition:'none',
speed:300,
maxWidth:'90%',
maxHeight:'90%',
returnFocus:false,
});
$('.colorbox-video').each(function(){
var $this=$(this);
var innerWidth, innerHeight;
if($this.data('width')) innerWidth=$this.data('width'); else innerWidth=640;
if($this.data('height')) innerHeight=$this.data('height'); else innerHeight=390;
$this.colorbox({
iframe:true,
innerWidth:innerWidth,
innerHeight:innerHeight,
});
});
}};
WITHEMES.blogslider=function(){
if($().flexslider){
$('.wi-blog-slider').each(function(){
var $this=$(this);
var easing=($this.data('effect')=='fade'&&!$this.data('easing')) ? 'linear':'easeInOutExpo';
var pager;
if($this.data('thumbnail-pager')) pager='thumbnails';
else pager=$this.data('pager');
$this.find('.flexslider').flexslider({
animation:$this.data('effect'),
pauseOnHover:true,
useCSS:false,
easing:easing,
animationSpeed:500,
slideshowSpeed:7000,
controlNav:pager,
directionNav:$this.data('navi'),
slideshow:$this.data('auto'),
prevText:'',
nextText:'',
smoothHeight:$this.data('smooth'),
});
});
}};
WITHEMES.mobile_menu=function(){
$('.topbar-menu .toggle-btn').on('click',function(){
$(this).parent().find('.topbar-mn').slideToggle('fast','easeOutExpo');
});
$('#topbar-toggle').on('click',function(){
$('#wi-topbar').find('.container').slideToggle('fast','easeOutExpo');
});
$('.toggle-menu').on('click',function(){
$('#wi-mainnav').slideToggle('fast','easeOutExpo');
});
$('#wi-mainnav .menu > ul > li a .indicator').on('click',function(e){
var $this=$(this);
e.preventDefault();
$this.parent().next().slideToggle('normal','easeOutExpo');
return false;
});
}
WITHEMES.bottom_popup=function(){
$('body').waypoint(function(direction){
$('#wi-bottom-popup').toggleClass('hiding', direction==="up");
$('#wi-bottom-popup .close-popup').on('click',function(){$('#wi-bottom-popup').addClass('hiding');});
}, {
offset: function(){
return $.waypoints('viewportHeight') - $(this).height() + 100;
}});
}
WITHEMES.blog_fade=function(){
$('.wi-article .post-thumbnail').each(function(){
var $this=$(this);
$this.bind('inview', function(event, isInView, visiblePartX, visiblePartY){
if(isInView){
$this.addClass('running');
}});
});
}
WITHEMES.woocommerce_quantity=function(){
var $testProp=$('div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)').find('qty');
if($testProp&&$testProp.prop('type')!='date'){
$('div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)').addClass('buttons_added').append('<input type="button" value="+" class="plus" />').prepend('<input type="button" value="-" class="minus" />');
$('input.qty:not(.product-quantity input.qty)').each(function(){
var min=parseFloat($(this).attr('min') );
if(min&&min > 0&&parseFloat($(this).val()) < min){
$(this).val(min);
}}
);
$(document).on('click', '.plus, .minus', function(){
var $qty=$(this).closest('.quantity').find('.qty'),
currentVal=parseFloat($qty.val()),
max=parseFloat($qty.attr('max') ),
min=parseFloat($qty.attr('min') ),
step=$qty.attr('step');
if(!currentVal||currentVal===''||currentVal==='NaN') currentVal=0;
if(max===''||max==='NaN') max='';
if(min===''||min==='NaN') min=0;
if(step==='any'||step===''||step===undefined||parseFloat(step)==='NaN') step=1;
if($(this).is('.plus') ){
if(max&&(max==currentVal||currentVal > max) ){
$qty.val(max);
}else{
$qty.val(currentVal + parseFloat(step) );
}}else{
if(min&&(min==currentVal||currentVal < min) ){
$qty.val(min);
}else if(currentVal > 0){
$qty.val(currentVal - parseFloat(step) );
}}
$qty.trigger('change');
}
);
}}
$(document).ready(function(){
WITHEMES.tipsy();
WITHEMES.zoom();
WITHEMES.fitvids();
WITHEMES.top_search();
WITHEMES.superfish();
WITHEMES.sticky_header();
WITHEMES.parallax();
WITHEMES.sidenav();
WITHEMES.scrollup();
WITHEMES.colorbox();
WITHEMES.blogslider();
WITHEMES.mobile_menu();
WITHEMES.bottom_popup();
WITHEMES.blog_fade();
WITHEMES.woocommerce_quantity();
});
})(jQuery);