summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/form/manager/_DisplayMixin.js
blob: ae544943196b7fda6bdd30de710cfdd88f00b050 (plain)
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
//>>built
define("dojox/form/manager/_DisplayMixin", [
	"dojo/_base/kernel",
	"dojo/dom-style",
	"dojo/_base/declare"
], function(dojo, domStyle, declare){
return declare("dojox.form.manager._DisplayMixin", null, {
	// summary:
	//		Form manager's mixin for controlling show/hide state of
	//		controlled elements (defined by dojoAttachPoint attributes).
	// description:
	//		This mixin provides unified show/hide functionality for
	//		controlled elements (indicated by dojoAttachPoint attribute).
	//		Essentially it provides a way to change "style.display"
	//		parameter of controlled nodes.
	//		It should be used together with dojox.form.manager.Mixin.

	gatherDisplayState: function(names){
		// summary:
		//		Gather display state of all attached elements and return as a dictionary.
		// names: Object?:
		//		If it is an array, it is a list of names to be processed.
		//		If it is an object, dictionary keys are names to be processed.
		//		If it is omitted, all known attach point nodes are to be processed.

		var result = this.inspectAttachedPoints(function(name, node){
			return domStyle.get(node, "display") != "none";
		}, names);

		return result;	// Object
	},

	show: function(state, defaultState){
		// summary:
		//		Show attached nodes according to the supplied state object.
		// state: Object?:
		//		Optional. If a name-value dictionary, the value is true
		//		to show and false to hide. If an array, all names in the
		//		array will be set to defaultState. If omitted, all form
		//		elements will be set to defaultState.
		// defaultState: Boolean?:
		//		The default state (true, if omitted).

		if(arguments.length < 2){
			defaultState = true;
		}

		this.inspectAttachedPoints(function(name, node, value){
			domStyle.set(node, "display", value ? "" : "none");
		}, state, defaultState);

		return this;	// self
	},

	hide: function(state){
		// summary:
		//		Hide attached nodes according to the supplied state object.
		// state: Object?:
		//		Optional. If a name-value dictionary, the value is true
		//		to show and false to hide. If an array, all names in the
		//		array will be hidden. If omitted, all form elements
		//		will be hidden.
		return this.show(state, false);	// self
	}
});
});