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