// Custom jQuery functions. var $j = jQuery.noConflict( ) , $window = $j( window ) , $can_scroll = true , $is_scrolling = true , $scroll_offset = 150 ; $j.ajaxSetup( { cache : false } ) ; var onLoad = { init : function ( ){ portfolioAjax.init( ) ; portfolioSorting.init( ) ; nav.init( ) ; nav.updateMenu( ) ; } } /* NAVIGATION - FIRES WHEN URL CHANGES */ var nav = { init : function ( ){ // Page reset only works without jQuery for some reason window.scrollTo( 0 , 0 ) ; // Handle address changes function onAddressChange ( e ){ if ( e.path != $j.address.path ){ // Get path array $folders = e.pathNames ; console.log('Folders: ' + $folders); // Get section name $section = $folders[ 0 ]; if($section === 'undefined'){ $section = 'awards'; } // Set section to showreel if undefined if ( $section == undefined || $section == "" ) { if ( window.location.toString( ).search( /showreel/ ) < 0 ){ if ( $j( window ).width( ) > 480 ) $j.address.path( "showreel/" ) ; else window.location.href = "https://kevinsargent.co.uk/showreel/" ; } } // Scroll offset $offset = -$scroll_offset ; if($section == 'latest'){ $offset = 0; } console.log('Section: '+$section); switch ( $section ){ case "audio" : $offset = -150; case "awards" : $offset = -150; case "showreel" : // Fix carousel offset var h = jQuery("#carouselWrap").height(); case "work" : if ( $folders.length > 1 ) { if ( portfolioAjax.currentPostPath != e.path ) { portfolioAjax.currentPostPath = e.path ; portfolioAjax.openItemFromURL( $j.address.baseURL( ) + e.path ) ; } else if ( $can_scroll ) { nav.scrollTo( portfolioAjax.portfolio_display , -$scroll_offset ) ; } $can_scroll = false ; break ; } default : if ( $can_scroll ){ // Scroll the page to the appropriate section nav.scrollTo( "#" + $section , $offset ) ; $can_scroll = false ; } // get the section name from the title tag in the main menu $section_name = $j( "#main-navigation" ).find( "a[title=\"" + $section + "\"]" ).text( ) ; if ( $section_name != "" ) $section_name = " | " + $section_name ; $title = "Kevin Sargent | Composer" + $section_name ; // Update the page's title tag $j.address.title( $title ) ; }// end switch } } // Bind event to function $j.address.change( onAddressChange ) ; // Main nav var $body = $j( "body" ) , $current_page = $j( ".current-menu-item" ) , $header = $j( "#header-section" ) , $logo = $j( "#logo" ).find( "img" ) , $nav = $j( "#main-navigation" ).find( "ul.menu" ) , $window = $window ; $current_page.addClass( "current" ) ; if ( $body.hasClass( "home" ) ) { var $nav_link_parent = $j( ".menu" ).find( "li" ) ; $nav_link_parent.on( "click" , "a" , function ( e ) { // Pause all videos $j( "body" ).find( "iframe" ).each( function ( ){ $j( this )[ 0 ].contentWindow.postMessage( JSON.stringify( { method : "pause" } ) , $j( this ).attr( "src" ).split( "?" )[ 0 ] ) ; } ) ; // Get section title var $nav_link_title = $j( this ).attr( "title" ) ; console.log('nav_link_title: '+$nav_link_title); if(!$nav_link_title){ $nav_link_title = 'awards' } if ( $nav_link_title ){ e.preventDefault( ); } // Stop page reloading //e.preventDefault( ); var $current = $j( this ) ; $nav_link_parent.removeClass( "current" ) ; $current.parent( ).addClass( "current" ) ; // Update address bar $can_scroll = true ; $j.address.path( $nav_link_title + "/" ) ; } ) ; } } , scrollTo : function ( scrollTarget , offset ){ console.log('Scrolling: '+scrollTarget +' '+ offset) $j.smoothScroll({ scrollTarget : scrollTarget , offset : offset , easing : "easeInOutExpo" , speed : 1000 , beforeScroll : nav.beforeScroll , afterScroll : nav.afterScroll } ) ; $isFirstLoad = false ; } , beforeScroll : function ( ){ $is_scrolling = true ; } , afterScroll : function ( ){ $is_scrolling = false ; } , updateMenu : function ( ){ var $inview = $j( "#content > section:in-viewport:first" ).attr( "id" ) , $menu_item = $j( ".menu li a" ) , $link = $menu_item.filter( "[title=" + $inview + " ]" ) ; if ( $inview == "work" && portfolioAjax.currentPostPath != null ) { if ( $j.inviewport( portfolioAjax.portfolio_display , { threshold : $j( "#header-section" ).height( ) } ) ) { $inview = portfolioAjax.currentPostPath.replace( /(\s+)?.$/ , "" ) ; } } if ( $link.length && ( ! $link.is( ".current" ) || porfolioAjax.currentPostPath == null ) ) { //$menu_item.parent( ).removeClass( "current" ) ; //$link.parent( ).addClass( "current" ) ; if ( ! $is_scrolling ){ //$j.address.path( $inview + "/" ) ; } } $j( "body" ).find( "section" ).each( function ( ){ var $section = $j( this ) , $heading = $section.find( ".section-heading" ) ; $id = $section.attr( "id" ) ; if ( $id != null && $inview.search( $id ) >= 0 ){ $heading.css( "position" , "fixed" ) ; $heading.css( "left", -$window.scrollLeft( ) ) ; $section_height = $section.height( ) ; if ( $id == "work" && portfolioAjax.currentPostID != null ) { $section_height -= portfolioAjax.portfolio_display.height( ) ; } $subtitle_offset = Math.min( $scroll_offset , $section.offset( ).top + $section_height - $window.scrollTop( ) - $heading.height( ) ) ; $heading.css( "top" , $heading.offset( ) ? $subtitle_offset : $scroll_offset ) ; } else { $heading.css( "position" , "absolute" ) ; $heading.css( "left" , 0 ) ; $heading.css( "top" , 0 ) ; } } ) ; } } ; ///////////////////////////////////////////// // VIDEO FUNCTIONS ///////////////////////////////////////////// function postToVideo ( f, action, value ){ var data = { method: action } , url = f.attr( "src" ).split( "?" )[ 0 ] ; url = url.split( 'https://' ).join( 'https://' ) ; if ( value ) data.value = value; f[ 0 ].contentWindow.postMessage( JSON.stringify( data ) , url ) ; } function pauseAllVideo ( ){ $j( "body" ).find( "iframe" ).each( function ( ) { postToVideo( $j( this ) , "pause" ) ; } ) ; } ///////////////////////////////////////////// // VIEWPORT FUNCTIONS ///////////////////////////////////////////// // Set viewport threshold ( function ( $ ) { $.extend( $.expr[ ":" ] , { "in-viewport" : function ( a , i , m ) { return $.inviewport( a , { threshold : $j( "#header-section" ).height( ) } ) ; } } ) ; } ) ( jQuery ) ; // Update menu on window scroll or resize $window.scroll( nav.updateMenu ) ; $window.resize( nav.updateMenu ) ; ///////////////////////////////////////////// // PORTFOLIO AJAX FUNCTIONS ///////////////////////////////////////////// var portfolioAjax = { // Variables portfolio_section : $j( "#work" ) , portfolio_display : $j( "#portfolio-display" ) , portfolio_items : $j( ".portfolio-items" ) , cont : $j( ".portfolio-ajax-drawer" ) , cont_inner : $j( ".portfolio-ajax-drawer-inner" ) , loading_bay : $j( ".loading-bay" ) , controls : $j( ".portfolio-controls" ) , current : null , current_item : null , currentPostID : null , currentPostPath : null , window_width : $window.width( ) , init : function ( ) { portfolioAjax.portfolio_items.on( "click" , "a:link" , function ( e ) { e.preventDefault( ) ; $path = $j( this ).attr( "href" ).split( "https://kevinsargent.co.uk" )[ 1 ] ; // Don't update address unless it has actually changed if ( $path != $j.address.path( ) ) { $can_scroll = true ; $j.address.path( $path ) ; } else { portfolioAjax.openScroll( ) ; } } ) ; portfolioAjax.controls.on( "click" , "a#portfolio-back" , closeItem ) ; portfolioAjax.controls.on( "click" , "a#portfolio-close" , closeItem ) ; function closeItem ( e ) { e.preventDefault( ) ; $j.address.path( "/work/" ) ; portfolioAjax.cont.slideUp( 600 ) ; portfolioAjax.current_item.removeClass( "current-item" ) ; portfolioAjax.currentPostID = null ; portfolioAjax.currentPostPath = null ; $j.smoothScroll( { scrollTarget : portfolioAjax.portfolio_section , offset : -$scroll_offset , easing : "easeInOutExpo" , speed : 1000 , beforeScroll : function ( ) { $is_scrolling = true ; portfolioAjax.unloadVideo( ) ; } , afterScroll : function ( ) { $is_scrolling = false ; portfolioAjax.countItems( ) ; } } ) ; } } , openScroll : function ( ) { $j.smoothScroll( { scrollTarget : portfolioAjax.portfolio_display , offset : -$scroll_offset , easing : "easeInOutExpo" , speed : 1000 , beforeScroll : function ( ) { $is_scrolling = true ; } , afterScroll : function ( ) { $is_scrolling = false ; } } ) ; } , openItemFromURL : function ( url ) { var item = portfolioAjax.portfolio_items.find( "a[href=\"" + url + "\"]" ) ; portfolioAjax.openItem( item , url ) ; } , openItem : function ( item , url ) { if ( item.attr( "href" ) || url != portfolioAjax.currentPostID ) { if ( portfolioAjax.current_item ) { portfolioAjax.current_item.removeClass( "current-item" ) ; } // Set current item portfolioAjax.current = item ; itemChanged( url ) ; if ( portfolioAjax.cont.is( ":visible" ) ) { portfolioAjax.countItems( ) ; portfolioAjax.loading_bay.load( portfolioAjax.currentPostID + " article.type-portfolio" , function ( response , status , xhr ) { var $error = $j( "#error" ) ; if ( status != "error" ) { portfolioAjax.openScroll( ) ; portfolioAjax.cont_inner.append( portfolioAjax.loading_bay.find( "article" ) ) ; portfolioAjax.cont_inner.cycle( { fx : "scrollUp" , delay : -4000 , autostop : 1 , easing : "easeInOutExpo" , after : onAfter } ) ; } else { $error.html( "Error: " + xhr.status + " " + xhr.statusText ) ; } } ) ; } else { portfolioAjax.cont_inner.load( portfolioAjax.currentPostID + " article.type-portfolio" , function ( response , status , xhr ) { var $error = $j( "#error" ) ; if ( status != "error" ) { portfolioAjax.openScroll( ) ; portfolioAjax.cont.slideDown( 600 ) ; portfolioAjax.cont_inner.slideDown( 600 ) ; // Get the height of the current slide var $slide_height = portfolioAjax.cont.find( "article" ).outerHeight( true ) ; // Get the container's height to that of the current slide portfolioAjax.cont.animate( { height : $slide_height } , 400 ) ; portfolioAjax.cont_inner.animate( { height : $slide_height } , 400 ) ; portfolioAjax.cont.find( "img.size-full" ).each( function ( ) { $j( this ).css( "height" , "auto" ) ; } ) ; } else { $error.html( "Error: " + xhr.status + " " + xhr.statusText ) ; } } ) ; } } function itemChanged ( url ) { portfolioAjax.current_item = $j( portfolioAjax.current ).parent( ).parent( ) ; portfolioAjax.current_item.addClass( "current-item" ) ; portfolioAjax.currentPostID = $j( portfolioAjax.current ).attr( "href" ) || url ; pauseAllVideo( ) ; } function onAfter ( ) { // 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 portfolioAjax.cont.animate( { height: $slide_height } ) ; portfolioAjax.cont_inner.animate( { height: $slide_height } ) ; portfolioAjax.cont_inner.find( "img.size-full" ).each( function ( ) { $j( this ).css( "height" , "auto" ) ; } ) ; } } , // Count items countItems : function ( ) { var $count = portfolioAjax.cont_inner.children( ).length ; if ( $count > 1 ) portfolioAjax.cont_inner.find( "article:first-child" ).remove( ) ; } , // Pause video pauseVideo : function ( ) { $iframes = portfolioAjax.cont_inner.find( "iframe" ) ; $iframes.each( function ( ) { postToVideo( $j( this ) , "pause" ) ; } ) ; } , // Unload video unloadVideo : function ( ) { $iframes = portfolioAjax.cont_inner.find( "iframe" ) ; $iframes.each( function ( ) { postToVideo( $j( this ) , "unload" ) ; } ) ; } } ; ///////////////////////////////////////////// // Portfolio Sorting ///////////////////////////////////////////// var portfolioSorting = { init : function ( ) { ( function ( $j ) { $j.fn.sorted = function ( customOptions ) { var options = { reversed : false , by : function ( a ) { return a.text( ) ; } } ; $j.extend( options , customOptions ) ; $data = $j( this ) ; arr = $data.get( ) ; return $j( arr ) ; } ; } ) ( $j ) ; $j( function ( ) { var read_button = function ( class_names ) { var r = { selected : false, type : 0 } ; for ( var i = 0 ; i < class_names.length ; i++ ){ if ( class_names[ i ].indexOf( "selected-" ) == 0 ) { r.selected = true ; } if ( class_names[ i ].indexOf( "segment-" ) == 0 ) { r.segment = class_names[ i ].split( "-" )[ 1 ] ; } } ; return r ; } ; var sort = function ( $buttons ) { var $selected = $buttons.parent( ).filter( "[class*=\"selected\" ]" ) ; return $selected.find( "a" ).attr( "data-value" ) ; } ; // Get the first collection var $portfolio_items = $j( ".portfolio-items" ) ; // Clone applications to get a second collection var $data = $portfolio_items.clone( ) ; // Show TV initially var $tv_data = $data.find( "li.tv" ) ; var $tv_sorted_data = $tv_data.sorted( { by : function ( v ) { return $j( v ).find( "strong" ).text( ).toLowerCase( ) ; } } ) ; $portfolio_items.quicksand( $tv_sorted_data , { duration: 0 } ) ; var $filter_selection = $j( "#filters" ) $filter_selection.each( function ( i ) { var $selection = $j( this ) ; var $buttons = $selection.find( "a" ) ; $buttons.bind( "click" , function ( e ) { var $button = $j( this ) ; var $button_container = $button.parent( ) ; var button_properties = read_button( $button_container.attr( "class" ).split( " " ) ) ; var selected = button_properties.selected ; if ( ! selected ) { $buttons.parent( ).removeClass( ) ; $button_container.addClass( "selected" ) ; var sorting = sort( $filter_selection.eq( 0 ).find( "a" ) ) ; if ( sorting == "all" ) { var $filtered_data = $data.find( "li" ) ; } else { var $filtered_data = $data.find( "li." + sorting ) ; } var $sorted_data = $filtered_data.sorted( { by : function ( v ) { return $j( v ).find( "strong" ).text( ).toLowerCase( ) ; } } ) ; $portfolio_items.quicksand( $sorted_data , { duration : 800 , adjustHeight : "dynamic" , easing : "easeInOutExpo" , useScaling : false } ) ; function onAfter ( ) { if ( $filter_selected.find( "p" ).length > 1 ) { setTimeout( function ( ) { if ( $filter_selected.find( "p" ).length > 1 ) { $filter_selected.find( "p:first-child" ).remove( ) ; } } , 400 ) ; } } $filter_selected = $j( "#filter-selected-inner" ) ; $filter_selected.append( "
" + $button.text( ) + "
" ) ; $filter_selected.cycle( { fx : "scrollUp" , autostop : 1 , delay : -4000 , speed : 400 , easing : "easeInOutExpo" , after : onAfter } ) ; } e.preventDefault( ) ; } ) ; } ) ; } ) ; } } ; $j( document ).ready( onLoad.init ) ;