Skip to content

Commit

Permalink
Add linter
Browse files Browse the repository at this point in the history
  • Loading branch information
dixso committed Dec 27, 2016
1 parent 508c8b3 commit cfd084a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
4 changes: 2 additions & 2 deletions src/custombox.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
54 changes: 26 additions & 28 deletions src/custombox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,6 @@ namespace Custombox {
const together: Array<string> = ['corner', 'slidetogether', 'scale', 'door', 'push', 'contentscale'];
const perspective: Array<string> = ['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<Element> = 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<Element> = 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<string>, match: string): boolean {
return values.indexOf(match) > -1;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -470,7 +447,28 @@ namespace Custombox {
});
}

private close(): void {
static close(id?: string): void {
const event: Event = new Event(`${CB}:close`);
let elements: NodeListOf<Element> = 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<Element> = 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<void>[] = [
this.content.bind(CLOSE).then(() => this.content.remove()),
];
Expand Down Expand Up @@ -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);
}
}
Expand Down
11 changes: 11 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"rules": {
"no-console": [
true,
"log"
],
"semicolon": [
true
]
}
}

0 comments on commit cfd084a

Please sign in to comment.