]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/ui/style.js
1 qwebirc
.ui
.style
.ModifiableStylesheet
= new Class({
2 initialize: function(url
) {
3 var n
= this.__parseStylesheet(this.__getStylesheet(url
));
5 this.__cssText
= n
.cssText
;
8 this.__tag
= this.__createTag();
10 __createTag: function() {
11 var tag
= document
.createElement("style");
12 tag
.type
= "text/css";
15 document
.getElementsByTagName("head")[0].appendChild(tag
);
19 __getStylesheet: function(url
) {
20 var r
= new Request({url: url
, async: false});
22 r
.addEvent("complete", function(x
) {
28 __setStylesheet: function(stylesheet
) {
29 var node
= this.__tag
;
31 if(node
.styleSheet
) { /* IE */
32 node
.styleSheet
.cssText
= stylesheet
;
34 var d
= document
.createTextNode(stylesheet
);
36 while(node
.childNodes
.length
> 1)
37 node
.removeChild(node
.firstChild
);
40 __parseStylesheet: function(data
) {
41 var lines
= data
.replace("\r\n", "\n").split("\n");
45 for(i
=0;i
<lines
.length
;i
++) {
47 if(line
.trim() === "")
50 var tokens
= line
.splitMax("=", 2);
51 if(tokens
.length
!= 2)
54 rules
[tokens
[0]] = tokens
[1];
58 for(;i
<lines
.length
;i
++)
59 cssLines
.push(lines
[i
]);
61 return {cssText: cssLines
.join("\n"), rules: rules
};
63 set: function(mutator
) {
64 if(!$defined(mutator
))
65 mutator = function(x
) { return x
; };
67 var text
= this.__cssText
;
68 for(var key
in this.rules
) {
69 var s
= this.rules
[key
].split(",");
70 var value
= mutator
.pass(s
);
72 text
= text
.replaceAll("$(" + key
+ ")", value
);
75 this.__setStylesheet(text
);