Here's the function I use in my onScreen widget to start an inPanel widget "silently". Basically, you start the panel, which starts the widget. After the widget starts, you hide the panel.
// For inPanel widgets that are not loaded at startup, load and open the panel.
_showPanel: function(widgetCfg, hide, panelMixinData) {
var def = new Deferred();
var panel;
if (widgetCfg) {
// Try getting the panel for this widget
panel = registry.byId(widgetCfg.id + '_panel');
if (panel) {
if (hide) {
// Hide the panel immediately.
domStyle.set(panel.domNode, 'display', 'none');
// panelManager.showPanel calls panelManager.openPanel, which returns a promise.
// We have to wait for the panel to open before we close it.
on.once(panel, 'open', function() {
panel.panelManager.closePanel(panel, false);
});
}
def.resolve(panel);
} else {
this.panelManager.showPanel(widgetCfg).then(lang.hitch(this, function(panel) {
if (hide) {
// Hide the panel immediately.
domStyle.set(panel.domNode, 'display', 'none');
// panelManager.showPanel calls panelManager.openPanel, which returns a promise.
// We have to wait for the panel to open before we close it.
on.once(panel, 'open', function() {
panel.panelManager.closePanel(panel, false);
});
}
lang.mixin(panel, panelMixinData);
def.resolve(panel);
}));
}
} else {
def.resolve(undefined);
}
return def;
},
The panelMixinData argument can be any object you want the widget to have access to when it starts. For example, if the panelMixinData = { myStuff: { stuff1: 'abc', stuff2: 123 } }, the widget you are starting can get that data as:
this.panel = registry.byId(this.id + '_panel');
var thing1 = this.panel.myStuff.stuff1; // 'abc'
var thing2 = this.panel.myStuff.stuff2; // 123
Here's a simplified version of the code at the top of my onScreen widget showing how I get access to the PanelManager:
define([
'jimu/PanelManager'
], function(
PanelManager
) {
var clazz = declare([BaseWidget], {
name: 'Acme',
baseClass: 'jimu-widget-acme',
startup: function() {
this.inherited(arguments);
this.panelManager = PanelManager.getInstance();
},
Hope this helps,
Larry