3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.util.CSS"></div>/**
17 * Utility class for manipulating CSS rules
20 Ext.util.CSS = function(){
24 var camelRe = /(-[a-z])/gi;
25 var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
28 <div id="method-Ext.util.CSS-createStyleSheet"></div>/**
29 * Creates a stylesheet from a text blob of rules.
30 * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
31 * @param {String} cssText The text containing the css rules
32 * @param {String} id An id to add to the stylesheet for later removal
33 * @return {StyleSheet}
35 createStyleSheet : function(cssText, id){
37 var head = doc.getElementsByTagName("head")[0];
38 var rules = doc.createElement("style");
39 rules.setAttribute("type", "text/css");
41 rules.setAttribute("id", id);
44 head.appendChild(rules);
45 ss = rules.styleSheet;
49 rules.appendChild(doc.createTextNode(cssText));
51 rules.cssText = cssText;
53 head.appendChild(rules);
54 ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
56 this.cacheStyleSheet(ss);
60 <div id="method-Ext.util.CSS-removeStyleSheet"></div>/**
61 * Removes a style or link tag by id
62 * @param {String} id The id of the tag
64 removeStyleSheet : function(id){
65 var existing = doc.getElementById(id);
67 existing.parentNode.removeChild(existing);
71 <div id="method-Ext.util.CSS-swapStyleSheet"></div>/**
72 * Dynamically swaps an existing stylesheet reference for a new one
73 * @param {String} id The id of an existing link tag to remove
74 * @param {String} url The href of the new stylesheet to include
76 swapStyleSheet : function(id, url){
77 this.removeStyleSheet(id);
78 var ss = doc.createElement("link");
79 ss.setAttribute("rel", "stylesheet");
80 ss.setAttribute("type", "text/css");
81 ss.setAttribute("id", id);
82 ss.setAttribute("href", url);
83 doc.getElementsByTagName("head")[0].appendChild(ss);
86 <div id="method-Ext.util.CSS-refreshCache"></div>/**
87 * Refresh the rule cache if you have dynamically added stylesheets
88 * @return {Object} An object (hash) of rules indexed by selector
90 refreshCache : function(){
91 return this.getRules(true);
95 cacheStyleSheet : function(ss){
99 try{// try catch for cross domain access issue
100 var ssRules = ss.cssRules || ss.rules;
101 for(var j = ssRules.length-1; j >= 0; --j){
102 rules[ssRules[j].selectorText.toLowerCase()] = ssRules[j];
107 <div id="method-Ext.util.CSS-getRules"></div>/**
108 * Gets all css rules for the document
109 * @param {Boolean} refreshCache true to refresh the internal cache
110 * @return {Object} An object (hash) of rules indexed by selector
112 getRules : function(refreshCache){
113 if(rules === null || refreshCache){
115 var ds = doc.styleSheets;
116 for(var i =0, len = ds.length; i < len; i++){
118 this.cacheStyleSheet(ds[i]);
125 <div id="method-Ext.util.CSS-getRule"></div>/**
126 * Gets an an individual CSS rule by selector(s)
127 * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
128 * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
129 * @return {CSSRule} The CSS rule or null if one is not found
131 getRule : function(selector, refreshCache){
132 var rs = this.getRules(refreshCache);
133 if(!Ext.isArray(selector)){
134 return rs[selector.toLowerCase()];
136 for(var i = 0; i < selector.length; i++){
138 return rs[selector[i].toLowerCase()];
145 <div id="method-Ext.util.CSS-updateRule"></div>/**
146 * Updates a rule property
147 * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
148 * @param {String} property The css property
149 * @param {String} value The new value for the property
150 * @return {Boolean} true If a rule was found and updated
152 updateRule : function(selector, property, value){
153 if(!Ext.isArray(selector)){
154 var rule = this.getRule(selector);
156 rule.style[property.replace(camelRe, camelFn)] = value;
160 for(var i = 0; i < selector.length; i++){
161 if(this.updateRule(selector[i], property, value)){