"use strict"; var isMenuOpen = false; var eventtype = mobilecheck() ? 'touchstart' : 'click'; var vc_swiper = {}; jQuery(function($) { /**************** ** VARIOUS *****************/ blu_full_calculate(); function blu_full_calculate(){ // make the first child element ignore the entry-content padding $('.blu_full').each(function(){ var padding = parseInt($('.entry-container').css('padding-left')); $(this).css('margin-left', '-' + (padding - parseInt($(this).css('margin-left'))+15) + 'px'); $(this).css('margin-right', '-' + (padding - parseInt($(this).css('margin-right'))+15) + 'px'); $(this).animate({ opacity: 1 }, 1000); }); } $('.blu_bold').each(function(){ // make sure it hasn't already been done (via php) if($(this).children('strong').length < 1 && $(this).children('.blu_boldsplit').length < 1){ // separate the text by spaces var text = $(this).html().split(" "); // drop the last word and store it in a variable var last = text.pop(); // join the text back and if it has more than 1 word add the span tag // to the last word if(text.length > 0){ $(this).html(text.join(" ") + " "+last+""); } return text.join(" ") + (text.length > 0 ? " "+last+"" : last); } }); $.fn.parallaxImg = function(){ $(this).each(function(){ var $that = jQuery(this), parallaxsrc = $that.attr('src'), captionDiv = $that.closest('.wp-caption'); // If there's a caption set if (captionDiv.length) { captionDiv.removeClass('wp-caption').addClass('post-break has-caption').css('width', 'auto'); $that.before(''); } else { $that.before(''); } $that.remove(); }); } $('img.parallax').parallaxImg(); /**************** ** BLUTH POSTS SLIDER *****************/ var blu_posts_sliders = [], sliderindex = 0; $.fn.blPostsSlider = function(e){ var $that = $(this); $(this).each(function(i){ blu_posts_sliders[i] = $(this).swiper({ speed: 500, autoplay: 7000, watchActiveIndex: true, resizeReInit: true, calculateHeight: false, onSlideChangeStart: function(swiper){ // $that.siblings('.tabs').children("a").removeClass('active'); // $that.siblings('.tabs').children("a").eq( blu_posts_sliders[i].activeIndex ).addClass('active'); }, onInit: function(swiper){ $that.find('.swiper-wrapper').css('height', $that.outerHeight()+'px'); } }); $(".tabs a").bind('touchstart mousedown', function(e){ if($(this).attr('href') == '#'){ e.preventDefault(); } $(this).parent().find("a").removeClass('active'); $(this).addClass('active'); blu_posts_sliders[i].swipeTo( $(this).index() ); }); $(".tabs a").click(function(e){ if($(this).attr('href') == '#'){ e.preventDefault(); } }); $(".arrow-left").bind('click', function(e){ e.preventDefault(); blu_posts_sliders[i].swipePrev(); // console.log( blu_posts_sliders[i].activeIndex ); }); $(".arrow-right").bind('click', function(e){ e.preventDefault(); blu_posts_sliders[i].swipeNext(); console.log( blu_posts_sliders[i].activeIndex ); }); blu_posts_sliders[i].wrapperTransitionEnd(function(){ /* hide right arrow at the end */ if((blu_posts_sliders[i].slides.length-1) <= blu_posts_sliders[i].activeIndex){ $that.siblings('.arrow-right').css('display','none'); }else{ $that.siblings('.arrow-right').css('display',''); } /* hide left arrow at the beginning */ if(blu_posts_sliders[i].activeIndex == 0){ $that.siblings('.arrow-left').css('display','none'); }else{ $that.siblings('.arrow-left').css('display',''); } $that.siblings('.tabs').children("a").removeClass('active'); $that.siblings('.tabs').children("a").eq( blu_posts_sliders[i].activeIndex ).addClass('active'); }, true); }); } function reinitSwiper(swiper) { setTimeout(function () { swiper.reInit(); swiper.resizeFix(); }, 1000); } if($(this).hasClass('swiper-container')){ $(window).bind('resizeEnd', function() { reinitSwiper($(this).swiper()); }); } $.fn.blFullWidth = function(){ var marginAmount; $(this).each(function(e){ $(this).css('margin-left', '' ).css('margin-right', '' ); marginAmount = ( ($(window).width() - $(this).width())/2 ); $(this).css('margin-left', '-'+marginAmount+'px' ).css('margin-right', '-'+marginAmount+'px' ); if($(this).hasClass('swiper-container')){ reinitSwiper($(this).swiper()); } }); } if($('.full-width').length){ $(window).bind('resizeEnd', function() { $('.full-width').blFullWidth(); }); $('.full-width').blFullWidth(); } if($('.bl_posts_slider').length){ $('.bl_posts_slider .swiper-container.full-width').animate({ opacity: 1 }, 400); $('.bl_posts_slider .swiper-container').blPostsSlider(); } /**************** ** MENU/HEADER *****************/ // Scroll extra for search at the top if($('#header-top').length){ var isAtTop = false; $( window ).on('mousewheel', function(e){ if( $( window ).scrollTop() == 0 ){ if(e.deltaY > 0){ isAtTop = true; $('#wrap').animate({ top : 47 }, 200); return false; // prevent default }else{ if(isAtTop){ isAtTop = false; $('#wrap').animate({ top : 0 }, 200); return false; // prevent default } } }else{ if(isAtTop){ isAtTop = false; $('#wrap').animate({ top : 0 }, 200); // return false; // prevent default } } }); } // Shrink header on scroll down if(blu.fixed_header == 'true' && $('#header-content').length > 0){ var y = $(window).scrollTop(); // set the width of the header $(window).on('resizeEnd', function(){ $('#header-content').css('width', $('#wrap').width()+'px'); }) $('#header-content').css('width', $('#wrap').width()+'px'); if($(window).width() > 979){ var masthead_height = $('#page-header').height(); var masthead_top = $('#header-content').offset().top+$('#header-content').height()+50; if(y > masthead_top){ $('#header-content').addClass('fixed'); $('#wrap').css('padding-top', (masthead_height)+'px'); } if(y > 150){ $('#header-content').addClass('shrink'); $('body').addClass('sticky_header_active'); } else{ $('#header-content').removeClass('shrink'); $('body').removeClass('sticky_header_active'); } // Shrink menu on scroll var didScroll = false; $(window).scroll(function() { didScroll = true; }); setInterval(function() { if ( didScroll ) { didScroll = false; y = $(window).scrollTop(); if(y > masthead_top){ $('#header-content').addClass('fixed'); $('#wrap').css('padding-top', (masthead_height)+'px'); } else{ $('#header-content').removeClass('fixed'); $('#wrap').css('padding-top', ''); } if(y > 500){ $('#header-content').addClass('shrink'); $('body').addClass('sticky_header_active'); } else{ $('#header-content').removeClass('shrink'); $('body').removeClass('sticky_header_active'); } } }, 50); }else{ $('#header-content').removeClass('shrink'); $('#header-content').removeClass('fixed'); } }else{ $('#page').addClass('static-header'); } // selectable category groups if($('#header-main-menu li.has-category-children li').length > 0){ // make first element active on load $('#header-main-menu li.has-category-children li:first').addClass('active'); $('#header-main-menu li.has-category-children .child-post:first').addClass('active'); // animate first titles in on hover on top element $('#header-main-menu li.has-category-children').on('hover', function(){ // $(this).find('li:first').css('opacity', '0.1'); $(this).find('li:first .post-title').each(function(e){ $(this).delay(e*150).animate({ opacity: 0 }, 10, function(){ // Put timeago attributes on the new posts $(this).css('opacity', ''); $(this).addClass('animate'); }); }); }); // categories $('#header-main-menu li.has-category-children li').each(function(e){ $(this).parent().children('li:first').addClass('active'); $(this).find('.child-post:first-child').addClass('active'); $(this).on('hover', function(){ $(this).closest('ul').children('li').removeClass('active'); $(this).children('.child-post:first').addClass('active'); $(this).addClass('active'); // animate titles in $(this).find('.post-title').each(function(e){ $(this).delay(e*150).animate({ opacity: 0 }, 10, function(){ // Put timeago attributes on the new posts $(this).css('opacity', ''); $(this).addClass('animate'); }); }); }); }); // posts $('#header-main-menu li.has-category-children .child-post').each(function(e){ $(this).on('hover', function(){ $(this).parent().find('.child-post').removeClass('active'); $(this).addClass('active'); }); }); } // selectable category if($('#header-main-menu li.is-category').length > 0){ // make first element active on load $('#header-main-menu li.is-category .child-post:nth-child(2)').addClass('active'); // posts $('#header-main-menu li.is-category .child-post').each(function(e){ $(this).on('hover', function(){ $(this).parent().find('.child-post').removeClass('active'); $(this).addClass('active'); }); }); } /**************** ** Post nav fade in *****************/ if($('body').hasClass('single-post')){ var didScroll_1 = false; $(window).scroll(function() { didScroll_1 = true; }); if(!mobilecheck()){ var content_top = $('#content').position().top; setInterval(function() { if ( didScroll_1 ) { didScroll_1 = false; y = jQuery(window).scrollTop(); if(y < content_top){ $('.single-pagination > span').fadeOut('fast'); }else{ $('.single-pagination > span').fadeIn(); } } }, 150); } } /**************** ** HEADER SWIPER *****************/ if($('.swiper-container-top-header').length > 0){ slidesPerView = 1; // Init Instagram widget var top_swiper = new Swiper('.swiper-container-top-header', { loop: true, pagination: '.swiper-top-header-pagination', paginationClickable: true, slidesPerView: slidesPerView, onTouchEnd : function(element) { $('.swiper-container').removeClass('active'); }, onTouchStart : function(element) { $('.swiper-container').addClass('active'); }, onSlideChangeEnd : function(element) { $('.swiper-container').removeClass('active'); }, calculateHeight: true, }); top_swiper.reInit(); $('.swiper-top-header-pagination span').each(function(e){ $(this).after('
'+$('.swiper-container-top-header .swiper-wrapper .swiper-slide').eq(e).attr('data-posttitle')+'
'); }); } /**************** ** MINIMIZE WIDGET HEADER *****************/ if($('.widget-head .min').length > 0){ $('.widget-head .min').click(function(e){ e.preventDefault(); $(this).parent().nextAll().toggle('fast'); }); } /**************** ** SOCIAL POSTS LOAD *****************/ var didScroll2 = true, normalLayout = false; // if the layout isn't twocolumn or three column then load the posts that are already in view immediately if(!$('#content').hasClass('twocolumn') && !$('#content').hasClass('threecolumn') && !$('#content').hasClass('fourcolumn') && !$('#content').hasClass('fivecolumn')){ normalLayout = true; } $(window).scroll(function() { didScroll2 = true; }); setInterval(function() { if ( didScroll2 ) { didScroll2 = false; var y2 = $(window).scrollTop(); if($('.facebook-store').length > 0){ $('.facebook-store').each(function(e){ if((y2 > $(this).offset().top - 800 && y2 < $(this).offset().top + 200) && !$(this).data('loaded') ) { $(this).data('loaded', '1'); $(this).html($(this).data('code')); FB.XFBML.parse($(this).get(0)); // if it's a column layout then remove the iframe and put in an icon with a link if(!normalLayout){ // $(this).find('iframe').remove(); $(this).html(''); } } }); } if($('.twitter-store').length > 0){ $('.twitter-store').each(function(e){ if((y2 > $(this).offset().top - 800 && y2 < $(this).offset().top + 200) && !$(this).data('loaded') ) { $(this).data('loaded', '1'); $(this).html($(this).data('code')); // if(twttr != 'undefined') // twttr.widgets.load(); } }); } if($('.google-store').length > 0){ $('.google-store').each(function(e){ if((y2 > $(this).offset().top - 800 && y2 < $(this).offset().top + 200) && !$(this).data('loaded') ) { $(this).data('loaded', '1'); $(this).html($(this).data('code')); gapi.follow.go(); } }); } } }, 600); /**************** ** AJAX *****************/ var post__not_in_array = Array(); function blu_ajax_post_calculate_posts(){ $('.bl_posts:last').each(function(){ post__not_in_array = $(this).find('.post__not_in:last').data('post__not_in'); }); } blu_ajax_post_calculate_posts(); // load more button $('.bl_posts').on('click', '.ajaxload', function(e, silent){ e.preventDefault(); $(this).closest('.bl_posts').find('.post__not_in').remove(); var countposts = 0, $that = $(this), $info = $(this).closest('.bl_posts').find('.bl_posts_information'), $clickCounter = parseInt($info.data('click-count')), $wp_order = ($info.data('order') == undefined ? 'DESC' : $info.data('order')), $data_args = $info.data('args'), original_text = $that.html(); $that.addClass('opened').addClass('open'); // show the loader instead of the button text $that.html('
'); // $info.data('offset', ($info.data('offset')*$clickCounter) ); if($data_args['post__not_in'] == undefined || $data_args['post__not_in'] == ''){ if($clickCounter == 0){ $info.data('offset', ($info.data('posts_per_page')) ); }else{ $info.data('offset', ($info.data('posts_per_page')*($clickCounter+1) ) ); } } $.ajax({ type: 'POST', url: blu.ajaxurl, data: { action: 'blu_ajaxload_posts', ajaxtype: 'loadmore', type: $info.data('type'), css: $info.data('css'), offset: $info.data('offset'), posts_per_page: $info.data('posts_per_page'), post__not_in: post__not_in_array, orderby: $info.data('orderby'), order: $wp_order, args: $info.data('args') }, success: function(data, textStatus, XMLHttpRequest){ if(data != 0) $info.append(data); // gather what posts not to show (what posts have already been shown) if( post__not_in_array != undefined ){ post__not_in_array = post__not_in_array.concat( $that.closest('.bl_posts').find('.post__not_in:last').data('post__not_in') ); $info.data('post__not_in', post__not_in_array ); } // add to the click counter $info.data('click-count', ($clickCounter+1)); // animate posts in $info.find('.new_post').each(function(e){ $(this).delay(e*250).animate({ opacity: 1 }, 10, function(){ $(this).css('opacity', ''); $(this).removeClass('new_post'); $(this).addClass('animate'); }); countposts++; }); $info.data('total-posts', $info.data('total-posts')+countposts); // Put timeago attributes on the new posts if(blu.disable_timeago !== "1"){ $('.timeago').timeago(); } // write out the original text if everything was okay $that.html(original_text); if(!data || data == 0 || countposts < $info.data('posts_per_page')){ $that.parent().fadeOut(); }else{ // change the address bar insertParam($that.attr('id'), $info.data('total-posts') ); } $that.removeClass('open'); }, error: function(MLHttpRequest, textStatus, errorThrown){ $that.html(original_text); } }) return false; }); // orderby button $('.bl_posts').on('click', '.orderposts a', function(e, silent){ e.preventDefault(); blu_ajax_post_calculate_posts(); var countposts = 0, $that = $(this), $info = $(this).closest('.bl_posts').find('.bl_posts_information'), $wp_order = ($that.data('order') == undefined ? 'DESC' : $that.data('order')), $clickCounter = parseInt($info.data('click-count')), original_text = $that.html(); // reset the click counter $clickCounter = 0; // fade in the load more button $that.closest('.bl_posts').find('.ajaxload').fadeIn(); // save the order by information $info.data('orderby', $that.data('orderby')); $info.data('order', $wp_order); // reset the post__not_in $info.data('post__not_in', ''); // reset the offset $info.data('offset', '0'); // show the loader instead of the button text $info.html('
'); $.ajax({ type: 'POST', url: blu.ajaxurl, data: { action: 'blu_ajaxload_posts', ajaxtype: 'orderby', type: $info.data('type'), css: $info.data('css'), offset: $info.data('offset'), posts_per_page: $info.data('posts_per_page'), orderby: $info.data('orderby'), order: $wp_order, args: $info.data('args') }, success: function(data, textStatus, XMLHttpRequest){ if(data != 0) $info.html(data); // gather what posts not to show (what posts have already been shown) post__not_in_array = post__not_in_array.concat( $that.closest('.bl_posts').find('.post__not_in:last').data('post__not_in') ); $info.data('post__not_in', post__not_in_array ); // $info.data('offset', $info.data('posts_per_page')); $info.find('.new_post').each(function(e){ $(this).delay(e*250).animate({ opacity: 1 }, 10, function(){ // Put timeago attributes on the new posts $(this).css('opacity', ''); $(this).removeClass('new_post'); $(this).addClass('animate'); }); }); if(blu.disable_timeago !== "1"){ $('.timeago').timeago(); } // change the address bar insertParam('ob'+$info.data('ajaxid'), $info.data('orderby')); insertParam('o'+$info.data('ajaxid'), $wp_order); insertParam('a'+$info.data('ajaxid'), '0'); $that.removeClass('open'); $info.siblings('.loadmore').fadeIn(); }, error: function(MLHttpRequest, textStatus, errorThrown){ } }) return false; }); // Bind to StateChange Event History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate var State = History.getState(); // Note: We are using History.getState() instead of event.state }); /**************** ** COMMENT SCORE *****************/ // AJAX Comment Vote $('.blu-comment-vote').unbind('click').click( function(e) { e.stopPropagation(); e.preventDefault(); var previousScore = +$(this).parent().find('.total-score').html(); var commentID = $(this).data('commentid'); var voteType; if($(this).hasClass('blu-comment-vote-up')){ previousScore++; voteType = 'up'; }else{ previousScore--; voteType = 'down'; } var $that = $(this); $.ajax({ type: 'POST', url: blu.ajaxurl, data: { action: 'blu_ajax_comment_score', commentid: commentID, votetype: voteType, previousScore: previousScore }, success: function(data, textStatus, XMLHttpRequest){ if(!data){ $that.css('color','#DDDDDD'); $that.parent().find('.total-score').html(previousScore++).addClass('vote-'+voteType); if(voteType = 'down' && ( previousScore - 1 < 0 )){ $that.closest('li').addClass('mute'); } }else{ $that.parent().find('.total-score').after('Already voted!'); } }, error: function(MLHttpRequest, textStatus, errorThrown){ $that.parent().find('.total-score').after('Error: ' + errorThrown + ''); } }); }); /**************** ** SOCIAL BUTTONS *****************/ // load google+ button if there's a button present if($('.google-plus-button').length > 0){ (function() { var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true; po.src = 'https://apis.google.com/js/platform.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s); })(); } // load twitter button if there's a button present if($('.twitter-button').length > 0){ !function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs'); } /**************** ** SWIPER *****************/ if($('.swiper-gallery').length > 0){ var galleryswiperNumber = 1; imagesLoaded( document.querySelector('#content'), function( instance ) { // Gallery $('.swiper-gallery').each(function(e){ $(this).attr('id', 'gallery-swiper-'+galleryswiperNumber); var gallery_swiper = new Swiper('#gallery-swiper-'+galleryswiperNumber, { pagination: '#gallery-swiper-'+galleryswiperNumber+' .swiper-pagination', loop:false, paginationClickable: true, slidesPerView: 1, preventLinks: false, releaseFormElements: true, keyboardControl: true, watchActiveIndex: true, noSwiping: true, calculateHeight: true, onSlideChangeStart: function(swiper){ $(swiper.container).height( $( swiper.activeSlide()).find('img').height() ); }, onImagesReady: function(swiper){ $('.swiper-gallery').css( 'opacity', '1' ); $(swiper.container).height( $( swiper.activeSlide()).find('img').height() ); } }); galleryswiperNumber++; gallery_swiper.reInit(); }); $('.swiper-gallery .arrow-left').on('click', function(e){ e.preventDefault(); $(this).closest('.swiper-gallery').swiper().swipePrev(); $(this).closest('.swiper-gallery').height($(this).closest('.swiper-gallery').find('.swiper-slide-active img').height()); }); $('.swiper-gallery .arrow-right').on('click', function(e){ e.preventDefault(); $(this).closest('.swiper-gallery').swiper().swipeNext(); $(this).closest('.swiper-gallery').height($(this).closest('.swiper-gallery').find('.swiper-slide-active img').height()); }); }); } /**************** ** IMAGE COMMENTS *****************/ // Add image comment classes on images inside posts /*$('.entry-content a').each(function(){ if($(this).children('img').length > 0){ $(this).attr('data-href', $(this).children('img').attr('src')); $(this).removeClass('lightbox'); $(this).addClass('image-comment'); } });*/ // Add Image Comment functionality if($('.image-comment').length > 0){ imagesLoaded( document.querySelector('.image-comment'), function( instance ) { $('.image-comment-on .image-comment').each(function(){ // insert lightbox button if(!$(this).hasClass('entry-head')){ $(this).find('img').after(''); $(this).find('.image-open').magnificPopup({type:'image'}); } }); $('.image-comment-on .image-comment .image-open').click( function(e) { e.stopPropagation(); // e.preventDefault(); }); $('.image-comment-on .image-comment').click( function(e) { e.stopPropagation(); e.preventDefault(); cropClose(); // comment container var information = ""; if($('#author').length > 0){ information = ""; } var container = '
×
' + information; if($(window).width() > 979){ container += 'Submit Comment
'; } $(this).remove('#image-comment-crop-container'); if($('#image-comment-crop-container').length < 1){ $(this).append(container); } $('#image-comment-crop-container #image-author').click(function(e){ e.stopPropagation(); e.preventDefault(); }); $('#image-comment-crop-container #image-author').change(function(e){ $('#author').val($(this).val()); }); $('#image-comment-crop-container #image-email').click(function(e){ e.stopPropagation(); e.preventDefault(); }); $('#image-comment-crop-container #image-email').change(function(e){ $('#email').val($(this).val()); }); $('#image-comment-crop-container textarea').click(function(e){ e.stopPropagation(); e.preventDefault(); }); $('#image-comment-crop-container textarea').change(function(e){ $('#comment').val($(this).val()); }); // put in the correct information when clicked ( if there is any ) if( $('#image-comment-crop-container #image-author').val() == '' ){ $('#image-comment-crop-container #image-author').val($('#author').val()); } if( $('#image-comment-crop-container #image-email').val() == '' ){ $('#image-comment-crop-container #image-email').val($('#email').val()); } if( $('#image-comment-crop-container textarea').text() == '' ){ $('#image-comment-crop-container textarea').text($('#comment').val()); } $('#image-comment-crop-container *:first-child').focus(); $('#image-comment-crop-container .btn').click(function(e){ e.stopPropagation(); e.preventDefault(); $('#comment').val($('#image-comment-crop-container textarea').val()); $('#commentform #submit').trigger('click'); $(this).unbind('click'); $('#image-comment-crop-container textarea').unbind('click'); $('#image-comment-crop-container textarea').unbind('change'); $('#image-comment-crop-container #image-author').unbind('click'); $('#image-comment-crop-container #image-author').unbind('change'); $('#image-comment-crop-container #image-email').unbind('click'); $('#image-comment-crop-container #image-email').unbind('change'); }); // close the crop tool and remove the selection $('.crop-close').click(function(e){ e.preventDefault(); cropClose(); e.stopPropagation(); }); var posX_old = $(this).offset().left, posY_old = $(this).offset().top, posX = $(this).offset().left, posY = $(this).offset().top, image_width = $(this).children('img').attr('width'), image_container_height = $(this).height(), image_container_width = $(this).width(), image_ratio = (image_width/image_container_width), mobile_multiplication = 1, mobileY_fix = 0, mobileX_fix = 0, crop_tool_scale = 100, crop_tool_position_X = crop_tool_scale/2, crop_tool_position_Y = crop_tool_scale/2; $('#image-comment-crop-container .crop-center').css('height',crop_tool_scale); $('#image-comment-crop-container .crop-center').css('width',crop_tool_scale); $(this).find('.submit-container').css('width', (crop_tool_scale*3)+'px'); $(this).find('.submit-container').css('margin-left', -(crop_tool_scale)+'px'); container_positionY = (image_container_height - (e.pageY - posY_old)); container_positionX = (image_container_width - (e.pageX - posX_old)); // WHERE TO DISPLAY THE CONTAINER: // if it's at the bottom if( container_positionY < (crop_tool_scale+100) || container_positionX < (crop_tool_scale+100)){ $(this).find('.submit-container').css('top','-'+(crop_tool_scale+50)+'px'); $(this).find('.submit-container').css('left', '-'+(crop_tool_scale+125)+'px'); } // if it's all the way to the left if( container_positionX > image_container_width - (crop_tool_scale+100) || ( container_positionY < (crop_tool_scale+100) && container_positionX > image_container_width - 500 )){ $(this).find('.submit-container').css('top','-'+(crop_tool_scale+50)+'px'); $(this).find('.submit-container').css('left','auto'); $(this).find('.submit-container').css('right', '-'+(crop_tool_scale+125)+'px'); } // if the image has an alignright class then put it to the left if( $(this).hasClass('alignright') ){ $(this).find('.submit-container').css('top','-'+(crop_tool_scale+50)+'px'); $(this).find('.submit-container').css('left', '-'+(crop_tool_scale+125)+'px'); $(this).find('.submit-container').css('right','auto'); } // if it's a mobile view then stop the nonsense and just display it below! if( $(window).width() < 979 ){ // add multiplier if it's mobile to enlargen the image mobile_multiplication = 2; mobileY_fix = -50; mobileX_fix = -50; $(this).find('.submit-container').css('display','none'); } // fix the height if it's out of bounds ( bottom, top ) if( (image_container_height - (e.pageY - posY)) < (crop_tool_scale)){ posY = image_container_height - crop_tool_scale; crop_tool_position_Y = crop_tool_scale; }else if( (e.pageY - posY) < (crop_tool_scale/2) ){ posY = 0; }else{ posY = (e.pageY - posY) - (crop_tool_scale/2); } // fix the width if it's out of bounds ( right, left ) if( (image_container_width - (e.pageX - posX)) < (crop_tool_scale)){ posX = image_container_width - crop_tool_scale; crop_tool_position_X = crop_tool_scale; }else if( (e.pageX - posX) < (crop_tool_scale/2) ){ posX = 0; }else{ posX = (e.pageX - posX) - (crop_tool_scale/2); } // place the container at the appropriate coordinates $('#image-comment-crop-container').css('left', posX).css('top', posY); // get ready to set the coordinates into the html posX = (posX * mobile_multiplication) - crop_tool_position_X - mobileY_fix; posY = (posY * mobile_multiplication) - crop_tool_position_Y - mobileY_fix; if(posY < 0){ posY = 0; } if(posX < 0){ posX = 0; } image_container_width = image_container_width * mobile_multiplication; image_container_height = image_container_height * mobile_multiplication; // put the image in the correct positions var img_src = $(this).children('img').attr('src'); // display the placeholder $('#image-comment-placeholder').css('display', 'block'); // position the image in the placeholder $('#image-comment-placeholder').html('').append('
×
').click(function(e){ cropClose(); e.stopPropagation(); }); $('#respond form').css('padding-left', '215px'); $('#comment_image_location').val(posY+ ',' + posX + ',' + img_src + ',' + image_container_width); }); }); } // Image Crop Container Close function cropClose(){ if($('#image-comment-crop-container').length > 0){ $('#image-comment-crop-container').remove(); $('#image-comment-placeholder').css('display','none'); $('#respond form').css('padding-left', '0'); $('#comment_image_location').val('false'); } } /**************** ** HELPERS *****************/ $( '.share-post' ).click(function(e){ e.preventDefault(); }); if( $( '.timeago' ).length > 0 ){ if(blu.disable_timeago !== "1"){ $('.timeago').timeago(); } } if( $( '.tips' ).length > 0 ){ $('.tips').tooltip(); } if( $( '.bl_popover' ).length > 0 ){ $('.bl_popover').popover(); } /**************** ** LIGHTBOX *****************/ if( $( '.lightbox' ).length > 0 ){ $('.lightbox' ).magnificPopup({type:'image'}); $( '.entry-content p .lightbox' ).each(function(){ $( this ).css('float', $( this ).children('img').css('float') ); }); } // fade everything in on page load // $('.entry-content').animate({opacity:'1'}, 800, 'swing'); // Lightbox Gallery var suffixjpg = '.jpg'; var suffixjpeg = '.jpeg'; var suffixpng = '.png'; var suffixgif = '.gif'; if( $( '.gallery' ).length > 0 ){ if( $( '.gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixjpg, $( '.gallery-item a' ).eq(0).length - suffixjpg.length) !== -1 || $( '.gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixjpeg, $( '.gallery-item a' ).eq(0).length - suffixjpeg.length) !== -1 || $( '.gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixpng, $( '.gallery-item a' ).eq(0).length - suffixpng.length) !== -1 || $( '.gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixgif, $( '.gallery-item a' ).eq(0).length - suffixgif.length) !== -1){ $( '.gallery' ).magnificPopup({ delegate: '.gallery-item a', // the container for each your gallery items type: 'image', gallery:{ enabled:true } }); } } // Jetpack Lightbox Gallery if( $( '.tiled-gallery').length > 0 ){ if( $( '.tiled-gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixjpg, $( '.tiled-gallery-item a' ).eq(0).length - suffixjpg.length) !== -1 || $( '.tiled-gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixjpeg, $( '.tiled-gallery-item a' ).eq(0).length - suffixjpeg.length) !== -1 || $( '.tiled-gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixpng, $( '.tiled-gallery-item a' ).eq(0).length - suffixpng.length) !== -1 || $( '.tiled-gallery-item a' ).eq(0).attr( 'href' ).indexOf(suffixgif, $( '.tiled-gallery-item a' ).eq(0).length - suffixgif.length) !== -1){ $( '.tiled-gallery' ).magnificPopup({ delegate: '.tiled-gallery-item a', // the container for each your gallery items type: 'image', gallery:{ enabled:true } }); } } /**************** ** SYNTAX HIGHLIGHTING *****************/ if( $("pre").length > 0 ){ $("pre.html").snippet("html",{style:"emacs"}); $("pre.css").snippet("css",{style:"emacs"}); $("pre.php").snippet("php",{style:"emacs"}); $("pre.js").snippet("javascript",{style:"emacs"}); } /**************** ** Post Title fixes *****************/ $('.format-quote .quote-area').each(function(e){ var width = $(this).outerWidth(); var height = $(this).outerHeight(); var image_height = $(this).next('img').height(); var font_change = 0; var final_width = width; // if the height of the text is larger than the height of the image, then shrink the final font size if(height > image_height-80){ final_width = final_width - (height - image_height + 50); } if(final_width < 200){ final_width = 200; } if(final_width > 1000){ final_width = 1000; } $(this).find('.quote-text').css('font-size', (final_width/14)+'px'); height = $(this).outerHeight(); $(this).outerHeight(height); $(this).css('margin-top', '-'+(height/2)+'px'); $(this).css('opacity', '1'); }); $('.author-posts-item').each(function(e){ var width = $(this).width(); $(this).height($(this).width()); $(this).find('h3').css('font-size', (width/7)+'px'); var height = $(this).height(); $(this).find('a').height(height); $(this).find('h3').css('margin-top', '-'+($(this).find('h3').outerHeight()/2)+'px'); // $(this).css('opacity', '1'); }); /**************** ** Instagram Widget *****************/ if($('.blu_instagram').length > 0){ slidesPerView = 1; // Init Instagram widget var instagram_swiper = new Swiper('.swiper-container-instagram', { loop: true, paginationClickable: true, slidesPerView: slidesPerView, onTouchEnd : function(element) { $('.swiper-container').removeClass('active'); }, onTouchStart : function(element) { $('.swiper-container').addClass('active'); }, onSlideChangeEnd : function(element) { $('.swiper-container').removeClass('active'); }, calculateHeight: true, }); // enable pagination arrows $('.swiper-container-instagram .arrow-left').on('click', function(e){ e.preventDefault(); instagram_swiper.swipePrev(); }); $('.swiper-container-instagram .arrow-right').on('click', function(e){ e.preventDefault(); instagram_swiper.swipeNext(); }); instagram_swiper.reInit(); } /**************** ** Flickr Widget *****************/ if($('.blu_flickr').length > 0){ slidesPerView = 1; // Init Instagram widget var flickr_swiper = new Swiper('.swiper-container-flickr', { loop: true, paginationClickable: true, slidesPerView: slidesPerView, onTouchEnd : function(element) { $('.swiper-container').removeClass('active'); }, onTouchStart : function(element) { $('.swiper-container').addClass('active'); }, onSlideChangeEnd : function(element) { $('.swiper-container').removeClass('active'); }, calculateHeight: true, }); // enable pagination arrows $('.swiper-container-flickr .arrow-left').on('click', function(e){ e.preventDefault(); flickr_swiper.swipePrev(); }); $('.swiper-container-flickr .arrow-right').on('click', function(e){ e.preventDefault(); flickr_swiper.swipeNext(); }); flickr_swiper.reInit(); } /**************** ** Featured Posts Widget *****************/ if($('.bl_featured_post').length > 0){ slidesPerView = 1; // Init Instagram widget var featured_swiper = new Swiper('.swiper-container-featured', { loop: true, paginationClickable: true, slidesPerView: slidesPerView, onTouchEnd : function(element) { $('.swiper-container').removeClass('active'); }, onTouchStart : function(element) { $('.swiper-container').addClass('active'); }, onSlideChangeEnd : function(element) { $('.swiper-container').removeClass('active'); }, calculateHeight: true, }); // enable pagination arrows $('.swiper-container-featured .arrow-left').on('click', function(e){ e.preventDefault(); featured_swiper.swipePrev(); }); $('.swiper-container-featured .arrow-right').on('click', function(e){ e.preventDefault(); featured_swiper.swipeNext(); }); $('.swiper-container-featured .swiper-slide a').each(function(e){ var width = $(this).find('.post-title').width(); $(this).find('.post-title').css('font-size', (width/10)+'px'); var height = $(this).height(); $(this).height(height); $(this).find('.post-title').css('margin-top', '-'+($(this).find('.post-title').height()/2)+'px'); $(this).find('.post-title').css('opacity', '1'); }); featured_swiper.reInit(); } /**************** ** MASONRY *****************/ if($('#content').hasClass('twocolumn') || $('#content').hasClass('threecolumn') || $('#content').hasClass('fourcolumn') || $('#content').hasClass('fivecolumn')){ var $container = $('#content .columns'); // initialize $container.masonry({ itemSelector: 'article' }); var didTimeOut = false; $('#content .columns article .entry-image').resize(function(e){ $('#content .columns').masonry(); }); } /**************** ** STICKY SIDEBAR *****************/ // make sure the element exists on the page before trying to initalize imagesLoaded( document.querySelector('#wrap'), function( instance ) { if($( '.sticky_sidebar' ).length){ setTimeout(function(){ blu_activate_sticky_sidebar(); }, 1000); } }); /**************** ** DETECT WIDOW RESIZE *****************/ $(window).resize(function() { if(this.resizeTO) clearTimeout(this.resizeTO); this.resizeTO = setTimeout(function() { $(this).trigger('resizeEnd'); }, 200); }); /**************** ** CATEGORY SCROLL *****************/ $('.category-scroll a').on('click', function(e){ e.preventDefault(); if($('article[data-categoryslug="' + $(this).data('categoryscroll') + '"]:first').length){ $('html, body').animate({ scrollTop: ($('article[data-categoryslug="' + $(this).data('categoryscroll') + '"]:first').offset().top - 200) }, 500) } }); }); // vertical align any element function blu_vertical_align(element){ jQuery(element).css('margin-top', '-'+((jQuery(element).outerHeight()/2)+20)+'px'); } // Read a page's GET URL variables and return them as an associative array. function insertParam(key, value) { key = encodeURI(key); value = encodeURI(value); var kvp = document.location.search.substr(1).split('&'); var i=kvp.length; var x; while(i--) { x = kvp[i].split('='); if (x[0]==key) { x[1] = value; kvp[i] = x.join('='); break; } } if(i<0) {kvp[kvp.length] = [key,value].join('=');} //this will reload the page, it's likely better to store this until finished // History.replaceState({}, document.title, window.location.toString()+'?'+$that.attr('id')+'='+$that.data('offset')); History.replaceState({}, document.title, '?'+kvp.join('&')); // document.location.search = kvp.join('&'); } function load_dynamictitles(){ // change the height of post titles in boxes to match the width of the box jQuery('.dynamic-title').each(function(e){ var box_width = jQuery(this).parent().outerWidth(); var font_size = box_width*0.11; // limit the max and min font size if(font_size > 54){ font_size = 54 } if(font_size < 22){ font_size = 22 } jQuery(this).css('font-size', font_size + 'px'); // only display them now if it isn't a slider (doesn't look right) if(jQuery(this).closest('.blu_posts_slider').length < 1){ jQuery(this).animate({ opacity: 1 }, 1000); } }); } function blu_activate_sticky_sidebar(){ // name your elements here var stickyElement = '.sticky_sidebar', // the element you want to make sticky bottomElement = '#footer', // the bottom element where you want the sticky element to stop (usually the footer) marginTop = 30; if(blu.fixed_header == 'true'){ marginTop += 60 + 3; } // make sure the element exists on the page before trying to initalize if(jQuery( stickyElement ).length){ jQuery( stickyElement ).each(function(){ // when should we start affixing? (the amount of pixels to the top from the element) var fromTop = jQuery( this ).offset().top, // where is the bottom of the element? fromBottom = jQuery( document ).height()-(jQuery( this ).offset().top + jQuery( this ).outerHeight()), // where should we stop? (the amount of pixels from the top where the bottom element is) // also add the outer height mismatch to the height of the element to account for padding and borders stopOn = jQuery( document ).height()-( jQuery( bottomElement ).offset().top)+(jQuery( this ).outerHeight() - jQuery( this ).height()); // if the element doesn't need to get sticky, then skip it so it won't mess up your layout if( (fromBottom-stopOn) > 200 ){ // let's put a sticky width on the element and assign it to the top jQuery( this ).css('width', jQuery( this ).width()).css('top', 0).css('position', ''); // assign the affix to the element jQuery( this ).affix({ offset: { top: fromTop-marginTop, // make it stick where the top pixel of the element is bottom: function(){ return jQuery( bottomElement ).outerHeight(); // make it stop where the top pixel of the bottom element is } } // when the affix get's called then make sure the position is the default (fixed) and it's at the top }).on('affix.bs.affix', function(){ jQuery( this ).css('top', 0).css('position', ''); }); } // trigger the scroll event so it always activates jQuery( window ).trigger('scroll'); }); } } function openMenu(e){ if( isMenuOpen ) return; // fixMenuHeight() jQuery('.blu-top-header .menu > li').addClass('selected'); isMenuOpen = true; } function closeMenu(){ if( !isMenuOpen ) return; jQuery('.blu-top-header .menu > li').removeClass('selected'); isMenuOpen = false; } function fixMenuHeight(){ if(mobilecheck() ){ jQuery('.menu-wrapper').height(jQuery(window).height()); }else{ jQuery('.menu-wrapper').height(jQuery('#page').height()); } } function addDocumentClickBind(){ jQuery(document).bind( eventtype, function(e){ closeMenu(); jQuery(this).unbind( eventtype ); }); } function social_share(data) { window.open( data, "fbshare", "height=450,width=760,resizable=0,toolbar=0,menubar=0,status=0,location=0,scrollbars=0" ); } function mobilecheck() { var check = false; (function(a){if(/(android|ipad|playbook|silk|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera); return check; }