2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-05 23:12:25 +03:00

reuse same html tag reference

This commit is contained in:
Declan de Wet
2016-11-02 06:36:25 +02:00
parent 84f0d3057d
commit d033b8ed12
2 changed files with 7 additions and 5 deletions
+5 -3
View File
@@ -2,14 +2,16 @@ import updateTitleTag from './updateTitleTag'
import updateHtmlTagAttributes from './updateHtmlTagAttributes'
import { SERVER_RENDERED_ATTRIBUTE } from './constants'
if (typeof window !== 'undefined' && window !== null) {
var htmlTag = document.getElementsByTagName('html')[0]
}
/**
* Performs client-side updates when new meta info is received
*
* @param {Object} newInfo - the meta info to update to
*/
export default function updateClientMetaInfo (newInfo) {
const htmlTag = document.getElementsByTagName('html')[0]
// if this is not a server render, then update
if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
if (newInfo.title) {
@@ -17,7 +19,7 @@ export default function updateClientMetaInfo (newInfo) {
}
if (newInfo.htmlAttrs) {
updateHtmlTagAttributes(newInfo.htmlAttrs)
updateHtmlTagAttributes(newInfo.htmlAttrs, htmlTag)
}
} else {
htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
+2 -2
View File
@@ -4,9 +4,9 @@ import { VUE_META_ATTRIBUTE } from './constants'
* updates the document's html tag attributes
*
* @param {Object} attrs - the new document html attributes
* @param {HTMLElement} [tag=<html/>] - the <html> tag
*/
export default function updateHtmlTagAttributes (attrs) {
const tag = document.getElementsByTagName('html')[0]
export default function updateHtmlTagAttributes (attrs, tag = document.getElementsByTagName('html')[0]) {
const vueMetaAttrString = tag.getAttribute(VUE_META_ATTRIBUTE)
const vueMetaAttrs = vueMetaAttrString ? vueMetaAttrString.split(',') : []
const toRemove = [].concat(vueMetaAttrs)