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@9: This function is used to insert a script into the active slot. jbe/bsw@0: jbe@10: WARNING: The given script MUST NOT include two closing square brackets directly followed by a greater-than sign, unless the output is interpreted strictly as XHTML. For string literals this is ensured automatically, if being encoded with encode.json{...}. jbe@10: jbe/bsw@0: --]]-- 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@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@9: ui.tag{ jbe/bsw@9: tag = "script", jbe/bsw@9: attr = attr, jbe/bsw@9: content = function() jbe/bsw@9: slot.put("/* ", "]]]]>"))) jbe/bsw@9: slot.put("/* ]]> */") jbe/bsw@9: end jbe/bsw@9: } jbe/bsw@0: end jbe/bsw@0: end