From cfd084a34c0a33879d901ff1d22fa7575d971531 Mon Sep 17 00:00:00 2001 From: dixso Date: Tue, 27 Dec 2016 07:31:33 +0100 Subject: [PATCH] Add linter --- package.json | 7 ++++-- src/custombox.spec.ts | 4 ++-- src/custombox.ts | 54 +++++++++++++++++++++---------------------- tslint.json | 11 +++++++++ 4 files changed, 44 insertions(+), 32 deletions(-) create mode 100644 tslint.json diff --git a/package.json b/package.json index 7caeb03..7767d96 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,10 @@ "main": "Gruntfile.js", "scripts": { "start": "grunt browserSync", - "test": "karma start karma.conf.js --single-run", - "watch:test": "karma start karma.conf.js" + "test": "npm run lint && karma start karma.conf.js --single-run", + "watch:test": "karma start karma.conf.js", + "lint": "npm run tslint \"src/**/*.ts\"", + "tslint": "tslint" }, "repository": { "type": "git", @@ -35,6 +37,7 @@ "karma-typescript": "^2.1.5", "matchdep": "^1.0.1", "time-grunt": "^1.4.0", + "tslint": "^4.2.0", "typescript": "^2.1.4" } } diff --git a/src/custombox.spec.ts b/src/custombox.spec.ts index 3c68f85..4adc06e 100644 --- a/src/custombox.spec.ts +++ b/src/custombox.spec.ts @@ -69,7 +69,7 @@ describe('Custombox', () => { }); setTimeout(() => { - Custombox.action.close(); + Custombox.modal.close(); expect(haveElement('.custombox-open')).toBe(false); expect(haveElement('.custombox-close')).toBe(true); done(); @@ -92,7 +92,7 @@ describe('Custombox', () => { setTimeout(() => { expect(haveElement(`#custombox-${ID}`)).toBe(true); - Custombox.action.close(ID); + Custombox.modal.close(ID); expect(haveElement('.custombox-close')).toBe(true); done(); }, 200); diff --git a/src/custombox.ts b/src/custombox.ts index dcf4525..83e0bc4 100644 --- a/src/custombox.ts +++ b/src/custombox.ts @@ -51,29 +51,6 @@ namespace Custombox { const together: Array = ['corner', 'slidetogether', 'scale', 'door', 'push', 'contentscale']; const perspective: Array = ['fall', 'sidefall', 'flip', 'sign', 'slit', 'letmein', 'makeway', 'slip']; - export class action { - static close(id?: string): void { - const event: Event = new Event(`${CB}:close`); - let elements: NodeListOf = document.querySelectorAll(`.${CB}-content`); - - if (id) { - elements = document.querySelectorAll(`#${CB}-${id}`); - } - - elements[elements.length - 1].dispatchEvent(event); - } - - static closeAll(): void { - const event: Event = new Event(`${CB}:close`); - const elements: NodeListOf = document.querySelectorAll(`.${CB}-content`); - const t = elements.length; - - for (let i = 0; i < t; i++) { - elements[i].dispatchEvent(event); - } - } - } - class Snippet { static check(values: Array, match: string): boolean { return values.indexOf(match) > -1; @@ -414,9 +391,9 @@ namespace Custombox { private scroll: Scroll; private action: EventListenerOrEventListenerObject = (event: KeyboardEvent) => { if (event.keyCode === 27) { - this.close(); + this._close(); } - }; + } constructor(options: OptionsSchema) { this.options = new Options(options); @@ -470,7 +447,28 @@ namespace Custombox { }); } - private close(): void { + static close(id?: string): void { + const event: Event = new Event(`${CB}:close`); + let elements: NodeListOf = document.querySelectorAll(`.${CB}-content`); + + if (id) { + elements = document.querySelectorAll(`#${CB}-${id}`); + } + + elements[elements.length - 1].dispatchEvent(event); + } + + static closeAll(): void { + const event: Event = new Event(`${CB}:close`); + const elements: NodeListOf = document.querySelectorAll(`.${CB}-content`); + const t = elements.length; + + for (let i = 0; i < t; i++) { + elements[i].dispatchEvent(event); + } + } + + private _close(): void { let close: Promise[] = [ this.content.bind(CLOSE).then(() => this.content.remove()), ]; @@ -528,12 +526,12 @@ namespace Custombox { this.content.element.addEventListener('click', (event: Event) => { if (event.target === this.content.element) { - this.close(); + this._close(); } }, true); this.content.element.addEventListener(`${CB}:close`, () => { - this.close(); + this._close(); }, true); } } diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..28d35a5 --- /dev/null +++ b/tslint.json @@ -0,0 +1,11 @@ +{ + "rules": { + "no-console": [ + true, + "log" + ], + "semicolon": [ + true + ] + } +} \ No newline at end of file