forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressbarColor.js
More file actions
71 lines (59 loc) · 1.6 KB
/
AddressbarColor.js
File metadata and controls
71 lines (59 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import Platform, { isSSR } from './Platform.js'
import { noop } from '../utils/event.js'
import { getBrand } from '../utils/colors.js'
let metaValue
function getProp () {
if (Platform.is.winphone) {
return 'msapplication-navbutton-color'
}
if (Platform.is.safari) {
return 'apple-mobile-web-app-status-bar-style'
}
// Chrome, Firefox OS, Opera, Vivaldi
return 'theme-color'
}
function getMetaTag (v) {
const els = document.getElementsByTagName('META')
for (const i in els) {
if (els[i].name === v) {
return els[i]
}
}
}
function setColor (hexColor) {
if (metaValue === void 0) {
// cache it
metaValue = getProp()
}
let metaTag = getMetaTag(metaValue)
const newTag = metaTag === void 0
if (newTag) {
metaTag = document.createElement('meta')
metaTag.setAttribute('name', metaValue)
}
metaTag.setAttribute('content', hexColor)
if (newTag) {
document.head.appendChild(metaTag)
}
}
export default {
install ({ $q, cfg }) {
this.set = isSSR === false && Platform.is.mobile === true && (
Platform.is.nativeMobile === true ||
Platform.is.winphone === true || Platform.is.safari === true ||
Platform.is.webkit === true || Platform.is.vivaldi === true
)
? hexColor => {
const val = hexColor || getBrand('primary')
if (Platform.is.nativeMobile === true && window.StatusBar) {
window.StatusBar.backgroundColorByHexString(val)
}
else {
setColor(val)
}
}
: noop
$q.addressbarColor = this
cfg.addressbarColor && this.set(cfg.addressbarColor)
}
}