fix: parse browser detection lazily

This commit is contained in:
Misko Hevery 2016-05-01 22:09:58 -07:00
parent 2570b72158
commit cd52318f48
1 changed files with 9 additions and 6 deletions

View File

@ -3,16 +3,19 @@ import {getDOM} from '../src/dom/dom_adapter';
import {isPresent, isString, RegExpWrapper, StringWrapper, RegExp} from '../src/facade/lang'; import {isPresent, isString, RegExpWrapper, StringWrapper, RegExp} from '../src/facade/lang';
export class BrowserDetection { export class BrowserDetection {
private _ua: string; private _overrideUa: string;
private get _ua():string {
if (isPresent(this._overrideUa)) {
return this._overrideUa;
} else {
return isPresent(getDOM()) ? getDOM().getUserAgent() : '';
}
}
static setup() { browserDetection = new BrowserDetection(null); } static setup() { browserDetection = new BrowserDetection(null); }
constructor(ua: string) { constructor(ua: string) {
if (isPresent(ua)) { this._overrideUa = ua;
this._ua = ua;
} else {
this._ua = isPresent(getDOM()) ? getDOM().getUserAgent() : '';
}
} }
get isFirefox(): boolean { return this._ua.indexOf('Firefox') > -1; } get isFirefox(): boolean { return this._ua.indexOf('Firefox') > -1; }