From 1f6b5a281aab792e824b416e040f22255aa5d958 Mon Sep 17 00:00:00 2001 From: Marc Peabody Date: Wed, 23 May 2012 10:23:48 -0400 Subject: [PATCH] scroll window to first fail --- public/javascripts/koans.js | 22 ++++++++++++---------- views/layout.haml | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/public/javascripts/koans.js b/public/javascripts/koans.js index 3c3cc7d..382aa58 100644 --- a/public/javascripts/koans.js +++ b/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' }); } @@ -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(); + } }); diff --git a/views/layout.haml b/views/layout.haml index 6bdb465..18dbcc3 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -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'}