Skip to content

Commit

Permalink
Merge pull request #6 from justeat/page-ready
Browse files Browse the repository at this point in the history
v0.5.0 — Toggle will initiate on page load.
  • Loading branch information
ashleynolan authored Sep 22, 2017
2 parents 5ec7b9e + 04ce00f commit 7ba06a6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).


v0.5.0
------------------------------
*September 21, 2017*

### Changed
- Toggle will initiate on page load.
- Updated Javascript documentation comments.


v0.4.0
------------------------------
*September 20, 2017*
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@justeat/f-toggle",
"description": "Fozzie vanilla JS toggle library.",
"version": "0.4.0",
"version": "0.5.0",
"main": "dist/index.js",
"homepage": "https://github.com/justeat/f-toggle",
"contributors": [
Expand All @@ -19,6 +19,7 @@
"node": ">=4.0.0"
},
"dependencies": {
"lite-ready": "^1.0.4",
"qwery": "^4.0.0"
},
"devDependencies": {
Expand Down
30 changes: 22 additions & 8 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/**
* @overview Fozzie vanilla JS toggle library.
*
* @module toggle
* @module f-toggle
*/

import $ from 'qwery';
import ready from 'lite-ready';
import $ from 'qwery';


/**
* Handles the toggle element click events
*
* @param {string} toggleClass
*
* @property {object} toggle Toggle an element's visibility.
* @property {object} show Shows an element.
* @property {object} hide Hides an element.
Expand All @@ -32,6 +35,7 @@ const toggles = toggleClass => ({
* Handles the toggle element click events
*
* @param {string|string[]} targets
* @param {string} toggleClass
*/
const handleToggles = (targets, toggleClass) => {
if (!Array.isArray(targets)) {
Expand All @@ -46,18 +50,19 @@ const handleToggles = (targets, toggleClass) => {
parts.unshift('toggle');
}

const [ toggleType, toggleName ] = parts;
const [toggleType, toggleName] = parts;

$(`[data-toggle-name~=${toggleName}]`)
.forEach(toggles(toggleClass)[toggleType]);
});

};

/**
* Bind the toggle element click events
*/
export default () => {
const setupToggle = () => {

/**
* Bind the toggle element click events
*/
$('[data-toggle-target]')
.forEach(toggle => {
toggle.addEventListener('click', e => {
Expand All @@ -69,4 +74,13 @@ export default () => {
handleToggles(target, toggleClass);
});
});
};

}

ready(() => {

setupToggle();

});

export default setupToggle;
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6733,6 +6733,10 @@ limiter@^1.0.5:
version "1.1.2"
resolved "https://registry.yarnpkg.com/limiter/-/limiter-1.1.2.tgz#229d8055891c8b11af9e0ee5200e8e09bb3dcbeb"

lite-ready@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/lite-ready/-/lite-ready-1.0.4.tgz#6dfe50f45a5a2840c87c8406a7abf3088bfd255e"

load-helpers@^0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/load-helpers/-/load-helpers-0.3.1.tgz#99a8ba07362901827c8e62c95b0b0b1fe9830549"
Expand Down

0 comments on commit 7ba06a6

Please sign in to comment.