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.AccordionContainer");
12
dojo.require("dojo.widget.*");
13
dojo.require("dojo.html.*");
14
dojo.require("dojo.lfx.html");
15
dojo.require("dojo.html.selection");
16
dojo.require("dojo.widget.html.layout");
17
dojo.require("dojo.widget.PageContainer");
18
dojo.widget.defineWidget("dojo.widget.AccordionContainer", dojo.widget.HtmlWidget, {isContainer:true, labelNodeClass:"label", containerNodeClass:"accBody", duration:250, fillInTemplate:function () {
19
	with (this.domNode.style) {
20
		if (position != "absolute") {
21
			position = "relative";
22
		}
23
		overflow = "hidden";
24
	}
25
}, addChild:function (widget) {
26
	var child = this._addChild(widget);
27
	this._setSizes();
28
	return child;
29
}, _addChild:function (widget) {
30
	if (widget.open) {
31
		dojo.deprecated("open parameter deprecated, use 'selected=true' instead will be removed in ", "0.5");
32
		dojo.debug(widget.widgetId + ": open == " + widget.open);
33
		widget.selected = true;
34
	}
35
	if (widget.widgetType != "AccordionPane") {
36
		var wrapper = dojo.widget.createWidget("AccordionPane", {label:widget.label, selected:widget.selected, labelNodeClass:this.labelNodeClass, containerNodeClass:this.containerNodeClass, allowCollapse:this.allowCollapse});
37
		wrapper.addChild(widget);
38
		this.addWidgetAsDirectChild(wrapper);
39
		this.registerChild(wrapper, this.children.length);
40
		return wrapper;
41
	} else {
42
		dojo.html.addClass(widget.containerNode, this.containerNodeClass);
43
		dojo.html.addClass(widget.labelNode, this.labelNodeClass);
44
		this.addWidgetAsDirectChild(widget);
45
		this.registerChild(widget, this.children.length);
46
		return widget;
47
	}
48
}, postCreate:function () {
49
	var tmpChildren = this.children;
50
	this.children = [];
51
	dojo.html.removeChildren(this.domNode);
52
	dojo.lang.forEach(tmpChildren, dojo.lang.hitch(this, "_addChild"));
53
	this._setSizes();
54
}, removeChild:function (widget) {
55
	dojo.widget.AccordionContainer.superclass.removeChild.call(this, widget);
56
	this._setSizes();
57
}, onResized:function () {
58
	this._setSizes();
59
}, _setSizes:function () {
60
	var totalCollapsedHeight = 0;
61
	var openIdx = 0;
62
	dojo.lang.forEach(this.children, function (child, idx) {
63
		totalCollapsedHeight += child.getLabelHeight();
64
		if (child.selected) {
65
			openIdx = idx;
66
		}
67
	});
68
	var mySize = dojo.html.getContentBox(this.domNode);
69
	var y = 0;
70
	dojo.lang.forEach(this.children, function (child, idx) {
71
		var childCollapsedHeight = child.getLabelHeight();
72
		child.resizeTo(mySize.width, mySize.height - totalCollapsedHeight + childCollapsedHeight);
73
		child.domNode.style.zIndex = idx + 1;
74
		child.domNode.style.position = "absolute";
75
		child.domNode.style.top = y + "px";
76
		y += (idx == openIdx) ? dojo.html.getBorderBox(child.domNode).height : childCollapsedHeight;
77
	});
78
}, selectChild:function (page) {
79
	dojo.lang.forEach(this.children, function (child) {
80
		child.setSelected(child == page);
81
	});
82
	var y = 0;
83
	var anims = [];
84
	dojo.lang.forEach(this.children, function (child, idx) {
85
		if (child.domNode.style.top != (y + "px")) {
86
			anims.push(dojo.lfx.html.slideTo(child.domNode, {top:y, left:0}, this.duration));
87
		}
88
		y += child.selected ? dojo.html.getBorderBox(child.domNode).height : child.getLabelHeight();
89
	}, this);
90
	dojo.lfx.combine(anims).play();
91
}});
92
dojo.widget.defineWidget("dojo.widget.AccordionPane", dojo.widget.HtmlWidget, {label:"", "class":"dojoAccordionPane", labelNodeClass:"label", containerNodeClass:"accBody", selected:false, templateString:"<div dojoAttachPoint=\"domNode\">\n<div dojoAttachPoint=\"labelNode\" dojoAttachEvent=\"onclick: onLabelClick\" class=\"${this.labelNodeClass}\">${this.label}</div>\n<div dojoAttachPoint=\"containerNode\" style=\"overflow: hidden;\" class=\"${this.containerNodeClass}\"></div>\n</div>\n", templateCssString:".dojoAccordionPane .label {\n\tcolor: #000;\n\tfont-weight: bold;\n\tbackground: url(\"images/soriaAccordionOff.gif\") repeat-x top left #85aeec;\n\tborder:1px solid #d9d9d9;\n\tfont-size:0.9em;\n}\n\n.dojoAccordionPane-selected .label {\n\tbackground: url(\"images/soriaAccordionSelected.gif\") repeat-x top left #85aeec;\n\tborder:1px solid #84a3d1;\n}\n\n.dojoAccordionPane .label:hover {\n\tcursor: pointer;\n}\n\n.dojoAccordionPane .accBody {\n\tbackground: #fff;\n\toverflow: auto;\n\tborder:1px solid #84a3d1;\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/AccordionPane.css"), isContainer:true, fillInTemplate:function () {
93
	dojo.html.addClass(this.domNode, this["class"]);
94
	dojo.widget.AccordionPane.superclass.fillInTemplate.call(this);
95
	dojo.html.disableSelection(this.labelNode);
96
	this.setSelected(this.selected);
97
}, setLabel:function (label) {
98
	this.labelNode.innerHTML = label;
99
}, resizeTo:function (width, height) {
100
	dojo.html.setMarginBox(this.domNode, {width:width, height:height});
101
	var children = [{domNode:this.labelNode, layoutAlign:"top"}, {domNode:this.containerNode, layoutAlign:"client"}];
102
	dojo.widget.html.layout(this.domNode, children);
103
	var childSize = dojo.html.getContentBox(this.containerNode);
104
	this.children[0].resizeTo(childSize.width, childSize.height);
105
}, getLabelHeight:function () {
106
	return dojo.html.getMarginBox(this.labelNode).height;
107
}, onLabelClick:function () {
108
	this.parent.selectChild(this);
109
}, setSelected:function (isSelected) {
110
	this.selected = isSelected;
111
	(isSelected ? dojo.html.addClass : dojo.html.removeClass)(this.domNode, this["class"] + "-selected");
112
	var child = this.children[0];
113
	if (child) {
114
		if (isSelected) {
115
			if (!child.isShowing()) {
116
				child.show();
117
			} else {
118
				child.onShow();
119
			}
120
		} else {
121
			child.onHide();
122
		}
123
	}
124
}});
125
dojo.lang.extend(dojo.widget.Widget, {open:false});
126