From d1efd21e67438e87e411f5849f1d74c8a1bd7d28 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 16 May 2014 12:25:49 +0100 Subject: [PATCH] New utility function subwidget, making it easier to write compoound widgets that compose subwidgets (either with each other or with static HTML). --- src/mkws-widget.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/mkws-widget.js b/src/mkws-widget.js index f050e77..25e6855 100644 --- a/src/mkws-widget.js +++ b/src/mkws-widget.js @@ -26,6 +26,34 @@ function widget($, team, type, node) { 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. + that.subwidget = function(type, overrides) { + var attrs = {}; + + // 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"); + } + + var s = []; + s.push('
'); + return s.join(''); + }; + for (var i = 0; i < node.attributes.length; i++) { var a = node.attributes[i]; if (a.name === 'data-mkws-config') { -- 1.7.10.4