Created
July 6, 2012 12:53
-
-
Save bbarry/3060013 to your computer and use it in GitHub Desktop.
code review 13377
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
//http://codereview.stackexchange.com/questions/13377/jquery-drawer-with-tab | |
/* | |
preference: rename jquery instance variables to start with $ | |
*/ | |
$(function () { | |
var $message = $('#message'), | |
$tab = $('#tab'), | |
$droid = $message.find('.droid'), | |
speed = 300; | |
function animateTab(top) { | |
return function () { | |
return $tab.animate({top: top}, speed); | |
}; | |
} | |
function animateMessage(top) { | |
return function () { | |
return $message.animate({marginTop: top}, speed); | |
}; | |
} | |
function animateDroid(bottom) { | |
return function () { | |
return $droid.delay(1000).animate({bottom: bottom}, 100); | |
}; | |
} | |
function queue(immediate) { | |
var rest = [].splice.call(arguments, 1); | |
if (immediate) { | |
$.when(immediate()).then(function () { | |
queue.apply(window, rest); | |
}); | |
} | |
} | |
function slideMessage() { | |
var tabVisible = $message.css('marginTop') !== "0px"; | |
if (tabVisible) { | |
queue(animateTab("-90px"), | |
animateMessage("0px") | |
); | |
animateDroid("0px")(); | |
} else { | |
queue(animateMessage("-60px"), | |
animateTab("0px") | |
); | |
animateDroid("-60px")(); | |
} | |
} | |
//Hide message if user has javascript | |
$message.css('marginTop', '-60px'); | |
$droid.css('bottom', '-60px'); | |
setTimeout(slideMessage, 1000); | |
$('#message .close, #tab').click(slideMessage); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment