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/bsw@11: WARNING: If the script contains two closing square brackets directly followed by a greater-than sign, it will be rejected to avoid ambiguity related to HTML vs. XML parsing. Additional space characters can be added within the program code to avoid occurrence of the character sequence. The function encode.json{...} encodes all string literals in a way that the sequence is not contained. 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@11: local script_string jbe/bsw@11: if type(script) == "function" then jbe/bsw@11: script_string = slot.use_temporary(script) jbe/bsw@11: else jbe/bsw@11: script_string = script jbe/bsw@11: end jbe/bsw@11: if string.find(script_string, "]]>") then jbe/bsw@11: error('Script contains character sequence "]]>" and is thus rejected to avoid ambiguity. If this sequence occurs as part of program code, please add additional space characters. If this sequence occurs inside a string literal, please encode one of this characters using the \\uNNNN unicode escape sequence.') jbe/bsw@11: end 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: end jbe/bsw@9: } jbe/bsw@0: end jbe/bsw@0: end