Giter Site home page Giter Site logo

Hash URLs about tabby HOT 10 CLOSED

cferdinandi avatar cferdinandi commented on May 17, 2024
Hash URLs

from tabby.

Comments (10)

tomByrer avatar tomByrer commented on May 17, 2024

Good idea. That would be a distinct difference between using JS & CSS-only for tabs organized layouts.

from tabby.

cferdinandi avatar cferdinandi commented on May 17, 2024

@silvenon @tomByrer I agree, this is a good idea! However, it can be done already today using the API. This should work:

;(function (window, document, undefined) {

    'use strict';

    // Get the hash
    var tabID = window.location.hash;

    // If there's a hash and tabby has been defined, toggle your tab
    if ( tabID && typeof tabby === 'function' ) {
        var toggle = document.querySelector('[data-tab="' + tabID + '"]'); // Get the tab toggle that matches the hash
        tabby.tabby.toggleTab( toggle, tabID );
    }

})(window, document);

from tabby.

silvenon avatar silvenon commented on May 17, 2024

Yes, it can be done, but I was proposing it as a feature of tabby, instead of having to manually do it on every project.

Also, your example covers only if the hash already exists, we should also implement changing the hash when a tab is toggled.

from tabby.

cferdinandi avatar cferdinandi commented on May 17, 2024

I hear you, but that's why the API exists. Tabby is intentionally lightweight, and a feature like this is relatively easy to bolt-on with the API.

from tabby.

cferdinandi avatar cferdinandi commented on May 17, 2024

It's worth mentioning: Adding functionality like that not only adds weight to the code, but forces me to make decisions that I don't at the moment.

  1. Does the navigation remain on non-supporting browsers, since links could still function as anchor links?
  2. What happens in that case if someone is using buttons for toggles instead of links?
  3. Should I also support (or even require) an href value for link toggles?

Those are things that might vary by project, and are frankly best left to the developers using the scripts rather than me.

from tabby.

tomByrer avatar tomByrer commented on May 17, 2024

Perhaps document somewhere, in README or WiKi?

from tabby.

cferdinandi avatar cferdinandi commented on May 17, 2024

@tomByrer - I can certainly look into adding some API examples in docs.

@silvenon - Regarding updating the URL on click, that may or may not be a desired behavior, which is again why I prefer to leave these things to the API. But that would be handled using the callback API:

tabby.init({
    callbackAfter: function ( toggle, tabID ) {
        if ( history.pushState ) {
            history.pushState( {
                pos: tabID
            }, '', window.location.pathname + tabID );
        }
    }
});

from tabby.

silvenon avatar silvenon commented on May 17, 2024

This functionality can be optional, passed as a flag when initializing tabby. 3. decision is IMO easy, just use href for <a> and use data-tab on non-<a> tabs. For the 1. decision, I would leave the links, because they can still link to that content. The 2. decision is tough, I agree.

from tabby.

cferdinandi avatar cferdinandi commented on May 17, 2024

@silvenon But the thing is, it's almost as easy to just let people who want this functionality build it themselves with the API. It gives them the freedom to make those decisions based on their project, and keeps the core code weight down. I could make each of those decisions a user configurable variable, but the code can bloat up pretty fast that way.

The only benefit I can see to baking this in is that people who have no idea how to write JS can still get in on it. But this is simple enough to learn, so I'm leaving it as an optional API feature.

from tabby.

silvenon avatar silvenon commented on May 17, 2024

Ok, fair enough 😃

from tabby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.