Skip to content

Commit

Permalink
Bug fix remvoe container classes (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
dixso committed Jun 11, 2017
1 parent 1fc0fff commit de35599
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/custombox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ namespace Custombox {
throw new Error('You need to instantiate Custombox when the document is fully loaded');
}

const selector: any = document.querySelector(this.options.content.container);
const selector: Element = document.querySelector(this.options.content.container);
if (selector) {
this.element = selector;
} else if (!document.querySelector(`.${CB}-container`)) {
Expand All @@ -205,7 +205,8 @@ namespace Custombox {
this.element = document.querySelector(`.${CB}-container`);
}

this.addSimpleClass();
this.element.classList.add(`${CB}-container`);
this.element.classList.add(`${CB}-${this.options.content.effect}`);
this.element.style.animationDuration = `${this.options.content.speedIn}ms`;

if (Snippet.check(animationValues, this.options.content.effect)) {
Expand All @@ -230,6 +231,24 @@ namespace Custombox {
this.element.classList.remove(CLOSE);
this.element.classList.remove(`${CB}-${this.options.content.effect}`);
this.element.style.removeProperty('animation-duration');

const elements: NodeListOf<Element> = document.querySelectorAll(`.${CB}-content`);
const container: Element = document.querySelector(this.options.content.container);
if (!elements.length) {
if (container) {
const classes = this.element.className.split(' ');
for (let i = 0, t = classes.length; i < t; i++) {
if (classes[i].startsWith(`${CB}-`)) {
this.element.classList.remove(classes[i]);
}
}
} else {
const container = document.querySelector(`.${CB}-container`);

while (container.firstChild) container.parentNode.insertBefore(container.firstChild, container);
container.parentNode.removeChild(container);
}
}
}

// Private methods
Expand All @@ -243,11 +262,6 @@ namespace Custombox {
});
}

private addSimpleClass(): void {
this.element.classList.add(`${CB}-container`);
this.element.classList.add(`${CB}-${this.options.content.effect}`);
}

private setAnimation(action: string = FROM): void {
for (let i = 0, t = positionValues.length; i < t; i++) {
if (this.element.classList.contains(`${CB}-${positionValues[i]}`)) {
Expand Down

0 comments on commit de35599

Please sign in to comment.