/** * The main namespace. **/ var Vn = { Config: {} ,jsIncludes: {} ,cssIncludes: {} ,customTags: {} ,head: document.getElementsByTagName ('head')[0] ,isMobileCached: null /** * Includes a new CSS stylesheet in the current document, if the stylesheet * its already included, does nothing. * * @param {string} fileName The stylesheet file name **/ ,includeCss: function (fileName) { var cssData = this.cssIncludes[fileName]; if (!cssData) { var link = document.createElement ('link'); link.rel = 'stylesheet'; link.type = 'text/css'; link.href = fileName +'?'+ Vn.Cookie.get ('hedera_version'); this.head.appendChild (link); this.cssIncludes[fileName] = { included: true ,link: link }; } else if (!cssData.included) { this.head.appendChild (cssData.link); cssData.included = true; } } /** * Excludes a CSS stylesheet from the current document. * * @param {string} fileName The stylesheet file name **/ ,excludeCss: function (fileName) { var cssData = this.cssIncludes[fileName]; if (cssData && cssData.included) { this.head.removeChild (cssData.link); cssData.included = false; } } /** * Includes a new Javascript in the current document, if the script * its already included, does nothing. * * @param {string} fileName The script file name * @param {Function} callback The function to call when script is * downloaded and included **/ ,includeJs: function (fileName, callback, skipVersion) { var includeData = this.jsIncludes[fileName]; if (includeData === undefined) { var src = fileName; if (!skipVersion) src = src +'?'+ Vn.Cookie.get ('hedera_version'); var script = document.createElement ('script'); script.type = 'text/javascript'; script.src = src; includeData = { script: script ,callbacks: [] ,loaded: false }; if (callback) includeData.callbacks.push (callback); script.onload = this.jsLoaded.bind (this, includeData); script.onreadystatechange = this.jsStateChanged.bind (this, includeData); this.jsIncludes[fileName] = includeData; this.head.appendChild (script); } else if (callback) { if (includeData.loaded) callback (); else includeData.callbacks.push (callback); } } ,jsStateChanged: function (includeData) { if (includeData.script.readyState == 'complete') this.jsLoaded (includeData); } ,jsLoaded: function (includeData) { if (includeData.loaded) return; for (var i = 0; i < includeData.callbacks.length; i++) includeData.callbacks[i] (); includeData.loaded = true; includeData.callbacks = null; } ,isMobile: function () { if (this.isMobileCached === null) this.isMobileCached = navigator.userAgent.match (/Android/i) || navigator.userAgent.match (/webOS/i) || navigator.userAgent.match (/iPhone/i) || navigator.userAgent.match (/iPad/i) || navigator.userAgent.match (/iPod/i) || navigator.userAgent.match (/BlackBerry/i) || navigator.userAgent.match (/Windows Phone/i); return this.isMobileCached; } ,get: function (id) { return document.getElementById (id); } };