-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #70 - user now stays in the same tab while navigating around th… #289
Changes from all commits
695d7ad
148b425
123c106
3625c74
f7a2ce7
d97eb26
830d72e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,10 +121,11 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |
|
||
function traverseTreeDown(currentItem, testContainer, suiteContainer, | ||
testUrlSelector) { | ||
var currentTest, | ||
currentLocation = window.location.hash, | ||
$nextElement, | ||
$firstElementInTest; | ||
var currentTest; | ||
var currentLocation = window.location.hash; | ||
var $nextElement; | ||
var $firstElementInTest; | ||
var currentTabLabel; | ||
|
||
if (!(ifRootPage(currentLocation, '/url/') || ifRootPage( | ||
currentLocation, '/test/') || ifRootPage(currentLocation, | ||
|
@@ -141,36 +142,36 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |
if (!_.isEmpty($(suiteContainer).nextAll( | ||
'.aside-report:not(.is-hidden)').first().find( | ||
'.test-name'))) { | ||
testContainer.removeClass('is-active'); | ||
currentItem.removeClass('is-active'); | ||
toggleNextTest(suiteContainer); | ||
currentTabLabel = getCurrentTabLabel(); | ||
$nextElement = suiteContainer.nextAll( | ||
'.aside-report:not(.is-hidden)').first(); | ||
$nextElement.addClass('is-expanded'); | ||
$nextElement.children().first().addClass('is-active'); | ||
scrollTo($nextElement.find('.is-active')); | ||
'.aside-report:not(.is-hidden)').first(); | ||
handleStyling(testContainer, currentItem, $nextElement); | ||
toggleNextTestItem(suiteContainer); | ||
userSettingsService.setLastTab(currentTabLabel); | ||
} | ||
|
||
} else { | ||
currentTabLabel = getCurrentTabLabel(); | ||
userSettingsService.setLastTab(currentTabLabel); | ||
nextUrl.click(); | ||
scrollTo(nextUrl); | ||
$(testUrlSelector).not(nextUrl).removeClass('is-active'); | ||
} | ||
} else { | ||
currentTest = findCurrentTest(currentLocation.split('/').pop()); | ||
$firstElementInTest = currentTest.find('.url-name:not(.is-hidden)').find( | ||
testUrlSelector).first(); | ||
currentTest.addClass('is-expanded'); | ||
$firstElementInTest.click(); | ||
scrollTo($firstElementInTest); | ||
currentTest = findCurrentTest(currentLocation.split('/').pop()); | ||
$firstElementInTest = currentTest.find('.url-name:not(.is-hidden)').find( | ||
testUrlSelector).first(); | ||
currentTest.addClass('is-expanded'); | ||
$firstElementInTest.click(); | ||
scrollTo($firstElementInTest); | ||
} | ||
} | ||
|
||
function traverseTreeUp(currentItem, testContainer, suiteContainer, | ||
testUrlSelector) { | ||
var previousTest, | ||
currentLocation = window.location.hash, | ||
$previousElement; | ||
var previousTest; | ||
var currentLocation = window.location.hash; | ||
var $previousElement; | ||
var currentTabLabel; | ||
|
||
if (!(ifRootPage(currentLocation, '/url/') || ifRootPage( | ||
currentLocation, '/test/') || ifRootPage(currentLocation, | ||
|
@@ -183,12 +184,19 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |
'.url-name:not(.is-hidden)').filter(':first').find( | ||
testUrlSelector); | ||
if (_.isEmpty(previousTest)) { | ||
$previousElement = suiteContainer.find('.test-name'); | ||
scrollTo($previousElement); | ||
$previousElement.click(); | ||
currentItem.parents('.url-name').removeClass('is-active'); | ||
suiteContainer.addClass('is-expanded'); | ||
if (!_.isEmpty($(suiteContainer).prevAll( | ||
'.aside-report:not(.is-hidden)').first() | ||
.find('.test-name'))) { | ||
currentTabLabel = getCurrentTabLabel(); | ||
$previousElement = suiteContainer.prevAll( | ||
'.aside-report:not(.is-hidden)').first(); | ||
handleStyling(testContainer, currentItem, $previousElement); | ||
togglePrevTestItem(suiteContainer); | ||
userSettingsService.setLastTab(currentTabLabel); | ||
} | ||
} else { | ||
currentTabLabel = getCurrentTabLabel(); | ||
userSettingsService.setLastTab(currentTabLabel); | ||
scrollTo(previousTest); | ||
previousTest.click(); | ||
} | ||
|
@@ -208,13 +216,66 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |
} | ||
} | ||
|
||
function toggleNextTest(currentTest) { | ||
$(currentTest).nextAll('.aside-report:not(.is-hidden)') | ||
.first() | ||
.find('.test-name') | ||
.click(); | ||
function handleStyling(testContainer, currentItem, $element) { | ||
testContainer.removeClass('is-active'); | ||
currentItem.removeClass('is-active'); | ||
$element.addClass('is-expanded'); | ||
$element.children().first().addClass('is-active'); | ||
scrollTo($element.find('.is-active')); | ||
} | ||
|
||
function toggleNextTestItem(currentTest) { | ||
$(currentTest).nextAll( | ||
'.aside-report:not(.is-hidden)') | ||
.first() | ||
.find('.test-url') | ||
.first() | ||
.click(); | ||
} | ||
|
||
function togglePrevTestItem(currentTest) { | ||
$(currentTest).prevAll( | ||
'.aside-report:not(.is-hidden)') | ||
.first() | ||
.find('.test-url') | ||
.last() | ||
.click(); | ||
} | ||
|
||
function getCurrentTabLabel() { | ||
return $('.nav-tabs > .nav-item').filter('.active').text().replace(/\s/g, ''); | ||
} | ||
|
||
function clickOnTab() { | ||
var currentTabLabel = userSettingsService.getLastTab(); | ||
var $nextTestTabs = $('.nav-tabs').children(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In some places you use multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed, but I still got some stuff to do (with MutationObserver) so I will commit tomorrow. |
||
$nextTestTabs.each(function() { | ||
if($(this).text().replace(/\s/g, '') === currentTabLabel) { | ||
$(this).find('a').click(); | ||
currentTabLabel = null; | ||
} | ||
}); | ||
} | ||
|
||
//MutationObserver fires a callback every time something changes on the page | ||
//and here it's used to click a tab before the page is actually rendered to get rid of flickering effect | ||
var mutationObserver = new MutationObserver(callback); | ||
|
||
function callback(mutList) { | ||
function findElement(element) { | ||
if($(element.target).hasClass('nav-tabs')) { | ||
clickOnTab(); | ||
return true; | ||
} | ||
} | ||
mutList.find(findElement); | ||
} | ||
|
||
mutationObserver.observe(document, { | ||
childList: true, | ||
subtree: true, | ||
}); | ||
|
||
function ifRootPage(url, type) { | ||
return url.search(type) > 0; | ||
} | ||
|
@@ -252,4 +313,4 @@ define(['angularAMD', 'userSettingsService'], function (angularAMD) { | |
} | ||
} | ||
} | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would be worth to put following 20 lines into a separate method?
traverseTreeUp
is a little to long now.