blob: b69ca3959e7a25362d9af418b0ef5ce5b370f57d [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
2 * Copyright 2014-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Directive } from '@angular/core';
17import { FnService } from './fw/util/fn.service';
18import { LogService } from './log.service';
19import { OnosService } from './onos.service';
20
21/**
22 * ONOS GUI -- Detect Browser Directive
23 */
24@Directive({
25 selector: '[onosDetectBrowser]'
26})
27export class DetectBrowserDirective {
28 constructor(
29 private fs: FnService,
30 private log: LogService,
31 private onos: OnosService
32 ) {
33 log.debug('DetectBrowserDirective constructed');
34
35 const body: HTMLBodyElement = document.getElementsByTagName('body')[0];
36// let body = d3.select('body');
37 let browser = '';
38 if (fs.isChrome()) {
39 browser = 'chrome';
Sean Condon49e15be2018-05-16 16:58:29 +010040 } else if (fs.isChromeHeadless()) {
41 browser = 'chromeheadless';
Sean Condon83fc39f2018-04-19 18:56:13 +010042 } else if (fs.isSafari()) {
43 browser = 'safari';
44 } else if (fs.isFirefox()) {
45 browser = 'firefox';
Sean Condon49e15be2018-05-16 16:58:29 +010046 } else {
47 this.log.warn('Unknown browser:', window.navigator.vendor);
Sean Condon83fc39f2018-04-19 18:56:13 +010048 }
49 body.classList.add(browser);
50// body.classed(browser, true);
51 this.onos.browser = browser;
52
53 if (fs.isMobile()) {
54 body.classList.add('mobile');
55 this.onos.mobile = true;
56 }
57
58 this.log.debug('Detected browser is', fs.cap(browser));
59 }
60}