diff --git a/ng2-material/all.ts b/ng2-material/all.ts index 19273f4c..d3fd90c6 100644 --- a/ng2-material/all.ts +++ b/ng2-material/all.ts @@ -74,7 +74,7 @@ export * from './components/tabs/tabs'; export * from './core/util/media'; -import {ViewportHelper, BrowserViewportHelper} from "./core/util/viewport"; +import {ViewportHelper, BrowserViewportHelper, NodeViewportHelper} from "./core/util/viewport"; import {provide} from "angular2/core"; export * from './core/util/viewport'; export * from './core/util/animate'; @@ -111,6 +111,7 @@ export const MATERIAL_DIRECTIVES: Type[] = CONST_EXPR([ * Material Design component providers for use in a Node.JS environment. */ export const MATERIAL_NODE_PROVIDERS: any[] = CONST_EXPR([ + provide(ViewportHelper, {useClass: NodeViewportHelper}), MdDialog, Media, SidenavService, diff --git a/ng2-material/components/backdrop/backdrop.ts b/ng2-material/components/backdrop/backdrop.ts index 8b2cb046..0e6d5008 100644 --- a/ng2-material/components/backdrop/backdrop.ts +++ b/ng2-material/components/backdrop/backdrop.ts @@ -1,6 +1,7 @@ import {Animate} from "../../core/util/animate"; import {ElementRef, ViewEncapsulation, Component, Input, Output, EventEmitter} from "angular2/core"; import {DOM} from "angular2/src/platform/dom/dom_adapter"; +import {ViewportHelper} from "../../core/util/viewport"; /** * An overlay for content on the page. @@ -55,7 +56,8 @@ export class MdBackdrop { @Output() onShown: EventEmitter = new EventEmitter(); - constructor(public element: ElementRef) { + constructor(public element: ElementRef, public viewport: ViewportHelper) { + this._body = DOM.querySelector(viewport.getDocumentNativeElement(), 'body'); } /** @@ -87,7 +89,7 @@ export class MdBackdrop { private _visible: boolean = false; private _transitioning: boolean = false; private _previousOverflow: string = null; - private _body: HTMLBodyElement = DOM.query('body'); + private _body: HTMLElement = null; onClick() { if (this.clickClose && !this._transitioning && this.visible) { diff --git a/ng2-material/components/sidenav/sidenav.ts b/ng2-material/components/sidenav/sidenav.ts index 606e7392..0336e80d 100644 --- a/ng2-material/components/sidenav/sidenav.ts +++ b/ng2-material/components/sidenav/sidenav.ts @@ -22,6 +22,7 @@ import {MdBackdrop} from "../backdrop/backdrop"; import {CONST} from "angular2/src/facade/lang"; import {SidenavService} from "./sidenav_service"; import {TimerWrapper} from "angular2/src/facade/async"; +import {ViewportHelper} from "../../core/util/viewport"; @CONST() @@ -129,12 +130,13 @@ export class MdSidenav extends MdBackdrop implements OnInit, OnDestroy { transitionAddClass = false; constructor(public element: ElementRef, + public viewport: ViewportHelper, @Inject(forwardRef(() => SidenavService)) public service: SidenavService, public renderer: Renderer, @Optional() @SkipSelf() @Host() @Inject(forwardRef(() => MdSidenavContainer)) public container: MdSidenavContainer) { - super(element); + super(element, viewport); this.renderer.setElementClass(this.element.nativeElement, this.transitionClass, !this.transitionAddClass); } diff --git a/ng2-material/core/util/viewport.ts b/ng2-material/core/util/viewport.ts index 6200514d..f6c6f218 100644 --- a/ng2-material/core/util/viewport.ts +++ b/ng2-material/core/util/viewport.ts @@ -17,15 +17,20 @@ export abstract class ViewportHelper { abstract matchMedia(query: string): ViewportMediaMatch; - abstract scrollTop():number; - - abstract requestFrame(fn:(elapsed?:number)=>any); + abstract scrollTop(): number; + abstract getDocumentNativeElement(): any; + + abstract requestFrame(fn: (elapsed?: number)=>any); } export class BrowserViewportHelper extends ViewportHelper { + getDocumentNativeElement(): any { + return window.document; + } requestFrame(fn: (elapsed?: number)=>any) { return window.requestAnimationFrame(fn); } + matchMedia(query: string): ViewportMediaMatch { return window.matchMedia(query); } @@ -35,3 +40,34 @@ export class BrowserViewportHelper extends ViewportHelper { } } + +export class NodeViewportMediaMatch implements ViewportMediaMatch { + constructor(public matches: boolean = false, public media: string = '') { + + } + + addListener(listener: MediaQueryListListener): void { + } + + removeListener(listener: MediaQueryListListener): void { + } + +} + +export class NodeViewportHelper extends ViewportHelper { + getDocumentNativeElement(): any { + return {}; + } + requestFrame(fn: (elapsed?: number)=>any) { + return process.nextTick(fn); + } + + matchMedia(query: string): ViewportMediaMatch { + return new NodeViewportMediaMatch(false, query); + } + + scrollTop(): number { + return 0; + } + +} diff --git a/package.json b/package.json index ab6cfb4a..9c1efb75 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ng2-material", "version": "0.3.4", "description": "", - "main": "all.ts", + "main": "dist/ng2-material.js", "repository": { "type": "git", "url": "git@github.com:justindujardin/ng2-material.git" diff --git a/tsconfig.build.json b/tsconfig.build.json index 8d04c771..cb3ef8d6 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -60,7 +60,6 @@ "ng2-material/core/util/util.ts", "ng2-material/core/util/viewport.ts", "ng2-material/webpack_all.ts", - "ng2-material/webpack_scripts.ts", "ng2-material/webpack_styles.ts" ] } \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index b7c7764f..568fba59 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,14 +1,10 @@ { - "version": "1.6.0", "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, "target": "es5", "module": "commonjs", - "declaration": false, - "noImplicitAny": false, "removeComments": true, - "noLib": false, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "sourceMap": true }, "filesGlob": [