Skip to content

Commit

Permalink
2.3.0 - add TypeScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
WezomDev committed Jan 14, 2020
1 parent 47859d2 commit 13d1a07
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 40 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

---

![types](https://img.shields.io/badge/types-TypeScript-blue)
[![npm](https://img.shields.io/badge/npm-install-red.svg)](https://www.npmjs.com/package/wezom-standard-tabs)
[![WezomAgency](https://img.shields.io/badge/wezom-agency-red.svg)](https://github.com/WezomAgency)
[![Javascript Style Guide](https://img.shields.io/badge/code_style-wezom_relax-red.svg)](https://github.com/WezomAgency/eslint-config-wezom-relax)
Expand Down
87 changes: 87 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
export module 'wezom-standard-tabs' {
type hook = (...args: any) => void;

interface WSTabs {
events: {
on: string;
off: string;
again: string;
};

hooks: {
beforeOn: hook[];
beforeOff: hook[];
beforeAgain: hook[];
on: hook[];
off: hook[];
again: hook[];
update: hook[];
};

cssClass: {
active: string;
disabled: string;
};

keys: {
ns: string;
button: string;
block: string;
};

/**
* Initialize.
* Set dependencies and delegated handlers
*/
init<TContext = Document>($context: JQuery<TContext> = $(document)): void;

/**
* Forced activation of tabs if there are no active one
*/
setActive<TContext = Document>($context: JQuery<TContext> = $(document)): void;

/**
* Remove all dependencies
*/
dropDependencies<
TButtons = HTMLElement,
TBlocks = HTMLElement,
TContext = Document
>(
$context: JQuery<TContext> = $(document)
): {
$buttons: JQuery<TButtons>;
$blocks: JQuery<TBlocks>;
};

/**
* Update all dependencies with pre-reset.
* Actual when dynamically adding new buttons and blocks to existing tab groups
*/
updateDependencies<TContext = Document>(
$context: JQuery<TContext> = $(document)
): void;

/**
* Ejecting tabs data from given tab button
*/
ejectData<TButtons = HTMLElement, TBlocks = HTMLElement, TContext = Document>(
$button: JQuery<TButtons>,
$context: JQuery<TContext> = $(document)
): {
myNs: string;
myName: string;
buttonsSelector: string;
buttonSyncSelector: string;
blocksSelector: string;
blockSelector: string;
$block: JQuery<TBlocks>;
$siblingBlocks: JQuery<TBlocks>;
$siblingButtons: JQuery<TButtons>;
$syncButtons: JQuery<TButtons>;
};
}

const wsTabs: WSTabs;
export = wsTabs;
}
40 changes: 1 addition & 39 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,22 +162,14 @@ function dropDependencies ($list, keys) {
// Public
// ----------------------------------------

/**
* @namespace
*/

const wsTabs = {
/**
* @enum {string}
*/
events: {
on: 'wstabs-on',
off: 'wstabs-off',
again: 'wstabs-again'
},

/**
* @enum {function[]}
*/
hooks: {
beforeOn: [],
beforeOff: [],
Expand All @@ -188,28 +180,17 @@ const wsTabs = {
update: []
},

/**
* @enum {string}
*/
cssClass: {
active: 'is-active',
disabled: 'is-disabled'
},

/**
* @enum {string}
*/
keys: {
ns: 'wstabs-ns',
button: 'wstabs-button',
block: 'wstabs-block'
},

/**
* Initialize.
* Set dependencies and delegated handlers
* @param {jQuery} [$context=$(document)]
*/
init ($context = $(document)) {
this.updateDependencies($context);
$context.on('click', `[data-${this.keys.button}]`, { $context }, function () {
Expand All @@ -231,20 +212,11 @@ const wsTabs = {
});
},

/**
* Forced activation of tabs if there are no active one
* @param {jQuery} [$context=$(document)]
*/
setActive ($context = $(document)) {
let $buttons = $context.find(`[data-${this.keys.button}]`);
setActiveIfNotHave($buttons, $context);
},

/**
* Remove all dependencies
* @param {jQuery} [$context=$(document)]
* @return {{$buttons: $jQuery, $blocks: $jQuery}}
*/
dropDependencies ($context = $(document)) {
let $buttons = $context.find(`[data-${this.keys.button}]`);
let $blocks = $context.find(`[data-${this.keys.block}]`);
Expand All @@ -253,11 +225,6 @@ const wsTabs = {
return { $buttons, $blocks };
},

/**
* Update all dependencies with pre-reset.
* Actual when dynamically adding new buttons and blocks to existing tab groups
* @param {jQuery} [$context=$(document)]
*/
updateDependencies ($context = $(document)) {
const { $buttons } = this.dropDependencies($context);
$buttons.each((i, button) => {
Expand All @@ -267,11 +234,6 @@ const wsTabs = {
});
},

/**
* @param {jQuery} $button
* @param {jQuery} [$context=$(document)]
* @returns {{myNs: string, myName: string, buttonsSelector: string, buttonSyncSelector: string, blocksSelector: string, blockSelector: string, $block: jQuery, $siblingBlocks: jQuery, $siblingButtons: jQuery, $syncButtons: jQuery}}
*/
ejectData ($button, $context = $(document)) {
return _ejectData($button, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wezom-standard-tabs",
"version": "2.2.1",
"version": "2.3.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 13d1a07

Please sign in to comment.