webmcp
view framework/env/ui/script.lua @ 6:5cba83b3f411
Version 1.0.6
Bugfix: class_prototype:add_reference{...} uses now qualified names in SQL queries to allow JOINs
Fixes in the documentation of slot.put_into and trace.debug
Bugfix: class_prototype:add_reference{...} uses now qualified names in SQL queries to allow JOINs
Fixes in the documentation of slot.put_into and trace.debug
| author | jbe/bsw | 
|---|---|
| date | Fri Jan 22 12:00:00 2010 +0100 (2010-01-22) | 
| parents | 5e32ef998acf | 
| children | 64f4540ce88c | 
 line source
     1 --[[--
     2 ui.script{
     3   noscript_attr = noscript_attr,  -- HTML attributes for noscript tag
     4   noscript      = noscript,       -- string or function for noscript content
     5   attr          = attr,           -- extra HTML attributes for script tag
     6   type          = type,           -- type of script, defaults to "text/javascript"
     7   script        = script,         -- string or function for script content
     8 }
    10 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.
    12 --]]--
    14 -- TODO: CDATA or SGML comment?
    16 function ui.script(args)
    17   local args = args or {}
    18   local noscript_attr = args.noscript_attr
    19   local noscript = args.noscript
    20   local attr = table.new(args.attr)
    21   attr.type = attr.type or args.type or "text/javascript"
    22   local script = args.script
    23   if script and type(script) ~= "function" then
    24     -- disable HTML entity escaping
    25     script = function()
    26       slot.put(args.script)
    27     end
    28   end
    29   if args.external then
    30     attr.src = encode.url{ external = args.external }
    31   elseif args.static then
    32     attr.src = encode.url{ static = args.static }
    33   end
    34   if noscript then
    35     ui.tag{ tag = "noscript", attr = attr, content = noscript }
    36   end
    37   if attr.src then
    38     ui.tag{ tag = "script", attr = attr, content = "" }
    39   elseif script then
    40     ui.tag{ tag = "script", attr = attr, content = script }
    41   end
    42 end
