Skip to content

Commit

Permalink
Merge pull request #14 from rah-emil/fix/set_hooks_after_actions
Browse files Browse the repository at this point in the history
fix/set hooks after actions
  • Loading branch information
rah-emil authored Aug 21, 2022
2 parents 56b1d67 + 74355ba commit a1af913
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 45 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ When you click the button, the class ```open``` will be added to ```<div id="ca


## Hooks
- **onToggle($el)** - hook before toggle action
- **onAdd($el)** - hook before add action
- **onRemove($el)** - hook before remove action
- **onRcoe($el)** - hook before rcoe action
- **onToggle($el)** - hook after action toggle
- **onAdd($el)** - hook after action add
- **onRemove($el)** - hook after action remove
- **onRcoe($el)** - hook after action rcoe
17 changes: 9 additions & 8 deletions dist/easy-toggler.cjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/*!
* EasyToggler v2.2.3 (https://github.com/rah-emil/easy-toggler#readme)
* EasyToggler v2.2.7 (https://github.com/rah-emil/easy-toggler#readme)
* Copyright 2022 Rah Emil <013131@mail.ru>
* Licensed under MIT (https://github.com/rah-emil/easy-toggler/blob/master/LICENSE)
*/
'use strict';

const toggle = ($toggler, attrs) => {
attrs.onToggle($toggler);

const _target = $toggler.getAttribute(attrs.toggle);

document.querySelectorAll(`[${attrs.toggle}]`).forEach(easyBlock => {
Expand All @@ -28,11 +26,11 @@ const toggle = ($toggler, attrs) => {
if (_selfClass) {
$toggler.classList.toggle(_selfClass);
}

attrs.onToggle($toggler);
};

const add = ($add, attrs) => {
attrs.onAdd($add);

const _target = $add.getAttribute(attrs.add);

const _class = $add.getAttribute(attrs.class);
Expand All @@ -46,11 +44,11 @@ const add = ($add, attrs) => {
if (_selfClass) {
$add.classList.add(_selfClass);
}

attrs.onAdd($add);
};

const remove = ($remove, attrs) => {
attrs.onRemove($remove);

const _target = $remove.getAttribute(attrs.remove);

const _class = $remove.getAttribute(attrs.class);
Expand All @@ -64,6 +62,8 @@ const remove = ($remove, attrs) => {
if (_selfClass) {
$remove.classList.remove(_selfClass);
}

attrs.onRemove($remove);
};

const rcoes = (e, attrs) => {
Expand All @@ -73,14 +73,15 @@ const rcoes = (e, attrs) => {
let block_class = $rcoe.getAttribute(attrs.class);

if (!e.target.closest(block)) {
attrs.onRcoe($rcoe);
document.querySelector(block)?.classList.remove(block_class);

const _selfClass = $rcoe.getAttribute(attrs.self);

if (_selfClass) {
$rcoe.classList.remove(_selfClass);
}

attrs.onRcoe($rcoe);
}
});
};
Expand Down
2 changes: 1 addition & 1 deletion dist/easy-toggler.cjs.map

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions dist/easy-toggler.iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/easy-toggler.iife.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/easy-toggler.iife.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a1af913

Please sign in to comment.