Comments (10)
Good idea. That would be a distinct difference between using JS & CSS-only for tabs organized layouts.
from tabby.
@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.
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.
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.
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.
- Does the navigation remain on non-supporting browsers, since links could still function as anchor links?
- What happens in that case if someone is using buttons for toggles instead of links?
- 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.
Perhaps document somewhere, in README or WiKi?
from tabby.
@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.
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.
@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.
Ok, fair enough 😃
from tabby.
Related Issues (20)
- Nested tabs HOT 2
- Init Tabby only on mobile HOT 4
- Callback events? HOT 1
- Add previous tab to event HOT 3
- TypeError when no tabs exist on a page HOT 2
- Stop video when tab is inactive HOT 1
- Instantiate multiple instances with the same selector HOT 8
- Add ES6 module HOT 4
- 'tabby' event is not emitted when the tab ID is specified in the URL hash HOT 3
- CustomEvent polyfill is required for IE9+ support HOT 1
- CSS file not available via CDN HOT 2
- Implement Manual Activation HOT 3
- Add to documentation - instantiate multiple instances HOT 1
- Ability to call nested tabs with anchors?
- Make Tabby Work with Anchor Links from Outside HOT 2
- It is recommended that the Chinese character set is freely configured
- Where is download page? HOT 2
- bug occur when use sz (lrzsz utils) HOT 1
- Allow passing a node instead of a selector
- Scroll jump to anchor then back to top HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tabby.