Skip to content

Commit

Permalink
fix: Various fixes in Quasar plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Jul 15, 2018
1 parent 9654766 commit f8dfc94
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 65 deletions.
4 changes: 4 additions & 0 deletions dev-umd/index.mat.umd.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@
<script>
// optional
window.quasarConfig = {
brand: {
primary: '#ff0000'
}
}
</script>
<script src="dist/umd/quasar.mat.umd.js"></script>
<script src="dist/umd/i18n.es.umd.min.js"></script>

<script>
Quasar.i18n.set(Quasar.i18n.es)
Quasar.plugins.Notify.create('Startup notification')

new Vue({
el: '#q-app',
Expand Down
9 changes: 2 additions & 7 deletions src/body.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ready } from './utils/dom.js'
import { setBrand } from './utils/colors.js'
import { isSSR } from './plugins/platform.js'

Expand Down Expand Up @@ -70,11 +69,7 @@ export default {
return
}

const init = cfg.brand && document.body
init && setColors(cfg.brand)
ready(() => {
!init && setColors(cfg.brand)
bodyInit($q.platform, cfg)
})
cfg.brand && setColors(cfg.brand)
bodyInit($q.platform, cfg)
}
}
9 changes: 3 additions & 6 deletions src/i18n.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import langEn from '../i18n/en-us.js'
import { isSSR } from './plugins/platform.js'
import { ready } from './utils/dom.js'

export default {
install ($q, queues, Vue, lang) {
Expand Down Expand Up @@ -30,11 +29,9 @@ export default {
lang.rtl = lang.rtl || false

if (!isSSR) {
ready(() => {
const el = document.documentElement
el.setAttribute('dir', lang.rtl ? 'rtl' : 'ltr')
el.setAttribute('lang', lang.lang)
})
const el = document.documentElement
el.setAttribute('dir', lang.rtl ? 'rtl' : 'ltr')
el.setAttribute('lang', lang.lang)
}

if (isSSR || $q.i18n) {
Expand Down
23 changes: 11 additions & 12 deletions src/plugins/addressbar-color.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Platform, { isSSR } from './platform.js'
import { ready } from '../utils/dom.js'
import { getBrand } from '../utils/colors.js'

let metaValue
Expand Down Expand Up @@ -41,31 +40,31 @@ function setColor (hexColor) {
metaTag.setAttribute('content', hexColor)

if (newTag) {
document.getElementsByTagName('HEAD')[0].appendChild(metaTag)
document.head.appendChild(metaTag)
}
}

export default {
install ({ $q, Vue }) {
install ({ $q, Vue, cfg }) {
this.set = !isSSR && Platform.is.mobile && (
Platform.is.cordova ||
Platform.is.winphone || Platform.is.safari ||
Platform.is.webkit || Platform.is.vivaldi
)
? hexColor => {
ready(() => {
const val = hexColor || getBrand('primary')
const val = hexColor || getBrand('primary')

if (Platform.is.cordova && window.StatusBar) {
window.StatusBar.backgroundColorByHexString(val)
}
else {
setColor(val)
}
})
if (Platform.is.cordova && window.StatusBar) {
window.StatusBar.backgroundColorByHexString(val)
}
else {
setColor(val)
}
}
: () => {}

$q.addressbarColor = this

cfg.addressbarColor && this.set(cfg.addressbarColor)
}
}
29 changes: 15 additions & 14 deletions src/plugins/meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ function changed (old, def) {
}
}

function bodyFilter (name) {
return !['class', 'style'].includes(name)
}

function htmlFilter (name) {
return !['lang', 'dir'].includes(name)
}

function diff (meta, other) {
let add = {}, remove = {}

Expand Down Expand Up @@ -89,10 +97,10 @@ function apply ({ add, remove }) {
remove.link.forEach(name => {
document.head.querySelector(`link[data-qmeta="${name}"]`).remove()
})
remove.htmlAttr.forEach(name => {
remove.htmlAttr.filter(htmlFilter).forEach(name => {
document.documentElement.removeAttribute(name)
})
remove.bodyAttr.forEach(name => {
remove.bodyAttr.filter(bodyFilter).forEach(name => {
document.body.removeAttribute(name)
})
}
Expand All @@ -109,27 +117,20 @@ function apply ({ add, remove }) {
document.head.appendChild(tag)
}
})
Object.keys(add.htmlAttr).forEach(name => {
Object.keys(add.htmlAttr).filter(htmlFilter).forEach(name => {
document.documentElement.setAttribute(name, add.htmlAttr[name] || '')
})
Object.keys(add.bodyAttr).forEach(name => {
Object.keys(add.bodyAttr).filter(bodyFilter).forEach(name => {
document.body.setAttribute(name, add.bodyAttr[name] || '')
})
}

function merge (main, { title, titleTemplate, ...other }) {
title && (main.title = title)
titleTemplate && (main.titleTemplate = titleTemplate)

extend(true, main, other)
}

function parseMeta (component, meta) {
if (component._inactive) { return }

const hasMeta = component.$options.meta
if (hasMeta) {
merge(meta, component.__qMeta)
extend(true, meta, component.__qMeta)
if (hasMeta.stopPropagation) { return }
}

Expand Down Expand Up @@ -200,12 +201,12 @@ function getServerMeta (app, html) {

const tokens = {
'%%Q_HTML_ATTRS%%': Object.keys(meta.htmlAttr)
.filter(name => !['lang', 'dir'].includes(name))
.filter(htmlFilter)
.map(getAttr(meta.htmlAttr))
.join(' '),
'%%Q_HEAD_TAGS%%': getHead(meta),
'%%Q_BODY_ATTRS%%': Object.keys(meta.bodyAttr)
.filter(name => name !== 'class')
.filter(bodyFilter)
.map(getAttr(meta.bodyAttr))
.join(' '),
'%%Q_BODY_TAGS%%': Object.keys(meta.noscript)
Expand Down
26 changes: 0 additions & 26 deletions src/plugins/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ const positionList = [
]

function init ({ Vue }) {
if (!document.body) {
ready(() => {
init.call(this, { Vue })
})
return
}

const node = document.createElement('div')
document.body.appendChild(node)

Expand Down Expand Up @@ -167,25 +160,6 @@ function init ({ Vue }) {
export default {
create (opts) {
if (isSSR) { return () => {} }

if (!document.body) {
let
cancelled = false,
cancelFn = () => {},
cancelFnWrapper = () => {
cancelled = true
cancelFn()
}

ready(() => {
if (!cancelled) {
cancelFn = this.create(opts)
}
})

return cancelFnWrapper
}

return this.__vm.add(opts)
},
setDefaults (opts) {
Expand Down

0 comments on commit f8dfc94

Please sign in to comment.