mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-13 06:02:24 +03:00
05163a77a8
* feat: add option for prepending (no)script to body * test: use browser getUrl * refactor: use pbody insteadn of pody * test: add prepend/append body generator test * test: add prepend body updater test * chore: remove typo
32 lines
791 B
JavaScript
32 lines
791 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(', ')))
|
|
}
|