/** * * To do: add a descriptive name instead of the url for the css file * * * * * */ function SkinManager() { SkinManager.config = { USE_CUSTOM_COOKIES : true, AUTO_DEFAULT_SKIN : 0, LANGUAGE : 'en', DEFAULT_COOKIE_EXPIRATION_DAYS : 180, SKINS_SKINSET : 'skins.skinset', SKINS_PROPERTIES : 'skins.properties', SKINS_ACTIVE_SKIN : 'active_skin', SKINS_CUSTOM_SKINS : 'custom_skins', EN_SKIN_LOGO : 'Webskins:', EN_ADD_CUSTOM_SKIN : '-[ Add Custom Skin ]-', EN_REMOVE_CUSTOM_SKIN : 'remove skin', EN_CUSTOM_PROMPT : 'Enter URL of the CSS file:' }; this.activeSkin = ''; /** * Initializes the SkinManager object */ SkinManager.initialize_skins = function() { var skins = SkinManager.get_config( SkinManager.config["SKINS_SKINSET"] ); skins = skins.split(","); if (SkinManager.config["AUTO_DEFAULT_SKIN"] >= 0 && skins && skins.length > 0) { this.add_stylesheet( SkinManager.config["SKINS_ACTIVE_SKIN"], skins[SkinManager.config["AUTO_DEFAULT_SKIN"]] ); } }; /** * Get a configuration value -- either from the
section or * as a config variable. */ SkinManager.get_config = function(name) { var desc = document.getElementById( name ); if (!desc) return ''; desc = desc.getAttribute("description"); if (!desc) return ''; return desc; }; /** * Get a configuration value -- either from the section or * as a config variable. */ SkinManager.get_parsed_config = function(name) { var props = document.getElementById( SkinManager.config["SKINS_PROPERTIES"] ); var value = ''; if (props && props.getAttribute("description")) { value = SkinManager.parse_get(props.getAttribute("description"), name); if (!value) value = SkinManager.config["DEFAULT_" + name.toUpperCase()]; } else { value = SkinManager.config["DEFAULT_" + name.toUpperCase()]; } return value; }; /** * Adds a stylesheet to the document */ SkinManager.add_stylesheet = function(id, url) { try { var elt = document.createElement("link"); elt.id = id; elt.href = url; elt.rel = 'stylesheet'; elt.type = 'text/css'; document.getElementsByTagName("head")[0].appendChild( elt ); } catch(e) { } }; /** * Creates a skin dropdown list * Control the look via the class 'skin_dropdown' */ SkinManager.show = function() { document.write(""); document.write(""); document.write("" + SkinManager.config["EN_SKIN_LOGO"] + ""); document.write(""); document.write("'); document.write(""); document.write("" + SkinManager.config["EN_REMOVE_CUSTOM_SKIN"] + ""); document.write(""); document.write(""); }; /** * Generic cookie to get a cookie value */ SkinManager.get_cookie = function(name) { if (!name || name == '') return null; try { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(name + "="); if (c_start != -1) { c_start = c_start + name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start,c_end)); } } } catch(e) { return null; } return null; }; /** * Generic function to set a cookie. * @return true iff a cookie was set. */ SkinManager.set_cookie = function(name, value, expire_days) { try { var expirationDate = new Date(); expirationDate.setTime(expirationDate.getTime() + (expire_days*24*3600*1000)); document.cookie = name + "=" + escape(value) + ((expire_days==null) ? "" : "; expires=" + expirationDate); } catch(e) { return false; } return true; }; /** * Removes a skin from the dropdown menu (cookie) */ SkinManager.remove_skin = function(skin) { // remove skin from the dropdown var sdd = document.getElementById('_skin_dropdown'); if (!sdd) return; for (i=0; i