/* ================================================== Custom jQuery functions. ================================================== */ ///////////////////////////////////////////// // NO CONFLICT ///////////////////////////////////////////// var $j = jQuery.noConflict(); var onLoad = { init: function(){ page.init(); header.init(); nav.init(); slider.init(); portfolio.init(); if ($j('.portfolio-items').hasClass('ajaxable')) { portfolioAjax.init(); } var deviceAgent = navigator.userAgent.toLowerCase(); var agentID = deviceAgent.match(/(iphone|ipad|ipod|android)/); if (!agentID) { prettyPhoto.init(); } else { $j('.view-full').each(function() { $j(this).removeAttr('href'); }); } contactForm.init(); reloadFunctions.init(); } }; ///////////////////////////////////////////// // PAGE FUNCTIONS ///////////////////////////////////////////// var page = { init: function () { var $add_comment = $j('#add-comment'), $reply_comment = $j('.comment-reply-link'), $respond_form = $j('#respond'); $add_comment.on('click', function(e) { e.preventDefault(); $respond_form.slideDown(400); $j('#respond-wrap').addClass('open'); setTimeout(function() { var pos = $respond_form.offset(); $j('body,html').animate({ scrollTop: pos.top - 60 }, 600); }, 400); }); $reply_comment.on('click', function(e) { $respond_form.slideDown(400); $j('#respond-wrap').addClass('open'); setTimeout(function() { var pos = $respond_form.offset(); $j('body,html').animate({ scrollTop: pos.top - 40 }, 600); }, 400); }); } }; ///////////////////////////////////////////// // HEADER ///////////////////////////////////////////// var header = { init: function(){ var $header_search = $j('#header-searchform input'), $hs_width = $header_search.css('width'); $header_search.focus(function() { $j(this).animate({ width: '128px' }, 500); }); $header_search.blur(function() { $j(this).animate({ width: $hs_width }, 500); }); $header_search.data('holder',$header_search.attr('value')); $header_search.focusin(function(){ $j(this).attr('value',''); }); $header_search.focusout(function(){ $j(this).attr('value', $j(this).data('holder')); }); } }; ///////////////////////////////////////////// // NAVIGATION ///////////////////////////////////////////// var nav = { init: function(){ $j("ul.sub-menu").parents().addClass('parent'); $j('ul.menu').superfish({ delay: 100, animation: {height:'show'}, speed: 300, autoArrows: false, dropShadows: false }); // Mobile Nav var $mobile_select = $j('.dropdown-menu'), $selected_page_text = $j('.selected-option'); $selected_page_text.html($mobile_select.find('option:selected').text()); $mobile_select.change(function() { location = $j(this).find("option:selected").val(); }); } }; ///////////////////////////////////////////// // WMUSLIDER FUNCTION ///////////////////////////////////////////// var slider = { init: function() { $j('.wmuSlider').wmuSlider({ animation: 'slide', animationDuration: 400, slideshow: true, slideshowSpeed: 6000, slideToStart: 0, navigationControl: true, paginationControl: true, previousText: '[', nextText: ']', touch: Modernizr.touch, slide: 'article', items: 1 }); } } var portfolioSlider = { init: function() { $j('.portfolio-slider').wmuSlider({ animation: 'slide', animationDuration: 400, slideshow: true, slideshowSpeed: 6000, slideToStart: 0, navigationControl: true, paginationControl: true, previousText: '[', nextText: ']', touch: Modernizr.touch, slide: 'article', items: 1 }); } } ///////////////////////////////////////////// // PORTFOLIO ///////////////////////////////////////////// var portfolio = { init: function() { // cache container var $container = $j('.filterable-items'); // initialize isotope $container.isotope({ animationEngine: 'best-available', animationOptions: { duration: 300, easing: 'easeInOutQuad', queue: false }, resizable: true, layoutMode: 'fitRows' }); // Enable filter options on when there are items from that skill $j('.filtering li').each( function() { var $filter = $j(this), $filter_name = $j(this).find('a').attr('class'); $j('.portfolio-items li').each( function() { if ( $j(this).hasClass($filter_name) ) { $filter.addClass('has-items'); } }); }); // filter items when filter link is clicked $j('.filtering li').on('click', 'a', function() { $j('.filtering li').removeClass('selected'); $j(this).parent().addClass('selected'); var selector = $j(this).attr('data-filter'); $container.isotope({ filter: selector }); return false; }); $j('.control-item').hover( function() { $j(this).find('.tooltip' ).stop().animate({ bottom: '36px', opacity: 1 }, 500, 'easeInOutExpo'); }, function() { $j(this).find('.tooltip').stop().animate({ bottom: '25px', opacity: 0 }, 500, 'easeInOutExpo'); }); // Show/hide detail portfolio information $j('#info-show').on('click', function(e) { e.preventDefault(); $j('.article-body-wrap').css('display', 'block'); $j('.article-body-wrap').animate({opacity: 1}, 400); $j('.article-body-wrap').css('z-index', '2'); $j('.wmuSliderPrev').animate({opacity: 0}, 400); $j('.wmuSliderNext').animate({opacity: 0}, 400); $j('.portfolio-detail-meta').css('display', 'block'); $j('.view-full').css('display', 'none'); }); $j('#info-hide').on('click', function(e) { e.preventDefault(); $j('.view-full').each( function() { $j(this).css('display', 'block'); }); $j('.article-body-wrap').animate({opacity: 0}, 400); $j('.wmuSliderPrev').animate({opacity: 1}, 400); $j('.wmuSliderNext').animate({opacity: 1}, 400); $j('.portfolio-detail-meta').css('display', 'none'); setTimeout(function() { $j('.article-body-wrap').css('display', 'none'); }, 400); }); } } ///////////////////////////////////////////// // PORTFOLIO AJAX FUNCTIONS ///////////////////////////////////////////// var portfolioAjax = { init: function(){ var $portfolio_section = $j('#portfolio'), $portfolio_items = $j('.portfolio-items'), $cont_wrap = $j('#portfolio-showcase-wrap'), $cont = $j('.portfolio-ajax-drawer'), $loading_bay = $j('.loading-bay'), $controls = $j('.portfolio-controls'), $loading = $j('#global-loading'), $small_loading = $j('#small-loading'); var $current = null, $current_item = $j('.portfolio-items').find('.current-item'), $currentPostID = null, $nextPortfolioPost = null, $prevPortfolioPost = null, $prevPortfolioPostID = null, $nextPortfolioPostID = null; var $offset = -50; $window_width = $j(window).width(); function itemInit() { $current = $current_item.find('figure a'); $currentPostID = $j($current).attr('href'); $nextPost = $j($current_item).closest('li.item').next('li.item').find('a.link'); $prevPost = $j($current_item).closest('li.item').prev('li.item').find('a.link'); $prevPostID = $j($prevPost).attr('href'); $nextPostID = $j($nextPost).attr('href'); $controls.find('#item-prev').attr('href', $prevPostID); $controls.find('#item-next').attr('href', $nextPostID); if(typeof $nextPostID == 'string') { $j('a#item-next').show(); } else { $j('a#item-next').hide(); } if(typeof $prevPostID == 'string') { $j('a#item-prev').show(); } else { $j('a#item-prev').hide(); } } itemInit(); function itemChanged() { foresight.reload(); $current_item = $j($current).parent().parent(); $current_item.addClass('current-item'); $currentPostID = $j($current).attr('href'); //window.history.pushState("string", "Title", $currentPostID); $nextPost = $j($current_item).closest('li.item').next('li.item').find('a.link'); $prevPost = $j($current_item).closest('li.item').prev('li.item').find('a.link'); $prevPostID = $j($prevPost).attr('href'); $nextPostID = $j($nextPost).attr('href'); $controls.find('#item-prev').attr('href', $prevPostID); $controls.find('#item-next').attr('href', $nextPostID); if(typeof $nextPostID == 'string') { $j('a#item-next').show(); } else { $j('a#item-next').hide(); } if(typeof $prevPostID == 'string') { $j('a#item-prev').show(); } else { $j('a#item-prev').hide(); } setTimeout(function() { $controls.css('display', 'inline-block'); $small_loading.hide(); $j('.tooltip').each( function() { $j(this).css( 'marginLeft', '-' + Math.round( ($j(this).outerWidth() / 2) ) + 'px' ); }); }, 1000); } function hasLoadedItem() { reloadFunctions.init(); portfolioSlider.init(); twttr.widgets.load(); try { FB.XFBML.parse(); } catch(ex){} $cont.find('#info-hide').on('click', function(e) { e.preventDefault(); $cont.find('.article-body-wrap').animate({opacity: 0}, 400); $j('.wmuSliderPrev').animate({opacity: 1}, 400); $j('.wmuSliderNext').animate({opacity: 1}, 400); }); } function countItems() { var $count = $cont.children().length; if ($count > 1) { $cont.find('.display-wrap:first-child').remove(); } } function onAfter(curr, next, opts, fwd) { var index = opts.currSlide; //get the height of the current slide var $slide_height = $j(this).outerHeight(true); //set the container's height to that of the current slide $cont.animate({height: $slide_height}); } $portfolio_items.on('click','a.link',function(e){ e.preventDefault(); if ($j(this).attr('href') == $currentPostID && $cont_wrap.is(":visible")) { return; } if ($current_item) { $current_item.removeClass('current-item'); } $current = $j(this); $current_item = $j($current).parent().parent(); $current_item.addClass('current-item'); $currentPostID = $j($current).attr('href'); //window.history.pushState("string", "Title", $currentPostID); if ($cont_wrap.is(":visible")) { var pos = $j('#ajax-section').offset(); $j('body,html').animate({ scrollTop: pos.top }, 600); setTimeout(function() { $cont.slideUp(400); }, 600); $controls.hide(); $small_loading.css('display', 'inline-block'); $current_item.removeClass('current-item'); setTimeout(function() { $cont.load($currentPostID + ' .display-wrap', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $loading.hide(); $cont_wrap.slideDown(400); $cont.slideDown(600); hasLoadedItem(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } itemChanged(); }); }, 600); } else { var pos = $j('#ajax-section').offset(); if ( $j('#ajax-section').hasClass('home-ajax-section') ) { $j('body,html').animate({ scrollTop: pos.top }, 600); } else { $j('body,html').animate({ scrollTop: pos.top - 50 }, 600); } $loading.show(); $cont.load($currentPostID + ' .display-wrap', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $loading.hide(); $controls.css('display', 'inline-block'); $small_loading.hide(); $cont_wrap.slideDown(400); $cont.slideDown(600); hasLoadedItem(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } itemChanged(); }); } }); $controls.on('click', 'a#item-close',function(e) { e.preventDefault(); if ( $j('#ajax-section').hasClass('home-ajax-section') ) { var pos = $j('#ajax-section').offset(); $j('body,html').animate({ scrollTop: pos.top }, 600); } else { $j('body,html').animate({ scrollTop: 0 }, 600); } $cont_wrap.slideUp(600); $controls.hide(); $current_item.removeClass('current-item'); setTimeout(function() { $cont.find('.display-wrap').remove(); }, 600); }); $controls.on('click', 'a#item-prev',function(e) { e.preventDefault(); $current_item.removeClass('current-item'); var pos = $j('#portfolio-showcase-wrap').offset(); $j('body,html').animate({ scrollTop: pos.top }); countItems(); $controls.hide(); $small_loading.css('display', 'inline-block'); $loading_bay.load($prevPostID + ' .display-wrap', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $cont.append($loading_bay.find('.display-wrap')); $cont.cycle({ fx: "scrollDown", delay: -4000, autostop: 1, after: onAfter }); hasLoadedItem(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } $current = $j($prevPost); itemChanged(); }); }); $controls.on('click', 'a#item-next',function(e) { e.preventDefault(); $current_item.removeClass('current-item'); var pos = $j('#portfolio-showcase-wrap').offset(); $j('body,html').animate({ scrollTop: pos.top }); countItems(); $controls.hide(); $small_loading.css('display', 'inline-block'); $loading_bay.load($nextPostID + ' .display-wrap', function(response, status, xhr){ var $error = $j("#error"); if (status != 'error') { $cont.append($loading_bay.find('.display-wrap')); $cont.cycle({ fx: "scrollUp", delay: -4000, autostop: 1, after: onAfter }); hasLoadedItem(); } else { $error.html('Error: ' + xhr.status + ' ' + xhr.statusText); } $current = $j($nextPost); itemChanged(); }); }); } }; ///////////////////////////////////////////// // PRETTYPHOTO FUNCTION ///////////////////////////////////////////// var prettyPhoto = { init: function() { $j("a[data-gal^='prettyPhoto']").prettyPhoto({ animation_speed: 'fast', /* fast/slow/normal */ slideshow: 5000, /* false OR interval time in ms */ autoplay_slideshow: false, /* true/false */ opacity: 0.80, /* Value between 0 and 1 */ show_title: true, /* true/false */ allow_resize: true, /* Resize the photos bigger than viewport. true/false */ default_width: 500, default_height: 344, counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */ // theme: 'light_square', /* light_rounded / dark_rounded / light_square / dark_square / facebook */ horizontal_padding: 20, /* The padding on each side of the picture */ hideflash: false, /* Hides all the flash object on a page, set to TRUE if flash appears over prettyPhoto */ wmode: 'opaque', /* Set the flash wmode attribute */ autoplay: true, /* Automatically start videos: True/False */ modal: false, /* If set to true, only the close button will close the window */ deeplinking: false, /* Allow prettyPhoto to update the url to enable deeplinking. */ overlay_gallery: true, /* If set to true, a gallery will overlay the fullscreen image on mouse over */ keyboard_shortcuts: true, /* Set to false if you open forms inside prettyPhoto */ changepicturecallback: function(){}, /* Called everytime an item is shown/changed */ callback: function(){}, /* Called when prettyPhoto is closed */ ie6_fallback: true }); } } ///////////////////////////////////////////// // CONTACT FORM FUNCTION ///////////////////////////////////////////// var contactForm = { init: function() { $j('form#contactForm').submit(function() { $j('form#contactForm label.error').remove(); $j('form#contactForm span.error').remove(); var hasError = false; $j('.requiredField').each(function() { $this = $j(this); if($j.trim($this.val()) == '') { $this.addClass('invalid'); hasError = true; } else if($this.hasClass('email-input')) { var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; if(!emailReg.test($j.trim($this.val()))) { $this.addClass('invalid'); hasError = true; } else { $this.removeClass('invalid'); } } else { $this.removeClass('invalid'); } }); if(!hasError) { $j('form#contactForm li.buttons button').fadeOut('normal', function() { $j(this).parent().append(''); }); var formInput = $j(this).serialize(); $j.post($j(this).attr('action'),formInput, function(data){ $j('form#contactForm').slideUp("fast", function() { $j('.contact-form h5').fadeOut(400); $j('p.thanks').fadeIn(1000); }); }); } return false; }); } } ///////////////////////////////////////////// // RELOAD FUNCTIONS ///////////////////////////////////////////// var reloadFunctions = { init:function() { // Remove title attributes from images to avoid showing on hover $j('img[title]').each(function() { $j(this).removeAttr('title'); }); $j('a[title]').each(function() { $j(this).removeAttr('title'); }); // Tabs Shortcode Function $j('.tabbed-asset').tabs(); // Accordion Shortcode Function $j('.accordion').accordion({ collapsible: true, autoHeight: false }); // Button hover tooltips $j('.tooltip').each( function() { $j(this).css( 'marginLeft', '-' + Math.round( ($j(this).outerWidth() / 2) ) + 'px' ); }); $j('.comment-avatar').hover( function() { $j(this).find('.tooltip' ).stop().animate({ bottom: '44px', opacity: 1 }, 500, 'easeInOutExpo'); }, function() { $j(this).find('.tooltip').stop().animate({ bottom: '25px', opacity: 0 }, 500, 'easeInOutExpo'); }); // Animate Top Links $j('.animate-top').on('click', function(e) { e.preventDefault(); var $link_target = $j(this).attr('href'); var pos = $j($link_target).offset(); $j('body,html').animate({ scrollTop: pos.top - 40 }, 600); }); // Mobile Based Code var deviceAgent = navigator.userAgent.toLowerCase(); var agentID = deviceAgent.match(/(iphone|ipad|ipod|android)/); if (!agentID) { prettyPhoto.init(); } else { $j('.view-full').each(function() { $j(this).removeAttr('href'); }); } } } $j(document).ready(onLoad.init); ///////////////////////////////////////////// // GOOGLE WEB FONT FUNCTION ///////////////////////////////////////////// WebFontConfig = { google: { families: ['Abel'] } }; (function() { var webfontscript = document.createElement('script'); webfontscript.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js'; webfontscript.type = 'text/javascript'; webfontscript.async = 'true'; var script = document.getElementsByTagName('script')[0]; script.parentNode.insertBefore(webfontscript, script); })();