2015-10-13 16:42:40 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
2015-10-20 11:35:32 +02:00
|
|
|
* Set the title in the browser window.
|
2015-10-13 16:42:40 +02:00
|
|
|
*/
|
|
|
|
export function setDocumentTitle(title) {
|
2015-10-20 11:35:32 +02:00
|
|
|
document.title = title;
|
2015-10-13 16:42:40 +02:00
|
|
|
}
|
2015-11-03 10:39:01 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} elementType: string, is the type of the element, such as link, meta, etc.
|
|
|
|
* @param {string} elementId id of the element
|
|
|
|
* @param {object} elementAttributes: hash table containing the attributes of the relevant element
|
|
|
|
*/
|
|
|
|
function constructHeadElement(elementType, elementId, elementAttributes) {
|
|
|
|
let head = (document.head || document.getElementsByTagName('head')[0]);
|
|
|
|
let element = document.createElement(elementType);
|
|
|
|
let oldElement = document.getElementById(elementId);
|
|
|
|
element.setAttribute('id', elementId);
|
|
|
|
for (let k in elementAttributes){
|
|
|
|
try {
|
|
|
|
element.setAttribute(k, elementAttributes[k]);
|
|
|
|
}
|
|
|
|
catch(e){
|
|
|
|
console.warn(e.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (oldElement) {
|
|
|
|
head.removeChild(oldElement);
|
|
|
|
}
|
|
|
|
head.appendChild(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accepts a dictionary of dictionaries which comprises a part or all of html head part
|
|
|
|
* @param {object} headObject {link : {id1: {rel: ... }}}
|
|
|
|
*/
|
|
|
|
export function constructHead(headObject){
|
|
|
|
for (let k in headObject){
|
|
|
|
let favicons = headObject[k];
|
|
|
|
for (let f in favicons){
|
|
|
|
constructHeadElement(k, f, favicons[f]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|