mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-12 20:12:24 +03:00
0ab76ee16b
refactor: server injectors feat: add head, bodyPrepend, bodyAppend injectors refactor: create browserbuild through rollup replace (not separate entry)
36 lines
946 B
JavaScript
36 lines
946 B
JavaScript
import { toArray } from './array'
|
|
|
|
export function getTag (tags, tag) {
|
|
if (!tags[tag]) {
|
|
tags[tag] = document.getElementsByTagName(tag)[0]
|
|
}
|
|
|
|
return tags[tag]
|
|
}
|
|
|
|
export function getElementsKey ({ body, pbody }) {
|
|
return body
|
|
? 'body'
|
|
: (pbody ? 'pbody' : 'head')
|
|
}
|
|
|
|
export function queryElements (parentNode, { appId, attribute, type, tagIDKeyName }, attributes = {}) {
|
|
const queries = [
|
|
`${type}[${attribute}="${appId}"]`,
|
|
`${type}[data-${tagIDKeyName}]`
|
|
].map((query) => {
|
|
for (const key in attributes) {
|
|
const val = attributes[key]
|
|
const attributeValue = val && val !== true ? `="${val}"` : ''
|
|
query += `[data-${key}${attributeValue}]`
|
|
}
|
|
return query
|
|
})
|
|
|
|
return toArray(parentNode.querySelectorAll(queries.join(', ')))
|
|
}
|
|
|
|
export function removeElementsByAppId ({ attribute }, appId) {
|
|
toArray(document.querySelectorAll(`[${attribute}="${appId}"]`)).map(el => el.remove())
|
|
}
|