}
this.$active.removeClass(this.options.activeClass);
- this.$active = this.$links.filter('[href="#' + this.$targets.eq(curIdx).data('magellan-target') + '"]').addClass(this.options.activeClass);
+ if(curIdx !== undefined){
+ this.$active = this.$links.filter('[href="#' + this.$targets.eq(curIdx).data('magellan-target') + '"]').addClass(this.options.activeClass);
+ }else{
+ this.$active = $();
+ }
if(this.options.deepLinking){
var hash = "";
- if(curIdx != undefined){
+ if(curIdx !== undefined){
hash = this.$active[0].getAttribute('href');
}
if(hash !== window.location.hash) {
if(window.history.pushState){
- window.history.pushState(null, null, hash);
+ // If there is no active idx, move to the same url without hash
+ // https://stackoverflow.com/a/5298684/4317384
+ var url = curIdx !== undefined ? hash : window.location.pathname + window.location.search;
+ window.history.pushState(null, null, url);
}else{
window.location.hash = hash;
}