X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/169c1428a0ed03a1418c9a07b29cdf7b28195c6eb283e094a6fc8bf63e27a110..5f41702296a6412c8ad69a57f4771701fdfd4d257cc0dc1dfeea1a505ff2c25c:/static/js/lib/common-lib.js diff --git a/static/js/lib/common-lib.js b/static/js/lib/common-lib.js index 09448ed..bd091b3 100644 --- a/static/js/lib/common-lib.js +++ b/static/js/lib/common-lib.js @@ -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 */