Skip to content

Commit

Permalink
Load JS after DOM is loaded, whoops
Browse files Browse the repository at this point in the history
  • Loading branch information
jimryan committed May 23, 2011
1 parent 5ff4af8 commit 84873e8
Showing 1 changed file with 30 additions and 28 deletions.
58 changes: 30 additions & 28 deletions lib/sybil/user_picker.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,36 @@
<input type="submit" value="Switch">
</div>
<script>
$up = $('#sybil_user_picker');
$up.css('top', -($up.height()+40))
function hideSybilUserPicker(){
$up.animate({top: -($up.height()+40)}, 200, function(){$up.hide();});
}
$up.find('input[type=submit]').click(function(){
id = $up.find('select[name=id]').val();
if(id == 'logout')
$.get('<%= sybil_logout_path %>', function(){ location.reload(true); });
else
$.post('<%= sybil_login_path %>', { id: id }, function() { location.reload(true); });
hideSybilUserPicker();
});
$(document).keypress(function(e){
if((e.keyCode==21) || (e.ctrlKey && (e.charCode==117))){
if($up.filter(':visible').length==0)
{
$up.show();
$up.animate({top: '0'}, 200);
}else{
hideSybilUserPicker();
}
$(document).ready(function(){
$up = $('#sybil_user_picker');
$up.css('top', -($up.height()+40))
function hideSybilUserPicker(){
$up.animate({top: -($up.height()+40)}, 200, function(){$up.hide();});
}
});
$('body').click(function(e){
$target = $(e.target);
if(!$target.is('#sybil_user_picker') && $target.parents('#sybil_user_picker').length==0)
if($up.filter(':visible').length>0)
hideSybilUserPicker();
$up.find('input[type=submit]').click(function(){
id = $up.find('select[name=id]').val();
if(id == 'logout')
$.get('<%= sybil_logout_path %>', function(){ location.reload(true); });
else
$.post('<%= sybil_login_path %>', { id: id }, function() { location.reload(true); });
hideSybilUserPicker();
});
$(document).keypress(function(e){
if((e.keyCode==21) || (e.ctrlKey && (e.charCode==117))){
if($up.filter(':visible').length==0)
{
$up.show();
$up.animate({top: '0'}, 200);
}else{
hideSybilUserPicker();
}
}
});
$('body').click(function(e){
$target = $(e.target);
if(!$target.is('#sybil_user_picker') && $target.parents('#sybil_user_picker').length==0)
if($up.filter(':visible').length>0)
hideSybilUserPicker();
});
});
</script>

0 comments on commit 84873e8

Please sign in to comment.