Permalink
Browse files

scroll window to first fail

  • Loading branch information...
1 parent a276849 commit 1f6b5a281aab792e824b416e040f22255aa5d958 Marc Peabody committed May 23, 2012
Showing with 13 additions and 11 deletions.
  1. +12 −10 public/javascripts/koans.js
  2. +1 −1 views/layout.haml
@@ -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' });
}
@@ -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();
+ }
});
View
@@ -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
@@ -36,6 +35,7 @@
};
googleAnalytics();
+ %script{:src => '/javascripts/koans.js'}
%body
#top_line
%img#swoosh{:src => '/images/enso.gif'}

0 comments on commit 1f6b5a2

Please sign in to comment.