Skip to content

Commit

Permalink
Update hash if changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mottie committed Apr 5, 2015
1 parent 642bd62 commit 1ebe71e
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions js/jquery.visualNav.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $.visualNav = function(el, options){
base.$win = $(window);
base.$doc = $(document);
base.$body = $('html, body'); // include 'html' for IE
base.curHash = '';

base.$lastItem = [ null ];
base.namespace = '.visualNav';
Expand Down Expand Up @@ -150,33 +151,33 @@ $.visualNav = function(el, options){
};

base.updateHash = function(){
var hash,
id = (o.selectedAppliedTo === o.link) ? base.$curItem.attr('href') : base.$curItem.find(o.link).attr('href');
if (id) {
hash = id.replace( /^#/, '' );
var fx, node = $( '#' + hash );
if ( node.length ) {
node.attr( 'id', '' );
fx = $( '<div></div>' )
.css({
position:'absolute',
visibility:'hidden',
top: $(document).scrollTop() + 'px'
})
.attr( 'id', hash )
.appendTo( document.body );
var $fx, $node,
id = (o.selectedAppliedTo === o.link) ? base.$curItem.attr('href') : base.$curItem.find(o.link).attr('href'),
hash = ( id || '' ).replace( /^#/, '' );
if (id && hash !== '' && hash !== base.curHash) {
$node = $( '#' + hash );
base.curHash = hash;
if ( $node.length ) {
$node.attr( 'id', '' );
$fx = $( '<div></div>' )
.css({
position: 'absolute',
visibility: 'hidden',
top: $(document).scrollTop() + 'px'
})
.attr( 'id', hash )
.appendTo( document.body );
}
base.setHash('#' + hash);
if ( node.length ) {
fx.remove();
node.attr( 'id', hash );
if ( $node.length ) {
$fx.remove();
$node.attr( 'id', hash );
}

}
};

base.setHash = function(newHash){
if (base.winLoc.hash !== newHash){
if (base.winLoc.hash !== newHash && newHash !== '#'){
if (base.winLoc.replace){
base.winLoc.replace(newHash);
} else {
Expand Down Expand Up @@ -260,7 +261,7 @@ $.visualNav = function(el, options){
}
}

if (o.useHash) {
if (o.useHash && base.initialized) {
base.updateHash();
}

Expand Down

0 comments on commit 1ebe71e

Please sign in to comment.