Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
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:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
11
dojo.provide("dojo.widget.Rounded");
12
dojo.widget.tags.addParseTreeHandler("dojo:rounded");
13
dojo.require("dojo.widget.*");
14
dojo.require("dojo.widget.ContentPane");
15
dojo.require("dojo.html.style");
16
dojo.require("dojo.html.display");
17
dojo.require("dojo.gfx.color");
18
dojo.deprecated("dojo.widget.Rounded will be removed in version 0.5; you can now apply rounded corners to any block element using dojo.lfx.rounded.", "0.5");
19
dojo.widget.defineWidget("dojo.widget.Rounded", dojo.widget.ContentPane, {isSafari:dojo.render.html.safari, boxMargin:"50px", radius:14, domNode:"", corners:"TR,TL,BR,BL", antiAlias:true, fillInTemplate:function (args, frag) {
20
	dojo.widget.Rounded.superclass.fillInTemplate.call(this, args, frag);
21
	dojo.html.insertCssFile(this.templateCssPath);
22
	if (this.domNode.style.height <= 0) {
23
		var minHeight = (this.radius * 1) + this.domNode.clientHeight;
24
		this.domNode.style.height = minHeight + "px";
25
	}
26
	if (this.domNode.style.width <= 0) {
27
		var minWidth = (this.radius * 1) + this.domNode.clientWidth;
28
		this.domNode.style.width = minWidth + "px";
29
	}
30
	var cornersAvailable = ["TR", "TL", "BR", "BL"];
31
	var cornersPassed = this.corners.split(",");
32
	this.settings = {antiAlias:this.antiAlias};
33
	var setCorner = function (currentCorner) {
34
		var val = currentCorner.toLowerCase();
35
		if (dojo.lang.inArray(cornersPassed, currentCorner)) {
36
			this.settings[val] = {radius:this.radius, enabled:true};
37
		} else {
38
			this.settings[val] = {radius:0};
39
		}
40
	};
41
	dojo.lang.forEach(cornersAvailable, setCorner, this);
42
	this.domNode.style.margin = this.boxMargin;
43
	this.curvyCorners(this.settings);
44
	this.applyCorners();
45
}, curvyCorners:function (settings) {
46
	this.box = this.domNode;
47
	this.topContainer = null;
48
	this.bottomContainer = null;
49
	this.masterCorners = [];
50
	var boxHeight = dojo.html.getStyle(this.box, "height");
51
	if (boxHeight == "") {
52
		boxHeight = "0px";
53
	}
54
	var boxWidth = dojo.html.getStyle(this.box, "width");
55
	var borderWidth = dojo.html.getStyle(this.box, "borderTopWidth");
56
	if (borderWidth == "") {
57
		borderWidth = "0px";
58
	}
59
	var borderColour = dojo.html.getStyle(this.box, "borderTopColor");
60
	if (borderWidth > 0) {
61
		this.antiAlias = true;
62
	}
63
	var boxColour = dojo.html.getStyle(this.box, "backgroundColor");
64
	var backgroundImage = dojo.html.getStyle(this.box, "backgroundImage");
65
	var boxPosition = dojo.html.getStyle(this.box, "position");
66
	this.boxHeight = parseInt(((boxHeight != "" && boxHeight != "auto" && boxHeight.indexOf("%") == -1) ? boxHeight.substring(0, boxHeight.indexOf("px")) : this.box.scrollHeight));
67
	this.boxWidth = parseInt(((boxWidth != "" && boxWidth != "auto" && boxWidth.indexOf("%") == -1) ? boxWidth.substring(0, boxWidth.indexOf("px")) : this.box.scrollWidth));
68
	this.borderWidth = parseInt(((borderWidth != "" && borderWidth.indexOf("px") !== -1) ? borderWidth.slice(0, borderWidth.indexOf("px")) : 0));
69
	var test = new dojo.gfx.color.Color(boxColour);
70
	this.boxColour = ((boxColour != "" && boxColour != "transparent") ? ((boxColour.substr(0, 3) == "rgb") ? this.rgb2Hex(boxColour) : boxColour) : "#ffffff");
71
	this.borderColour = ((borderColour != "" && borderColour != "transparent" && this.borderWidth > 0) ? ((borderColour.substr(0, 3) == "rgb") ? this.rgb2Hex(borderColour) : borderColour) : this.boxColour);
72
	this.borderString = this.borderWidth + "px" + " solid " + this.borderColour;
73
	this.backgroundImage = ((backgroundImage != "none") ? backgroundImage : "");
74
	if (boxPosition != "absolute") {
75
		this.box.style.position = "relative";
76
	}
77
	this.applyCorners = function () {
78
		for (var t = 0; t < 2; t++) {
79
			switch (t) {
80
			  case 0:
81
				if (this.settings.tl.enabled || this.settings.tr.enabled) {
82
					var newMainContainer = document.createElement("DIV");
83
					with (newMainContainer.style) {
84
						width = "100%";
85
						fontSize = "1px";
86
						overflow = "hidden";
87
						position = "absolute";
88
						paddingLeft = this.borderWidth + "px";
89
						paddingRight = this.borderWidth + "px";
90
						var topMaxRadius = Math.max(this.settings.tl ? this.settings.tl.radius : 0, this.settings.tr ? this.settings.tr.radius : 0);
91
						height = topMaxRadius + "px";
92
						top = 0 - topMaxRadius + "px";
93
						left = 0 - this.borderWidth + "px";
94
					}
95
					this.topContainer = this.box.appendChild(newMainContainer);
96
				}
97
				break;
98
			  case 1:
99
				if (this.settings.bl.enabled || this.settings.br.enabled) {
100
					var newMainContainer = document.createElement("DIV");
101
					with (newMainContainer.style) {
102
						width = "100%";
103
						fontSize = "1px";
104
						overflow = "hidden";
105
						position = "absolute";
106
						paddingLeft = this.borderWidth + "px";
107
						paddingRight = this.borderWidth + "px";
108
						var botMaxRadius = Math.max(this.settings.bl ? this.settings.bl.radius : 0, this.settings.br ? this.settings.br.radius : 0);
109
						height = botMaxRadius + "px";
110
						bottom = 0 - botMaxRadius + "px";
111
						left = 0 - this.borderWidth + "px";
112
					}
113
					this.bottomContainer = this.box.appendChild(newMainContainer);
114
				}
115
				break;
116
			}
117
		}
118
		if (this.topContainer) {
119
			this.box.style.borderTopWidth = "0px";
120
		}
121
		if (this.bottomContainer) {
122
			this.box.style.borderBottomWidth = "0px";
123
		}
124
		var corners = ["tr", "tl", "br", "bl"];
125
		for (var i in corners) {
126
			var cc = corners[i];
127
			if (!this.settings[cc]) {
128
				if (((cc == "tr" || cc == "tl") && this.topContainer != null) || ((cc == "br" || cc == "bl") && this.bottomContainer != null)) {
129
					var newCorner = document.createElement("DIV");
130
					newCorner.style.position = "relative";
131
					newCorner.style.fontSize = "1px";
132
					newCorner.style.overflow = "hidden";
133
					if (this.backgroundImage == "") {
134
						newCorner.style.backgroundColor = this.boxColour;
135
					} else {
136
						newCorner.style.backgroundImage = this.backgroundImage;
137
					}
138
					switch (cc) {
139
					  case "tl":
140
						with (newCorner.style) {
141
							height = topMaxRadius - this.borderWidth + "px";
142
							marginRight = this.settings.tr.radius - (this.borderWidth * 2) + "px";
143
							borderLeft = this.borderString;
144
							borderTop = this.borderString;
145
							left = -this.borderWidth + "px";
146
						}
147
						break;
148
					  case "tr":
149
						with (newCorner.style) {
150
							height = topMaxRadius - this.borderWidth + "px";
151
							marginLeft = this.settings.tl.radius - (this.borderWidth * 2) + "px";
152
							borderRight = this.borderString;
153
							borderTop = this.borderString;
154
							backgroundPosition = "-" + this.boxWidth + "px 0px";
155
							left = this.borderWidth + "px";
156
						}
157
						break;
158
					  case "bl":
159
						with (newCorner.style) {
160
							height = botMaxRadius - this.borderWidth + "px";
161
							marginRight = this.settings.br.radius - (this.borderWidth * 2) + "px";
162
							borderLeft = this.borderString;
163
							borderBottom = this.borderString;
164
							left = -this.borderWidth + "px";
165
						}
166
						break;
167
					  case "br":
168
						with (newCorner.style) {
169
							height = botMaxRadius - this.borderWidth + "px";
170
							marginLeft = this.settings.bl.radius - (this.borderWidth * 2) + "px";
171
							borderRight = this.borderString;
172
							borderBottom = this.borderString;
173
							left = this.borderWidth + "px";
174
						}
175
						break;
176
					}
177
				}
178
			} else {
179
				if (this.masterCorners[this.settings[cc].radius]) {
180
					var newCorner = this.masterCorners[this.settings[cc].radius].cloneNode(true);
181
				} else {
182
					var newCorner = document.createElement("DIV");
183
					with (newCorner.style) {
184
						height = this.settings[cc].radius + "px";
185
						width = this.settings[cc].radius + "px";
186
						position = "absolute";
187
						fontSize = "1px";
188
						overflow = "hidden";
189
					}
190
					var borderRadius = parseInt(this.settings[cc].radius - this.borderWidth);
191
					for (var intx = 0, j = this.settings[cc].radius; intx < j; intx++) {
192
						if ((intx + 1) >= borderRadius) {
193
							var y1 = -1;
194
						} else {
195
							var y1 = (Math.floor(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow((intx + 1), 2))) - 1);
196
						}
197
						if (borderRadius != j) {
198
							if ((intx) >= borderRadius) {
199
								var y2 = -1;
200
							} else {
201
								var y2 = Math.ceil(Math.sqrt(Math.pow(borderRadius, 2) - Math.pow(intx, 2)));
202
							}
203
							if ((intx + 1) >= j) {
204
								var y3 = -1;
205
							} else {
206
								var y3 = (Math.floor(Math.sqrt(Math.pow(j, 2) - Math.pow((intx + 1), 2))) - 1);
207
							}
208
						}
209
						if ((intx) >= j) {
210
							var y4 = -1;
211
						} else {
212
							var y4 = Math.ceil(Math.sqrt(Math.pow(j, 2) - Math.pow(intx, 2)));
213
						}
214
						if (y1 > -1) {
215
							this.drawPixel(intx, 0, this.boxColour, 100, (y1 + 1), newCorner, -1, this.settings[cc].radius);
216
						}
217
						if (borderRadius != j) {
218
							if (this.antiAlias) {
219
								for (var inty = (y1 + 1); inty < y2; inty++) {
220
									if (this.backgroundImage != "") {
221
										var borderFract = (this.pixelFraction(intx, inty, borderRadius) * 100);
222
										if (borderFract < 30) {
223
											this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, 0, this.settings[cc].radius);
224
										} else {
225
											this.drawPixel(intx, inty, this.borderColour, 100, 1, newCorner, -1, this.settings[cc].radius);
226
										}
227
									} else {
228
										var pixelcolour = dojo.gfx.color.blend(this.boxColour, this.borderColour, this.pixelFraction(intx, inty, borderRadius));
229
										this.drawPixel(intx, inty, pixelcolour, 100, 1, newCorner, 0, this.settings[cc].radius);
230
									}
231
								}
232
							}
233
							if (y3 >= y2) {
234
								if (y1 == -1) {
235
									y1 = 0;
236
								}
237
								this.drawPixel(intx, y2, this.borderColour, 100, (y3 - y2 + 1), newCorner, 0, this.settings[cc].radius);
238
							}
239
							var outsideColour = this.borderColour;
240
						} else {
241
							var outsideColour = this.boxColour;
242
							var y3 = y1;
243
						}
244
						if (this.antiAlias) {
245
							for (var inty = (y3 + 1); inty < y4; inty++) {
246
								this.drawPixel(intx, inty, outsideColour, (this.pixelFraction(intx, inty, j) * 100), 1, newCorner, ((this.borderWidth > 0) ? 0 : -1), this.settings[cc].radius);
247
							}
248
						}
249
					}
250
					this.masterCorners[this.settings[cc].radius] = newCorner.cloneNode(true);
251
				}
252
				if (cc != "br") {
253
					for (var t = 0, k = newCorner.childNodes.length; t < k; t++) {
254
						var pixelBar = newCorner.childNodes[t];
255
						var pixelBarTop = parseInt(pixelBar.style.top.substring(0, pixelBar.style.top.indexOf("px")));
256
						var pixelBarLeft = parseInt(pixelBar.style.left.substring(0, pixelBar.style.left.indexOf("px")));
257
						var pixelBarHeight = parseInt(pixelBar.style.height.substring(0, pixelBar.style.height.indexOf("px")));
258
						if (cc == "tl" || cc == "bl") {
259
							pixelBar.style.left = this.settings[cc].radius - pixelBarLeft - 1 + "px";
260
						}
261
						if (cc == "tr" || cc == "tl") {
262
							pixelBar.style.top = this.settings[cc].radius - pixelBarHeight - pixelBarTop + "px";
263
						}
264
						var value;
265
						switch (cc) {
266
						  case "tr":
267
							value = (-1 * (Math.abs((this.boxWidth - this.settings[cc].radius + this.borderWidth) + pixelBarLeft) - (Math.abs(this.settings[cc].radius - pixelBarHeight - pixelBarTop - this.borderWidth))));
268
							pixelBar.style.backgroundPosition = value + "px";
269
							break;
270
						  case "tl":
271
							value = (-1 * (Math.abs((this.settings[cc].radius - pixelBarLeft - 1) - this.borderWidth) - (Math.abs(this.settings[cc].radius - pixelBarHeight - pixelBarTop - this.borderWidth))));
272
							pixelBar.style.backgroundPosition = value + "px";
273
							break;
274
						  case "bl":
275
							value = (-1 * (Math.abs((this.settings[cc].radius - pixelBarLeft - 1) - this.borderWidth) - (Math.abs((this.boxHeight + this.settings[cc].radius + pixelBarTop) - this.borderWidth))));
276
							pixelBar.style.backgroundPosition = value + "px";
277
							break;
278
						}
279
					}
280
				}
281
			}
282
			if (newCorner) {
283
				switch (cc) {
284
				  case "tl":
285
					if (newCorner.style.position == "absolute") {
286
						newCorner.style.top = "0px";
287
					}
288
					if (newCorner.style.position == "absolute") {
289
						newCorner.style.left = "0px";
290
					}
291
					if (this.topContainer) {
292
						this.topContainer.appendChild(newCorner);
293
					}
294
					break;
295
				  case "tr":
296
					if (newCorner.style.position == "absolute") {
297
						newCorner.style.top = "0px";
298
					}
299
					if (newCorner.style.position == "absolute") {
300
						newCorner.style.right = "0px";
301
					}
302
					if (this.topContainer) {
303
						this.topContainer.appendChild(newCorner);
304
					}
305
					break;
306
				  case "bl":
307
					if (newCorner.style.position == "absolute") {
308
						newCorner.style.bottom = "0px";
309
					}
310
					if (newCorner.style.position == "absolute") {
311
						newCorner.style.left = "0px";
312
					}
313
					if (this.bottomContainer) {
314
						this.bottomContainer.appendChild(newCorner);
315
					}
316
					break;
317
				  case "br":
318
					if (newCorner.style.position == "absolute") {
319
						newCorner.style.bottom = "0px";
320
					}
321
					if (newCorner.style.position == "absolute") {
322
						newCorner.style.right = "0px";
323
					}
324
					if (this.bottomContainer) {
325
						this.bottomContainer.appendChild(newCorner);
326
					}
327
					break;
328
				}
329
			}
330
		}
331
		var radiusDiff = [];
332
		radiusDiff["t"] = this.settings.tl.enabled && this.settings.tr.enabled ? Math.abs(this.settings.tl.radius - this.settings.tr.radius) : 0;
333
		radiusDiff["b"] = this.settings.bl.enabled && this.settings.br.enabled ? Math.abs(this.settings.bl.radius - this.settings.br.radius) : 0;
334
		for (var z in radiusDiff) {
335
			if (radiusDiff[z]) {
336
				var smallerCornerType = ((this.settings[z + "l"].radius < this.settings[z + "r"].radius) ? z + "l" : z + "r");
337
				var newFiller = document.createElement("DIV");
338
				with (newFiller.style) {
339
					height = radiusDiff[z] + "px";
340
					width = this.settings[smallerCornerType].radius + "px";
341
					position = "absolute";
342
					fontSize = "1px";
343
					overflow = "hidden";
344
					backgroundColor = this.boxColour;
345
				}
346
				switch (smallerCornerType) {
347
				  case "tl":
348
					with (newFiller.style) {
349
						bottom = "0px";
350
						left = "0px";
351
						borderLeft = this.borderString;
352
					}
353
					this.topContainer.appendChild(newFiller);
354
					break;
355
				  case "tr":
356
					with (newFiller.style) {
357
						bottom = "0px";
358
						right = "0px";
359
						borderRight = this.borderString;
360
					}
361
					this.topContainer.appendChild(newFiller);
362
					break;
363
				  case "bl":
364
					with (newFiller.style) {
365
						top = "0px";
366
						left = "0px";
367
						borderLeft = this.borderString;
368
					}
369
					this.bottomContainer.appendChild(newFiller);
370
					break;
371
				  case "br":
372
					with (newFiller.style) {
373
						top = "0px";
374
						right = "0px";
375
						borderRight = this.borderString;
376
					}
377
					this.bottomContainer.appendChild(newFiller);
378
					break;
379
				}
380
			}
381
			var newFillerBar = document.createElement("DIV");
382
			with (newFillerBar.style) {
383
				position = "relative";
384
				fontSize = "1px";
385
				overflow = "hidden";
386
				backgroundColor = this.boxColour;
387
			}
388
			switch (z) {
389
			  case "t":
390
				if (this.topContainer) {
391
					with (newFillerBar.style) {
392
						height = topMaxRadius - this.borderWidth + "px";
393
						marginLeft = this.settings.tl.radius - this.borderWidth + "px";
394
						marginRight = this.settings.tr.radius - this.borderWidth + "px";
395
						borderTop = this.borderString;
396
					}
397
					this.topContainer.appendChild(newFillerBar);
398
				}
399
				break;
400
			  case "b":
401
				if (this.bottomContainer) {
402
					with (newFillerBar.style) {
403
						height = botMaxRadius - this.borderWidth + "px";
404
						marginLeft = this.settings.bl.radius - this.borderWidth + "px";
405
						marginRight = this.settings.br.radius - this.borderWidth + "px";
406
						borderBottom = this.borderString;
407
					}
408
					this.bottomContainer.appendChild(newFillerBar);
409
				}
410
				break;
411
			}
412
		}
413
	};
414
	this.drawPixel = function (intx, inty, colour, transAmount, height, newCorner, image, cornerRadius) {
415
		var pixel = document.createElement("DIV");
416
		pixel.style.height = height + "px";
417
		pixel.style.width = "1px";
418
		pixel.style.position = "absolute";
419
		pixel.style.fontSize = "1px";
420
		pixel.style.overflow = "hidden";
421
		if (image == -1 && this.backgroundImage != "") {
422
			pixel.style.backgroundImage = this.backgroundImage;
423
			pixel.style.backgroundPosition = "-" + (this.boxWidth - (cornerRadius - intx) + this.borderWidth) + "px -" + ((this.boxHeight + cornerRadius + inty) - this.borderWidth) + "px";
424
		} else {
425
			pixel.style.backgroundColor = colour;
426
		}
427
		if (transAmount != 100) {
428
			dojo.html.setOpacity(pixel, transAmount);
429
		}
430
		pixel.style.top = inty + "px";
431
		pixel.style.left = intx + "px";
432
		newCorner.appendChild(pixel);
433
	};
434
}, pixelFraction:function (x, y, r) {
435
	var pixelfraction = 0;
436
	var xvalues = [];
437
	var yvalues = [];
438
	var point = 0;
439
	var whatsides = "";
440
	var intersect = Math.sqrt((Math.pow(r, 2) - Math.pow(x, 2)));
441
	if ((intersect >= y) && (intersect < (y + 1))) {
442
		whatsides = "Left";
443
		xvalues[point] = 0;
444
		yvalues[point] = intersect - y;
445
		point = point + 1;
446
	}
447
	var intersect = Math.sqrt((Math.pow(r, 2) - Math.pow(y + 1, 2)));
448
	if ((intersect >= x) && (intersect < (x + 1))) {
449
		whatsides = whatsides + "Top";
450
		xvalues[point] = intersect - x;
451
		yvalues[point] = 1;
452
		point = point + 1;
453
	}
454
	var intersect = Math.sqrt((Math.pow(r, 2) - Math.pow(x + 1, 2)));
455
	if ((intersect >= y) && (intersect < (y + 1))) {
456
		whatsides = whatsides + "Right";
457
		xvalues[point] = 1;
458
		yvalues[point] = intersect - y;
459
		point = point + 1;
460
	}
461
	var intersect = Math.sqrt((Math.pow(r, 2) - Math.pow(y, 2)));
462
	if ((intersect >= x) && (intersect < (x + 1))) {
463
		whatsides = whatsides + "Bottom";
464
		xvalues[point] = intersect - x;
465
		yvalues[point] = 0;
466
	}
467
	switch (whatsides) {
468
	  case "LeftRight":
469
		pixelfraction = Math.min(yvalues[0], yvalues[1]) + ((Math.max(yvalues[0], yvalues[1]) - Math.min(yvalues[0], yvalues[1])) / 2);
470
		break;
471
	  case "TopRight":
472
		pixelfraction = 1 - (((1 - xvalues[0]) * (1 - yvalues[1])) / 2);
473
		break;
474
	  case "TopBottom":
475
		pixelfraction = Math.min(xvalues[0], xvalues[1]) + ((Math.max(xvalues[0], xvalues[1]) - Math.min(xvalues[0], xvalues[1])) / 2);
476
		break;
477
	  case "LeftBottom":
478
		pixelfraction = (yvalues[0] * xvalues[1]) / 2;
479
		break;
480
	  default:
481
		pixelfraction = 1;
482
	}
483
	return pixelfraction;
484
}, rgb2Hex:function (rgbColour) {
485
	try {
486
		var rgbArray = this.rgb2Array(rgbColour);
487
		var red = parseInt(rgbArray[0]);
488
		var green = parseInt(rgbArray[1]);
489
		var blue = parseInt(rgbArray[2]);
490
		var hexColour = "#" + this.intToHex(red) + this.intToHex(green) + this.intToHex(blue);
491
	}
492
	catch (e) {
493
		alert("There was an error converting the RGB value to Hexadecimal in function rgb2Hex");
494
	}
495
	return hexColour;
496
}, intToHex:function (strNum) {
497
	var base = strNum / 16;
498
	var rem = strNum % 16;
499
	var base = base - (rem / 16);
500
	var baseS = this.makeHex(base);
501
	var remS = this.makeHex(rem);
502
	return baseS + "" + remS;
503
}, makeHex:function (x) {
504
	if ((x >= 0) && (x <= 9)) {
505
		return x;
506
	} else {
507
		switch (x) {
508
		  case 10:
509
			return "A";
510
		  case 11:
511
			return "B";
512
		  case 12:
513
			return "C";
514
		  case 13:
515
			return "D";
516
		  case 14:
517
			return "E";
518
		  case 15:
519
			return "F";
520
		}
521
	}
522
}, rgb2Array:function (rgbColour) {
523
	var rgbValues = rgbColour.substring(4, rgbColour.indexOf(")"));
524
	var rgbArray = rgbValues.split(", ");
525
	return rgbArray;
526
}});
527