webmcp

diff framework/env/ui/script.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children 5e32ef998acf
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/ui/script.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,35 @@
     1.4 +--[[--
     1.5 +ui.script{
     1.6 +  noscript_attr = noscript_attr,  -- HTML attributes for noscript tag
     1.7 +  noscript      = noscript,       -- string or function for noscript content
     1.8 +  attr          = attr,           -- extra HTML attributes for script tag
     1.9 +  type          = type,           -- type of script, defaults to "text/javascript"
    1.10 +  script        = script,         -- string or function for script content
    1.11 +}
    1.12 +
    1.13 +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.
    1.14 +
    1.15 +--]]--
    1.16 +
    1.17 +-- TODO: CDATA or SGML comment?
    1.18 +
    1.19 +function ui.script(args)
    1.20 +  local args = args or {}
    1.21 +  local noscript_attr = args.noscript_attr
    1.22 +  local noscript = args.noscript
    1.23 +  local attr = table.new(args.attr)
    1.24 +  attr.type = attr.type or args.type or "text/javascript"
    1.25 +  local script = args.script
    1.26 +  if script and type(script) ~= "function" then
    1.27 +    -- disable HTML entity escaping
    1.28 +    script = function()
    1.29 +      slot.put(args.script)
    1.30 +    end
    1.31 +  end
    1.32 +  if noscript then
    1.33 +    ui.tag{ tag = "noscript", attr = attr, content = noscript }
    1.34 +  end
    1.35 +  if script then
    1.36 +    ui.tag{ tag = "script", attr = attr, content = script }
    1.37 +  end
    1.38 +end

Impressum / About Us