The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PApp::ECMAScript - make javascript horrors less horrible

SYNOPSIS

 use PApp::ECMAScript;

DESCRIPTION

$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.

unique

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.

$js->add_headercode($code)

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

$js->need_headercode($code)

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

$js->headercode

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.

$js->can_css

Return wether the browser supports CSS.

$js->visibility_hidden
$js->visibility_visible

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

$js->event

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

$js->get_style_object($name)

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

$js->event_page_x
$js->event_page_y

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

$js->window_height
$js->window_width

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
$layer->id([newid])

Return the current object id (optionally setting it).

$layer->content([newcontent])

Return the current object content (optionally setting it).

$layer->code

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.

$layer->style_object

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

$layer->showxy($x,$y)

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

$layer->show_relmouse($x,$y)

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

$layer->show

Return code to display the layer object.

$layer->hide

Return code to hide the layer object.

SEE ALSO

PApp.

AUTHOR

 Marc Lehmann <schmorp@schmorp.de>
 http://home.schmorp.de/