jbe/bsw@0: --[[-- jbe/bsw@0: ui.container{ jbe/bsw@0: auto_args = auto_args, jbe/bsw@0: attr = attr, -- HTML attributes for the surrounding div or fieldset jbe/bsw@0: label = label, -- text to be used as label jbe/bsw@0: label_for = label_for, -- DOM id of element to which the label should refer jbe/bsw@0: label_attr = label_attr, -- extra HTML attributes for a label tag jbe/bsw@0: legend = legend, -- text to be used as legend jbe/bsw@0: legend_attr = legend_attr, -- HTML attributes for a legend tag jbe/bsw@0: content_first = content_first, -- set to true to place label or legend after the content jbe/bsw@0: content = function() jbe/bsw@14: ... jbe/bsw@0: end jbe/bsw@0: } jbe/bsw@0: jbe/bsw@0: This function encloses content in a div element (or a fieldset element, if 'legend' is given). An additional 'label' or 'legend' can be placed before the content or after the content. The argument 'auto_args' is set by other ui helper functions when calling ui.container automatically. jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: function ui.container(args) jbe/bsw@0: local attr, label, label_attr, legend, legend_attr, content jbe/bsw@0: local auto_args = args.auto_args jbe/bsw@0: if auto_args then jbe/bsw@0: attr = auto_args.container_attr jbe/bsw@0: label = auto_args.label jbe/bsw@0: label_attr = auto_args.label_attr jbe/bsw@0: legend = auto_args.legend jbe/bsw@0: legend_attr = auto_args.legend_attr jbe/bsw@0: if label and auto_args.attr and auto_args.attr.id then jbe/bsw@0: label_attr = table.new(label_attr) jbe/bsw@0: label_attr["for"] = auto_args.attr.id jbe/bsw@0: end jbe/bsw@0: else jbe/bsw@0: attr = args.attr jbe/bsw@0: label = args.label jbe/bsw@0: label_attr = args.label_attr or {} jbe/bsw@0: legend = args.legend jbe/bsw@0: legend_attr = args.legend_attr jbe/bsw@0: content = content jbe/bsw@0: if args.label_for then jbe/bsw@0: label_attr["for"] = args.label_for jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: local content = args.content jbe/bsw@0: if label and not legend then jbe/bsw@0: return ui.tag { jbe/bsw@0: tag = "div", jbe/bsw@0: attr = attr, jbe/bsw@0: content = function() jbe/bsw@0: if not args.content_first then jbe/bsw@0: ui.tag{ tag = "label", attr = label_attr, content = label } jbe/bsw@0: slot.put(" ") jbe/bsw@0: end jbe/bsw@0: if type(content) == "function" then jbe/bsw@0: content() jbe/bsw@0: elseif content then jbe/bsw@0: slot.put(encode.html(content)) jbe/bsw@0: end jbe/bsw@0: if args.content_first then jbe/bsw@0: slot.put(" ") jbe/bsw@0: ui.tag{ tag = "label", attr = label_attr, content = label } jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: } jbe/bsw@0: elseif legend and not label then jbe/bsw@0: return ui.tag { jbe/bsw@0: tag = "fieldset", jbe/bsw@0: attr = attr, jbe/bsw@0: content = function() jbe/bsw@0: if not args.content_first then jbe/bsw@0: ui.tag{ tag = "legend", attr = legend_attr, content = legend } jbe/bsw@0: slot.put(" ") jbe/bsw@0: end jbe/bsw@0: if type(content) == "function" then jbe/bsw@0: content() jbe/bsw@0: elseif content then jbe/bsw@0: slot.put(encode.html(content)) jbe/bsw@0: end jbe/bsw@0: if args.content_first then jbe/bsw@0: slot.put(" ") jbe/bsw@0: ui.tag{ tag = "legend", attr = legend_attr, content = legend } jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@0: } jbe/bsw@0: elseif fieldset and label then jbe/bsw@0: error("ui.container{...} may either get a label or a legend.") jbe/bsw@0: else jbe/bsw@0: return ui.tag{ tag = "div", attr = attr, content = content } jbe/bsw@0: end jbe/bsw@0: end