egroupware_official/etemplate/js/et2_widget_styles.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

/**
* eGroupWare eTemplate2 - JS widget class containing styles
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Andreas Stöckel
* @copyright Stylite 2011
* @version $Id$
*/
"use strict";
/*egw:uses
et2_core_widget;
*/
/**
* Function which appends the encapsulated style data to the head tag of the
* page.
*
* TODO: The style data could be parsed for rules and appended using the JS
* stylesheet interface, allowing the style only to modifiy nodes of the current
* template.
*/
var et2_styles = et2_widget.extend({
init: function() {
this._super.apply(this, arguments);
// Allow no child widgets
this.supportedWidgetClasses = [];
// Create the style node and append it to the head node
this.styleNode = document.createElement("style");
this.styleNode.setAttribute("type", "text/css");
(document.getElementsByTagName("head")[0]).appendChild(this.styleNode);
},
destroy: function() {
this._super.apply(this, arguments);
// Remove the style node again and delete any reference to it
(document.getElementsByTagName("head")[0]).removeChild(this.styleNode);
this.styleNode = null;
},
loadContent: function(_content) {
if (this.styleNode.styleSheet)
{
// IE
this.styleNode.styleSheet.cssText += _content;
}
else
{
this.styleNode.appendChild(document.createTextNode(_content));
}
}
});
et2_register_widget(et2_styles, ["styles"]);