jbe/bsw@0: --[[-- jbe/bsw@0: ui.script{ jbe/bsw@0: noscript_attr = noscript_attr, -- HTML attributes for noscript tag jbe/bsw@0: noscript = noscript, -- string or function for noscript content jbe/bsw@0: attr = attr, -- extra HTML attributes for script tag jbe/bsw@0: type = type, -- type of script, defaults to "text/javascript" jbe/bsw@0: script = script, -- string or function for script content jbe/bsw@0: } jbe/bsw@0: jbe/bsw@0: This function is used to insert a script into the active slot. It is currently not XML compliant and the script must not contain a closing script tag. jbe/bsw@0: jbe/bsw@0: --]]-- jbe/bsw@0: jbe/bsw@0: -- TODO: CDATA or SGML comment? jbe/bsw@0: jbe/bsw@0: function ui.script(args) jbe/bsw@0: local args = args or {} jbe/bsw@0: local noscript_attr = args.noscript_attr jbe/bsw@0: local noscript = args.noscript jbe/bsw@0: local attr = table.new(args.attr) jbe/bsw@0: attr.type = attr.type or args.type or "text/javascript" jbe/bsw@0: local script = args.script jbe/bsw@0: if script and type(script) ~= "function" then jbe/bsw@0: -- disable HTML entity escaping jbe/bsw@0: script = function() jbe/bsw@0: slot.put(args.script) jbe/bsw@0: end jbe/bsw@0: end jbe/bsw@4: if args.external then jbe/bsw@4: attr.src = encode.url{ external = args.external } jbe/bsw@4: elseif args.static then jbe/bsw@4: attr.src = encode.url{ static = args.static } jbe/bsw@4: end jbe/bsw@0: if noscript then jbe/bsw@0: ui.tag{ tag = "noscript", attr = attr, content = noscript } jbe/bsw@0: end jbe/bsw@4: if attr.src then jbe/bsw@4: ui.tag{ tag = "script", attr = attr, content = "" } jbe/bsw@4: elseif script then jbe/bsw@0: ui.tag{ tag = "script", attr = attr, content = script } jbe/bsw@0: end jbe/bsw@0: end