Skip to content

Commit

Permalink
scroll window to first fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Peabody committed May 25, 2012
1 parent a276849 commit 1f6b5a2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions public/javascripts/koans.js
@@ -1,13 +1,4 @@
$(function () {
var firstFail = $(".failed:first"),
offset = firstFail.offset(),
top = offset ? offset.top : 0;

if($('.example form').length === 0){
firstFail.find("input:first").focus();
}
$("html,body").animate({scrollTop: top - 280}, 0);

$(document).ready(function() {
if($('#rotateTeam').length > 0){
$('#rotateTeam').cycle({ fx: 'shuffle' });
}
Expand All @@ -26,4 +17,15 @@ $(function () {
}
e.preventDefault();
});

var firstFail = $(".failed:first"),
offset = firstFail.offset(),
top = offset ? offset.top : 0;

if($('.example form').length === 0){
if($('.passed').length){
window.scrollTo(0, top);
}
firstFail.find("input:first").focus();
}
});
2 changes: 1 addition & 1 deletion views/layout.haml
Expand Up @@ -6,7 +6,6 @@
%script{:src => '/javascripts/jquery-1.4.4.min.js'}
- if @end
%script{:src => "http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"}
%script{:src => '/javascripts/koans.js'}
%script{:src => "http://tab-slide-out.googlecode.com/files/jquery.tabSlideOut.v1.3.js"}

:javascript
Expand Down Expand Up @@ -36,6 +35,7 @@
};
googleAnalytics();

%script{:src => '/javascripts/koans.js'}
%body
#top_line
%img#swoosh{:src => '/images/enso.gif'}
Expand Down

0 comments on commit 1f6b5a2

Please sign in to comment.