Index: openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.adp,v diff -u -r1.2.2.2 -r1.2.2.3 --- openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.adp 6 Sep 2016 17:33:55 -0000 1.2.2.2 +++ openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.adp 9 Sep 2016 08:12:25 -0000 1.2.2.3 @@ -17,7 +17,7 @@ enforce the order, it is put here. - @@ -28,7 +28,7 @@ @head;literal@ - class="@body.class;literal@" id="@body.id;literal@"@event_handlers;literal@> + class="@body.class;literal@" id="@body.id;literal@"> @header;literal@ @footer;literal@ Index: openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.tcl,v diff -u -r1.2.2.6 -r1.2.2.7 --- openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.tcl 6 Sep 2016 17:33:55 -0000 1.2.2.6 +++ openacs-4/packages/acs-bootstrap-installer/installer/www/blank-master.tcl 9 Sep 2016 08:12:25 -0000 1.2.2.7 @@ -91,21 +91,9 @@ # Add standard javascript # # Include core.js inclusion to the bottom of the body. -# The only function needed alread onload is acs_Focus() -# + template::add_body_script -type "text/javascript" -src "/resources/acs-subsite/core.js" -template::head::add_javascript -script { - function acs_Focus(form_name, element_name) { - if (document.forms == null) return; - if (document.forms[form_name] == null) return; - if (document.forms[form_name].elements[element_name] == null) return; - if (document.forms[form_name].elements[element_name].type == 'hidden') return; - - document.forms[form_name].elements[element_name].focus(); - } -} - # # Add css for the current subsite, defaulting to the old list/form css which was # hard-wired in previous versions of OpenACS. @@ -238,21 +226,36 @@ } if {[info exists focus] && $focus ne ""} { - # Handle elements where the name contains a dot + # + # Handle only values of focus where the provided name contains a + # dot. + # if { [regexp {^([^.]*)\.(.*)$} $focus match form_name element_name] } { - template::add_body_handler \ - -event onload \ - -script "acs_Focus('${form_name}', '${element_name}');" \ - -identifier "focus" + set focus_script { + function acs_Focus(form_name, element_name) { + if (document.forms == null) return; + if (document.forms[form_name] == null) return; + if (document.forms[form_name].elements[element_name] == null) return; + if (document.forms[form_name].elements[element_name].type == 'hidden') return; + + document.forms[form_name].elements[element_name].focus(); + }} + append focus_script "acs_Focus('${form_name}', '${element_name}');\n" + template::add_body_script -script $focus_script + } else { + ns_log warning "blank-master: variable focus has invalid value '$focus'" } } # Retrieve headers and footers set header [template::get_header_html] set footer [template::get_footer_html] template::head::prepare_multirows -set event_handlers [template::get_body_event_handlers] +# body event handlers are converted into body_scripts +template::get_body_event_handlers + + # Local variables: # mode: tcl # tcl-indent-level: 4 Index: openacs-4/packages/acs-templating/tcl/head-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/head-procs.tcl,v diff -u -r1.20.2.3 -r1.20.2.4 --- openacs-4/packages/acs-templating/tcl/head-procs.tcl 5 Sep 2016 11:34:40 -0000 1.20.2.3 +++ openacs-4/packages/acs-templating/tcl/head-procs.tcl 9 Sep 2016 08:12:25 -0000 1.20.2.4 @@ -695,10 +695,26 @@ unset body_handlers($name) } - # Now create the event handlers string + set js "" foreach {event script} [array get body_handlers] { - append event_handlers " " $event = \" [join $script { }] \" + # + # 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 [subst { + window.addEventListener('$event', function () { + [join $script { }] + }); + }] } + if {$js ne ""} { + template::add_body_script -script $js + } + unset body_handlers } Index: openacs-4/www/blank-master.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/www/blank-master.adp,v diff -u -r1.31.2.2 -r1.31.2.3 --- openacs-4/www/blank-master.adp 6 Sep 2016 17:33:55 -0000 1.31.2.2 +++ openacs-4/www/blank-master.adp 9 Sep 2016 08:12:25 -0000 1.31.2.3 @@ -17,7 +17,7 @@ enforce the order, it is put here. - @@ -28,7 +28,7 @@ @head;literal@ - class="@body.class;literal@" id="@body.id;literal@"@event_handlers;literal@> + class="@body.class;literal@" id="@body.id;literal@"> @header;literal@ @footer;literal@ Index: openacs-4/www/blank-master.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/www/blank-master.tcl,v diff -u -r1.56.2.7 -r1.56.2.8 --- openacs-4/www/blank-master.tcl 6 Sep 2016 17:33:55 -0000 1.56.2.7 +++ openacs-4/www/blank-master.tcl 9 Sep 2016 08:12:25 -0000 1.56.2.8 @@ -91,21 +91,9 @@ # Add standard javascript # # Include core.js inclusion to the bottom of the body. -# The only function needed alread onload is acs_Focus() -# + template::add_body_script -type "text/javascript" -src "/resources/acs-subsite/core.js" -template::head::add_javascript -script { - function acs_Focus(form_name, element_name) { - if (document.forms == null) return; - if (document.forms[form_name] == null) return; - if (document.forms[form_name].elements[element_name] == null) return; - if (document.forms[form_name].elements[element_name].type == 'hidden') return; - - document.forms[form_name].elements[element_name].focus(); - } -} - # # Add css for the current subsite, defaulting to the old list/form css which was # hard-wired in previous versions of OpenACS. @@ -238,21 +226,36 @@ } if {[info exists focus] && $focus ne ""} { - # Handle elements where the name contains a dot + # + # Handle only values of focus where the provided name contains a + # dot. + # if { [regexp {^([^.]*)\.(.*)$} $focus match form_name element_name] } { - template::add_body_handler \ - -event onload \ - -script "acs_Focus('${form_name}', '${element_name}');" \ - -identifier "focus" + set focus_script { + function acs_Focus(form_name, element_name) { + if (document.forms == null) return; + if (document.forms[form_name] == null) return; + if (document.forms[form_name].elements[element_name] == null) return; + if (document.forms[form_name].elements[element_name].type == 'hidden') return; + + document.forms[form_name].elements[element_name].focus(); + }} + append focus_script "acs_Focus('${form_name}', '${element_name}');\n" + template::add_body_script -script $focus_script + } else { + ns_log warning "blank-master: variable focus has invalid value '$focus'" } } # Retrieve headers and footers set header [template::get_header_html] set footer [template::get_footer_html] template::head::prepare_multirows -set event_handlers [template::get_body_event_handlers] +# body event handlers are converted into body_scripts +template::get_body_event_handlers + + # Local variables: # mode: tcl # tcl-indent-level: 4