https://github.com/stopsopa/tabs
(not maintained) Another js tab component
https://github.com/stopsopa/tabs
Last synced: about 1 month ago
JSON representation
(not maintained) Another js tab component
- Host: GitHub
- URL: https://github.com/stopsopa/tabs
- Owner: stopsopa
- Created: 2015-10-21T11:05:32.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-02T00:14:41.000Z (over 1 year ago)
- Last Synced: 2024-04-14T01:50:27.906Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Doc mostly outdated
Documentation was created for old version of this component created back in 2015 based on jQuery.
I'll update it laterCurrent [version](https://stopsopa.github.io/tabs/) was rewritten to use to use vanilla [event delegation](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/Event_bubbling#event_delegation) technique
.
## Demo
[Demo](https://stopsopa.github.io/tabs/)
***
## Npm instalation
```
npm install stopsopa.tabs
```## Example
### include files
```html
```
### html
```html
```
### javascript
```javascript
$('[data-tabs]').tabs();
```
## Api
Initialize and select specific tab on start:
```javascript
$('[data-tabs]').tabs({
active: 2 // make active this tab on start (default: 0)
});
```
you can also check tab as a selected on start in html by adding 'active' class in one of two places:
```html
```(activating by api has higher priority then in html and
adding class 'active' in [data-buttons] has higher priority then adding in section [data-tabs])
Change tab programmatically:
```javascript
$('[data-tabs]').tabs('active', 2); // active third tab
```
Destroy component - unbind all methods and clean up all context, (dom nodes stay as is),
after that you can initialize widget on the same dom element again.```javascript
$('[data-tabs]').tabs('destroy');
```
There is also available special selector to find all initialized tab components ... :
```javascript
$(':tabs').tabs('active', 1) // active second tab for all tab components
```
... or to check if dom element is already initialized as a tab component:
```javascript
var element = $('... some selector ...');
if (element.is(':tabs')) {
// do stuff
}
```
# events
```javascript
$('[data-tabs]')
.on('tabs:change', function (e, i, tab, div, isFirst) {
// better define .on() events before call .tabs(),
// because .tabs() will have no opportunity to call this event
// during initialization
if (isFirst) { // isFirst -> is this a first click on tab?,
div.find('.editor, .syntax').aceedit();
// initialize javascripts on content of tab
}
// e - native event object
// i - index of current tab
// tab - jQuery element representing clicked tab
// div - jQuery element representing div with tab content
// isFirst - flag to determine if this is first show of
// tab content, usially useful for initialize
// javascript inside tab that can't be done
// if content is display: none;
})
.tabs()
```
### License
The MIT License (MIT)
Copyright (c) 2016 Szymon Działowski
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.