blob: a7471f5f678c0511a9511f21ca1f1902bf1aea55 [file] [log] [blame]
Matteo Scandolo9d7940c2017-01-19 18:28:43 -08001import * as $ from 'jquery';
Matteo Scandolo4222a432017-01-23 12:18:40 -08002import {IXosComponentInjectorService} from '../services/helpers/component-injector.helpers';
Matteo Scandolo9d7940c2017-01-19 18:28:43 -08003
4export interface IXosSidePanelService {
5 open(): void;
6 close(): void;
7 injectComponent(componentName: string, attributes?: any, transclude?: string): void;
8}
9
10export class XosSidePanel implements IXosSidePanelService {
Matteo Scandolo4222a432017-01-23 12:18:40 -080011 static $inject = ['$rootScope', '$compile', 'XosComponentInjector'];
Matteo Scandolo9d7940c2017-01-19 18:28:43 -080012 public sidePanelElName = 'xos-side-panel';
13 public sidePanelElClass = '.xos-side-panel';
14 public sidePanelEl: JQuery;
15
16 constructor (
17 private $rootScope: ng.IRootScopeService,
Matteo Scandolo4222a432017-01-23 12:18:40 -080018 private $compile: ng.ICompileService,
19 private XosComponentInjector: IXosComponentInjectorService
Matteo Scandolo9d7940c2017-01-19 18:28:43 -080020 ) {
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 Scandolo4222a432017-01-23 12:18:40 -080033 this.XosComponentInjector.injectComponent('#side-panel-container', componentName, attributes, transclude, true);
Matteo Scandolo9d7940c2017-01-19 18:28:43 -080034 this.open();
35 }
Matteo Scandolo9d7940c2017-01-19 18:28:43 -080036}