Skip to content

Instantly share code, notes, and snippets.

Created June 6, 2013 20:58
Show Gist options
  • Save anonymous/5724876 to your computer and use it in GitHub Desktop.
Save anonymous/5724876 to your computer and use it in GitHub Desktop.
main.js
;(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);
$('#background img').attr("src",result.background);
// change height of content boxes
//$('#home-logo').aniAutoHeight(aniHeightSpeed); /* home-logo home-copy container-fluid */
$('#home-logo').aniAutoHeight(aniHeightSpeed).height($(document).height() - $('#home-logo').offset().top);
$('#home-copy').aniAutoHeight(aniHeightSpeed).animate({ backgroundColor: 'white', color: 'gray', paddingTop: 50 }, aniHeightSpeed, function(e) {
if ($(document).height() > ($('#home-copy').offset().top + $('#home-copy').outerHeight())) {
$('#home-copy').height($(document).height() - $('#home-copy').offset().top);
}
$('#home-logo').animate({ height: $('#home-copy').height() }, aniHeightSpeed);
});
// scroll to top of content div, make veiwing easier
//$('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 500); // speed of scroll set at 1 second
// hide footer
$('#footer-row').hide();
// change background
//$('#content-area').backstretch(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');
}
});
}
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, function(e) {
$('#home-copy').height($(document).height() - $('#home-copy').offset().top);
});
$('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 500); // 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, function(e) {
$('#home-copy').height($(document).height() - $('#home-copy').offset().top);
});
$('html, body').animate({ scrollTop: $("#home-copy").offset().top }, 500); // 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.jpg");
// 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