Skip to content

Commit

Permalink
Bug fix on reopen a modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dixso committed Jan 14, 2017
1 parent 1e9e5c4 commit 0f6c059
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
9 changes: 3 additions & 6 deletions src/custombox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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) => {
Expand Down
41 changes: 23 additions & 18 deletions src/custombox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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<Element> = document.querySelectorAll(`.${CB}-content`);
Expand Down

0 comments on commit 0f6c059

Please sign in to comment.