| 1 |
define(["dojo/_base/array", "dojo/_base/declare", "dojo/_base/lang", "dojo/dom-style", "dojo/_base/kernel", "dojo/query", "dijit/registry", "dijit/Menu","dijit/MenuItem"], |
| 2 |
function(array, declare, lang, style, kernel, query, registry, Menu, MenuItem){ |
| 3 |
|
| 4 |
kernel.experimental("dojox.widget.PlaceholderMenuItem"); |
| 5 |
|
| 6 |
var PlaceholderMenuItem = declare("dojox.widget.PlaceholderMenuItem", MenuItem, { |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
_replaced: false, |
| 13 |
_replacedWith: null, |
| 14 |
_isPlaceholder: true, |
| 15 |
|
| 16 |
postCreate: function(){ |
| 17 |
style.set(this.domNode, "display", "none"); |
| 18 |
this._replacedWith = []; |
| 19 |
if(!this.label){ |
| 20 |
this.label = this.containerNode.innerHTML; |
| 21 |
} |
| 22 |
this.inherited(arguments); |
| 23 |
}, |
| 24 |
|
| 25 |
replace: function( menuItems){ |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
if(this._replaced){ return false; } |
| 33 |
|
| 34 |
var index = this.getIndexInParent(); |
| 35 |
if(index < 0){ return false; } |
| 36 |
|
| 37 |
var p = this.getParent(); |
| 38 |
|
| 39 |
array.forEach(menuItems, function(item){ |
| 40 |
p.addChild(item, index++); |
| 41 |
}); |
| 42 |
this._replacedWith = menuItems; |
| 43 |
|
| 44 |
this._replaced = true; |
| 45 |
return true; |
| 46 |
}, |
| 47 |
|
| 48 |
unReplace: function( destroy){ |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
if(!this._replaced){ return []; } |
| 59 |
|
| 60 |
var p = this.getParent(); |
| 61 |
if(!p){ return []; } |
| 62 |
|
| 63 |
var r = this._replacedWith; |
| 64 |
array.forEach(this._replacedWith, function(item){ |
| 65 |
p.removeChild(item); |
| 66 |
if(destroy){ |
| 67 |
item.destroyRecursive(); |
| 68 |
} |
| 69 |
}); |
| 70 |
this._replacedWith = []; |
| 71 |
this._replaced = false; |
| 72 |
|
| 73 |
return r; |
| 74 |
} |
| 75 |
}); |
| 76 |
|
| 77 |
|
| 78 |
lang.extend(Menu, { |
| 79 |
getPlaceholders: function( label){ |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
var r = []; |
| 89 |
|
| 90 |
var children = this.getChildren(); |
| 91 |
array.forEach(children, function(child){ |
| 92 |
if(child._isPlaceholder && (!label || child.label == label)){ |
| 93 |
r.push(child); |
| 94 |
}else if(child._started && child.popup && child.popup.getPlaceholders){ |
| 95 |
r = r.concat(child.popup.getPlaceholders(label)); |
| 96 |
}else if(!child._started && child.dropDownContainer){ |
| 97 |
var node = query("[widgetId]", child.dropDownContainer)[0]; |
| 98 |
var menu = registry.byNode(node); |
| 99 |
if(menu.getPlaceholders){ |
| 100 |
r = r.concat(menu.getPlaceholders(label)); |
| 101 |
} |
| 102 |
} |
| 103 |
}, this); |
| 104 |
return r; |
| 105 |
} |
| 106 |
}); |
| 107 |
|
| 108 |
return PlaceholderMenuItem; |
| 109 |
|
| 110 |
}); |