Skip to content

Commit

Permalink
Add .editorconfig
Browse files Browse the repository at this point in the history
* Add .editorconfig to control some of IDE settings
* Change indent-size to 2 instead of 4
  • Loading branch information
DethAriel committed Aug 19, 2016
1 parent cc16531 commit 7319b2b
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 108 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
@@ -0,0 +1,8 @@
root = true

[*]
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .npmignore
Expand Up @@ -19,3 +19,4 @@ ng2-lint.json

# Other
.travis.yml
.editorconfig
56 changes: 28 additions & 28 deletions recaptcha/recaptcha-loader.service.ts
@@ -1,39 +1,39 @@
import {
Injectable,
Optional,
Injectable,
Optional,
} from '@angular/core';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { Observable } from 'rxjs/Observable';

@Injectable()
export class RecaptchaLoaderService {
/** @internal */
private _language: string;
/** @internal */
private static _ready: BehaviorSubject<ReCaptchaV2.ReCaptcha>;
public ready: Observable<ReCaptchaV2.ReCaptcha>;
/** @internal */
private _language: string;
/** @internal */
private static _ready: BehaviorSubject<ReCaptchaV2.ReCaptcha>;
public ready: Observable<ReCaptchaV2.ReCaptcha>;

constructor(@Optional() language?: string) {
this._language = language;
this._init();
this.ready = RecaptchaLoaderService._ready.asObservable();
}
constructor( @Optional() language?: string) {
this._language = language;
this._init();
this.ready = RecaptchaLoaderService._ready.asObservable();
}

/** @internal */
private _init() {
if (RecaptchaLoaderService._ready) {
return;
}
window.ng2recaptchaloaded = () => {
RecaptchaLoaderService._ready.next(grecaptcha);
};
RecaptchaLoaderService._ready = new BehaviorSubject<ReCaptchaV2.ReCaptcha>(null);
let head = <HTMLHeadElement> document.head;
let script = <HTMLScriptElement>document.createElement('script');
script.innerHTML = '';
script.src = 'https://www.google.com/recaptcha/api.js?render=explicit&onload=ng2recaptchaloaded' + (this._language ? '&hl=' + this._language : '');
script.async = true;
script.defer = true;
head.appendChild(script);
/** @internal */
private _init() {
if (RecaptchaLoaderService._ready) {
return;
}
window.ng2recaptchaloaded = () => {
RecaptchaLoaderService._ready.next(grecaptcha);
};
RecaptchaLoaderService._ready = new BehaviorSubject<ReCaptchaV2.ReCaptcha>(null);
let head = <HTMLHeadElement>document.head;
let script = <HTMLScriptElement>document.createElement('script');
script.innerHTML = '';
script.src = 'https://www.google.com/recaptcha/api.js?render=explicit&onload=ng2recaptchaloaded' + (this._language ? '&hl=' + this._language : '');
script.async = true;
script.defer = true;
head.appendChild(script);
}
}
28 changes: 14 additions & 14 deletions recaptcha/recaptcha-value-accessor.directive.ts
@@ -1,23 +1,23 @@
import {
Directive,
forwardRef,
Provider,
Directive,
forwardRef,
Provider,
} from '@angular/core';
import {
ControlValueAccessor,
NG_VALUE_ACCESSOR,
ControlValueAccessor,
NG_VALUE_ACCESSOR,
} from '@angular/forms';

import { RecaptchaComponent } from './recaptcha.component';

export const RECAPTCHA_VALUE_ACCESSOR = new Provider(NG_VALUE_ACCESSOR, {
multi: true,
useExisting: forwardRef(() => RecaptchaValueAccessor),
multi: true,
useExisting: forwardRef(() => RecaptchaValueAccessor),
});

@Directive({
selector: 'recaptcha',
host: {'(resolved)': 'onResolve($event)'},
host: { '(resolved)': 'onResolve($event)' },
providers: [RECAPTCHA_VALUE_ACCESSOR],
})
export class RecaptchaValueAccessor implements ControlValueAccessor {
Expand All @@ -37,12 +37,12 @@ export class RecaptchaValueAccessor implements ControlValueAccessor {
/** @internal */
// tslint:disable-next-line:no-unused-variable
private onResolve($event: string) {
if (this.onChange) {
this.onChange($event);
}
if (this.onTouched) {
this.onTouched();
}
if (this.onChange) {
this.onChange($event);
}
if (this.onTouched) {
this.onTouched();
}
}

registerOnChange(fn: (value: string) => void): void { this.onChange = fn; }
Expand Down
130 changes: 65 additions & 65 deletions recaptcha/recaptcha.component.ts
@@ -1,12 +1,12 @@
import {
AfterViewInit,
Component,
ElementRef,
EventEmitter,
Input,
NgZone,
OnDestroy,
Output,
AfterViewInit,
Component,
ElementRef,
EventEmitter,
Input,
NgZone,
OnDestroy,
Output,
} from '@angular/core';
import { Subscription } from 'rxjs/Subscription';

Expand All @@ -15,72 +15,72 @@ import { RecaptchaLoaderService } from './recaptcha-loader.service';
let nextId = 0;

@Component({
selector: 'recaptcha',
template: `<div [id]="id"></div>`,
selector: 'recaptcha',
template: `<div [id]="id"></div>`,
})
export class RecaptchaComponent implements AfterViewInit, OnDestroy {
@Input() id = `ngrecaptcha-${nextId++}`;
@Input() id = `ngrecaptcha-${nextId++}`;

@Input() siteKey: string;
@Input() theme: ReCaptchaV2.Theme;
@Input() type: ReCaptchaV2.Type;
@Input() size: ReCaptchaV2.Size;
@Input() tabIndex: number;
@Input() siteKey: string;
@Input() theme: ReCaptchaV2.Theme;
@Input() type: ReCaptchaV2.Type;
@Input() size: ReCaptchaV2.Size;
@Input() tabIndex: number;

@Output() resolved = new EventEmitter<string>();
@Output() resolved = new EventEmitter<string>();

/** @internal */
private subscription: Subscription;
/** @internal */
private widget: number;
/** @internal */
private _grecaptcha: ReCaptchaV2.ReCaptcha;
/** @internal */
private subscription: Subscription;
/** @internal */
private widget: number;
/** @internal */
private _grecaptcha: ReCaptchaV2.ReCaptcha;

constructor(
private _el: ElementRef,
private _loader: RecaptchaLoaderService,
private _zone: NgZone
) {
}
ngAfterViewInit() {
this.subscription = this._loader.ready.subscribe(grecaptcha => {
if (grecaptcha != null) {
this._grecaptcha = grecaptcha;
this._renderRecaptcha();
}
});
}
constructor(
private _el: ElementRef,
private _loader: RecaptchaLoaderService,
private _zone: NgZone
) {
}
ngAfterViewInit() {
this.subscription = this._loader.ready.subscribe(grecaptcha => {
if (grecaptcha != null) {
this._grecaptcha = grecaptcha;
this._renderRecaptcha();
}
});
}

ngOnDestroy() {
this.subscription.unsubscribe();
}
ngOnDestroy() {
this.subscription.unsubscribe();
}

reset() {
if (this.widget != null) {
this._grecaptcha.reset(this.widget);
this.resolved.emit(null);
}
reset() {
if (this.widget != null) {
this._grecaptcha.reset(this.widget);
this.resolved.emit(null);
}
}

/** @internal */
private captchaReponseCallback(response: string) {
this.resolved.emit(response);
}
/** @internal */
private captchaReponseCallback(response: string) {
this.resolved.emit(response);
}

/** @internal */
private _renderRecaptcha() {
this.widget = this._grecaptcha.render(this.id, {
callback: (response: string) => {
this._zone.run(() => this.captchaReponseCallback(response));
},
'expired-callback': () => {
this._zone.run(() => this.reset());
},
sitekey: this.siteKey,
size: this.size,
tabindex: this.tabIndex,
theme: this.theme,
type: this.type,
});
}
/** @internal */
private _renderRecaptcha() {
this.widget = this._grecaptcha.render(this.id, {
callback: (response: string) => {
this._zone.run(() => this.captchaReponseCallback(response));
},
'expired-callback': () => {
this._zone.run(() => this.reset());
},
sitekey: this.siteKey,
size: this.size,
tabindex: this.tabIndex,
theme: this.theme,
type: this.type,
});
}
}
2 changes: 1 addition & 1 deletion recaptcha/window.extend.ts
@@ -1,3 +1,3 @@
interface Window {
ng2recaptchaloaded: () => void;
ng2recaptchaloaded: () => void;
}

0 comments on commit 7319b2b

Please sign in to comment.