- return {
- <div id="method-Ext.util.CSS-createStyleSheet"></div>/**
- * Creates a stylesheet from a text blob of rules.
- * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
- * @param {String} cssText The text containing the css rules
- * @param {String} id An id to add to the stylesheet for later removal
- * @return {StyleSheet}
- */
- createStyleSheet : function(cssText, id){
- var ss;
- var head = doc.getElementsByTagName("head")[0];
- var rules = doc.createElement("style");
- rules.setAttribute("type", "text/css");
- if(id){
- rules.setAttribute("id", id);
- }
- if(Ext.isIE){
- head.appendChild(rules);
- ss = rules.styleSheet;
- ss.cssText = cssText;
- }else{
- try{
- rules.appendChild(doc.createTextNode(cssText));
- }catch(e){
- rules.cssText = cssText;
- }
- head.appendChild(rules);
- ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
- }
- this.cacheStyleSheet(ss);
- return ss;
- },
+ return {
+
+ singleton: true,
+
+ constructor: function() {
+ this.rules = {};
+ this.initialized = false;
+ },
+
+<span id='Ext-util.CSS-method-createStyleSheet'> /**
+</span> * Creates a stylesheet from a text blob of rules.
+ * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
+ * @param {String} cssText The text containing the css rules
+ * @param {String} id An id to add to the stylesheet for later removal
+ * @return {StyleSheet}
+ */
+ createStyleSheet : function(cssText, id) {
+ var ss,
+ head = doc.getElementsByTagName("head")[0],
+ styleEl = doc.createElement("style");
+
+ styleEl.setAttribute("type", "text/css");
+ if (id) {
+ styleEl.setAttribute("id", id);
+ }
+
+ if (Ext.isIE) {
+ head.appendChild(styleEl);
+ ss = styleEl.styleSheet;
+ ss.cssText = cssText;
+ } else {
+ try{
+ styleEl.appendChild(doc.createTextNode(cssText));
+ } catch(e) {
+ styleEl.cssText = cssText;
+ }
+ head.appendChild(styleEl);
+ ss = styleEl.styleSheet ? styleEl.styleSheet : (styleEl.sheet || doc.styleSheets[doc.styleSheets.length-1]);
+ }
+ this.cacheStyleSheet(ss);
+ return ss;
+ },
+
+<span id='Ext-util.CSS-method-removeStyleSheet'> /**
+</span> * Removes a style or link tag by id
+ * @param {String} id The id of the tag
+ */
+ removeStyleSheet : function(id) {
+ var existing = document.getElementById(id);
+ if (existing) {
+ existing.parentNode.removeChild(existing);
+ }
+ },
+
+<span id='Ext-util.CSS-method-swapStyleSheet'> /**
+</span> * Dynamically swaps an existing stylesheet reference for a new one
+ * @param {String} id The id of an existing link tag to remove
+ * @param {String} url The href of the new stylesheet to include
+ */
+ swapStyleSheet : function(id, url) {
+ var doc = document;
+ this.removeStyleSheet(id);
+ var ss = doc.createElement("link");
+ ss.setAttribute("rel", "stylesheet");
+ ss.setAttribute("type", "text/css");
+ ss.setAttribute("id", id);
+ ss.setAttribute("href", url);
+ doc.getElementsByTagName("head")[0].appendChild(ss);
+ },
+
+<span id='Ext-util.CSS-method-refreshCache'> /**
+</span> * Refresh the rule cache if you have dynamically added stylesheets
+ * @return {Object} An object (hash) of rules indexed by selector
+ */
+ refreshCache : function() {
+ return this.getRules(true);
+ },
+
+ // private
+ cacheStyleSheet : function(ss) {
+ if(!rules){
+ rules = {};
+ }
+ try {// try catch for cross domain access issue
+ var ssRules = ss.cssRules || ss.rules,
+ selectorText,
+ i = ssRules.length - 1,
+ j,
+ selectors;
+
+ for (; i >= 0; --i) {
+ selectorText = ssRules[i].selectorText;
+ if (selectorText) {
+
+ // Split in case there are multiple, comma-delimited selectors
+ selectorText = selectorText.split(',');
+ selectors = selectorText.length;
+ for (j = 0; j < selectors; j++) {
+ rules[Ext.String.trim(selectorText[j]).toLowerCase()] = ssRules[i];
+ }
+ }
+ }
+ } catch(e) {}
+ },
+
+<span id='Ext-util.CSS-method-getRules'> /**
+</span> * Gets all css rules for the document
+ * @param {Boolean} refreshCache true to refresh the internal cache
+ * @return {Object} An object (hash) of rules indexed by selector
+ */
+ getRules : function(refreshCache) {
+ if (rules === null || refreshCache) {
+ rules = {};
+ var ds = doc.styleSheets,
+ i = 0,
+ len = ds.length;