Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 1 | import * as $ from 'jquery'; |
Matteo Scandolo | 4222a43 | 2017-01-23 12:18:40 -0800 | [diff] [blame] | 2 | import {IXosComponentInjectorService} from '../services/helpers/component-injector.helpers'; |
Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 3 | |
| 4 | export interface IXosSidePanelService { |
| 5 | open(): void; |
| 6 | close(): void; |
| 7 | injectComponent(componentName: string, attributes?: any, transclude?: string): void; |
| 8 | } |
| 9 | |
| 10 | export class XosSidePanel implements IXosSidePanelService { |
Matteo Scandolo | 4222a43 | 2017-01-23 12:18:40 -0800 | [diff] [blame] | 11 | static $inject = ['$rootScope', '$compile', 'XosComponentInjector']; |
Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 12 | public sidePanelElName = 'xos-side-panel'; |
| 13 | public sidePanelElClass = '.xos-side-panel'; |
| 14 | public sidePanelEl: JQuery; |
| 15 | |
| 16 | constructor ( |
| 17 | private $rootScope: ng.IRootScopeService, |
Matteo Scandolo | 4222a43 | 2017-01-23 12:18:40 -0800 | [diff] [blame] | 18 | private $compile: ng.ICompileService, |
| 19 | private XosComponentInjector: IXosComponentInjectorService |
Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 20 | ) { |
| 21 | this.sidePanelEl = $(`${this.sidePanelElName} > ${this.sidePanelElClass}`); |
| 22 | } |
| 23 | |
| 24 | public open() { |
| 25 | $(`${this.sidePanelElName} > ${this.sidePanelElClass}`).addClass('open'); |
| 26 | }; |
| 27 | |
| 28 | public close() { |
| 29 | $(`${this.sidePanelElName} > ${this.sidePanelElClass}`).removeClass('open'); |
| 30 | }; |
| 31 | |
| 32 | public injectComponent(componentName: string, attributes?: any, transclude?: string) { |
Matteo Scandolo | 4222a43 | 2017-01-23 12:18:40 -0800 | [diff] [blame] | 33 | this.XosComponentInjector.injectComponent('#side-panel-container', componentName, attributes, transclude, true); |
Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 34 | this.open(); |
| 35 | } |
Matteo Scandolo | 9d7940c | 2017-01-19 18:28:43 -0800 | [diff] [blame] | 36 | } |