Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1318 Rev 1422
1
/*
1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
3
	All Rights Reserved.
4
 
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
9
*/
-
 
10
 
-
 
11
 
10
 
12
 
11
dojo.provide("dojo.html.style");
13
dojo.provide("dojo.html.style");
12
dojo.require("dojo.html.common");
14
dojo.require("dojo.html.common");
13
dojo.require("dojo.uri.Uri");
15
dojo.require("dojo.uri.Uri");
14
dojo.html.getClass = function (node) {
16
dojo.html.getClass = function (node) {
15
	node = dojo.byId(node);
17
	node = dojo.byId(node);
16
	if (!node) {
18
	if (!node) {
17
		return "";
19
		return "";
18
	}
20
	}
19
	var cs = "";
21
	var cs = "";
20
	if (node.className) {
22
	if (node.className) {
21
		cs = node.className;
23
		cs = node.className;
22
	} else {
24
	} else {
23
		if (dojo.html.hasAttribute(node, "class")) {
25
		if (dojo.html.hasAttribute(node, "class")) {
24
			cs = dojo.html.getAttribute(node, "class");
26
			cs = dojo.html.getAttribute(node, "class");
25
		}
27
		}
26
	}
28
	}
27
	return cs.replace(/^\s+|\s+$/g, "");
29
	return cs.replace(/^\s+|\s+$/g, "");
28
};
30
};
29
dojo.html.getClasses = function (node) {
31
dojo.html.getClasses = function (node) {
30
	var c = dojo.html.getClass(node);
32
	var c = dojo.html.getClass(node);
31
	return (c == "") ? [] : c.split(/\s+/g);
33
	return (c == "") ? [] : c.split(/\s+/g);
32
};
34
};
33
dojo.html.hasClass = function (node, classname) {
35
dojo.html.hasClass = function (node, classname) {
34
	return (new RegExp("(^|\\s+)" + classname + "(\\s+|$)")).test(dojo.html.getClass(node));
36
	return (new RegExp("(^|\\s+)" + classname + "(\\s+|$)")).test(dojo.html.getClass(node));
35
};
37
};
36
dojo.html.prependClass = function (node, classStr) {
38
dojo.html.prependClass = function (node, classStr) {
37
	classStr += " " + dojo.html.getClass(node);
39
	classStr += " " + dojo.html.getClass(node);
38
	return dojo.html.setClass(node, classStr);
40
	return dojo.html.setClass(node, classStr);
39
};
41
};
40
dojo.html.addClass = function (node, classStr) {
42
dojo.html.addClass = function (node, classStr) {
41
	if (dojo.html.hasClass(node, classStr)) {
43
	if (dojo.html.hasClass(node, classStr)) {
42
		return false;
44
		return false;
43
	}
45
	}
44
	classStr = (dojo.html.getClass(node) + " " + classStr).replace(/^\s+|\s+$/g, "");
46
	classStr = (dojo.html.getClass(node) + " " + classStr).replace(/^\s+|\s+$/g, "");
45
	return dojo.html.setClass(node, classStr);
47
	return dojo.html.setClass(node, classStr);
46
};
48
};
47
dojo.html.setClass = function (node, classStr) {
49
dojo.html.setClass = function (node, classStr) {
48
	node = dojo.byId(node);
50
	node = dojo.byId(node);
49
	var cs = new String(classStr);
51
	var cs = new String(classStr);
50
	try {
52
	try {
51
		if (typeof node.className == "string") {
53
		if (typeof node.className == "string") {
52
			node.className = cs;
54
			node.className = cs;
53
		} else {
55
		} else {
54
			if (node.setAttribute) {
56
			if (node.setAttribute) {
55
				node.setAttribute("class", classStr);
57
				node.setAttribute("class", classStr);
56
				node.className = cs;
58
				node.className = cs;
57
			} else {
59
			} else {
58
				return false;
60
				return false;
59
			}
61
			}
60
		}
62
		}
61
	}
63
	}
62
	catch (e) {
64
	catch (e) {
63
		dojo.debug("dojo.html.setClass() failed", e);
65
		dojo.debug("dojo.html.setClass() failed", e);
64
	}
66
	}
65
	return true;
67
	return true;
66
};
68
};
67
dojo.html.removeClass = function (node, classStr, allowPartialMatches) {
69
dojo.html.removeClass = function (node, classStr, allowPartialMatches) {
68
	try {
70
	try {
69
		if (!allowPartialMatches) {
71
		if (!allowPartialMatches) {
70
			var newcs = dojo.html.getClass(node).replace(new RegExp("(^|\\s+)" + classStr + "(\\s+|$)"), "$1$2");
72
			var newcs = dojo.html.getClass(node).replace(new RegExp("(^|\\s+)" + classStr + "(\\s+|$)"), "$1$2");
71
		} else {
73
		} else {
72
			var newcs = dojo.html.getClass(node).replace(classStr, "");
74
			var newcs = dojo.html.getClass(node).replace(classStr, "");
73
		}
75
		}
74
		dojo.html.setClass(node, newcs);
76
		dojo.html.setClass(node, newcs);
75
	}
77
	}
76
	catch (e) {
78
	catch (e) {
77
		dojo.debug("dojo.html.removeClass() failed", e);
79
		dojo.debug("dojo.html.removeClass() failed", e);
78
	}
80
	}
79
	return true;
81
	return true;
80
};
82
};
81
dojo.html.replaceClass = function (node, newClass, oldClass) {
83
dojo.html.replaceClass = function (node, newClass, oldClass) {
82
	dojo.html.removeClass(node, oldClass);
84
	dojo.html.removeClass(node, oldClass);
83
	dojo.html.addClass(node, newClass);
85
	dojo.html.addClass(node, newClass);
84
};
86
};
85
dojo.html.classMatchType = {ContainsAll:0, ContainsAny:1, IsOnly:2};
87
dojo.html.classMatchType = {ContainsAll:0, ContainsAny:1, IsOnly:2};
86
dojo.html.getElementsByClass = function (classStr, parent, nodeType, classMatchType, useNonXpath) {
88
dojo.html.getElementsByClass = function (classStr, parent, nodeType, classMatchType, useNonXpath) {
87
	useNonXpath = false;
89
	useNonXpath = false;
88
	var _document = dojo.doc();
90
	var _document = dojo.doc();
89
	parent = dojo.byId(parent) || _document;
91
	parent = dojo.byId(parent) || _document;
90
	var classes = classStr.split(/\s+/g);
92
	var classes = classStr.split(/\s+/g);
91
	var nodes = [];
93
	var nodes = [];
92
	if (classMatchType != 1 && classMatchType != 2) {
94
	if (classMatchType != 1 && classMatchType != 2) {
93
		classMatchType = 0;
95
		classMatchType = 0;
94
	}
96
	}
95
	var reClass = new RegExp("(\\s|^)((" + classes.join(")|(") + "))(\\s|$)");
97
	var reClass = new RegExp("(\\s|^)((" + classes.join(")|(") + "))(\\s|$)");
96
	var srtLength = classes.join(" ").length;
98
	var srtLength = classes.join(" ").length;
97
	var candidateNodes = [];
99
	var candidateNodes = [];
98
	if (!useNonXpath && _document.evaluate) {
100
	if (!useNonXpath && _document.evaluate) {
99
		var xpath = ".//" + (nodeType || "*") + "[contains(";
101
		var xpath = ".//" + (nodeType || "*") + "[contains(";
100
		if (classMatchType != dojo.html.classMatchType.ContainsAny) {
102
		if (classMatchType != dojo.html.classMatchType.ContainsAny) {
101
			xpath += "concat(' ',@class,' '), ' " + classes.join(" ') and contains(concat(' ',@class,' '), ' ") + " ')";
103
			xpath += "concat(' ',@class,' '), ' " + classes.join(" ') and contains(concat(' ',@class,' '), ' ") + " ')";
102
			if (classMatchType == 2) {
104
			if (classMatchType == 2) {
103
				xpath += " and string-length(@class)=" + srtLength + "]";
105
				xpath += " and string-length(@class)=" + srtLength + "]";
104
			} else {
106
			} else {
105
				xpath += "]";
107
				xpath += "]";
106
			}
108
			}
107
		} else {
109
		} else {
108
			xpath += "concat(' ',@class,' '), ' " + classes.join(" ') or contains(concat(' ',@class,' '), ' ") + " ')]";
110
			xpath += "concat(' ',@class,' '), ' " + classes.join(" ') or contains(concat(' ',@class,' '), ' ") + " ')]";
109
		}
111
		}
110
		var xpathResult = _document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
112
		var xpathResult = _document.evaluate(xpath, parent, null, XPathResult.ANY_TYPE, null);
111
		var result = xpathResult.iterateNext();
113
		var result = xpathResult.iterateNext();
112
		while (result) {
114
		while (result) {
113
			try {
115
			try {
114
				candidateNodes.push(result);
116
				candidateNodes.push(result);
115
				result = xpathResult.iterateNext();
117
				result = xpathResult.iterateNext();
116
			}
118
			}
117
			catch (e) {
119
			catch (e) {
118
				break;
120
				break;
119
			}
121
			}
120
		}
122
		}
121
		return candidateNodes;
123
		return candidateNodes;
122
	} else {
124
	} else {
123
		if (!nodeType) {
125
		if (!nodeType) {
124
			nodeType = "*";
126
			nodeType = "*";
125
		}
127
		}
126
		candidateNodes = parent.getElementsByTagName(nodeType);
128
		candidateNodes = parent.getElementsByTagName(nodeType);
127
		var node, i = 0;
129
		var node, i = 0;
128
	outer:
130
	outer:
129
		while (node = candidateNodes[i++]) {
131
		while (node = candidateNodes[i++]) {
130
			var nodeClasses = dojo.html.getClasses(node);
132
			var nodeClasses = dojo.html.getClasses(node);
131
			if (nodeClasses.length == 0) {
133
			if (nodeClasses.length == 0) {
132
				continue outer;
134
				continue outer;
133
			}
135
			}
134
			var matches = 0;
136
			var matches = 0;
135
			for (var j = 0; j < nodeClasses.length; j++) {
137
			for (var j = 0; j < nodeClasses.length; j++) {
136
				if (reClass.test(nodeClasses[j])) {
138
				if (reClass.test(nodeClasses[j])) {
137
					if (classMatchType == dojo.html.classMatchType.ContainsAny) {
139
					if (classMatchType == dojo.html.classMatchType.ContainsAny) {
138
						nodes.push(node);
140
						nodes.push(node);
139
						continue outer;
141
						continue outer;
140
					} else {
142
					} else {
141
						matches++;
143
						matches++;
142
					}
144
					}
143
				} else {
145
				} else {
144
					if (classMatchType == dojo.html.classMatchType.IsOnly) {
146
					if (classMatchType == dojo.html.classMatchType.IsOnly) {
145
						continue outer;
147
						continue outer;
146
					}
148
					}
147
				}
149
				}
148
			}
150
			}
149
			if (matches == classes.length) {
151
			if (matches == classes.length) {
150
				if ((classMatchType == dojo.html.classMatchType.IsOnly) && (matches == nodeClasses.length)) {
152
				if ((classMatchType == dojo.html.classMatchType.IsOnly) && (matches == nodeClasses.length)) {
151
					nodes.push(node);
153
					nodes.push(node);
152
				} else {
154
				} else {
153
					if (classMatchType == dojo.html.classMatchType.ContainsAll) {
155
					if (classMatchType == dojo.html.classMatchType.ContainsAll) {
154
						nodes.push(node);
156
						nodes.push(node);
155
					}
157
					}
156
				}
158
				}
157
			}
159
			}
158
		}
160
		}
159
		return nodes;
161
		return nodes;
160
	}
162
	}
161
};
163
};
162
dojo.html.getElementsByClassName = dojo.html.getElementsByClass;
164
dojo.html.getElementsByClassName = dojo.html.getElementsByClass;
163
dojo.html.toCamelCase = function (selector) {
165
dojo.html.toCamelCase = function (selector) {
164
	var arr = selector.split("-"), cc = arr[0];
166
	var arr = selector.split("-"), cc = arr[0];
165
	for (var i = 1; i < arr.length; i++) {
167
	for (var i = 1; i < arr.length; i++) {
166
		cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
168
		cc += arr[i].charAt(0).toUpperCase() + arr[i].substring(1);
167
	}
169
	}
168
	return cc;
170
	return cc;
169
};
171
};
170
dojo.html.toSelectorCase = function (selector) {
172
dojo.html.toSelectorCase = function (selector) {
171
	return selector.replace(/([A-Z])/g, "-$1").toLowerCase();
173
	return selector.replace(/([A-Z])/g, "-$1").toLowerCase();
172
};
174
};
173
if (dojo.render.html.ie) {
175
if (dojo.render.html.ie) {
174
	dojo.html.getComputedStyle = function (node, property, value) {
176
	dojo.html.getComputedStyle = function (node, property, value) {
175
		node = dojo.byId(node);
177
		node = dojo.byId(node);
176
		if (!node || !node.style) {
178
		if (!node || !node.currentStyle) {
177
			return value;
179
			return value;
178
		}
180
		}
179
		return node.currentStyle[dojo.html.toCamelCase(property)];
181
		return node.currentStyle[dojo.html.toCamelCase(property)];
180
	};
182
	};
181
	dojo.html.getComputedStyles = function (node) {
183
	dojo.html.getComputedStyles = function (node) {
182
		return node.currentStyle;
184
		return node.currentStyle;
183
	};
185
	};
184
} else {
186
} else {
185
	dojo.html.getComputedStyle = function (node, property, value) {
187
	dojo.html.getComputedStyle = function (node, property, value) {
186
		node = dojo.byId(node);
188
		node = dojo.byId(node);
187
		if (!node || !node.style) {
189
		if (!node || !node.style) {
188
			return value;
190
			return value;
189
		}
191
		}
190
		var s = document.defaultView.getComputedStyle(node, null);
192
		var s = document.defaultView.getComputedStyle(node, null);
191
		return (s && s[dojo.html.toCamelCase(property)]) || "";
193
		return (s && s[dojo.html.toCamelCase(property)]) || "";
192
	};
194
	};
193
	dojo.html.getComputedStyles = function (node) {
195
	dojo.html.getComputedStyles = function (node) {
194
		return document.defaultView.getComputedStyle(node, null);
196
		return document.defaultView.getComputedStyle(node, null);
195
	};
197
	};
196
}
198
}
197
dojo.html.getStyleProperty = function (node, cssSelector) {
199
dojo.html.getStyleProperty = function (node, cssSelector) {
198
	node = dojo.byId(node);
200
	node = dojo.byId(node);
199
	return (node && node.style ? node.style[dojo.html.toCamelCase(cssSelector)] : undefined);
201
	return (node && node.style ? node.style[dojo.html.toCamelCase(cssSelector)] : undefined);
200
};
202
};
201
dojo.html.getStyle = function (node, cssSelector) {
203
dojo.html.getStyle = function (node, cssSelector) {
202
	var value = dojo.html.getStyleProperty(node, cssSelector);
204
	var value = dojo.html.getStyleProperty(node, cssSelector);
203
	return (value ? value : dojo.html.getComputedStyle(node, cssSelector));
205
	return (value ? value : dojo.html.getComputedStyle(node, cssSelector));
204
};
206
};
205
dojo.html.setStyle = function (node, cssSelector, value) {
207
dojo.html.setStyle = function (node, cssSelector, value) {
206
	node = dojo.byId(node);
208
	node = dojo.byId(node);
207
	if (node && node.style) {
209
	if (node && node.style) {
208
		var camelCased = dojo.html.toCamelCase(cssSelector);
210
		var camelCased = dojo.html.toCamelCase(cssSelector);
209
		node.style[camelCased] = value;
211
		node.style[camelCased] = value;
210
	}
212
	}
211
};
213
};
212
dojo.html.setStyleText = function (target, text) {
214
dojo.html.setStyleText = function (target, text) {
213
	try {
215
	try {
214
		target.style.cssText = text;
216
		target.style.cssText = text;
215
	}
217
	}
216
	catch (e) {
218
	catch (e) {
217
		target.setAttribute("style", text);
219
		target.setAttribute("style", text);
218
	}
220
	}
219
};
221
};
220
dojo.html.copyStyle = function (target, source) {
222
dojo.html.copyStyle = function (target, source) {
221
	if (!source.style.cssText) {
223
	if (!source.style.cssText) {
222
		target.setAttribute("style", source.getAttribute("style"));
224
		target.setAttribute("style", source.getAttribute("style"));
223
	} else {
225
	} else {
224
		target.style.cssText = source.style.cssText;
226
		target.style.cssText = source.style.cssText;
225
	}
227
	}
226
	dojo.html.addClass(target, dojo.html.getClass(source));
228
	dojo.html.addClass(target, dojo.html.getClass(source));
227
};
229
};
228
dojo.html.getUnitValue = function (node, cssSelector, autoIsZero) {
230
dojo.html.getUnitValue = function (node, cssSelector, autoIsZero) {
229
	var s = dojo.html.getComputedStyle(node, cssSelector);
231
	var s = dojo.html.getComputedStyle(node, cssSelector);
230
	if ((!s) || ((s == "auto") && (autoIsZero))) {
232
	if ((!s) || ((s == "auto") && (autoIsZero))) {
231
		return {value:0, units:"px"};
233
		return {value:0, units:"px"};
232
	}
234
	}
233
	var match = s.match(/(\-?[\d.]+)([a-z%]*)/i);
235
	var match = s.match(/(\-?[\d.]+)([a-z%]*)/i);
234
	if (!match) {
236
	if (!match) {
235
		return dojo.html.getUnitValue.bad;
237
		return dojo.html.getUnitValue.bad;
236
	}
238
	}
237
	return {value:Number(match[1]), units:match[2].toLowerCase()};
239
	return {value:Number(match[1]), units:match[2].toLowerCase()};
238
};
240
};
239
dojo.html.getUnitValue.bad = {value:NaN, units:""};
241
dojo.html.getUnitValue.bad = {value:NaN, units:""};
240
if (dojo.render.html.ie) {
242
if (dojo.render.html.ie) {
241
	dojo.html.toPixelValue = function (element, styleValue) {
243
	dojo.html.toPixelValue = function (element, styleValue) {
242
		if (!styleValue) {
244
		if (!styleValue) {
243
			return 0;
245
			return 0;
244
		}
246
		}
245
		if (styleValue.slice(-2) == "px") {
247
		if (styleValue.slice(-2) == "px") {
246
			return parseFloat(styleValue);
248
			return parseFloat(styleValue);
247
		}
249
		}
248
		var pixelValue = 0;
250
		var pixelValue = 0;
249
		with (element) {
251
		with (element) {
250
			var sLeft = style.left;
252
			var sLeft = style.left;
251
			var rsLeft = runtimeStyle.left;
253
			var rsLeft = runtimeStyle.left;
252
			runtimeStyle.left = currentStyle.left;
254
			runtimeStyle.left = currentStyle.left;
253
			try {
255
			try {
254
				style.left = styleValue || 0;
256
				style.left = styleValue || 0;
255
				pixelValue = style.pixelLeft;
257
				pixelValue = style.pixelLeft;
256
				style.left = sLeft;
258
				style.left = sLeft;
257
				runtimeStyle.left = rsLeft;
259
				runtimeStyle.left = rsLeft;
258
			}
260
			}
259
			catch (e) {
261
			catch (e) {
260
			}
262
			}
261
		}
263
		}
262
		return pixelValue;
264
		return pixelValue;
263
	};
265
	};
264
} else {
266
} else {
265
	dojo.html.toPixelValue = function (element, styleValue) {
267
	dojo.html.toPixelValue = function (element, styleValue) {
266
		return (styleValue && (styleValue.slice(-2) == "px") ? parseFloat(styleValue) : 0);
268
		return (styleValue && (styleValue.slice(-2) == "px") ? parseFloat(styleValue) : 0);
267
	};
269
	};
268
}
270
}
269
dojo.html.getPixelValue = function (node, styleProperty, autoIsZero) {
271
dojo.html.getPixelValue = function (node, styleProperty, autoIsZero) {
270
	return dojo.html.toPixelValue(node, dojo.html.getComputedStyle(node, styleProperty));
272
	return dojo.html.toPixelValue(node, dojo.html.getComputedStyle(node, styleProperty));
271
};
273
};
272
dojo.html.setPositivePixelValue = function (node, selector, value) {
274
dojo.html.setPositivePixelValue = function (node, selector, value) {
273
	if (isNaN(value)) {
275
	if (isNaN(value)) {
274
		return false;
276
		return false;
275
	}
277
	}
276
	node.style[selector] = Math.max(0, value) + "px";
278
	node.style[selector] = Math.max(0, value) + "px";
277
	return true;
279
	return true;
278
};
280
};
279
dojo.html.styleSheet = null;
281
dojo.html.styleSheet = null;
280
dojo.html.insertCssRule = function (selector, declaration, index) {
282
dojo.html.insertCssRule = function (selector, declaration, index) {
281
	if (!dojo.html.styleSheet) {
283
	if (!dojo.html.styleSheet) {
282
		if (document.createStyleSheet) {
284
		if (document.createStyleSheet) {
283
			dojo.html.styleSheet = document.createStyleSheet();
285
			dojo.html.styleSheet = document.createStyleSheet();
284
		} else {
286
		} else {
285
			if (document.styleSheets[0]) {
287
			if (document.styleSheets[0]) {
286
				dojo.html.styleSheet = document.styleSheets[0];
288
				dojo.html.styleSheet = document.styleSheets[0];
287
			} else {
289
			} else {
288
				return null;
290
				return null;
289
			}
291
			}
290
		}
292
		}
291
	}
293
	}
292
	if (arguments.length < 3) {
294
	if (arguments.length < 3) {
293
		if (dojo.html.styleSheet.cssRules) {
295
		if (dojo.html.styleSheet.cssRules) {
294
			index = dojo.html.styleSheet.cssRules.length;
296
			index = dojo.html.styleSheet.cssRules.length;
295
		} else {
297
		} else {
296
			if (dojo.html.styleSheet.rules) {
298
			if (dojo.html.styleSheet.rules) {
297
				index = dojo.html.styleSheet.rules.length;
299
				index = dojo.html.styleSheet.rules.length;
298
			} else {
300
			} else {
299
				return null;
301
				return null;
300
			}
302
			}
301
		}
303
		}
302
	}
304
	}
303
	if (dojo.html.styleSheet.insertRule) {
305
	if (dojo.html.styleSheet.insertRule) {
304
		var rule = selector + " { " + declaration + " }";
306
		var rule = selector + " { " + declaration + " }";
305
		return dojo.html.styleSheet.insertRule(rule, index);
307
		return dojo.html.styleSheet.insertRule(rule, index);
306
	} else {
308
	} else {
307
		if (dojo.html.styleSheet.addRule) {
309
		if (dojo.html.styleSheet.addRule) {
308
			return dojo.html.styleSheet.addRule(selector, declaration, index);
310
			return dojo.html.styleSheet.addRule(selector, declaration, index);
309
		} else {
311
		} else {
310
			return null;
312
			return null;
311
		}
313
		}
312
	}
314
	}
313
};
315
};
314
dojo.html.removeCssRule = function (index) {
316
dojo.html.removeCssRule = function (index) {
315
	if (!dojo.html.styleSheet) {
317
	if (!dojo.html.styleSheet) {
316
		dojo.debug("no stylesheet defined for removing rules");
318
		dojo.debug("no stylesheet defined for removing rules");
317
		return false;
319
		return false;
318
	}
320
	}
319
	if (dojo.render.html.ie) {
321
	if (dojo.render.html.ie) {
320
		if (!index) {
322
		if (!index) {
321
			index = dojo.html.styleSheet.rules.length;
323
			index = dojo.html.styleSheet.rules.length;
322
			dojo.html.styleSheet.removeRule(index);
324
			dojo.html.styleSheet.removeRule(index);
323
		}
325
		}
324
	} else {
326
	} else {
325
		if (document.styleSheets[0]) {
327
		if (document.styleSheets[0]) {
326
			if (!index) {
328
			if (!index) {
327
				index = dojo.html.styleSheet.cssRules.length;
329
				index = dojo.html.styleSheet.cssRules.length;
328
			}
330
			}
329
			dojo.html.styleSheet.deleteRule(index);
331
			dojo.html.styleSheet.deleteRule(index);
330
		}
332
		}
331
	}
333
	}
332
	return true;
334
	return true;
333
};
335
};
334
dojo.html._insertedCssFiles = [];
336
dojo.html._insertedCssFiles = [];
335
dojo.html.insertCssFile = function (URI, doc, checkDuplicates, fail_ok) {
337
dojo.html.insertCssFile = function (URI, doc, checkDuplicates, fail_ok) {
336
	if (!URI) {
338
	if (!URI) {
337
		return;
339
		return;
338
	}
340
	}
339
	if (!doc) {
341
	if (!doc) {
340
		doc = document;
342
		doc = document;
341
	}
343
	}
342
	var cssStr = dojo.hostenv.getText(URI, false, fail_ok);
344
	var cssStr = dojo.hostenv.getText(URI, false, fail_ok);
343
	if (cssStr === null) {
345
	if (cssStr === null) {
344
		return;
346
		return;
345
	}
347
	}
346
	cssStr = dojo.html.fixPathsInCssText(cssStr, URI);
348
	cssStr = dojo.html.fixPathsInCssText(cssStr, URI);
347
	if (checkDuplicates) {
349
	if (checkDuplicates) {
348
		var idx = -1, node, ent = dojo.html._insertedCssFiles;
350
		var idx = -1, node, ent = dojo.html._insertedCssFiles;
349
		for (var i = 0; i < ent.length; i++) {
351
		for (var i = 0; i < ent.length; i++) {
350
			if ((ent[i].doc == doc) && (ent[i].cssText == cssStr)) {
352
			if ((ent[i].doc == doc) && (ent[i].cssText == cssStr)) {
351
				idx = i;
353
				idx = i;
352
				node = ent[i].nodeRef;
354
				node = ent[i].nodeRef;
353
				break;
355
				break;
354
			}
356
			}
355
		}
357
		}
356
		if (node) {
358
		if (node) {
357
			var styles = doc.getElementsByTagName("style");
359
			var styles = doc.getElementsByTagName("style");
358
			for (var i = 0; i < styles.length; i++) {
360
			for (var i = 0; i < styles.length; i++) {
359
				if (styles[i] == node) {
361
				if (styles[i] == node) {
360
					return;
362
					return;
361
				}
363
				}
362
			}
364
			}
363
			dojo.html._insertedCssFiles.shift(idx, 1);
365
			dojo.html._insertedCssFiles.shift(idx, 1);
364
		}
366
		}
365
	}
367
	}
366
	var style = dojo.html.insertCssText(cssStr, doc);
368
	var style = dojo.html.insertCssText(cssStr, doc);
367
	dojo.html._insertedCssFiles.push({"doc":doc, "cssText":cssStr, "nodeRef":style});
369
	dojo.html._insertedCssFiles.push({"doc":doc, "cssText":cssStr, "nodeRef":style});
368
	if (style && djConfig.isDebug) {
370
	if (style && djConfig.isDebug) {
369
		style.setAttribute("dbgHref", URI);
371
		style.setAttribute("dbgHref", URI);
370
	}
372
	}
371
	return style;
373
	return style;
372
};
374
};
373
dojo.html.insertCssText = function (cssStr, doc, URI) {
375
dojo.html.insertCssText = function (cssStr, doc, URI) {
374
	if (!cssStr) {
376
	if (!cssStr) {
375
		return;
377
		return;
376
	}
378
	}
377
	if (!doc) {
379
	if (!doc) {
378
		doc = document;
380
		doc = document;
379
	}
381
	}
380
	if (URI) {
382
	if (URI) {
381
		cssStr = dojo.html.fixPathsInCssText(cssStr, URI);
383
		cssStr = dojo.html.fixPathsInCssText(cssStr, URI);
382
	}
384
	}
383
	var style = doc.createElement("style");
385
	var style = doc.createElement("style");
384
	style.setAttribute("type", "text/css");
386
	style.setAttribute("type", "text/css");
385
	var head = doc.getElementsByTagName("head")[0];
387
	var head = doc.getElementsByTagName("head")[0];
386
	if (!head) {
388
	if (!head) {
387
		dojo.debug("No head tag in document, aborting styles");
389
		dojo.debug("No head tag in document, aborting styles");
388
		return;
390
		return;
389
	} else {
391
	} else {
390
		head.appendChild(style);
392
		head.appendChild(style);
391
	}
393
	}
392
	if (style.styleSheet) {
394
	if (style.styleSheet) {
393
		var setFunc = function () {
395
		var setFunc = function () {
394
			try {
396
			try {
395
				style.styleSheet.cssText = cssStr;
397
				style.styleSheet.cssText = cssStr;
396
			}
398
			}
397
			catch (e) {
399
			catch (e) {
398
				dojo.debug(e);
400
				dojo.debug(e);
399
			}
401
			}
400
		};
402
		};
401
		if (style.styleSheet.disabled) {
403
		if (style.styleSheet.disabled) {
402
			setTimeout(setFunc, 10);
404
			setTimeout(setFunc, 10);
403
		} else {
405
		} else {
404
			setFunc();
406
			setFunc();
405
		}
407
		}
406
	} else {
408
	} else {
407
		var cssText = doc.createTextNode(cssStr);
409
		var cssText = doc.createTextNode(cssStr);
408
		style.appendChild(cssText);
410
		style.appendChild(cssText);
409
	}
411
	}
410
	return style;
412
	return style;
411
};
413
};
412
dojo.html.fixPathsInCssText = function (cssStr, URI) {
414
dojo.html.fixPathsInCssText = function (cssStr, URI) {
413
	if (!cssStr || !URI) {
415
	if (!cssStr || !URI) {
414
		return;
416
		return;
415
	}
417
	}
416
	var match, str = "", url = "", urlChrs = "[\\t\\s\\w\\(\\)\\/\\.\\\\'\"-:#=&?~]+";
418
	var match, str = "", url = "", urlChrs = "[\\t\\s\\w\\(\\)\\/\\.\\\\'\"-:#=&?~]+";
417
	var regex = new RegExp("url\\(\\s*(" + urlChrs + ")\\s*\\)");
419
	var regex = new RegExp("url\\(\\s*(" + urlChrs + ")\\s*\\)");
418
	var regexProtocol = /(file|https?|ftps?):\/\//;
420
	var regexProtocol = /(file|https?|ftps?):\/\//;
419
	regexTrim = new RegExp("^[\\s]*(['\"]?)(" + urlChrs + ")\\1[\\s]*?$");
421
	regexTrim = new RegExp("^[\\s]*(['\"]?)(" + urlChrs + ")\\1[\\s]*?$");
420
	if (dojo.render.html.ie55 || dojo.render.html.ie60) {
422
	if (dojo.render.html.ie55 || dojo.render.html.ie60) {
421
		var regexIe = new RegExp("AlphaImageLoader\\((.*)src=['\"](" + urlChrs + ")['\"]");
423
		var regexIe = new RegExp("AlphaImageLoader\\((.*)src=['\"](" + urlChrs + ")['\"]");
422
		while (match = regexIe.exec(cssStr)) {
424
		while (match = regexIe.exec(cssStr)) {
423
			url = match[2].replace(regexTrim, "$2");
425
			url = match[2].replace(regexTrim, "$2");
424
			if (!regexProtocol.exec(url)) {
426
			if (!regexProtocol.exec(url)) {
425
				url = (new dojo.uri.Uri(URI, url).toString());
427
				url = (new dojo.uri.Uri(URI, url).toString());
426
			}
428
			}
427
			str += cssStr.substring(0, match.index) + "AlphaImageLoader(" + match[1] + "src='" + url + "'";
429
			str += cssStr.substring(0, match.index) + "AlphaImageLoader(" + match[1] + "src='" + url + "'";
428
			cssStr = cssStr.substr(match.index + match[0].length);
430
			cssStr = cssStr.substr(match.index + match[0].length);
429
		}
431
		}
430
		cssStr = str + cssStr;
432
		cssStr = str + cssStr;
431
		str = "";
433
		str = "";
432
	}
434
	}
433
	while (match = regex.exec(cssStr)) {
435
	while (match = regex.exec(cssStr)) {
434
		url = match[1].replace(regexTrim, "$2");
436
		url = match[1].replace(regexTrim, "$2");
435
		if (!regexProtocol.exec(url)) {
437
		if (!regexProtocol.exec(url)) {
436
			url = (new dojo.uri.Uri(URI, url).toString());
438
			url = (new dojo.uri.Uri(URI, url).toString());
437
		}
439
		}
438
		str += cssStr.substring(0, match.index) + "url(" + url + ")";
440
		str += cssStr.substring(0, match.index) + "url(" + url + ")";
439
		cssStr = cssStr.substr(match.index + match[0].length);
441
		cssStr = cssStr.substr(match.index + match[0].length);
440
	}
442
	}
441
	return str + cssStr;
443
	return str + cssStr;
442
};
444
};
443
dojo.html.setActiveStyleSheet = function (title) {
445
dojo.html.setActiveStyleSheet = function (title) {
444
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
446
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
445
	while (a = els[i++]) {
447
	while (a = els[i++]) {
446
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
448
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
447
			a.disabled = true;
449
			a.disabled = true;
448
			if (a.getAttribute("title") == title) {
450
			if (a.getAttribute("title") == title) {
449
				a.disabled = false;
451
				a.disabled = false;
450
			}
452
			}
451
		}
453
		}
452
	}
454
	}
453
};
455
};
454
dojo.html.getActiveStyleSheet = function () {
456
dojo.html.getActiveStyleSheet = function () {
455
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
457
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
456
	while (a = els[i++]) {
458
	while (a = els[i++]) {
457
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
459
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
458
			return a.getAttribute("title");
460
			return a.getAttribute("title");
459
		}
461
		}
460
	}
462
	}
461
	return null;
463
	return null;
462
};
464
};
463
dojo.html.getPreferredStyleSheet = function () {
465
dojo.html.getPreferredStyleSheet = function () {
464
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
466
	var i = 0, a, els = dojo.doc().getElementsByTagName("link");
465
	while (a = els[i++]) {
467
	while (a = els[i++]) {
466
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) {
468
		if (a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("rel").indexOf("alt") == -1 && a.getAttribute("title")) {
467
			return a.getAttribute("title");
469
			return a.getAttribute("title");
468
		}
470
		}
469
	}
471
	}
470
	return null;
472
	return null;
471
};
473
};
472
dojo.html.applyBrowserClass = function (node) {
474
dojo.html.applyBrowserClass = function (node) {
473
	var drh = dojo.render.html;
475
	var drh = dojo.render.html;
474
	var classes = {dj_ie:drh.ie, dj_ie55:drh.ie55, dj_ie6:drh.ie60, dj_ie7:drh.ie70, dj_iequirks:drh.ie && drh.quirks, dj_opera:drh.opera, dj_opera8:drh.opera && (Math.floor(dojo.render.version) == 8), dj_opera9:drh.opera && (Math.floor(dojo.render.version) == 9), dj_khtml:drh.khtml, dj_safari:drh.safari, dj_gecko:drh.mozilla};
476
	var classes = {dj_ie:drh.ie, dj_ie55:drh.ie55, dj_ie6:drh.ie60, dj_ie7:drh.ie70, dj_iequirks:drh.ie && drh.quirks, dj_opera:drh.opera, dj_opera8:drh.opera && (Math.floor(dojo.render.version) == 8), dj_opera9:drh.opera && (Math.floor(dojo.render.version) == 9), dj_khtml:drh.khtml, dj_safari:drh.safari, dj_gecko:drh.mozilla};
475
	for (var p in classes) {
477
	for (var p in classes) {
476
		if (classes[p]) {
478
		if (classes[p]) {
477
			dojo.html.addClass(node, p);
479
			dojo.html.addClass(node, p);
478
		}
480
		}
479
	}
481
	}
480
};
482
};
481
 
483