import $ from 'jquery'; import { Observable, fromEvent } from 'rxjs'; export class WindowService { private static $window: JQuery = $( window ); public static onLoad(): Observable { return fromEvent( window, 'load' ); } public static onResize(): Observable { return fromEvent( window, 'resize'); } public static onScroll(): Observable { return fromEvent( window, 'scroll'); } public static getWindow(): JQuery { return WindowService.$window; } public static getScrollY() { return (window.pageYOffset || document.documentElement.scrollTop) - (document.documentElement.clientTop || 0); } public static getWidth(): number { return WindowService.$window.width(); } public static getHeight(): number { return WindowService.$window.height(); } public static getWindowEl(): Window { return WindowService.$window[0]; } public static getOrientation(): string { return WindowService.getWidth() > WindowService.getHeight() ? 'landscape' : 'portrait'; } }