X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-widget.js;h=25e68555170ee64f1767123c358aaa3236bfb486;hb=d1104229b6ce759a8f825f39d58bde19813a223c;hp=a3a491403e3999a36102f7889c1b70d6071f37ad;hpb=3ddfc388bc88a21cafee6e979f27bbcb4f4f42f6;p=mkws-moved-to-github.git diff --git a/src/mkws-widget.js b/src/mkws-widget.js index a3a4914..25e6855 100644 --- a/src/mkws-widget.js +++ b/src/mkws-widget.js @@ -9,8 +9,7 @@ function widget($, team, type, node) { var that = { team: team, type: type, - node: node, - jqnode: $(node), + node: $(node), config: mkws.objectInheritingFrom(team.config()) }; @@ -25,7 +24,35 @@ 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. + 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]; @@ -122,10 +149,10 @@ widget.autosearch = function(widget) { // Utility function for all widgets that want to hide in narrow windows widget.hideWhenNarrow = function(widget) { widget.team.queue("resize-narrow").subscribe(function(n) { - widget.jqnode.hide(); + widget.node.hide(); }); widget.team.queue("resize-wide").subscribe(function(n) { - widget.jqnode.show(); + widget.node.show(); }); };