X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget.js;h=8be006482852f6031de084ed2b7d5384b1a829f0;hb=13b29fcfe3c38ab073a0f56fc30930d81f7798dc;hp=a0a5795bc88aece3fe6bd4e4e8759ad938353a4b;hpb=16708a6aebe10acd3b72bcb20b03c54d1195a1b9;p=mkws-moved-to-github.git diff --git a/src/mkws-widget.js b/src/mkws-widget.js index a0a5795..8be0064 100644 --- a/src/mkws-widget.js +++ b/src/mkws-widget.js @@ -24,7 +24,47 @@ function widget($, team, type, node) { that.value = function() { return node.value; - } + }; + + // Returns the HTML of a subwidget of the specified type. It gets + // the same attributes at the parent widget that invokes this + // function, except where overrides are passed in. If defaults are + // also provided, then these are used when the parent widget + // provides no values. + that.subwidget = function(type, overrides, defaults) { + var attrs = { _team: team.name() }; + + // Copy locally-set properties from the parent widget + for (var name in this.config) { + if (this.config.hasOwnProperty(name)) { + attrs[name] = this.config[name]; + log(this + " copied property " + name + "='" + attrs[name] + "' to " + type + " subwidget"); + } + } + + for (var name in overrides) { + attrs[name] = overrides[name]; + log(this + " overrode property " + name + "='" + attrs[name] + "' for " + type + " subwidget"); + } + + if (defaults) { + for (var name in defaults) { + if (!attrs[name]) { + attrs[name] = defaults[name]; + log(this + " fell back to default property " + name + "='" + attrs[name] + "' for " + type + " subwidget"); + } + } + } + + var s = []; + s.push('
'); + return s.join(''); + }; for (var i = 0; i < node.attributes.length; i++) { var a = node.attributes[i];