Web UI for ARGUS server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
5.6 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  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>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.util.CSS"></div>/**
  16. * @class Ext.util.CSS
  17. * Utility class for manipulating CSS rules
  18. * @singleton
  19. */
  20. Ext.util.CSS = function(){
  21. var rules = null;
  22. var doc = document;
  23. var camelRe = /(-[a-z])/gi;
  24. var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
  25. return {
  26. <div id="method-Ext.util.CSS-createStyleSheet"></div>/**
  27. * Creates a stylesheet from a text blob of rules.
  28. * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
  29. * @param {String} cssText The text containing the css rules
  30. * @param {String} id An id to add to the stylesheet for later removal
  31. * @return {StyleSheet}
  32. */
  33. createStyleSheet : function(cssText, id){
  34. var ss;
  35. var head = doc.getElementsByTagName("head")[0];
  36. var rules = doc.createElement("style");
  37. rules.setAttribute("type", "text/css");
  38. if(id){
  39. rules.setAttribute("id", id);
  40. }
  41. if(Ext.isIE){
  42. head.appendChild(rules);
  43. ss = rules.styleSheet;
  44. ss.cssText = cssText;
  45. }else{
  46. try{
  47. rules.appendChild(doc.createTextNode(cssText));
  48. }catch(e){
  49. rules.cssText = cssText;
  50. }
  51. head.appendChild(rules);
  52. ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
  53. }
  54. this.cacheStyleSheet(ss);
  55. return ss;
  56. },
  57. <div id="method-Ext.util.CSS-removeStyleSheet"></div>/**
  58. * Removes a style or link tag by id
  59. * @param {String} id The id of the tag
  60. */
  61. removeStyleSheet : function(id){
  62. var existing = doc.getElementById(id);
  63. if(existing){
  64. existing.parentNode.removeChild(existing);
  65. }
  66. },
  67. <div id="method-Ext.util.CSS-swapStyleSheet"></div>/**
  68. * Dynamically swaps an existing stylesheet reference for a new one
  69. * @param {String} id The id of an existing link tag to remove
  70. * @param {String} url The href of the new stylesheet to include
  71. */
  72. swapStyleSheet : function(id, url){
  73. this.removeStyleSheet(id);
  74. var ss = doc.createElement("link");
  75. ss.setAttribute("rel", "stylesheet");
  76. ss.setAttribute("type", "text/css");
  77. ss.setAttribute("id", id);
  78. ss.setAttribute("href", url);
  79. doc.getElementsByTagName("head")[0].appendChild(ss);
  80. },
  81. <div id="method-Ext.util.CSS-refreshCache"></div>/**
  82. * Refresh the rule cache if you have dynamically added stylesheets
  83. * @return {Object} An object (hash) of rules indexed by selector
  84. */
  85. refreshCache : function(){
  86. return this.getRules(true);
  87. },
  88. // private
  89. cacheStyleSheet : function(ss){
  90. if(!rules){
  91. rules = {};
  92. }
  93. try{// try catch for cross domain access issue
  94. var ssRules = ss.cssRules || ss.rules;
  95. for(var j = ssRules.length-1; j >= 0; --j){
  96. rules[ssRules[j].selectorText.toLowerCase()] = ssRules[j];
  97. }
  98. }catch(e){}
  99. },
  100. <div id="method-Ext.util.CSS-getRules"></div>/**
  101. * Gets all css rules for the document
  102. * @param {Boolean} refreshCache true to refresh the internal cache
  103. * @return {Object} An object (hash) of rules indexed by selector
  104. */
  105. getRules : function(refreshCache){
  106. if(rules === null || refreshCache){
  107. rules = {};
  108. var ds = doc.styleSheets;
  109. for(var i =0, len = ds.length; i < len; i++){
  110. try{
  111. this.cacheStyleSheet(ds[i]);
  112. }catch(e){}
  113. }
  114. }
  115. return rules;
  116. },
  117. <div id="method-Ext.util.CSS-getRule"></div>/**
  118. * Gets an an individual CSS rule by selector(s)
  119. * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
  120. * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
  121. * @return {CSSRule} The CSS rule or null if one is not found
  122. */
  123. getRule : function(selector, refreshCache){
  124. var rs = this.getRules(refreshCache);
  125. if(!Ext.isArray(selector)){
  126. return rs[selector.toLowerCase()];
  127. }
  128. for(var i = 0; i < selector.length; i++){
  129. if(rs[selector[i]]){
  130. return rs[selector[i].toLowerCase()];
  131. }
  132. }
  133. return null;
  134. },
  135. <div id="method-Ext.util.CSS-updateRule"></div>/**
  136. * Updates a rule property
  137. * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
  138. * @param {String} property The css property
  139. * @param {String} value The new value for the property
  140. * @return {Boolean} true If a rule was found and updated
  141. */
  142. updateRule : function(selector, property, value){
  143. if(!Ext.isArray(selector)){
  144. var rule = this.getRule(selector);
  145. if(rule){
  146. rule.style[property.replace(camelRe, camelFn)] = value;
  147. return true;
  148. }
  149. }else{
  150. for(var i = 0; i < selector.length; i++){
  151. if(this.updateRule(selector[i], property, value)){
  152. return true;
  153. }
  154. }
  155. }
  156. return false;
  157. }
  158. };
  159. }();</pre>
  160. </body>
  161. </html>