Skip to content

Commit

Permalink
Merge pull request #3956 from pjackson28/fixchromehashhandling
Browse files Browse the repository at this point in the history
Tabs: Ensures the tabs remain below the top of the viewport for a hash-related focus
  • Loading branch information
Paul Jackson authored and Paul Jackson committed Dec 9, 2013
2 parents 080eb1e + d348beb commit 84ad38b
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions src/plugins/tabs/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ var pluginName = "wb-tabs",
activeId = wb.pageUrlParts.hash.substring( 1 ),
$openPanel = activeId.length !== 0 ? $panels.filter( "#" + activeId ) : undefined,
elmId = $elm.attr( "id" ),
$panel, i, len, tablist, isOpen, newId, $summaries, summary;
hashFocus = false,
$panel, i, len, tablist, isOpen, newId,
$summaries, summary, positionY;

// Ensure there is an id on the element
if ( !elmId ) {
Expand All @@ -68,23 +70,22 @@ var pluginName = "wb-tabs",
uniqueCount += 1;
}

// If the panel was not set by URL hash, then attempt to
// retrieve from sessionStorage
if ( !$openPanel || $openPanel.length === 0 ) {
try {
try {

// If the panel was not set by URL hash, then attempt to
// retrieve from sessionStorage
if ( !$openPanel || $openPanel.length === 0 ) {
activeId = sessionStorage.getItem( elmId + activePanel );
if ( activeId ) {
$openPanel = $panels.filter( "#" + activeId );
}
} catch ( error ) {
}

// If the panel was set by URL hash, then store in sessionStorage
} else {
try {
// If the panel was set by URL hash, then store in sessionStorage
} else {
hashFocus = true;
sessionStorage.setItem( elmId + activePanel, activeId );
} catch ( error ) {
}
} catch ( error ) {
}

// Determine the current view
Expand Down Expand Up @@ -191,6 +192,19 @@ var pluginName = "wb-tabs",
createControls( $tablist, excludePlay );
}

// If focus is being set by the URL hash, then ensure the tabs are
// not above the top of the viewport
if ( hashFocus ) {

// Need a slight delay to allow for the reflow
setTimeout(function() {
positionY = $tablist.offset().top;
if ( positionY < document.body.scrollTop ) {
document.body.scrollTop = positionY;
}
}, 1 );
}

$elm.data({
"panels": $panels,
"tablist": $tablist,
Expand Down

0 comments on commit 84ad38b

Please sign in to comment.