Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { Directive } from '@angular/core'; |
| 17 | import { FnService } from './fw/util/fn.service'; |
| 18 | import { LogService } from './log.service'; |
| 19 | import { OnosService } from './onos.service'; |
| 20 | |
| 21 | /** |
| 22 | * ONOS GUI -- Detect Browser Directive |
| 23 | */ |
| 24 | @Directive({ |
| 25 | selector: '[onosDetectBrowser]' |
| 26 | }) |
| 27 | export 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'; |
| 40 | } else if (fs.isSafari()) { |
| 41 | browser = 'safari'; |
| 42 | } else if (fs.isFirefox()) { |
| 43 | browser = 'firefox'; |
| 44 | } |
| 45 | body.classList.add(browser); |
| 46 | // body.classed(browser, true); |
| 47 | this.onos.browser = browser; |
| 48 | |
| 49 | if (fs.isMobile()) { |
| 50 | body.classList.add('mobile'); |
| 51 | this.onos.mobile = true; |
| 52 | } |
| 53 | |
| 54 | this.log.debug('Detected browser is', fs.cap(browser)); |
| 55 | } |
| 56 | } |