Skip to content

Commit

Permalink
fix(window): fixed window usage
Browse files Browse the repository at this point in the history
closes #909, fixes #908, fixes #906
  • Loading branch information
mwe authored and valorkin committed Sep 2, 2016
1 parent 341dcf8 commit 0b7012a
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 26 deletions.
5 changes: 0 additions & 5 deletions components/dropdown/dropdown-toggle.directive.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import {
Directive, ElementRef, Host, HostBinding, HostListener, Input, OnInit
} from '@angular/core';
import { Type } from '@angular/core';

import { DropdownDirective } from './dropdown.directive';

/* tslint:disable */
const MouseEvent = (Type as any).MouseEvent as MouseEvent;
/* tslint:enable */

@Directive({
selector: '[dropdownToggle]',
exportAs: 'bs-dropdown-toggle'
Expand Down
6 changes: 3 additions & 3 deletions components/modal/modal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ import {
Output,
Renderer
} from '@angular/core';
import { Type } from '@angular/core';

import { ComponentsHelper } from '../utils/components-helper.service';
import { Utils } from '../utils/utils.class';
import { ModalBackdropComponent, ModalBackdropOptions } from './modal-backdrop.component';
import { ClassName, modalConfigDefaults, ModalOptions, Selector } from './modal-options.class';

import { window } from '../utils/facade/browser';

const TRANSITION_DURATION = 300;
const BACKDROP_TRANSITION_DURATION = 150;

Expand Down Expand Up @@ -302,8 +303,7 @@ export class ModalDirective implements AfterViewInit, OnDestroy {
/** Scroll bar tricks */

private checkScrollbar():void {
// this._isBodyOverflowing = document.body.clientWidth < window.innerWidth
this.isBodyOverflowing = this.document.body.clientWidth < (Type as any).innerWidth;
this.isBodyOverflowing = this.document.body.clientWidth < window.innerWidth;
this.scrollbarWidth = this.getScrollbarWidth();
}

Expand Down
5 changes: 3 additions & 2 deletions components/ng2-bootstrap-config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Type } from '@angular/core';
import { window } from './utils/facade/browser';

export enum Ng2BootstrapTheme {BS3 = 1, BS4 = 2}

export class Ng2BootstrapConfig {
private static _theme:Ng2BootstrapTheme;

public static get theme():Ng2BootstrapTheme {
// hack as for now
if (Type && (Type as any).__theme === 'bs4') {
if (window.__theme === 'bs4') {
return Ng2BootstrapTheme.BS4;
}
return (this._theme || Ng2BootstrapTheme.BS3);
Expand Down
5 changes: 0 additions & 5 deletions components/rating/rating.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import {
Component, EventEmitter, HostListener, Input, OnInit, Output, Self
} from '@angular/core';
import { Type } from '@angular/core';
import { ControlValueAccessor, NgModel } from '@angular/forms';

/* tslint:disable */
const KeyboardEvent = (Type as any).KeyboardEvent as KeyboardEvent;
/* tslint:enable */

@Component({
/* tslint:disable */
selector: 'rating[ngModel]',
Expand Down
2 changes: 1 addition & 1 deletion components/typeahead/typeahead-container.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export class TypeaheadContainerComponent {
this._active = value;
}

protected hightlight(item:any, query:string):string {
protected hightlight(item:any, query:any):string {
let itemStr:string = TypeaheadUtils.getValueFromObject(item, this._field);
let itemStrHelper:string = (this.parent.typeaheadLatinize
? TypeaheadUtils.latinize(itemStr)
Expand Down
4 changes: 0 additions & 4 deletions components/typeahead/typeahead.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/toArray';

import { Type } from '@angular/core';
import { ComponentsHelper } from '../utils/components-helper.service';
/* tslint:disable */
const KeyboardEvent = (Type as any).KeyboardEvent as KeyboardEvent;
/* tslint:enable */

@Directive({
/* tslint:disable */
Expand Down
7 changes: 5 additions & 2 deletions components/utils/components-helper.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export class ComponentsHelper {
providers?:ResolvedReflectiveProvider[]):ComponentRef<T> {
let componentFactory = this.componentFactoryResolver.resolveComponentFactory(ComponentClass);
let parentInjector = location.parentInjector;
let childInjector = providers !== undefined && providers.length > 0 ?
ReflectiveInjector.fromResolvedProviders(providers, parentInjector) : parentInjector;
let childInjector: Injector = parentInjector;
if (providers && providers.length > 0) {
childInjector = ReflectiveInjector.fromResolvedProviders(providers, parentInjector);
}

return location.createComponent(componentFactory, location.length, childInjector);
}

Expand Down
26 changes: 26 additions & 0 deletions components/utils/facade/browser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*tslint:disable */
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/

/**
* JS version of browser APIs. This library can only run in the browser.
*/
var win = typeof window !== 'undefined' && window || <any>{};

export {win as window};
export var document = win.document;
export var location = win.location;
export var gc = win['gc'] ? () => win['gc']() : (): any => null;
export var performance = win['performance'] ? win['performance'] : null;
export const Event = win['Event'];
export const MouseEvent = win['MouseEvent'];
export const KeyboardEvent = win['KeyboardEvent'];
export const EventTarget = win['EventTarget'];
export const History = win['History'];
export const Location = win['Location'];
export const EventListener = win['EventListener'];
8 changes: 4 additions & 4 deletions components/utils/utils.class.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { Type } from '@angular/core';
import { window } from './facade/browser';

export class Utils {
public static reflow(element:any):void {
public static reflow(element: any): void {
new Function('bs', 'return bs')(element.offsetHeight);
}

// source: https://github.com/jquery/jquery/blob/master/src/css/var/getStyles.js
public static getStyles(elem:any):any {
public static getStyles(elem: any): any {
// Support: IE <=11 only, Firefox <=30 (#15098, #14150)
// IE throws on elements created in popups
// FF meanwhile throws on frame elements through "defaultView.getComputedStyle"
let view = elem.ownerDocument.defaultView;

if (!view || !view.opener) {
view = Type;
view = window;
}

return view.getComputedStyle(elem);
Expand Down

0 comments on commit 0b7012a

Please sign in to comment.