Last active
December 18, 2015 02:59
-
-
Save JDMcKinstry/5715174 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;(function($) { | |
| if (!$.aniAutoHeight) { | |
| $.extend({ | |
| aniAutoHeight: function(elm, speed) { | |
| if (!speed) speed = 200; | |
| return elm.each(function(index){ | |
| var curHeight = $(this).height(), | |
| autoHeight = $(this).css('height', 'auto').height(); | |
| $(this).height(curHeight).animate({height: autoHeight}, speed, function() { $(this).height('auto'); }); | |
| }); | |
| } | |
| }); | |
| $.fn.extend({ | |
| aniAutoHeight: function(speed) { | |
| return $.aniAutoHeight($(this), speed); | |
| } | |
| }); | |
| } | |
| })(jQuery); | |
| var aniHeightSpeed = 1; // this variable controls the speed of all height animations | |
| function handleAjax(e) { | |
| // get the page we want | |
| getPage = $(this).attr('href'); | |
| // make AJAX call | |
| $.get('ajax.php', {page: getPage}, function(data) { | |
| result = $.parseJSON(data); | |
| // fill in new page | |
| $('#subnav').html(result.subnav); | |
| $('#home-copy').html(result.copy); | |
| //var docheight= $('home-copy').height(); | |
| // get document height and get rid of 15% minus the height of the boxes and padding | |
| //docHeight = [$(document).height()-($(document).height()*.15)]-100; | |
| // scroll to top of content div, make veiwing easier | |
| $('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 1000); // speed of scroll set at 1 second | |
| // hide footer | |
| $('#footer-row').hide(); | |
| // change background | |
| //$('#content-area').backstretch(result.background); | |
| $('#background img').attr("src",result.background); | |
| // clear old nav | |
| $('.current_page_item_green').removeClass('current_page_item_green'); | |
| $('.current_page_item').removeClass('current_page_item'); | |
| // update navigation | |
| if (result.nav_color == 'green') { | |
| // add green | |
| $('.nav-link').each(function() { $(this).addClass('green'); }); | |
| $(result.current_page_item).addClass('current_page_item_green'); | |
| } | |
| else { | |
| $('.nav-link').each(function() { $(this).removeClass('green'); }); | |
| $(result.current_page_item).addClass('current_page _item'); | |
| } | |
| // change height of content boxes | |
| $('#home-copy').animate({ backgroundColor: 'white', color: 'gray', paddingTop: 50 }, aniHeightSpeed, function(e) { | |
| $('#home-logo, #home-copy').css("height", "auto"); // reset both content box heights to "auto" | |
| // check height of copy box, make sure it touches bottom, if not, set it to do so | |
| if ($(document).height() > ($('#home-copy').offset().top + $('#home-copy').outerHeight())) { | |
| $('#home-copy').height($(document).height() - $('#home-copy').offset().top); | |
| } | |
| // set height of logo box to touch bottom, as it will not to begin with | |
| $('#home-logo').height($('#home-copy').height()); // 50 is our buffer, may need adjustment in future | |
| console.log("doc height", $(document).height()); | |
| console.log("logo height", $('#home-logo').height()) | |
| console.log("copy height", $('#home-copy').height()) | |
| // final check | |
| setTimeout(function() { $('#home-logo').height($('#home-copy').height()); }, 100); | |
| }); | |
| }); | |
| } | |
| function map1(num){ | |
| if (num == 1) { | |
| $('#map1').toggle(aniHeightSpeed, function(e) { | |
| if ($(this).is(":visible")) { | |
| $('#home-copy').aniAutoHeight(aniHeightSpeed).animate({ backgroundColor: '#004329', color: 'white', paddingTop: 0 }, aniHeightSpeed); | |
| $('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 1000); // speed of scroll set at 1 second | |
| } | |
| }) | |
| } | |
| else { | |
| $('#map2').toggle(aniHeightSpeed, function(e) { | |
| if ($(this).is(":visible")) { | |
| $('#home-copy').aniAutoHeight(aniHeightSpeed).animate({ backgroundColor: '#004329', color: 'white', paddingTop: 0 }, aniHeightSpeed); | |
| $('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 1000); // speed of scroll set at 1 second | |
| } | |
| }) | |
| } | |
| } | |
| $(function() { // lol, this is the same thing as $(window).load( | |
| // set initial background image | |
| $('#background img').attr("src", "img/layout/bg_home.png"); | |
| // set initial heights | |
| $('#home-logo, #home-copy').css("height", "200px"); | |
| // handle logo home | |
| $(document).on("click", "#logo", function(e) { | |
| // get home info | |
| $.get('ajax.php', {page: 'home'}, function(data) { | |
| result = $.parseJSON(data); | |
| // reset background | |
| //$('#content-area').backstretch(result.background); | |
| $('#background img').attr("src",result.background); | |
| //$('#content-area').overflow(hidden); | |
| // reset navigation | |
| $('.current_page_item_green').removeClass('current_page_item_green'); | |
| $('.current_page_item').removeClass('current_page_item'); | |
| $('.nav-link').each(function() { $(this).removeClass('green'); }); | |
| // fade out the footer | |
| $('#footer-row').fadeIn(); | |
| // reset copy | |
| $('#subnav').html(''); | |
| $('#home-copy').html(result.copy); | |
| // reset sizes and colors | |
| $('#home-logo').animate({ height: 200 }, aniHeightSpeed); | |
| $('#home-copy').animate({ height: 200, backgroundColor: '#004329', color: 'white', paddingTop: 0 }, aniHeightSpeed); | |
| //$('#home-copy').css('overflow','hidden'); | |
| }); | |
| }); | |
| //handle contact | |
| $(document).on("click", "#contact-link", function(e) { | |
| // get home info | |
| $.get('ajax.php', {page: 'contact'}, function(data) { | |
| result = $.parseJSON(data); | |
| // reset background | |
| //$('#content-area').backstretch(result.background); | |
| $('#background img').attr("src",result.background); | |
| // reset navigation | |
| $('.current_page_item_green').removeClass('current_page_item_green'); | |
| $('.current_page_item').removeClass('current_page_item'); | |
| $('.nav-link').each(function() { $(this).removeClass('green'); }); | |
| // fade out the footer | |
| $('#footer-row').fadeIn(); | |
| // reset copy | |
| $('#subnav').html(''); | |
| $('#home-copy').html(result.copy); | |
| // reset sizes and colors | |
| $('#home-logo').animate({height: 200}, aniHeightSpeed); | |
| $('#home-copy').animate({ height: 200, backgroundColor: '#004329', color: 'white', paddingTop: 0 }, aniHeightSpeed); | |
| $('#home-copy').css('overflow','hidden'); | |
| }); | |
| }); | |
| // handle AJAX page calls | |
| $(document).on("click", ".nav-link-ajax", handleAjax); | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment