1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
|
/* ************************************************************************
qooxdoo - the new era of web development
http://qooxdoo.org
Copyright:
2004-2007 1&1 Internet AG, Germany, http://www.1and1.org
2006 STZ-IDA, Germany, http://www.stz-ida.de
License:
LGPL: http://www.gnu.org/licenses/lgpl.html
EPL: http://www.eclipse.org/org/documents/epl-v10.php
See the LICENSE file in the project's top-level directory for details.
Authors:
* Sebastian Werner (wpbasti)
* Andreas Ecker (ecker)
* Andreas Junghans (lucidcake)
************************************************************************ */
/* ************************************************************************
#module(ui_core)
#require(qx.core.Client)
************************************************************************ */
qx.OO.defineClass("qx.html.StyleSheet");
/**
* Include a CSS file
*
* @param vHref {String} Href value
*/
qx.html.StyleSheet.includeFile = function(vHref)
{
var el = document.createElement("link");
el.type = "text/css";
el.rel = "stylesheet";
el.href = vHref;
var head = document.getElementsByTagName("head")[0];
head.appendChild(el);
};
/**
* create a new Stylesheet node and append it to the document
*
* @param vCssText {String} optional string of css rules
*/
qx.html.StyleSheet.createElement = function(vCssText) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.createElement = function(vCssText)
{
var vSheet = document.createStyleSheet();
if (vCssText) {
vSheet.cssText = vCssText;
}
return vSheet;
};
}
else // FF, Opera, Safari
{
qx.html.StyleSheet.createElement = function(vCssText)
{
var vElement = document.createElement("style");
vElement.type = "text/css";
// Safari 2.0 doesn't like empty stylesheets
vElement.appendChild(document.createTextNode(vCssText || "body {}"));
document.getElementsByTagName("head")[0].appendChild(vElement);
if (vElement.sheet) {
return vElement.sheet;
} else {
// Safari 2.0 doesn't support element.sheet so we neet a workaround
var styles = document.styleSheets;
for (var i=styles.length-1; i>=0; i--) {
if (styles[i].ownerNode == vElement) {
return styles[i];
}
}
}
throw "Error: Could not get a reference to the sheet object";
};
}
/**
* insert a new CSS rule into a given Stylesheet
*
* @param vSheet {Object} the target Stylesheet object
* @param vSelector {String} the selector
* @param vStyle {String} style rule
*/
qx.html.StyleSheet.addRule = function(vSheet, vSelector, vStyle) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.addRule = function(vSheet, vSelector, vStyle) {
vSheet.addRule(vSelector, vStyle);
};
}
else if (qx.core.Client.getInstance().isSafari2()) // insertRule in Safari 2 doesn't work
{
qx.html.StyleSheet.addRule = function(vSheet, vSelector, vStyle) {
if (!vSheet._qxRules) {
vSheet._qxRules = {};
}
if (!vSheet._qxRules[vSelector]) {
var ruleNode = document.createTextNode(vSelector + "{" + vStyle + "}");
vSheet.ownerNode.appendChild(ruleNode);
vSheet._qxRules[vSelector] = ruleNode;
}
};
}
else // FF, Opera
{
qx.html.StyleSheet.addRule = function(vSheet, vSelector, vStyle) {
vSheet.insertRule(vSelector + "{" + vStyle + "}", vSheet.cssRules.length);
};
}
/**
* remove a CSS rule from a stylesheet
*
* @param vSheet {Object} the Stylesheet
* @param vSelector {String} the Selector of the rule to remove
*/
qx.html.StyleSheet.removeRule = function(vSheet, vSelector) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.removeRule = function(vSheet, vSelector)
{
var vRules = vSheet.rules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--)
{
if (vRules[i].selectorText == vSelector) {
vSheet.removeRule(i);
}
}
};
}
else if (qx.core.Client.getInstance().isSafari2()) // removeRule in Safari 2 doesn't work
{
qx.html.StyleSheet.removeRule = function(vSheet, vSelector)
{
var warn = function() {
qx.log.Logger.ROOT_LOGGER.warn("In Safari/Webkit you can only remove rules that are created using qx.html.StyleSheet.addRule");
}
if (!vSheet._qxRules) {
warn();
}
var ruleNode = vSheet._qxRules[vSelector];
if (ruleNode) {
vSheet.ownerNode.removeChild(ruleNode);
vSheet._qxRules[vSelector] = null;
} else {
warn();
}
};
}
else
{
qx.html.StyleSheet.removeRule = function(vSheet, vSelector)
{
var vRules = vSheet.cssRules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--)
{
if (vRules[i].selectorText == vSelector) {
vSheet.deleteRule(i);
}
}
};
}
/**
* remove all CSS rules from a stylesheet
*
* @param vSheet {Object} the stylesheet object
*/
qx.html.StyleSheet.removeAllRules = function(vSheet) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.removeAllRules = function(vSheet)
{
var vRules = vSheet.rules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--) {
vSheet.removeRule(i);
}
};
}
else if (qx.core.Client.getInstance().isSafari2()) // removeRule in Safari 2 doesn't work
{
qx.html.StyleSheet.removeAllRules = function(vSheet)
{
var node = vSheet.ownerNode;
var rules = node.childNodes;
while (rules.length > 0) {
node.removeChild(rules[0]);
}
};
}
else // FF, etc
{
qx.html.StyleSheet.removeAllRules = function(vSheet)
{
var vRules = vSheet.cssRules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--) {
vSheet.deleteRule(i);
}
};
}
// TODO import functions are not working crossbrowser (Safari) !!
// see CSS_1.html test
/**
* add an import of an external CSS file to a stylesheet
* @param vSheet {Object} the stylesheet object
* @param vUrl {String} URL of the external stylesheet file
*/
qx.html.StyleSheet.addImport = function(vSheet, vUrl) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.addImport = function(vSheet, vUrl) {
vSheet.addImport(vUrl);
};
}
else if (qx.core.Client.getInstance().isSafari2()) // insertRule in Safari 2 doesn't work
{
qx.html.StyleSheet.addImport = function(vSheet, vUrl) {
vSheet.ownerNode.appendChild(document.createTextNode('@import "' + vUrl + '";'));
};
}
else // FF, etc
{
qx.html.StyleSheet.addImport = function(vSheet, vUrl) {
vSheet.insertRule('@import "' + vUrl + '";', vSheet.cssRules.length);
};
}
/**
* removes an import from a stylesheet
*
* @param vSheet {Object} the stylesheet object
* @param vUrl {String} URL of the importet CSS file
*/
qx.html.StyleSheet.removeImport = function(vSheet, vUrl) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.removeImport = function(vSheet, vUrl) {
var vImports = vSheet.imports;
var vLength = vImports.length;
for (var i=vLength-1; i>=0; i--) {
if (vImports[i].href == vUrl) {
vSheet.removeImport(i);
}
}
};
}
else // FF, etc
{
qx.html.StyleSheet.removeImport = function(vSheet, vUrl) {
var vRules = vSheet.cssRules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--) {
if (vRules[i].href == vUrl) {
vSheet.deleteRule(i);
}
}
};
}
/**
* remove all imports from a stylesheet
*
* @param vSheet {Object} the stylesheet object
*/
qx.html.StyleSheet.removeAllImports = function(vSheet) {};
if (document.createStyleSheet) // IE 4+
{
qx.html.StyleSheet.removeAllImports = function(vSheet) {
var vImports = vSheet.imports;
var vLength = vImports.length;
for (var i=vLength-1; i>=0; i--) {
vSheet.removeImport(i);
}
};
}
else // FF, etc
{
qx.html.StyleSheet.removeAllImports = function(vSheet) {
var vRules = vSheet.cssRules;
var vLength = vRules.length;
for (var i=vLength-1; i>=0; i--) {
if (vRules[i].type == vRules[i].IMPORT_RULE) {
vSheet.deleteRule(i);
}
}
};
}
|