npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tabz

v1.1.3

Published

Easy hierarchial HTML folder tabs.

Downloads

108

Readme

tabz

Easy hierarchial HTML folder tabs.

Demo

A demo can be found here.

Usage

Flat

A 2-tab tab panel with the first tab enabled:

<div class="tabz" style="width: 300px; height: 500px;">

    <header>Tab A</header>
    <section>Content A</section>

    <header id="click-me">Tab B</header>
    <section>Content B</section>

</div>
Hierarchical

A 2-tab tab panel nested within the 2nd tab of another 2-tab tab panel.

<div class="tabz" style="width: 300px; height: 500px;">

    <header>Tab A</header>
    <section>Content A</section>

    <header>Tab B</header>
    <section>
        Content B
        <div class="tabz">

            <header>Tab B.1</header>
            <section>Content B.1</section>

            <header>Tab B.2</header>
            <section>Content B.2</section>

        </div>
    </section>
</div>

The outer-most tab panel needs to be sized. This is not necessary for inner tab panel.

The following, called after page load, will instantiate an single object to service all the .tabz panels above.

var Tabz = require('tabz');
var tabz = new Tabz();

Alternatively, you could instantiate separate objects for specific panels or sets of panels.

In any case, the first tab of each .tabz panel will be enabled by default. See option defaultTabSelector (below) to override this.

Switch to a tab programmatically

To trigger a tab, you can call the .tabTo() method with the tab's <header> element or a selector that resolves to it:

tabz.tabTo('#click-me');
Discover currently selected tab

To find out which tab in a panel is the currently selected tab, call the following with the panel element (or any element within it):

// returns the tab (`<header>`) element
var enabledTab = tabz.enabled(element);
Easily find tab panels, tabs, and folders
// ref to element with class 'tabz' containing `element`
var nearestPanelElement = tabz.panel(element);

// ref to <header> containing `element`
var nearestTabElement = tabz.tab(element);

// ref to <section> containing `element`
var nearestFolderElement = tabz.folder(element);

Overload: All of the above can alternatively take a string, a selector for a specific panel, tab, or folder, respectively. The advantage of using these functions rather than simply document.querySelector() is: (a) search domain is restricted to options.root (if given on instantiation); and (b) result is guaranteed to be the expected type of element (otherwise null is returned).

Callbacks

There are callbacks for each of the following events:

// called before a previously enabled tab is disabled
tabz.onDisable = function(tab, folder) { ... }

// called before a previously disabled tab is enabled
tabz.onEnable = function(tab, folder) { ... }

// called after a previously enabled tab is disabled
tabz.onDisabled = function(tab, folder) { ... }

// called after a previously disabled tab is enabled
tabz.onEnabled = function(tab, folder) { ... }

The calling context for each of these (the .this value) is tabz.

CSS included

The stylesheet is baked into the code and is programmatically injected into the DOM with the id tabz-css-base. You have control of where to place it with the referenceElement parameter.

The default color for a tab is white. The stylesheet includes six pastel colors in selectors .tabz-bg1 through .tabz-bg6. If you want to use these, reference them from both the tab and the folder (<header> and <section>) elements.

Hints

Set visibility:hidden in the style attribute of your root tab bar div so it won't be visible before the stylesheet loads.

You will probably need to adjust the dimensions of your sections. Adjust the width and height properties using the .tabz > header + section selector. Nested tabs will need their own dimensions.

For example, you can find the following on the demo page.

.tabz {
    visibility:hidden;
}
.tabz > header + section {
    width: 300px;
    height: 350px;
}
.tabz > header + section >
.tabz > header + section {
    width: 280px;
    height: 295px;
}

Initialization options

var tabz = new Tabz( options )

options.root - Where to look for .tabz panels. Defaults to document.

options.unhook - Skip normal initialization and just remove event listener from .tabz elements. Defaults to false.

options.referenceElement - Explicitly position <style> element before this element. Default position is in <head>, before the first <link rel="stylesheet"> or <style> element, if any; otherwise at the end of <head>.

defaultTabSelector - A .classname or #id of the tab(s) to select by default. This string is appended to .tabz > header to ensure only one of our tabs is selected. Defaults to '.default-tab'.

onEnable - Callback implementation.

onDisable - Callback implementation.

onEnabled - Callback implementation.

onDisabled - Callback implementation.

Events

Not events really, but callbacks:

  • tabz.tabEnabled(tabEvent) - Called when a previously disabled tab is enabled.

  • tabz.tabDisabled(tabEvent) - Called when a previously enabled tab is disabled by another tab being enabled.

Both of the above are called with a tabEvent which is:

{
    target: tab, // the <header> HTMLElement of the tab in question
    id: id // the string id of the tab (form the id attribute of the above HTMLElement)
}

Acceptance Testing

  • Chromium 40.0.2214.91
  • Chrome 48.0.2564.109
  • Safari 9.0.3
  • Firefox 44.0.2

CDN versions

To use in a browser, you have two options:

  1. Incorporate the node module into your own browserified project.
  2. Use the browserified versions tabz.js or tabz.min.js available on the Github pages CDN.