From cc1e44d0a1bdfac1ea03a3acd420cdbc017ef48b Mon Sep 17 00:00:00 2001 From: Arsen Melikyan Date: Tue, 19 Jan 2016 13:08:46 +0400 Subject: [PATCH] Auto-scroll to the last visited/completed challenge --- client/main.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/client/main.js b/client/main.js index 05fedb25f1..18d099aaf8 100644 --- a/client/main.js +++ b/client/main.js @@ -263,15 +263,23 @@ $(document).ready(function() { window.location.href = link; }); - if ($('.sr-only').length) { - var lastChallenge = $('.sr-only').filter(function() { - return $(this).text() === ' Complete'; - }); - if (lastChallenge.length) { - lastChallenge = lastChallenge[lastChallenge.length - 1]; - var scrollTo = $(lastChallenge).offset().top - 380; - $('html, body, .map-accordion').scrollTop(scrollTo); + var scrollTo, dashedName = localStorage.getItem('currentDashedName'), + elemsToSearch = $('p.padded-ionic-icon a'), currOrLastChallenge; + if (!dashedName && $('.sr-only').length) { + elemsToSearch = $('.sr-only'); + } + + currOrLastChallenge = elemsToSearch.filter(function() { + if (dashedName) { + return $(this).attr('href').match(dashedName); } + return $(this).text() === ' Complete'; + }); + + if (currOrLastChallenge.length) { + currOrLastChallenge = currOrLastChallenge[currOrLastChallenge.length - 1]; + scrollTo = $(currOrLastChallenge).offset().top - 380; + $('html, body, .map-accordion').scrollTop(scrollTo); } if (String(window.location).match(/\/map$/ig)) {