PApp::ECMAScript - make javascript horrors less horrible


 use PApp::ECMAScript;


$obj = new PApp::ECMAScript

Create a new object. Better use the init function.

init PApp::ECMAScript

Create a new global PApp::ECMAScript object, storing it in the (exported) variable $js, which should be shared between all modules for caching purposes. Consequently, this function should be called once in the request callback or in the global stylesheet.


Return a unique identifier. This is useful when generating function names or other identifiers.

escape_string_sq $string [EXPORTED]
escape_string_dq $string [EXPORTED]

Escape the given string as required and return it (escape_string_sq will use single quotes to delimit the string, escape_string_dq will use double quotes). Remember that many browsers do not like quoting, so use the right function to minimize impact.


Add the given code fragment to the HTML/HEAD/SCRIPT section.


Mark the given code fragment as to be added to the html head section. The same fragment will only be added once.


Return the code to be put in the head section.

$js->add_onevent("event", "code")
$js->need_onevent("event", "code")

Add code that is run when the given event occurs. Event should be something like "window.onclick" or "document.onload".

$code = $js->is_ns
$code = $js->is_ns4
$code = $js->is_ie
$code = $js->is_ie4
$code = $js->is_ie5
$code = $js->is_konquerer

Return javascript code that checks wether the code is running under netscape, netscape 4 (or higher), ie, ie4 (or higher) or ie5 (or higher), respectively.


Return wether the browser supports CSS.


Return the string that should be used to set the visibility attribute to "hidden" or "visible".


Return the name of the event object (either window.event or event).


Return code that finds the style object with the given name and returns it.


Return the window x or y coordinate from the current event relative to the current page.


Return the (approximate) height and width of the scrollable area, i.e. the inner width and height of the window.

The PApp::ECMAScript::Layer Class

This class manages floating cxx objects (i.e. objects with style invisible that can be shown, hidden, moved etc... using javascript).

$layer = new PApp::ECMAScript::Layer arg => val, ...

Create a new layer object (does not output anything).

   js      => the javascript object to use (default $PApp::ECMAScript::js)
   id      => the name (html id), default autogenerated
   content => the content of the layer/div element
   element => the element used for the layer

Return the current object id (optionally setting it).


Return the current object content (optionally setting it).


Return the javascript code used to create the (initially hidden) layer. The best place for this is the top of the document, just below the BODY tag, but that's not a requirement for working browsers ;)

Please note that all javascript code returned is not quoted, which is not a problem when outputting it directly since browsers actually EXPECT misquoted input, but it is a problem when you output strict html (xml) or want to feed this into an XSLT stylesheet, in which case you need to escape_html() the code first and use disable-output-escaping in your stylesheet to deliberatly create broken HTML on output.


Return an expression that evaluates to the style object used by the code.


Return code to display the layer object at position ($x,$y) (which should be valid javascript expressions).


Same as howxy, but use the current mouse position as origin.


Return code to display the layer object.


Return code to hide the layer object.




 Marc Lehmann <>