blob: a65dec7d39ab532b39afa0dc1f48b757defa8bdd [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 */
Sean Condonfd6d11b2018-06-02 20:29:49 +010016import { Inject } from '@angular/core';
Sean Condon83fc39f2018-04-19 18:56:13 +010017import { Directive } from '@angular/core';
18import { FnService } from './fw/util/fn.service';
19import { LogService } from './log.service';
20import { OnosService } from './onos.service';
21
22/**
23 * ONOS GUI -- Detect Browser Directive
24 */
25@Directive({
26 selector: '[onosDetectBrowser]'
27})
28export class DetectBrowserDirective {
29 constructor(
30 private fs: FnService,
31 private log: LogService,
Sean Condonfd6d11b2018-06-02 20:29:49 +010032 private onos: OnosService,
Sean Condona00bf382018-06-23 07:54:01 +010033 @Inject('Window') private w: Window
Sean Condon83fc39f2018-04-19 18:56:13 +010034 ) {
Sean Condon83fc39f2018-04-19 18:56:13 +010035 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 {
Sean Condonfd6d11b2018-06-02 20:29:49 +010047 this.log.warn('Unknown browser. ',
48 'Vendor:', this.w.navigator.vendor,
49 'Agent:', this.w.navigator.userAgent);
50 return;
Sean Condon83fc39f2018-04-19 18:56:13 +010051 }
52 body.classList.add(browser);
53// body.classed(browser, true);
54 this.onos.browser = browser;
55
56 if (fs.isMobile()) {
57 body.classList.add('mobile');
58 this.onos.mobile = true;
59 }
60
61 this.log.debug('Detected browser is', fs.cap(browser));
62 }
63}