Skip to content

Instantly share code, notes, and snippets.

@jaketoolson
Created October 31, 2012 16:14
Show Gist options
  • Save jaketoolson/3987970 to your computer and use it in GitHub Desktop.
Save jaketoolson/3987970 to your computer and use it in GitHub Desktop.
jQuery code sample 2
// Jake Toolson
// jQuery used to handle the rotating fullsize background images, the external AJAX page loading, opening and closing of the book. Looking at it now, clearly places where I could rewrite it to clean it up.
jQuery.fx.interval = 33;
$(document).ready(function(){
var img_folder = 'http://www.jaketoolson.com/ems/images/';
$.supersized({
slideshow : 1,
autoplay : 1,
slide_links : 'blank',
slides : [
{image : '/images/backgrounds/photogallery.jpg', title : ''}
]
});
// Imporant!
// Allows the correct page/tab to be loaded based on the #hash
var hash = window.location.hash.substr(1);
var href = $('#nav li a').each(function(){
var href = $(this).attr('href');
if(hash==href.substr(0,href.length-4)){
var toLoad = hash+'.php #content_holder';
$('#content').load(toLoad);
}
});
$('#nav li a').click(function(){
var toLoad = $(this).attr('href');
var pageName = toLoad.substr(0,$(this).attr('href').length-4);
var currentPage = '#'+pageName;
// Is the tab already active?
if($(this).parent().hasClass('active'))
{
return false;
}
$(this).parent().toggleClass('active').siblings().removeClass('active');
loadContent();
window.location.hash = pageName;
function loadContent() {
if( ! book_is_open())
{
open_book();
}
$('#content').load(toLoad+' #content_holder','',hideLoader())
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
$('#ems').mouseover(function() {
$(this).animate({'width': 90}, 60, 'easeInOutExpo');
}).mouseout(function(){
$(this).animate({'width': 80}, 60, 'easeInOutExpo');
});
setTimeout(open_book, 500);
$('#ems').addClass('active').siblings().removeClass('active');
});
//-----------------
//--- Functions ---
//-----------------
//--- Body toggle ---
$('.switch').click(function() {
open_or_close_body();
if (book_is_open())
{
load_page('index');
}
$(this).addClass('active').siblings().removeClass('active');
return false;
});
function open_book()
{
$('#book-body').animate({'left':'0'}, 500, 'easeInOutExpo').removeClass('closed').addClass('open');
$('#page-detail').animate({'left':'0'}, 500, 'easeInOutExpo');
$('#ems').css({'width':'80'});
api.options.slideshow = 0;
$("#cover").fadeIn('slow');
function mousedown()
{
$(document).mousedown(function(event) {
return event.which;
});
}
//---------------------
// In order to create a method to allow clicking anywhere outside of the book to close the book
// we need to first make it so clicking anywhere within the book will NOT close it. These functions
// need to be re-run everytime the book is opened, not just once.
$("#book-body").one("click",function(){
return false;
});
// Click anywhere outside of the book, and the book will close.
$('#cover').one("click", function(e) {
close_book()
});
}
function close_book()
{
$('#book-body').animate({'left':'-600'}, 500, 'easeInOutExpo', function(){
$(this).removeClass('open').addClass('closed');
$('#page-detail').animate({'left':'-600'}, 500, 'easeInOutExpo');
$('#ems').css({'width':'90'});
api.options.slideshow = 1;
$("#cover").fadeOut('slow');
});
}
function load_page(page)
{
$('#content').load(page+'.php #content_holder');
}
function book_is_open()
{
// Is the book open?
if ($('#book-body.closed').length && (!$('.detail-panel.open').length) )
{
return false;
}
return true;
}
function open_or_close_body()
{
if ( ! book_is_open())
{
open_book();
}
else
{
close_book();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment