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

tabit

v2.2.2

Published

Just javascript tabs. Use it anywhere. No dependencies. Lightweight. Customizable.

Downloads

29

Readme

Tabit! Build Status

Just javascript tabs. Use it anywhere. No dependencies. Lightweight. Customizable.

Examples: http://andrey-hohlov.github.io/tabit/

Install

Download using NPM

$ npm install tabit --save

Prepare HTML

<div id="tabs">
  <nav>
    <a href="#tab-1">Tab 1</a>
    <a href="#tab-2">Tab 2</a>
    <a href="#tab-3">Tab 3</a>
  </nav>
  <div id="tab-1">Content of first tab</div>
  <div id="tab-2">Content of second tab</div>
  <div id="tab-3">Content of third tab</div>
</div>

Import and call


import Tabit from 'Tabit'

const element = document.getElementById('tabs');
const options = {};
const tabit = new Tabit(element, options); 

...or manually download and inject the minified script into your website.

Options

{
  buttonSelector: 'a',
  contentSelector: 'div',
  buttonAttribute: 'href',
  contentAttribute: 'id', 
  buttonActiveClass: null,
  contentActiveClass: null,
  event: 'click',
  activeIndex: 0,
  toggleDisplay: true, 
  closable: false,
  beforeInit: null,
  onInit: null,
  beforeChange: null,
  onChange: null, 
  onDestroy: null
}
  • buttonSelector - (string) CSS selector for tab button - trigger for change tab
  • contentSelector - (string) CSS selector for tab content block
  • buttonAttribute - (string) attribute that contains a reference to the value of the contentAttribute, for href attribute will be removed first #
  • contentAttribute - (string) attribute contains the value that is referred to by buttonAttribute
  • buttonActiveClass - (string) class for active tab button
  • contentActiveClass - (string) class for active tab content block
  • event - (string | array) event or events fired on tab button, support: click, mouseover, touchstart
  • activeIndex - (number) index of active tab on init, set -1 for no active tab
  • toggleDisplay - (boolean) toggle css display property for tabs content blocks (display: none for inactive)
  • closable - (boolean) close active tab after click
  • beforeInit - (function) callback when instance created but not set active tab yet, arguments: Tabit instance
  • onInit - (function) callback after successfully init, arguments: Tabit instance
  • beforeChange - (function) callback before tab changed, arguments: current active tab, new tab, Tabit instance
  • onChange - (function) callback after tab changed, arguments: new active tab, Tabit instance
  • onDestroy - (function) callback after instance destroyed

API

  • next() - go to next tab, turn to first from last
  • prev() - go to previous tab, turn to last from first
  • getActiveTab() - return active tab
  • getActiveTabIndex() - return active tab index
  • getTab(index) - get tab by index
  • setActiveTab(index) - set active tab by index
  • destroy() - destroy Tabit instance
  • Tabit.getInstance(element) - get Tabit instance from element

Browser support

  • IE 10+
  • Chrome 24+
  • Firefox 23+
  • Opera 15+
  • Safari 7+
  • Android Browser 4.4+
  • iOS Safari 7.1+

Works in IE 9 with Element.prototype.classList polyfill.

Find polyfills on polyfill.io.

Recipes

Custom HTML structure

<divid="tabs">
  <div>
    <button type="button" data-target="tab-1">Tab 1</button>
    <button type="button" data-target="tab-2">Tab 2</button>
    <button type="button" data-target="tab-3">Tab 3</button>
  </div>
  <div>
    <div data-content="tab-1">Content of first tab</div>
    <div data-content="tab-2">Content of second tab</div>
    <div data-content="tab-3">Content of third tab</div>
  </div>
</div>
new Tabit(
  document.getElementById('tabs'),
  {
    buttonSelector: '[data-target]',
    contentSelector: 'data-target',
    buttonAttribute: '[data-content]',
    contentAttribute: 'data-content',  
  }
);

Only change CSS class

new Tabit(
  document.getElementById('tabs'),
  {
    contentActiveClass: 'is-active',
    toggleDisplay: false
  }
);
div:not(.is-active) {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

Change on hover

new Tabit(
  document.getElementById('tabs'),
  {
    event: ['mouseover', 'click']
  }
);

Use custom animations

new Tabit(
  document.getElementById('tabs'),
  {
    toggleDisplay: false,
    onInit: function (instance) {
      this.tabs.forEach(function (item, i) {
        if (i !== 0) $(item.content).hide();
      });
    },
    beforeChange: function (activeTab, newTab, instance) {
      if (!activeTab) return; // no animate on init
      $(activeTab.content)
        .stop()
        .fadeOut(function () {
          $(newTab.content).stop().fadeIn()
        });
    }
  }
);

Auto rotation

var tabit = new Tabit(document.getElementById('tabs'));
var rotate = setInterval(function() {
  tabit.next();      
}, 2000)

Live examples

Changelog

2.2

  • Add instance cache
  • Add getInstance method

2.1

2.0

  • Full rewrite on ES6.

License

The MIT License

Copyright (c) 2017 Andrey Hohlov