Skip to content

Commit

Permalink
fix(toggle): fix timing delay fnc with queueStop other queue like in …
Browse files Browse the repository at this point in the history
…comment + comments
  • Loading branch information
minimit committed Jun 23, 2020
1 parent 24b78ef commit 9d0ef45
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 45 deletions.
55 changes: 16 additions & 39 deletions src/core/toggle/toggle.js
Expand Up @@ -227,7 +227,7 @@ class Toggle {
currents++
// reactivate
requestAnimationFrame(() => {
// activate
// activation
self.eventOn(element, true)
})
}
Expand All @@ -243,7 +243,7 @@ class Toggle {
}
// initial
currents += todo
// activate
// activation
requestAnimationFrame(() => {
for (let i = start; i < todo; i++) {
self.eventOn(self.elements[i], true)
Expand Down Expand Up @@ -1143,7 +1143,7 @@ class Toggle {
*/
activate(el) {
const self = this
// activate
// activation
el.classList.add(...self.classes)
el.classList.remove(...self.classesIn)
el.classList.remove(...self.classesInDone)
Expand All @@ -1168,7 +1168,7 @@ class Toggle {
*/
activateDone(el) {
const self = this
// activate
// activation
el.classList.add(...self.classesInDone)
}

Expand All @@ -1178,7 +1178,7 @@ class Toggle {
*/
deactivate(el) {
const self = this
// activate
// activation
el.classList.remove(...self.classes)
el.classList.remove(...self.classesIn)
el.classList.remove(...self.classesInDone)
Expand All @@ -1199,7 +1199,7 @@ class Toggle {
*/
deactivateDone(el) {
const self = this
// activate
// activation
el.classList.remove(...self.classesOut)
}

Expand Down Expand Up @@ -1253,12 +1253,12 @@ class Toggle {
for (const type in self.detail['queue' + actionCurrent][0]) {
self.queueStart(actionCurrent, actionOther, type, 0, true)
}
// activated
// activationd
return true
} else if (!e || !e.type || e.type !== 'on.trigger.xt') {
self.eventOff(element, false, e)
}
// activated
// activationd
return false
}

Expand Down Expand Up @@ -1310,7 +1310,7 @@ class Toggle {
const actionCurrent = 'Off'
const actionOther = 'On'
self.eventQueue(actionCurrent, groupElements, targets, elementsInner, targetsInner, e)
// if queue too big
// remove queue not started if queue too big
if (self.detail['queue' + actionCurrent].length > options.max) {
// remove queue and stop
const removedOn = self.detail['queue' + actionOther].shift()
Expand Down Expand Up @@ -1608,36 +1608,13 @@ class Toggle {
clearTimeout(Xt.dataStorage.get(el, self.componentNamespace + 'DelayTimeout'))
clearTimeout(Xt.dataStorage.get(el, self.componentNamespace + 'AnimTimeout'))
// done other queue
self.queueDelayDone(actionCurrent, actionOther, obj, el, type, true)
self.queueAnimDone(actionCurrent, actionOther, obj, el, type, true)
self.queueDelayDone(actionOther, actionCurrent, obj, el, type, true)
self.queueAnimDone(actionOther, actionCurrent, obj, el, type, true)
}
}
}
}

/**
* queue stop all
*/
queueStopAll() {
const self = this
// stop all obj in queues
if (self.detail) {
// @FIX not already initialized
const actions = [
{ current: 'On', other: 'Off' },
{ current: 'Off', other: 'On' },
]
for (const action of actions) {
// @FIX slider resize multiple queues
// @FIX autoclose with appendTo outside ajax
// remove queue and stop
const removed = self.detail['queue' + action.current].shift()
self.queueStop(action.current, action.other, removed)
self.detail['queue' + action.current] = []
}
}
}

/**
* queue delay
* @param {String} actionCurrent Current action
Expand Down Expand Up @@ -1709,7 +1686,7 @@ class Toggle {
const self = this
const options = self.options
if (actionCurrent === 'On') {
// activate
// activation
self.activate(el)
// special
const before = getComputedStyle(el, ':before')
Expand All @@ -1728,8 +1705,8 @@ class Toggle {
const el = obj.targets ? obj.targets.queueEls[0] : obj.elements.queueEls[0]
Xt.focusLimit.on(el)
}
// @FIX when standalone !self.targets.length && type === 'elements'
if (type === 'targets' || (!self.targets.length && type === 'elements')) {
// @FIX when standalone
// appendTo
if (options.appendTo) {
const appendToTarget = document.querySelector(options.appendTo)
Expand Down Expand Up @@ -1772,7 +1749,7 @@ class Toggle {
// listener dispatch
el.dispatchEvent(new CustomEvent('on.xt'))
} else if (actionCurrent === 'Off') {
// activate
// activation
self.deactivate(el)
// special
const before = getComputedStyle(el, ':before')
Expand Down Expand Up @@ -1855,7 +1832,7 @@ class Toggle {
const self = this
const options = self.options
if (actionCurrent === 'On') {
// activate
// activation
self.activateDone(el)
// special
const before = getComputedStyle(el, ':before')
Expand All @@ -1868,7 +1845,7 @@ class Toggle {
// listener dispatch
el.dispatchEvent(new CustomEvent('ondone.xt'))
} else if (actionCurrent === 'Off') {
// activate
// activation
self.deactivateDone(el)
// special
if (type === 'targets' || (!self.targets.length && type === 'elements')) {
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/ajax/ajax.js
Expand Up @@ -95,7 +95,7 @@ class Ajax extends Xt.Toggle {
if (url !== '') {
if (loc === url) {
found = true
// activate
// activation
self.eventOn(element, true)
} else {
// deactivate
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/scroll/scroll.js
Expand Up @@ -209,7 +209,7 @@ class Scroll extends Xt.Toggle {
}
// direction
self.inverse = current > self.detail.trigger
// activate
// activation
Xt.dataStorage.set(el, self.componentNamespace + 'OnCount', currentOn)
Xt.dataStorage.set(el, self.componentNamespace + 'OnTot', currentsOn.length)
currentOn++
Expand Down
4 changes: 2 additions & 2 deletions src/extensions/slider/slider.js
Expand Up @@ -963,7 +963,7 @@ class Slider extends Xt.Toggle {
self.detail.dragRatio = Math.abs(self.detail.dragStart - self.detail.dragCurrent) / self.detail.draggerWidth
self.detail.dragRatioInverse = 1 - self.detail.dragRatio
self.direction = self.detail.dragStart - self.detail.dragCurrent < 0 ? -1 : 1
self.inverse = self.direction === -1
self.inverse = self.direction < 0
// drag position
if (self.initial) {
self.dragger.classList.add('transition-none')
Expand Down Expand Up @@ -991,7 +991,7 @@ class Slider extends Xt.Toggle {
const dragPosCurrent = self.detail.dragPosCurrent || 0
// prevent dragging animation
dragger.classList.remove('duration-none')
// activate or reset
// activation or reset
const dragDist = self.detail.dragPosReal - dragPosCurrent
const direction = Math.sign(dragDist)
const dragDistAbs = Math.abs(dragDist)
Expand Down
4 changes: 2 additions & 2 deletions src/gatsby/assets/scripts/demo.js
Expand Up @@ -384,7 +384,7 @@ const populateDemo = (container, i) => {
currentOffset = element.closest('.gatsby_demo').offsetTop
}
document.scrollingElement.scrollTo(0, document.scrollingElement.scrollTop - currentOffset + prevOffset)
// activate demo last
// activation demo last
const s = Xt.get('xt-toggle', demos[prev])
s.goToNum(-1)
}
Expand Down Expand Up @@ -424,7 +424,7 @@ const populateDemo = (container, i) => {
currentOffset = element.closest('.gatsby_demo').offsetTop
}
document.scrollingElement.scrollTo(0, document.scrollingElement.scrollTop - currentOffset + nextOffset)
// activate demo first
// activation demo first
const s = Xt.get('xt-toggle', demos[next])
s.goToNum(0)
}
Expand Down

0 comments on commit 9d0ef45

Please sign in to comment.