Javascript For Datatypes In <head>

Author Message

Douglas Hammond

Monday 23 June 2003 8:11:13 am

There are many cases where one would like to include a js lib in the <head></head> of the document and have it only there if the datatype that uses it, is being used. Plus for adding code to a function that is done for <body onload="function">.

It would be nice if there was a stantdard way to do this.

or can one inject this somehow by refering to the head {section}

Gabriel Ambuehl

Monday 23 June 2003 1:05:17 pm

I duly second this request.

Visit http://triligon.org

Bruce Morrison

Monday 23 June 2003 3:49:46 pm

How about something like

<head>
<script language="JavaScript" src={concat("script/class_",$DesignKeys:used.class,".js")|ezdesign} type="text/JavaScript"></script>
</head>

And you would need to have a javascript file for each class id.

Cheers
Bruce
designIT

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Sven Ryen

Monday 23 June 2003 11:55:50 pm

FWIW, scripts tag can be included anywhere on the page, not just within head tags. I include the javascript src tag at the top of the edit.tpl files of my datatypes.

For onload, how about this snippet:

<script type="text/javascript" language="Javascript">
<!--
document.body.onload = function() { alert('hello world'); }
//-->
</script>

Sven Ryen

Tuesday 24 June 2003 12:12:03 am

As for your request to _append_ to the onload function, this code, although weird, will do the trick:

<script type="text/javascript" language="Javascript">
<!--
onloadtext = "alert('1');";
//-->
</script>

<script type="text/javascript" language="Javascript">
<!--
onloadtext += "alert('2');";
//-->
</script>

<script type="text/javascript" language="Javascript">
<!--
eval("document.body.onload = function() { "+onloadtext+" }");
//-->
</script>

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 20:31:25
Script start
Timing: Jan 30 2025 20:31:25
Module start 'layout'
Timing: Jan 30 2025 20:31:25
Module start 'content'
Timing: Jan 30 2025 20:31:25
Module end 'content'
Timing: Jan 30 2025 20:31:25
Script end

Main resources:

Total runtime0.0616 sec
Peak memory usage8,192.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 588.1406151.2109
Module start 'layout' 0.00460.0051 739.3516220.7031
Module start 'content' 0.00970.0444 960.05471,001.8047
Module end 'content' 0.05410.0074 1,961.859433.9922
Script end 0.0615  1,995.8516 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00386.1207140.0003
Check MTime0.00193.0172140.0001
Mysql Total
Database connection0.00050.756710.0005
Mysqli_queries0.00315.063630.0010
Looping result0.00000.022810.0000
Template Total0.006911.310.0069
Template load0.00609.737910.0060
Template processing0.00091.516510.0009
Override
Cache load0.00142.256610.0014
General
dbfile0.011819.101580.0015
String conversion0.00000.015940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs