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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
//>>built
define("dojox/widget/PlaceholderMenuItem", ["dojo", "dijit", "dojox", "dijit/Menu","dijit/MenuItem"], function(dojo, dijit, dojox){
dojo.experimental("dojox.widget.PlaceholderMenuItem");
dojo.declare("dojox.widget.PlaceholderMenuItem", dijit.MenuItem, {
// summary:
// A menu item that can be used as a placeholder. Set the label
// of this item to a unique key and you can then use it to add new
// items at that location. This item is not displayed.
_replaced: false,
_replacedWith: null,
_isPlaceholder: true,
postCreate: function(){
this.domNode.style.display = "none";
this._replacedWith = [];
if(!this.label){
this.label = this.containerNode.innerHTML;
}
this.inherited(arguments);
},
replace: function(/*dijit.MenuItem[]*/ menuItems){
// summary:
// replaces this menu item with the given menuItems. The original
// menu item is not actually removed from the menu - so if you want
// it removed, you must do that explicitly.
// returns:
// true if the replace happened, false if not
if(this._replaced){ return false; }
var index = this.getIndexInParent();
if(index < 0){ return false; }
var p = this.getParent();
dojo.forEach(menuItems, function(item){
p.addChild(item, index++);
});
this._replacedWith = menuItems;
this._replaced = true;
return true;
},
unReplace: function(/*Boolean?*/ destroy){
// summary:
// Removes menu items added by calling replace(). It returns the
// array of items that were actually removed (in case you want to
// clean them up later)
// destroy:
// Also call destroy on any removed items.
// returns:
// The array of items that were actually removed
if(!this._replaced){ return []; }
var p = this.getParent();
if(!p){ return []; }
var r = this._replacedWith;
dojo.forEach(this._replacedWith, function(item){
p.removeChild(item);
if(destroy){
item.destroyRecursive();
}
});
this._replacedWith = [];
this._replaced = false;
return r; // dijit.MenuItem[]
}
});
// Se need to extend dijit.Menu so that we have a getPlaceholders function.
dojo.extend(dijit.Menu, {
getPlaceholders: function(/*String?*/ label){
// summary:
// Returns an array of placeholders with the given label. There
// can be multiples.
// label:
// Label to search for - if not specified, then all placeholders
// are returned
// returns:
// An array of placeholders that match the given label
var r = [];
var children = this.getChildren();
dojo.forEach(children, function(child){
if(child._isPlaceholder && (!label || child.label == label)){
r.push(child);
}else if(child._started && child.popup && child.popup.getPlaceholders){
r = r.concat(child.popup.getPlaceholders(label));
}else if(!child._started && child.dropDownContainer){
var node = dojo.query("[widgetId]", child.dropDownContainer)[0];
var menu = dijit.byNode(node);
if(menu.getPlaceholders){
r = r.concat(menu.getPlaceholders(label));
}
}
}, this);
return r; // dojox.widget.PlaceholderMenuItem[]
}
});
return dojox.widget.PlaceholderMenuItem;
});
|