mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
'use strict';
|
|
var widgets = require('../');
|
|
var DUMMY_WIDGET_DEF = {
|
|
elId: function () {
|
|
}
|
|
};
|
|
exports.render = function (input, context) {
|
|
var path = input.path;
|
|
var config = input.config || input._cfg;
|
|
var widgetArgs = context.attributes.widgetArgs;
|
|
var elId = input.elId;
|
|
var scope = input.scope;
|
|
var assignedId = input.assignedId;
|
|
var events;
|
|
if (widgetArgs) {
|
|
delete context.attributes.widgetArgs;
|
|
scope = scope || widgetArgs.scope;
|
|
assignedId = assignedId || widgetArgs.id;
|
|
events = widgetArgs.events;
|
|
}
|
|
if (!elId && input.hasOwnProperty('elId')) {
|
|
throw new Error('Invalid widget ID for "' + path + '"');
|
|
}
|
|
var widgetsContext = widgets.getWidgetsContext(context);
|
|
if (path) {
|
|
widgetsContext.beginWidget({
|
|
path: path,
|
|
id: elId,
|
|
assignedId: assignedId,
|
|
config: config,
|
|
scope: scope,
|
|
events: events,
|
|
createWidget: input.createWidget
|
|
}, function (widgetDef) {
|
|
input.invokeBody(widgetDef);
|
|
});
|
|
} else {
|
|
input.invokeBody(DUMMY_WIDGET_DEF);
|
|
}
|
|
}; |