]> Lady’s Gitweb - Gitweb/blobdiff - static/js/lib/common-lib.js
gitweb.js: Add UI for selecting common timezone to display dates
[Gitweb] / static / js / lib / common-lib.js
index 09448ed80b11164a182d691faa1fbf4bb7e0e8d1d9b87da02169a118962b4e7a..bd091b3f9c66e051c95dc321713c023655c443c84a3c3d2fefce021c52717592 100644 (file)
@@ -64,7 +64,7 @@ function padLeft(input, width, ch) {
 
 
 /* ............................................................ */
-/* Ajax */
+/* Handling browser incompatibilities */
 
 /**
  * Create XMLHttpRequest object in cross-browser way
@@ -88,6 +88,31 @@ function createRequestObject() {
 }
 
 
+/**
+ * Insert rule giving specified STYLE to given SELECTOR at the end of
+ * first CSS stylesheet.
+ *
+ * @param {String} selector: CSS selector, e.g. '.class'
+ * @param {String} style: rule contents, e.g. 'background-color: red;'
+ */
+function addCssRule(selector, style) {
+       var stylesheet = document.styleSheets[0];
+
+       var theRules = [];
+       if (stylesheet.cssRules) {     // W3C way
+               theRules = stylesheet.cssRules;
+       } else if (stylesheet.rules) { // IE way
+               theRules = stylesheet.rules;
+       }
+
+       if (stylesheet.insertRule) {    // W3C way
+               stylesheet.insertRule(selector + ' { ' + style + ' }', theRules.length);
+       } else if (stylesheet.addRule) { // IE way
+               stylesheet.addRule(selector, style);
+       }
+}
+
+
 /* ............................................................ */
 /* Support for legacy browsers */
 
This page took 0.151571 seconds and 4 git commands to generate.