]>
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
), 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
, url
) {
41 var lines
= data
.replace("\r\n", "\n").split("\n");
42 var baseURL
= new URI("../", {base: url
}).toString();
46 for(i
=0;i
<lines
.length
;i
++) {
48 if(line
.trim() === "")
51 var tokens
= line
.splitMax("=", 2);
52 if(tokens
.length
!= 2)
55 rules
[tokens
[0]] = tokens
[1];
59 for(;i
<lines
.length
;i
++) {
61 line
= line
.replaceAll("$(base_url)", baseURL
);
64 return {cssText: cssLines
.join("\n"), rules: rules
};
66 set: function(mutator
) {
67 if(!$defined(mutator
))
68 mutator = function(x
) { return x
; };
70 var text
= this.__cssText
;
71 for(var key
in this.rules
) {
72 var s
= this.rules
[key
].split(",");
73 var value
= mutator
.pass(s
);
75 text
= text
.replaceAll("$(" + key
+ ")", value
);
78 this.__setStylesheet(text
);