diff --git a/CHANGELOG.md b/CHANGELOG.md index 6583cf9..5ca18ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/package.json b/package.json index 5f8e4d1..adee440 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -19,6 +19,7 @@ "node": ">=4.0.0" }, "dependencies": { + "lite-ready": "^1.0.4", "qwery": "^4.0.0" }, "devDependencies": { diff --git a/src/index.js b/src/index.js index d5f41eb..cbad748 100644 --- a/src/index.js +++ b/src/index.js @@ -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. @@ -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)) { @@ -46,7 +50,7 @@ const handleToggles = (targets, toggleClass) => { parts.unshift('toggle'); } - const [ toggleType, toggleName ] = parts; + const [toggleType, toggleName] = parts; $(`[data-toggle-name~=${toggleName}]`) .forEach(toggles(toggleClass)[toggleType]); @@ -54,10 +58,11 @@ const handleToggles = (targets, toggleClass) => { }; -/** - * 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 => { @@ -69,4 +74,13 @@ export default () => { handleToggles(target, toggleClass); }); }); -}; + +} + +ready(() => { + + setupToggle(); + +}); + +export default setupToggle; diff --git a/yarn.lock b/yarn.lock index 315b126..01477a8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"