diff --git a/index.html b/index.html index 9b52fb85..28b4d222 100644 --- a/index.html +++ b/index.html @@ -2,30 +2,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - ascribe diff --git a/js/components/header.js b/js/components/header.js index bac85d70..042d2b1c 100644 --- a/js/components/header.js +++ b/js/components/header.js @@ -29,6 +29,8 @@ import NavRoutesLinks from './nav_routes_links'; import { mergeOptions } from '../utils/general_utils'; import { getLangText } from '../utils/lang_utils'; +import {constructHead} from '../utils/head_setter'; + let Header = React.createClass({ propTypes: { @@ -61,11 +63,17 @@ let Header = React.createClass({ WhitelabelStore.unlisten(this.onChange); }, - getLogo(){ + getLogo() { let { whitelabel } = this.state; + + if (whitelabel.head) { + constructHead(whitelabel.head); + } + if (whitelabel.subdomain && whitelabel.subdomain !== 'www' && whitelabel.logo){ return (); } + return ( diff --git a/js/utils/head_setter.js b/js/utils/head_setter.js new file mode 100644 index 00000000..6ca2c9b0 --- /dev/null +++ b/js/utils/head_setter.js @@ -0,0 +1,37 @@ +'use strict'; + +// 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 + +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); + continue; + } + } + if (oldElement) { + head.removeChild(oldElement); + } + head.appendChild(element); +} + +// 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]); + } + } +}