diff --git a/src/custombox.spec.ts b/src/custombox.spec.ts index 9f368a5..eb86acb 100644 --- a/src/custombox.spec.ts +++ b/src/custombox.spec.ts @@ -981,7 +981,7 @@ describe('Custombox', () => { }, 200); }); - it('should show loader when the overlay is disabled', (done) => { + it('should show loader when the overlay is disabled', () => { new (Custombox as any).modal({ content: { effect: 'fadein', @@ -993,12 +993,9 @@ describe('Custombox', () => { loader: { active: true } - }); + }).open(); - setTimeout(() => { - expect(hasElement('.custombox-loader')).toBe(true); - done(); - }, 200); + expect(hasElement('.custombox-loader')).toBe(true); }); it(`shouldn't show loader`, (done) => { diff --git a/src/custombox.ts b/src/custombox.ts index a3aa43e..fcf8d90 100644 --- a/src/custombox.ts +++ b/src/custombox.ts @@ -484,28 +484,12 @@ namespace Custombox { constructor(options: OptionsSchema) { this.options = new Options(options); - - // Create loader - if (this.options.loader.active) { - this.loader = new Loader(this.options); - } - - // Create container - if (Snippet.check(containerValues, this.options.content.effect)) { - this.container = new Container(this.options); - } - - // Create overlay - if (this.options.overlay.active) { - this.overlay = new Overlay(this.options); - } - - // Create content - this.content = new Content(this.options); } // Public methods open(): void { + this.build(); + if (this.options.loader.active) { this.loader.show(); } @@ -556,6 +540,27 @@ namespace Custombox { }); } + // Private methods + build(): void { + // Create loader + if (this.options.loader.active) { + this.loader = new Loader(this.options); + } + + // Create container + if (Snippet.check(containerValues, this.options.content.effect)) { + this.container = new Container(this.options); + } + + // Create overlay + if (this.options.overlay.active) { + this.overlay = new Overlay(this.options); + } + + // Create content + this.content = new Content(this.options); + } + static close(id?: string): void { const event: Event = new Event(`${CB}:close`); let elements: NodeListOf = document.querySelectorAll(`.${CB}-content`);