Skip to content
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

#undefinded added to normal url tabs with selectorAttribute not used at all #37

Open
Bhoft opened this issue Sep 30, 2019 · 0 comments
Open

Comments

@Bhoft
Copy link

Bhoft commented Sep 30, 2019

Hi,

I have an issue that with the widget kartik-v/yii2-tabs-x/ for yii2 which uses jquery-stickytabs.

Whenever you click a tab with a normal href link (so another page is requested on tab click) #undefined is added to the current url before the actual given url of the href is requested.

I have already opened an issue there today but i think is a more on an issue of this package.
See: kartik-v/yii2-tabs-x#66

The problem is that there isn't any check if the some hash is actually given.
And because of this #undefined is added if no anchor is used in the url.

This code:

 $('a', context).on('click', function(e) {
      var hash = this.href.split('#')[1];
      var adjustedhash = settings.getHashCallback(hash, this);
      changeHash(adjustedhash);
      setTimeout(backToTop, 1);
  });

doesn't check if the hash is undefined or not.

In my opinion the default getHashCallback function
which is

getHashCallback: function(hash, btn) { return hash },

should be at least

getHashCallback: function(hash, btn) {if (hash === undefined) { return '';} return hash },

so #undefined isn't attached to tabs with "normal href" links.
Then only only # but at least this looks better than #undefined.

Or the changeHash function should be extended to check if the given hash isn't undefined before attaching it to the url.

So a browser back would not return to the previous url with "#undefinded" attached.

I also wonder why the selectorAttribute of the link isn't added to the url e.g. via a getHashCallback function like:

function(hash, btn) {
    if (hash === undefined) {
        var btn_selector_hash = $(btn).attr(this.selectorAttribute);
        if (btn_selector_hash !== undefined) {
            return btn_selector_hash;
        }
        return '';
    }
    return hash;
}

regards Benjamin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant