2015-10-06 17:24:53 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-06 17:26:30 +02:00
|
|
|
// elementType: string, is the type of the element, such as link, meta, etc.
|
|
|
|
// elementId id of the element
|
|
|
|
// elementAttributes: hash table containing the attributes of the relevant element
|
2015-10-06 17:24:53 +02:00
|
|
|
|
2015-10-08 12:04:40 +02:00
|
|
|
function constructHeadElement(elementType, elementId, elementAttributes) {
|
2015-10-08 11:28:41 +02:00
|
|
|
let head = (document.head || document.getElementsByTagName('head')[0]);
|
|
|
|
let element = document.createElement(elementType);
|
|
|
|
let oldElement = document.getElementById(elementId);
|
2015-10-09 10:14:59 +02:00
|
|
|
element.setAttribute('id', elementId);
|
2015-10-08 11:28:41 +02:00
|
|
|
for (let k in elementAttributes){
|
|
|
|
try {
|
|
|
|
element.setAttribute(k, elementAttributes[k]);
|
|
|
|
}
|
|
|
|
catch(e){
|
|
|
|
console.log(e.message);
|
|
|
|
console.log(elementAttributes);
|
|
|
|
continue;
|
2015-10-06 17:24:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldElement) {
|
|
|
|
head.removeChild(oldElement);
|
|
|
|
}
|
|
|
|
head.appendChild(element);
|
2015-10-08 12:04:40 +02:00
|
|
|
}
|
2015-10-06 17:24:53 +02:00
|
|
|
|
|
|
|
// Accepts a dictionary of dictionaries which comprises a part or all of html head part
|
|
|
|
// {link : {id1: {rel: ... }}}
|
|
|
|
// traverses a tree of depth 3 (no backtracking)
|
|
|
|
export function constructHead(headObject){
|
|
|
|
for (let k in headObject){
|
|
|
|
let favicons = headObject[k];
|
|
|
|
for (let f in favicons){
|
|
|
|
constructHeadElement(k, f, favicons[f]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-07 15:47:54 +02:00
|
|
|
|
|
|
|
export function setTitle(titleString){
|
|
|
|
document.title = titleString;
|
|
|
|
}
|