Created
June 7, 2013 19:29
-
-
Save bmegod/5731746 to your computer and use it in GitHub Desktop.
main.js
This file contains 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 | |
//**********************************************handle pages except home/contact************************************ | |
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); | |
// hide footer | |
$('#footer-row').hide(); | |
// change 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'); | |
//here to do if the page is #about , the navbar text becomes white | |
// 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: 50 }, aniHeightSpeed, function(e) { | |
$('#home-logo, #home-copy').css("height", "auto"); // reset both content box heights to "auto" | |
$('#home-logo').animate({ height: 200 }, aniHeightSpeed); | |
// 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($(window).height() - $('#home-copy').offset().top); | |
} | |
});//end function(e) | |
}//end second if | |
})//end function(e),toggle | |
}//enf first if | |
else { | |
$('#map2').toggle(aniHeightSpeed, function(e) { | |
if ($(this).is(":visible")) { | |
$('#home-copy').aniAutoHeight(aniHeightSpeed).animate({ backgroundColor: '#004329', color: 'white', paddingTop: 50 }, aniHeightSpeed, function(e) { | |
$('#home-logo, #home-copy').css("height", "auto"); // reset both content box heights to "auto" | |
$('#home-logo').animate({ height: 200 }, aniHeightSpeed); | |
// 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($(window).height() - $('#home-copy').offset().top); | |
} | |
});//end function(e) | |
}//end second if | |
})//end function(e),toggle | |
}//end else | |
}//end map1() | |
//**********************************************same thing as $(window).load()-handle contact/logo/home************************************ | |
$(function() { | |
// 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 | |
$(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 home | |
$(document).on("click", "#homelogo", 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