// JavaScript Document jQuery(document).ready(function($) { $(window).load(function(){ var current_state, new_state, height_diff, elem_margin, elem_height; var slider_wrapper = $( '#slider-wrapper' ); var modal_dots = $( '.modal_dots' ); // If control button is clicked, calculate next state and advance slide $( '.slider-control' ).on( 'click', function (e) { e.preventDefault(); current_state = slider_wrapper.find( '#homepage_slider' ).data( 'state' ); var total_slides = slider_wrapper.find( '#homepage_slider' ).data( 'num' ); if( $(this).hasClass( 'slider-control-prev' ) ) { new_state = parseFloat( current_state ) - 1; if( new_state < 1 ) { new_state = total_slides; } } else { new_state = parseFloat( current_state ) + 1; if( new_state > total_slides ) { new_state = 1; } } slider_wrapper.find( '#homepage_slider li' ).fadeOut( 'slow' ); slider_wrapper.find( '#homepage_slider li#slide-'+new_state).fadeIn( 'slow' ); slider_wrapper.find( '#homepage_slider' ).data( 'state', new_state ); }); var modal_list = $( '#modal-windows' ); // If modal button is clicked, open window on first content card $( '.slider-modal' ).on( 'click', function (e) { e.preventDefault(); $( 'html, body' ).css( { 'overflow': 'hidden', 'height': '100%', 'padding-right': '9px' } ); modal_list.css( 'height', $(document).height() ); modal_list.fadeIn( 'medium' ); change_modal( 1 ); }); // If close modal button is clicked $( '.modal-close' ).on( 'click', function (e) { e.preventDefault(); $( 'html, body' ).css( { 'overflow': 'auto', 'height': 'auto', 'padding-right': '0' } ); modal_list.css( 'display', 'none' ); modal_list.css( 'height', 'auto' ); modal_list.css( 'padding-top', 0 ); }); // If next / previous modal button is clicked $( '.modal-control' ).on( 'click', function (e) { e.preventDefault(); current_state = modal_list.data( 'state' ); var total_modals = modal_list.data( 'num' ); if( $(this).hasClass( 'modal-prev' ) ) { new_state = parseFloat( current_state ) - 1; if( new_state < 1 ) { new_state = total_modals; } } else { new_state = parseFloat( current_state ) + 1; if( new_state > total_modals ) { new_state = 1; } } change_modal( new_state ); }); // If modal dot is clicked $( '.modal-dot' ).on( 'click', function (e) { e.preventDefault(); new_state = $(this).data( 'state' ); change_modal( new_state ); }); function change_modal( new_state ) { modal_list.find( '.single-modal' ).css( 'display', 'none' ); modal_list.find( '#modal-'+new_state ).css( 'display', 'block' ); elem_height = modal_list.find( '#modal-'+new_state ).outerHeight(); height_diff = $(window).height() - elem_height; if( height_diff > 120 ) { elem_margin = ( ( height_diff ) / 2) - 40; modal_list.css( 'padding-top', elem_margin ); } else { modal_list.css( 'padding-top', '20px' ); } modal_list.data( 'state', new_state ); modal_dots.find( 'a' ).removeClass( 'current' ); modal_dots.find( 'a[data-state="'+new_state+'"]' ).addClass( 'current' ); } }); });