Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary spread, use {} as triggerMap #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const MicroModal = (() => {
this.config = { debugMode, disableScroll, openTrigger, closeTrigger, openClass, onShow, onClose, awaitCloseAnimation, awaitOpenAnimation, disableFocus }

// Register click events only if pre binding eventListeners
if (triggers.length > 0) this.registerTriggers(...triggers)
if (triggers.length > 0) this.registerTriggers(triggers)

// pre bind functions for event listeners
this.onClick = this.onClick.bind(this)
Expand All @@ -49,7 +49,7 @@ const MicroModal = (() => {
* @param {array} triggers [Array of node elements]
* @return {void}
*/
registerTriggers (...triggers) {
registerTriggers (triggers) {
triggers.filter(Boolean).forEach(trigger => {
trigger.addEventListener('click', event => this.showModal(event))
})
Expand Down Expand Up @@ -140,7 +140,7 @@ const MicroModal = (() => {

getFocusableNodes () {
const nodes = this.modal.querySelectorAll(FOCUSABLE_ELEMENTS)
return Array(...nodes)
return Array.prototype.slice.call(nodes)
}

/**
Expand Down Expand Up @@ -208,14 +208,14 @@ const MicroModal = (() => {
let activeModal = null

/**
* Generates an associative array of modals and it's
* Generates an object containing modals and it's
* respective triggers
* @param {array} triggers An array of all triggers
* @param {string} triggerAttr The data-attribute which triggers the module
* @return {array}
* @return {object}
*/
const generateTriggerMap = (triggers, triggerAttr) => {
const triggerMap = []
const triggerMap = {}

triggers.forEach(trigger => {
const targetModal = trigger.attributes[triggerAttr].value
Expand Down Expand Up @@ -258,7 +258,7 @@ const MicroModal = (() => {
* Checks if triggers and their corresponding modals
* are present in the DOM
* @param {array} triggers Array of DOM nodes which have data-triggers
* @param {array} triggerMap Associative array of modals and their triggers
* @param {object} triggerMap Object containing modals and their triggers
* @return {boolean}
*/
const validateArgs = (triggers, triggerMap) => {
Expand All @@ -278,7 +278,7 @@ const MicroModal = (() => {
const options = Object.assign({}, { openTrigger: 'data-micromodal-trigger' }, config)

// Collects all the nodes with the trigger
const triggers = [...document.querySelectorAll(`[${ options.openTrigger }]`)]
const triggers = Array.prototype.slice.call(document.querySelectorAll(`[${ options.openTrigger }]`))

// Makes a mappings of modals with their trigger nodes
const triggerMap = generateTriggerMap(triggers, options.openTrigger)
Expand All @@ -288,9 +288,9 @@ const MicroModal = (() => {

// For every target modal creates a new instance
for (var key in triggerMap) {
let value = triggerMap[key]
let valueArr = triggerMap[key]
options.targetModal = key
options.triggers = [...value]
options.triggers = valueArr
activeModal = new Modal(options) // eslint-disable-line no-new
}
}
Expand Down