- Publicity: Public Only All
head-procs.tcl
The template::head::* API manipulates the head section of the document that will be returned to the users client. Packages should use this API to add package specific javascripts, CSS, link tags and meta tags to the HTML document.
- Location:
- packages/acs-templating/tcl/head-procs.tcl
- Created:
- 2007-05-18
- Author:
- Lee Denison <lee@xarg.co.uk>
Procedures in this file
- template::add_body_handler (public)
- template::add_body_script (public)
- template::add_confirm_handler (public)
- template::add_event_listener (public)
- template::add_footer (public)
- template::add_header (public)
- template::add_refresh_on_history_handler (public)
- template::add_script (public)
- template::collect_body_scripts (public)
- template::get_body_event_handlers (public)
- template::get_footer_html (public)
- template::get_header_html (public)
- template::head::add_css (public)
- template::head::add_javascript (public)
- template::head::add_link (public)
- template::head::add_meta (public)
- template::head::add_script (public)
- template::head::add_style (public)
- template::head::can_resolve_urn (public)
- template::head::flush_link (public)
- template::head::flush_script (public)
- template::head::includes (public)
- template::register_urn (public)
- template::set_css_property (public)
Detailed information
template::add_body_handler (public)
template::add_body_handler -event event -script script \ [ -identifier identifier ]
Adds JavaScript code to an event handler in the body tag. Several JavaScript code blocks may be assigned to each handler by subsequent calls to template::add_body_handler.
If your script may only be added once you may supply an identifier. Subsequent calls to template::add_body_handler with the same identifier will replace your script rather than appending to it.
event
may be one of:
- onload
- onunload
- onclick
- ondblclick
- onmousedown
- onmouseup
- onmouseover
- onmousemove
- onmouseout
- onkeypress
- onkeydown
- onkeyup
- Switches:
- -event (required)
- the event during which the supplied script should be executed
- -script (required)
- the JavaScript code to execute
- -identifier (optional, defaults to
"anonymous"
)- a name, if supplied, used to ensure this JavaScript code is only added to the handler once
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::add_body_script (public)
template::add_body_script [ -async ] [ -charset charset ] \ [ -crossorigin crossorigin ] [ -defer ] [ -integrity integrity ] \ [ -script script ] [ -src src ] [ -type type ]
Add a script to the start of the body section of the document to be returned to the users client. You must supply either src or script.
- Switches:
- -async (optional, boolean)
- whether execution of the script should be executed asynchronously as soon as it is available
- -charset (optional)
- the charset attribute of the script tag, i.e. the character set of the script if it differs from the main document
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -defer (optional, boolean)
- whether execution of the script should be deferred until after the page has been loaded
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -script (optional)
- the inline script for the body of the script tag. This parameter will be ignored if a value has been supplied for src
- -src (optional)
- the src attribute of the script tag, i.e. the source url of the script
- -type (optional, defaults to
"text/javascript"
)- the type attribute of the script tag, e.g. 'text/javascript'
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts, xowiki_test_cases
template::add_confirm_handler (public)
template::add_confirm_handler [ -event event ] [ -message message ] \ [ -CSSclass CSSclass ] [ -id id ] [ -selector selector ] \ [ -formfield formfield ]
Register an event handler for confirmation dialogs for elements either with a specified ID, CSS class, a formfield targeted by form id and field name or a CSS selector.
- Switches:
- -event (optional, defaults to
"click"
)- register confirm handler for this type of event
- -message (optional, defaults to
"Are you sure?"
)- Message to be displayed in the confirmation dialog. If the message looks like a message key (starting and ending with a hash sign) it is treated as a message key
- -CSSclass (optional, defaults to
"acs-confirm"
)- register confirm handler for this CSS class
- -id (optional)
- register confirm handler for this HTML ID
- -selector (optional)
- register confirm handler for elements identified by this CSS selector. When a CSS selector contains double and single quotes, we won't add any of those around the selector automatically. Instead, the user must specify them explicitly, for instance like this: ... -selector {'[name="o\'hara"]'}. If the selector does not contain any single or double quotes, we can let the user omit them, as for the case of a simple tag name selector: ... -selector "li". Quotes can also be omitted if the selector contains only one kind of them, like ... -selector {[data-property='value']} or ... -selector {[data-property="value"]}
- -formfield (optional)
- register confirm handler for this formfield, specified in a list of two elements in the form
{ form_id field_name }
- Author:
- Gustaf Neumann
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::add_event_listener (public)
template::add_event_listener [ -event event ] [ -CSSclass CSSclass ] \ [ -id id ] [ -formfield formfield ] [ -selector selector ] \ [ -usecapture ] [ -preventdefault ] -script script
Register an event handler for elements. The affected elements can be specified in different ways, which will be checked in the following order of precedence: id, formfield, selector and CSSclass. Normally one needs to provide only one kind of specification.
- Switches:
- -event (optional, defaults to
"click"
)- register handler for this type of event
- -CSSclass (optional, defaults to
"acs-listen"
)- register handler for this CSS class
- -id (optional)
- register handler for this HTML ID
- -formfield (optional)
- register handler for this formfield, specified in a list of two elements in the form
{ form_id field_name }
- -selector (optional)
- register handler for elements identified by this CSS selector. When a CSS selector contains double and single quotes, we won't add any of those around the selector automatically. Instead, the user must specify them explicitly, for instance like this: ... -selector {'[name="o\'hara"]'}. If the selector does not contain any single or double quotes, we can let the user omit them, as for the case of a simple tag name selector: ... -selector "li". Quotes can also be omitted if the selector contains only one kind of them, like ... -selector {[data-property='value']} or ... -selector {[data-property="value"]}
- -usecapture (optional, boolean, defaults to
"false"
)- indicating whether event will be dispatched to the registered listener before being dispatched to any EventTarget beneath it in the DOM tree.
- -preventdefault (optional, boolean, defaults to
"true"
)- this option can the used prevent default click handling
- -script (required)
- Author:
- Gustaf Neumann
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::add_footer (public)
template::add_footer [ -direction direction ] [ -src src ] \ [ -params params ] [ -html html ]
Add a footer include to the end of the document body. This function is used by site-wide services to add functionality to the end of a page. Examples include the developer support toolbar, acs-lang translation interface and the acs-templating WYSIWYG editor textarea place holder. If you are not implementing a site-wide service, you should not be using this function to add content to your page. You must supply either src or html.
- Switches:
- -direction (optional, defaults to
"outer"
)- whether the footer should be added as the outer most page content or the inner most
- -src (optional)
- the path to the include
- -params (optional)
- a list of name, value pairs to pass as parameter to the include
- -html (optional)
- literal html to include in the page. This parameter will be ignored if a values has been supplied for src.
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::add_header (public)
template::add_header [ -direction direction ] [ -src src ] \ [ -params params ] [ -html html ]
Add a header include to the beginning of the document body. This function is used by site-wide services to add functionality to the beginning of a page. Examples include the developer support toolbar, acs-lang translation interface and the acs-templating WYSIWYG editor textarea place holder. If you are not implementing a site-wide service, you should not be using this function to add content to your page. You must supply either src or html.
- Switches:
- -direction (optional, defaults to
"outer"
)- whether the header should be added as the outer most page content or the inner most
- -src (optional)
- the path to the include
- -params (optional)
- a list of name, value pairs to pass as parameter to the include
- -html (optional)
- literal html to include in the page. This parameter will be ignored if a values has been supplied for src.
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::add_refresh_on_history_handler (public)
template::add_refresh_on_history_handler
Register an event handler which will trigger a complete page refresh when we land on this page by accessing the browser's history (back and forward buttons). This is useful e.g. for those pages where some push interaction is happening and retrieving the page from the browser history would display it in an inconsistent state.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::add_script (public)
template::add_script [ -async ] [ -charset charset ] \ [ -crossorigin crossorigin ] [ -defer ] [ -integrity integrity ] \ [ -order order ] [ -script script ] [ -section section ] \ [ -src src ] [ -type type ]
- Switches:
- -async (optional, boolean)
- whether execution of the script should be executed asynchronously as soon as it is available
- -charset (optional)
- the charset attribute of the script tag, i.e. the character set of the script if it differs from the main document
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -defer (optional, boolean)
- whether execution of the script should be deferred until after the page has been loaded
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -order (optional, defaults to
"0"
)- specify inclusion order
- -script (optional)
- the inline script for the body of the script tag. This parameter will be ignored if a value has been supplied for src
- -section (optional, defaults to
"head"
)- section, where script is added ("head" or "body")
- -src (optional)
- the src attribute of the script tag, i.e. the source url of the script
- -type (optional, defaults to
"text/javascript"
)- the type attribute of the script tag, e.g. 'text/javascript'
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::collect_body_scripts (public)
template::collect_body_scripts
Collect the body scripts via an easy to call function, hiding the template used for the implementation.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::get_body_event_handlers (public)
template::get_body_event_handlers
Get body event handlers specified with template::add_body_handler. The proc clears the global variable ::template::body_handlers after having processed its content.
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- templates_and_scripts
template::get_footer_html (public)
template::get_footer_html
Get footers as a chunk of html suitable for insertion into blank-master.adp Called only from blank-master.tcl
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::get_header_html (public)
template::get_header_html
Get headers as a chunk of html suitable for insertion into blank-master.adp Called only from blank-master.tcl
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::head::add_css (public)
template::head::add_css [ -alternate ] [ -crossorigin crossorigin ] \ -href href [ -integrity integrity ] [ -lang lang ] \ [ -media media ] [ -order order ] [ -title title ]
Add a link tag with relation type 'stylesheet' or 'alternate stylesheet', and type 'text/css' to the head section of the document to be returned to the users client. A given target stylesheet may only be added once; subsequent calls to add_css will replace the existing entry. This function is a wrapper around template::head::add_link.
- Switches:
- -alternate (optional, boolean)
- sets the rel attribute of the link tag defining to 'alternate stylesheet' if set, sets it to 'stylesheet' otherwise
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -href (required)
- the href attribute of the link tag, e.g. the target stylesheet
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -lang (optional)
- the lang attribute of the link tag specifying the language of its attributes if they differ from the document language
- -media (optional, defaults to
"all"
)- the media attribute of the link tag describing which display media this link is relevant to. This may be a comma separated list of values, e.g. 'screen,print,braille'
- -order (optional, defaults to
"0"
)- -title (optional)
- the title attribute of the link tag describing the target of this link
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- xowiki_test_cases
template::head::add_javascript (public)
template::head::add_javascript [ -async ] [ -charset charset ] \ [ -crossorigin crossorigin ] [ -defer ] [ -integrity integrity ] \ [ -order order ] [ -script script ] [ -src src ]
Add a script of type 'text/javascript' to the head section of the document to be returned to the users client. This function is a wrapper around template::head::add_script. You must supply either src or script.
- Switches:
- -async (optional, boolean)
- whether execution of the script should be executed asynchronously as soon as it is available
- -charset (optional)
- the charset attribute of the script tag, i.e. the character set of the script if it differs from the main document
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -defer (optional, boolean)
- whether execution of the script should be deferred until after the page has been loaded
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -order (optional, defaults to
"0"
)- specify inclusion order
- -script (optional)
- the inline script for the body of the script tag. This parameter will be ignored if a value has been supplied for src
- -src (optional)
- the src attribute of the script tag, i.e. the source url of the script
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::head::add_link (public)
template::head::add_link [ -crossorigin crossorigin ] -href href \ [ -integrity integrity ] [ -lang lang ] [ -media media ] \ [ -order order ] -rel rel [ -title title ] [ -type type ]
Add a link tag to the head section of the document to be returned to the users client. A given target document may only be added once for a specified relation; subsequent calls to add_link will replace the existing entry.
- Switches:
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -href (required)
- the href attribute of the link tag, e.g. the target document of the link
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -lang (optional)
- the lang attribute of the link tag specifying the language of its attributes if they differ from the document language
- -media (optional)
- the media attribute of the link tag describing which display media this link is relevant to. This may be a comma
- -order (optional, defaults to
"0"
)- specify inclusion order
- -rel (required)
- the rel attribute of the link tag defining the relationship of the linked document to the current one, e.g. 'stylesheet'
- -title (optional)
- the title attribute of the link tag describing the target of this link
- -type (optional)
- the type attribute of the link tag, e.g. 'text/css' separated list of values, e.g. 'screen,print,braille'
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::head::add_meta (public)
template::head::add_meta [ -http_equiv http_equiv ] [ -name name ] \ [ -scheme scheme ] [ -content content ] [ -lang lang ]
Add a meta tag to the head section of the document to be returned to the users client. A meta tag with a given name or http-equiv may only be added once; subsequent calls to add_meta will replace the existing entry. You must supply either name or http_equiv.
- Switches:
- -http_equiv (optional)
- the http-equiv attribute of the meta tag, i.e. the HTTP header which this metadata is equivalent to e.g. 'content-type'
- -name (optional)
- the name attribute of the meta tag, i.e. the metadata identifier
- -scheme (optional)
- the scheme attribute of the meta tag defining which metadata scheme should be used to interpret the metadata, e.g. 'DC' for Dublin Core (http://dublincore.org/)
- -content (optional)
- the content attribute of the meta tag, i.e. the metadata value
- -lang (optional)
- the lang attribute of the meta tag specifying the language of its attributes if they differ from the document language
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- xowiki_test_cases
template::head::add_script (public)
template::head::add_script [ -async ] [ -charset charset ] \ [ -crossorigin crossorigin ] [ -defer ] [ -integrity integrity ] \ [ -order order ] [ -script script ] [ -src src ] [ -type type ]
Add a script to the head section of the document to be returned to the users client. A script library in an external file may only be included once; subsequent calls to add_script will replace the existing entry. Anonymous script blocks will be added without checking for duplicates; the caller must ensure that anonymous script blocks are not inadvertently added multiple times. You must supply either src or script.
- Switches:
- -async (optional, boolean)
- whether execution of the script should be executed asynchronously as soon as it is available
- -charset (optional)
- the charset attribute of the script tag, i.e. the character set of the script if it differs from the main document
- -crossorigin (optional)
- Enumerated attribute to indicate whether CORS (Cross-Origin Resource Sharing) should be used
- -defer (optional, boolean)
- whether execution of the script should be deferred until after the page has been loaded
- -integrity (optional)
- provide hash values for W3C Subresource Integrity recommendation
- -order (optional, defaults to
"0"
)- specify inclusion order
- -script (optional)
- the inline script for the body of the script tag. This parameter will be ignored if a value has been supplied for src
- -src (optional)
- the src attribute of the script tag, i.e. the source url of the script
- -type (optional, defaults to
"text/javascript"
)- the type attribute of the script tag, e.g. 'text/javascript'
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::head::add_style (public)
template::head::add_style -style style [ -title title ] [ -lang lang ] \ [ -media media ] [ -type type ]
Add an embedded css style declaration
- Switches:
- -style (required)
- CSS content to be included in the style tag
- -title (optional)
- the title attribute of the link tag describing the target of this link
- -lang (optional)
- the lang attribute of the link tag specifying the language of its attributes if they differ from the document language
- -media (optional)
- the media attribute of the link tag describing which display media this link is relevant to. This may be a comma separated list of values, e.g. 'screen,print,braille'
- -type (optional, defaults to
"text/css"
)- the type attribute of the link tag, e.g. 'text/css'
- Author:
- Dave Bauer <dave@thedesignexperience.org>
- Created:
- 2007-11-30
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.
template::head::can_resolve_urn (public)
template::head::can_resolve_urn resource
Return a boolean value indicating, whether we can resolve the URN.
- Parameters:
- resource (required)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- urn_api
template::head::flush_link (public)
template::head::flush_link -href href -rel rel
Flush a link tag, which was previously set in the head section via template::head::add_link
- Switches:
- -href (required)
- the href attribute of the link tag, e.g. the target document of the link. A glob pattern similar link in "string match" can be provided.
- -rel (required)
- the rel attribute of the link tag defining the relationship of the linked document to the current one, e.g. 'stylesheet'
- Author:
- Gustaf Neumann
- Created:
- 2018-03-09
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- head_includes
template::head::flush_script (public)
template::head::flush_script -src src
Flush a script tag, which was previously set in the head section via template::add_script. One can delete multiple entries by providing a glob pattern.
- Switches:
- -src (required)
- src attribute of the script tag, i.e. the source url of the script. A glob pattern similar link in "string match" can be provided.
- Author:
- Gustaf Neumann
- Created:
- 2018-03-09
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- head_includes
template::head::includes (public)
template::head::includes -container container -parts parts
Define, that a compound resource (container) contains multiple parts. Container and parts are typically URLs, which are referred to by a "href" attribute or by link or a "src" attribute of a script.
- Switches:
- -container (required)
- compound resource
- -parts (required)
- list of resources, which are included in a compound resource (container).
- Author:
- Gustaf Neumann
- Created:
- 2018-03-09
- See Also:
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- head_includes
template::register_urn (public)
template::register_urn -urn urn -resource resource \ [ -csp_list csp_list ]
Register a URN for a resource. These URNs provide a single place for e.g. updating references to external resources when switching between a CDN and a local resource, or when a resource should be updated. We could consider a dns-prefetch for CDN requests. When the url-check is performed at register time, the performance for processing the url can be neglected.
- Switches:
- -urn (required)
- -resource (required)
- -csp_list (optional)
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- urn_api
template::set_css_property (public)
template::set_css_property [ -class class ] \ [ -querySelector querySelector ] -property property -value value
Set the specified CSS property in the DOM tree of the browser for elements for the specified class or query selector. This function should be used sparely in special situations, where CSS modification other approaches might be too complex.
- Switches:
- -class (optional)
- CSS class for which properties is set
- -querySelector (optional)
- CSS querySelector via the javascript function querySelectorAll
- -property (required)
- CSS property
- -value (required)
- value for the CSS property
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- No testcase defined.