webmcp

annotate framework/env/ui/container.lua @ 484:66086fa01d6e

Code cleanup; Pass moonbridge_io.poll to main handlers
author jbe
date Sun Jun 11 22:29:20 2017 +0200 (2017-06-11)
parents a2ff42a66212
children efc700d98c17
rev   line source
jbe/bsw@0 1 --[[--
jbe/bsw@0 2 ui.container{
jbe/bsw@0 3 auto_args = auto_args,
jbe/bsw@0 4 attr = attr, -- HTML attributes for the surrounding div or fieldset
jbe/bsw@0 5 label = label, -- text to be used as label
jbe/bsw@0 6 label_for = label_for, -- DOM id of element to which the label should refer
jbe/bsw@0 7 label_attr = label_attr, -- extra HTML attributes for a label tag
jbe/bsw@0 8 legend = legend, -- text to be used as legend
jbe/bsw@0 9 legend_attr = legend_attr, -- HTML attributes for a legend tag
jbe/bsw@0 10 content_first = content_first, -- set to true to place label or legend after the content
jbe/bsw@0 11 content = function()
jbe/bsw@14 12 ...
jbe/bsw@0 13 end
jbe/bsw@0 14 }
jbe/bsw@0 15
jbe/bsw@0 16 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 17
jbe/bsw@0 18 --]]--
jbe/bsw@0 19
jbe/bsw@0 20 function ui.container(args)
bsw@475 21 local attr, label, label_attr, legend, legend_attr, value_container_attr, content
jbe/bsw@0 22 local auto_args = args.auto_args
jbe/bsw@0 23 if auto_args then
jbe/bsw@0 24 attr = auto_args.container_attr
jbe/bsw@0 25 label = auto_args.label
jbe/bsw@0 26 label_attr = auto_args.label_attr
jbe/bsw@0 27 legend = auto_args.legend
jbe/bsw@0 28 legend_attr = auto_args.legend_attr
bsw@475 29 value_container_attr = auto_args.value_container_attr
jbe/bsw@0 30 if label and auto_args.attr and auto_args.attr.id then
jbe/bsw@0 31 label_attr = table.new(label_attr)
jbe/bsw@0 32 label_attr["for"] = auto_args.attr.id
jbe/bsw@0 33 end
jbe/bsw@0 34 else
jbe/bsw@0 35 attr = args.attr
jbe/bsw@0 36 label = args.label
jbe/bsw@0 37 label_attr = args.label_attr or {}
jbe/bsw@0 38 legend = args.legend
jbe/bsw@0 39 legend_attr = args.legend_attr
jbe/bsw@0 40 content = content
jbe/bsw@0 41 if args.label_for then
jbe/bsw@0 42 label_attr["for"] = args.label_for
jbe/bsw@0 43 end
jbe/bsw@0 44 end
jbe/bsw@0 45 local content = args.content
jbe/bsw@0 46 if label and not legend then
jbe/bsw@0 47 return ui.tag {
jbe/bsw@0 48 tag = "div",
jbe/bsw@0 49 attr = attr,
jbe/bsw@0 50 content = function()
jbe/bsw@0 51 if not args.content_first then
jbe/bsw@0 52 ui.tag{ tag = "label", attr = label_attr, content = label }
jbe/bsw@0 53 slot.put(" ")
jbe/bsw@0 54 end
jbe/bsw@0 55 if type(content) == "function" then
bsw@475 56 if value_container_attr then
bsw@475 57 ui.container{
bsw@475 58 attr = value_container_attr,
bsw@475 59 content = content
bsw@475 60 }
bsw@475 61 else
bsw@475 62 content()
bsw@475 63 end
jbe/bsw@0 64 elseif content then
jbe/bsw@0 65 slot.put(encode.html(content))
jbe/bsw@0 66 end
jbe/bsw@0 67 if args.content_first then
jbe/bsw@0 68 slot.put(" ")
jbe/bsw@0 69 ui.tag{ tag = "label", attr = label_attr, content = label }
jbe/bsw@0 70 end
jbe/bsw@0 71 end
jbe/bsw@0 72 }
jbe/bsw@0 73 elseif legend and not label then
jbe/bsw@0 74 return ui.tag {
jbe/bsw@0 75 tag = "fieldset",
jbe/bsw@0 76 attr = attr,
jbe/bsw@0 77 content = function()
jbe/bsw@0 78 if not args.content_first then
jbe/bsw@0 79 ui.tag{ tag = "legend", attr = legend_attr, content = legend }
jbe/bsw@0 80 slot.put(" ")
jbe/bsw@0 81 end
jbe/bsw@0 82 if type(content) == "function" then
jbe/bsw@0 83 content()
jbe/bsw@0 84 elseif content then
jbe/bsw@0 85 slot.put(encode.html(content))
jbe/bsw@0 86 end
jbe/bsw@0 87 if args.content_first then
jbe/bsw@0 88 slot.put(" ")
jbe/bsw@0 89 ui.tag{ tag = "legend", attr = legend_attr, content = legend }
jbe/bsw@0 90 end
jbe/bsw@0 91 end
jbe/bsw@0 92 }
bsw@475 93 elseif legend and label then
jbe/bsw@0 94 error("ui.container{...} may either get a label or a legend.")
jbe/bsw@0 95 else
jbe/bsw@0 96 return ui.tag{ tag = "div", attr = attr, content = content }
jbe/bsw@0 97 end
jbe/bsw@0 98 end

Impressum / About Us