| |
468 |
468 |
if {$alternate_p} { |
| |
469 |
469 |
set rel "alternate stylesheet" |
| |
470 |
470 |
} else { |
| |
471 |
471 |
set rel "stylesheet" |
| |
472 |
472 |
} |
| |
473 |
473 |
|
| |
474 |
474 |
template::head::add_link -rel $rel \ |
| |
475 |
475 |
-type text/css \ |
| |
476 |
476 |
-href $href \ |
| |
477 |
477 |
-media $media \ |
| |
478 |
478 |
-title $title \ |
| |
479 |
479 |
-lang $lang \ |
| |
480 |
480 |
-order $order |
| |
481 |
481 |
} |
| |
482 |
482 |
|
| |
483 |
483 |
ad_proc -public template::add_body_handler { |
| |
484 |
484 |
{-event:required} |
| |
485 |
485 |
{-script:required} |
| |
486 |
486 |
{-identifier anonymous} |
| |
487 |
487 |
} { |
| |
488 |
|
Adds javascript code to an event handler in the body tag. Several |
| |
489 |
|
javascript code blocks may be assigned to each handler by subsequent calls |
| |
|
488 |
Adds JavaScript code to an event handler in the body tag. Several |
| |
|
489 |
JavaScript code blocks may be assigned to each handler by subsequent calls |
| |
490 |
490 |
to template::add_body_handler. |
| |
491 |
491 |
|
| |
492 |
492 |
<p>If your script may only be added once you may supply an identifier. |
| |
493 |
493 |
Subsequent calls to template::add_body_handler with the same identifier |
| |
494 |
494 |
will replace your script rather than appending to it.</p> |
| |
495 |
495 |
|
| |
496 |
496 |
<p><code>event</code> may be one of:</p> |
| |
497 |
497 |
<ul> |
| |
498 |
498 |
<li>onload</li> |
| |
499 |
499 |
<li>onunload</li> |
| |
500 |
500 |
<li>onclick</li> |
| |
501 |
501 |
<li>ondblclick</li> |
| |
502 |
502 |
<li>onmousedown</li> |
| |
503 |
503 |
<li>onmouseup</li> |
| |
504 |
504 |
<li>onmouseover</li> |
| |
505 |
505 |
<li>onmousemove</li> |
| |
506 |
506 |
<li>onmouseout</li> |
| |
507 |
507 |
<li>onkeypress</li> |
| |
508 |
508 |
<li>onkeydown</li> |
| |
509 |
509 |
<li>onkeyup</li> |
| |
510 |
510 |
</ul> |
| |
511 |
511 |
|
| |
512 |
512 |
@param event the event during which the supplied script should be |
| |
513 |
513 |
executed |
| |
514 |
|
@param script the javascript code to execute |
| |
515 |
|
@param identifier a name, if supplied, used to ensure this javascript code |
| |
|
514 |
@param script the JavaScript code to execute |
| |
|
515 |
@param identifier a name, if supplied, used to ensure this JavaScript code |
| |
516 |
516 |
is only added to the handler once |
| |
517 |
517 |
} { |
| |
518 |
518 |
variable ::template::body_handlers |
| |
519 |
519 |
|
| |
520 |
520 |
if {$identifier eq "anonymous"} { |
| |
521 |
521 |
lappend body_handlers($event,anonymous) $script |
| |
522 |
522 |
} else { |
| |
523 |
523 |
# Even a one event handler needs to be added in a list |
| |
524 |
524 |
# since all handlers, anonymous and specific are treated as a |
| |
525 |
525 |
# list in blank-master.tcl |
| |
526 |
526 |
set body_handlers($event,$identifier) [list $script] |
| |
527 |
527 |
} |
| |
528 |
528 |
} |
| |
529 |
529 |
|
| |
530 |
530 |
ad_proc -public template::add_body_script { |
| |
531 |
531 |
{-async:boolean} |
| |
532 |
532 |
{-charset ""} |
| |
533 |
533 |
{-crossorigin ""} |
| |
534 |
534 |
{-defer:boolean} |
| |
535 |
535 |
{-integrity ""} |
|
| |
865 |
865 |
set footer "" |
| |
866 |
866 |
if {[info exists footers]} { |
| |
867 |
867 |
foreach footer_list $footers { |
| |
868 |
868 |
lassign $footer_list type src params |
| |
869 |
869 |
if {$type eq "literal"} { |
| |
870 |
870 |
append footer $src |
| |
871 |
871 |
} else { |
| |
872 |
872 |
append footer [template::adp_include $src $params] |
| |
873 |
873 |
} |
| |
874 |
874 |
} |
| |
875 |
875 |
unset footers |
| |
876 |
876 |
} |
| |
877 |
877 |
return $footer |
| |
878 |
878 |
} |
| |
879 |
879 |
|
| |
880 |
880 |
ad_proc template::get_body_event_handlers { |
| |
881 |
881 |
} { |
| |
882 |
882 |
Get body event handlers specified with template::add_body_handler |
| |
883 |
883 |
} { |
| |
884 |
884 |
# |
| |
885 |
|
# Concatenate the javascript event handlers for the body tag |
| |
|
885 |
# Concatenate the JavaScript event handlers for the body tag |
| |
886 |
886 |
# |
| |
887 |
887 |
variable ::template::body_handlers |
| |
888 |
888 |
set event_handlers "" |
| |
889 |
889 |
|
| |
890 |
890 |
if {[array exists body_handlers]} { |
| |
891 |
891 |
|
| |
892 |
892 |
# |
| |
893 |
893 |
# Collect all entries for one event type (e.g. "onload") |
| |
894 |
894 |
# |
| |
895 |
895 |
foreach name [array names body_handlers] { |
| |
896 |
896 |
set event [lindex [split $name ","] 0] |
| |
897 |
|
foreach javascript $body_handlers($name) { |
| |
898 |
|
lappend body_handlers($event) "[string trimright $javascript {; }];" |
| |
|
897 |
foreach js $body_handlers($name) { |
| |
|
898 |
lappend body_handlers($event) "[string trimright $js {; }];" |
| |
899 |
899 |
} |
| |
900 |
900 |
unset body_handlers($name) |
| |
901 |
901 |
} |
| |
902 |
902 |
|
| |
903 |
903 |
# |
| |
904 |
904 |
# Turn events into calls for event listener and add these via |
| |
905 |
905 |
# add_body_script. |
| |
906 |
906 |
# |
| |
907 |
907 |
set js "" |
| |
908 |
908 |
foreach {event script} [array get body_handlers] { |
| |
909 |
909 |
# |
| |
910 |
910 |
# Remove the "on" prefix if provided. E.g. "onload" is |
| |
911 |
911 |
# mapped to the "load" event on "window" (UIevent). It |
| |
912 |
912 |
# would as well be possible to map to DOM events (on |
| |
913 |
913 |
# "document") |
| |
914 |
914 |
# (https://developer.mozilla.org/en-US/docs/Web/Events) |
| |
915 |
915 |
# |
| |
916 |
916 |
regsub ^on $event "" event |
| |
917 |
917 |
append js [subst { |
| |
918 |
918 |
window.addEventListener('$event', function () { |