template::get_body_event_handlers (public)

 template::get_body_event_handlers

Defined in packages/acs-templating/tcl/head-procs.tcl

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):
%3 test_templates_and_scripts templates_and_scripts (test acs-templating) template::get_body_event_handlers template::get_body_event_handlers test_templates_and_scripts->template::get_body_event_handlers template::add_body_script template::add_body_script (public) template::get_body_event_handlers->template::add_body_script template::register_double_click_handler template::register_double_click_handler (private) template::get_body_event_handlers->template::register_double_click_handler packages/acs-bootstrap-installer/installer/www/blank-master.tcl packages/acs-bootstrap-installer/ installer/www/blank-master.tcl packages/acs-bootstrap-installer/installer/www/blank-master.tcl->template::get_body_event_handlers packages/acs-templating/lib/body_scripts.tcl packages/acs-templating/ lib/body_scripts.tcl packages/acs-templating/lib/body_scripts.tcl->template::get_body_event_handlers

Testcases:
templates_and_scripts
Source code:
    template::register_double_click_handler

    #
    # Concatenate the JavaScript event handlers for the body tag
    #
    variable ::template::body_handlers
    set event_handlers ""

    if {[array exists body_handlers]} {

        #
        # Collect all entries for one event type (e.g. "onload")
        #
        foreach name [array names body_handlers] {
            set event [lindex [split $name ","] 0]
            foreach js $body_handlers($name) {
                lappend body_handlers($event"[string trimright $js {; }];"
            }
            unset body_handlers($name)
        }

        #
        # Turn events into calls for event listener and add these via
        # add_body_script.
        #
        set js ""
        foreach {event script} [array get body_handlers] {
            #
            # Remove the "on" prefix if provided. E.g. "onload" is
            # mapped to the "load" event on "window" (UIevent). It
            # would as well be possible to map to DOM events (on
            # "document")
            # (https://developer.mozilla.org/en-US/docs/Web/Events)
            #
            regsub ^on $event "" event
            append js [ns_trim -delimiter | [subst {
                | window.addEventListener('$event', function () {
                |     [join $script { }]
                | }, false);
                |}]]
        }
        if {$js ne ""} {
            template::add_body_script -script $js
        }

        unset body_handlers
    }

    return $event_handlers
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: