Difference between revisions of "Adding JavaScript"

From Joomla! Documentation

(Added reference to https://docs.joomla.org/J3.x:Adding_JavaScript_and_CSS_to_the_page)
 
(60 intermediate revisions by 22 users not shown)
Line 1: Line 1:
{{cookiejar}}
+
<noinclude><languages /></noinclude>
===Adding JavaScript===
+
<noinclude>{{Joomla version|version=2.5 & 3.x|comment=<translate><!--T:1-->
----
+
series</translate>}}</noinclude>
This chunk should describe in detail how to add JavaScript to the head of
+
{{-}}
a template using the Joomla! 1.5 API calls. It should be aimed at
+
 
people who have only minimal knowledge of PHP, HTML and JavaScript.
+
'''Note that a more up-to-date Joomla document covering this topic can be found at [[Adding JavaScript and CSS to the page]], although it currently doesn't cover the more advanced topics at the bottom of this page.'''
----
+
 
[[Category:Templates]]
+
<translate>
[[Category:Modules]]
+
<!--T:2-->
[[Category:Components]]
+
JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods.
[[Category:Plugins]]
+
</translate>
 +
<translate>
 +
<!--T:3-->
 +
There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.
 +
</translate>
 +
 
 +
<translate>==Usage== <!--T:4--></translate>
 +
 
 +
<translate>
 +
<!--T:5-->
 +
There are three methods for embedding JavaScript into your code using the Joomla API; [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script]. These methods should be called either in your component's View class <tt><yourcomponent>/views/<yourview>/view.html.php</tt> or template script <tt><yourcomponent>/views/<yourview>/tmpl/<yourtemplate>.php</tt> or in the case of a module, in its template script <tt><yourmodule>/tmpl/<yourtemplate>.php</tt>.
 +
</translate>
 +
 
 +
<translate>===Inline JavaScript=== <!--T:6--></translate>
 +
 
 +
<translate>
 +
<!--T:7-->
 +
Blocks of JavaScript code can be declared directly within a component or module's display template using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration addScriptDeclaration] method:
 +
</translate>
 +
 
 +
<source lang="php">
 +
<?php
 +
$document = JFactory::getDocument();
 +
$document->addScriptDeclaration('
 +
    window.event("domready", function() {
 +
        alert("An inline JavaScript Declaration");
 +
    });
 +
');
 +
?>
 +
</source>
 +
 
 +
<translate>===External JavaScript=== <!--T:8--></translate>
 +
 
 +
<translate>
 +
<!--T:9-->
 +
Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.
 +
</translate>
 +
 
 +
<translate>
 +
<!--T:10-->
 +
There are two ways to include a JavaScript file using the Joomla! API. The first involves using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html JDocument] class' [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript addScript] method:
 +
</translate>
 +
 
 +
<source lang="php">
 +
<?php
 +
$document = JFactory::getDocument();
 +
$document->addScript('/media/system/js/sample.js');
 +
?>
 +
</source>
 +
 
 +
<translate><!--T:11-->
 +
The second uses the [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html JHTML] class' [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] method:</translate>
 +
 
 +
<source lang="php">
 +
<?php
 +
// Add the path parameter if the path is different than 'media/system/js/'
 +
JHTML::script('sample.js', 'templates/custom/js/');
 +
?>
 +
</source>
 +
 
 +
<translate>
 +
<!--T:12-->
 +
API has changed in 3.x, so the second parameter cannot be a string. If you really need to use this method, you must include the absolute link to your JavaScript file:
 +
</translate>
 +
 
 +
<source lang="php">
 +
<?php
 +
JHtml::script(Juri::base() . 'templates/custom/js/sample.js');
 +
?>
 +
</source>
 +
 
 +
You can use options in a third parameter. This example shows the options <tt>version </tt> and <tt>relative </tt>. The file example should be saved in the folder <tt>media/com_example/'''js'''/example.min.js</tt>. So you do NOT need to insert the <tt>js</tt> in the path you insert as second parameter.
 +
 
 +
<source lang="php">
 +
<?php
 +
JHtml::_('script', 'com_example/example.min.js', array('version' => 'auto', 'relative' => true));
 +
?>
 +
</source>
 +
 
 +
<translate>
 +
==Description== <!--T:13-->
 +
The Joomla API's [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration], [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] and [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods embed JavaScript into Joomla's index.php via the jdoc head tag:
 +
</translate>
 +
 
 +
<source lang="html4strict">
 +
<jdoc:include type="head"/>
 +
</source>
 +
 
 +
<translate>
 +
<!--T:14-->
 +
Using the [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScript JDocument::addScript] or [http://api.joomla.org/1.5/Joomla-Framework/HTML/JHTML.html#script script] methods to embed JavaScript includes would result in the index.php rendering the following HTML:
 +
</translate>
 +
 
 +
<source lang="html4strict">
 +
<head>
 +
...
 +
<script type="text/javaScript" src="/media/system/js/sample.js"></script>
 +
...
 +
</head>
 +
</source>
 +
 
 +
<translate>
 +
<!--T:15-->
 +
Calling the class method [http://api.joomla.org/1.5/Joomla-Framework/Document/JDocument.html#addScriptDeclaration JDocument::addScriptDeclaration] would render the following HTML:
 +
</translate>
 +
 
 +
<source lang="html4strict">
 +
<head>
 +
...
 +
<script type="text/javaScript">
 +
window.addEvent("domready", function() {
 +
    alert("Embedded block of JS here");
 +
});
 +
</script>
 +
...
 +
</head>
 +
</source>
 +
 
 +
<translate>
 +
<!--T:16-->
 +
Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the <head></head> tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).
 +
</translate>
 +
 
 +
<translate>== Using a JavaScript Framework == <!--T:17--></translate>
 +
 
 +
<translate>
 +
<!--T:18-->
 +
A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.
 +
</translate>
 +
 
 +
<translate>
 +
<!--T:19-->
 +
Two [[S:MyLanguage/Javascript Frameworks|Javascript Frameworks]] are provided as part of Joomla 3.x; jQuery and Mootools. jQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by jQuery and is included for backwards compatibility with 3rd party extensions.
 +
</translate>
 +
 
 +
<translate>
 +
<!--T:20-->
 +
In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.
 +
</translate>
 +
 
 +
<translate>
 +
===Joomla 3.x jQuery === <!--T:21-->
 +
Please see the guide on [[Javascript_Frameworks|Javascript Frameworks in Joomla 3.x]] for information about including a framework in Joomla 3.x
 +
</translate>
 +
 
 +
<translate>
 +
=== Joomla 1.5/2.5 Mootools === <!--T:22-->
 +
Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for Joomla 2.5 or earlier it is recommended you use jQuery instead.
 +
</translate>
 +
 
 +
<translate>
 +
<!--T:23-->
 +
Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:
 +
</translate>
 +
 
 +
<translate><!--T:24-->
 +
FOR JOOMLA 1.5</translate>
 +
<source lang="php">
 +
JHTML::_('behavior.mootools');
 +
</source>
 +
 
 +
<translate><!--T:25-->
 +
FOR JOOMLA 2.5</translate>
 +
<source lang="php">
 +
JHtml::_('behavior.framework');
 +
</source>
 +
 
 +
<translate>
 +
<!--T:26-->
 +
The above code results in the same outcome as the similar jQuery framework statement; that is it ensures Mootools is included correctly and only once.
 +
</translate>
 +
 
 +
<translate><!--T:27-->
 +
Then using Mootools is almost identical to jQuery:</translate>
 +
 
 +
<source lang="php">
 +
JFactory::getDocument()->addScriptDeclaration('
 +
window.addEvent("domready", function() {
 +
    alert($("list").getElements("li").length);
 +
});
 +
');
 +
</source>
 +
 
 +
<translate>
 +
<!--T:28-->
 +
More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.
 +
</translate>
  
Add the following code to have the javascript library /media/system/js/sample.js included in your template.
+
<translate>== Important notes for 3rd party developers == <!--T:29--></translate>
  
 +
<translate>
 +
<!--T:30-->
 +
If you are creating a custom template override or extension that needs to add a custom JS file, make sure to add important dependencies such as Jquery or Mootools before your custom JS files. JS framework files must always be  loaded before any other files to make sure they get executed first, otherwise other files that load before the frameworks they need are likely to end in JS exceptions.
 +
</translate>
  
<?php
+
<translate><!--T:31-->
$document = &JFactory::getDocument();
+
Some templates like Protostar or Beez insert all the dependencies you need using functions like</translate>
$document->addScript( '/media/system/js/sample.js' );
 
?>
 
  
 +
JHtml::_('bootstrap.framework');
  
==Explanation==
+
<translate>
 +
<!--T:32-->
 +
to load Jquery + Bootstrap, but you should not rely in this fact on your extensions or custom templates overrides. Always make sure your extension or custom override load the dependencies you need before the template does it, I will explain why later:
 +
</translate>
  
Ultimately you are trying to have the resulting HTML page have in the <head> ... </head> area have a javascript include:
+
<translate>
 +
<!--T:33-->
 +
For example if you got a custom template override that needs to insert a JS file with some Jquery scripts that does fancy things on all the pages where that template override is being used. In that case you should declare this on the top section of that override file:
 +
</translate>
  
For Example:
+
JHtml::_('jquery.framework');
  <script type="text/javascript" src="/media/system/js/sample.js"></script>
+
  $doc->addScript('templates/'.$this->template.'/js/fancy-script.js');
  
Ensure that the javascript you want to include is in the directory,  from the above example:
+
<translate><!--T:34-->
/media/system/js/sample.js
+
If you are developing a 3rd party extension that you plan to put on the Joomla! extension directory you should do something like this:</translate>
  
 +
if($params->get('add_extension_resources', false))
 +
{
 +
    JHtml::_('jquery.framework');
 +
    $doc->addScript('media/com_fancy/js/fancy-script.js');
 +
}
  
When you are able to load both your page and see the <script> tag in the <head> area, and be able to load the javascript from the address
+
<translate>
 +
<!--T:35-->
 +
The conditional clause to decide whether to add or not the extension resources is '''strongly encouraged''' and considered a '''good practice''' because it gives flexibility to 3rd party developers who don't want to use your extension resources and use custom/modified files without having to battle with Joomla! using workarounds and hacks to be able to remove your original extensions resources in order to avoid duplicates and conflicts.
 +
</translate>
  
Again, using the example:
+
<translate>
  <nowiki>http://www.example.com/media/system/js/sample.js</nowiki>
+
==== Explanation ==== <!--T:36-->
  
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.
+
<!--T:37-->
 +
If you check the source code of the index.php from the Protostar template, you can see that the statements
 +
</translate>
  
Do not directly add the <script> to your template's index.php.
+
JHtml::_('bootstrap.framework');
  
The code will insert the the <script> line where your index.php has the following line:
+
<translate><!--T:38-->
 +
is added way before the statement</translate>
  
 
  <jdoc:include type="head" />
 
  <jdoc:include type="head" />
  
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.
+
<translate><!--T:39-->
 +
this can make you think that the framework files and your 3rd party files using methods like</translate>
  
<?php
+
  $doc->addScript('templates/'.$this->template.'/js/fancy-script.js');
  $document = &JFactory::getDocument();
+
  $doc->addScript('media/com_fancy/js/fancy-script.js');
  $document->addScript( '/media/system/js/sample.js' );
 
?>
 
  
 
+
<translate>
Reload your template and view the page, and ensure that the sample.js is included in the <head>
+
<!--T:40-->
 +
will be added in the right order at the right spot, '''but that is not the case''', because extension files and template override files are processed '''first''' and the index.php file of your current template is processed the '''last'''. This will cause that your custom JS files get inserted first and the framework files inserted from the template get inserted after.
 +
</translate>  
  
 +
<translate>
 +
<!--T:41-->
 +
This happens because the Joomla! API (such as $doc->addScript) uses an array to store the JS files paths and they get rendered in the document in the same order they where inserted into that array (FIFO stack). Also, once a file path is inserted on the array and another API call tries to insert the same file this action is ignored to avoid duplicates. It also means that the order of the files is not altered when the same files is attempted to be inserted several times.
 +
</translate>
  
 +
<translate><!--T:42-->
 +
Having said that doing this</translate>
  
== Adding Javascript Files Using JHTML ==
+
JHtml::_('jquery.framework');
 +
$doc->addScript('templates/'.$this->template.'/js/fancy-script.js');
  
You may also use the [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html JHTML] [http://api.joomla.org/Joomla-Framework/HTML/JHTML.html#script script] method to add a javascript file to the head of your document.
+
<translate><!--T:43-->
 +
at your custom templates overrides and extension, is '''required''' and does not cause harm or conflict with the call</translate>
  
  <?php
+
  JHtml::_('bootstrap.framework');
    $filename = 'path/to/file/filename.js';
 
    JHTML::script($filename);
 
?>
 
  
 +
<translate><!--T:44-->
 +
at your template index.php file.</translate>
  
There is a second parameter that can be passed to the script method. The parameter is a boolean (true/false). You would set this to true if you wanted MooTools loaded as well.
+
<translate>== External Links == <!--T:45--></translate>
  
<?php
+
{{JVer|2.5}} https://api.joomla.org/cms-2.5/classes/JHtmlBehavior.html#method_framework
    $filename = 'path/to/file/filename.js';
 
    JHTML::script($filename, true); // MooTools will load if it is not already loaded
 
?>
 
  
''''Please Note: Joomla 1.6+ may or may not handle MooTools differently than in previous versions.''''<ref>[http://forum.joomla.org/viewtopic.php?f=502&t=273960 Whitepaper] Upgrade to mootools 1.2</ref>
+
{{JVer|3.x}} https://api.joomla.org/cms-3/classes/JHtmlBehavior.html#method_framework
  
 +
http://en.wikipedia.org/wiki/JavaScript
  
 +
http://www.w3schools.com/js/default.asp
  
== References ==
+
http://mootools.net/
<references/>
+
 
 +
http://jquery.com/
 +
 
 +
<noinclude>
 +
<translate>
 +
<!--T:46-->
 +
[[Category:Templates]]
 +
[[Category:Modules]]
 +
[[Category:Components]]
 +
[[Category:Plugins]]
 +
[[Category:Tutorials]]
 +
[[Category:JavaScript]]
 +
</translate>
 +
</noinclude>

Latest revision as of 06:15, 17 January 2020

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎eesti • ‎español • ‎français • ‎português do Brasil • ‎български • ‎فارسی • ‎हिन्दी • ‎বাংলা • ‎中文(台灣)‎
Joomla! 
2.5 & 3.x
series

Note that a more up-to-date Joomla document covering this topic can be found at Adding JavaScript and CSS to the page, although it currently doesn't cover the more advanced topics at the bottom of this page.

JavaScript (also known as ECMAScript) is a scripting language primarily used in client-side web site development to extend and enhance an end-user's experience. Joomla provides developers with easy-to-use mechanisms to include JavaScript in their extensions using existing API methods. There are a number of methods for including JavaScript in your Joomla extensions; some of these are described below.

Usage[edit]

There are three methods for embedding JavaScript into your code using the Joomla API; JDocument::addScriptDeclaration, JDocument::addScript and script. These methods should be called either in your component's View class <yourcomponent>/views/<yourview>/view.html.php or template script <yourcomponent>/views/<yourview>/tmpl/<yourtemplate>.php or in the case of a module, in its template script <yourmodule>/tmpl/<yourtemplate>.php.

Inline JavaScript[edit]

Blocks of JavaScript code can be declared directly within a component or module's display template using the JDocument class' addScriptDeclaration method:

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration('
    window.event("domready", function() {
        alert("An inline JavaScript Declaration");
    });
');
?>

External JavaScript[edit]

Alternatively, you may wish to separate your JavaScript into a separate file. Separating your JavaScript into an external file can make your template code easier to read especially if the JavaScript is lengthy or complex.

There are two ways to include a JavaScript file using the Joomla! API. The first involves using the JDocument class' addScript method:

<?php
$document = JFactory::getDocument();
$document->addScript('/media/system/js/sample.js');
?>

The second uses the JHTML class' script method:

<?php
// Add the path parameter if the path is different than 'media/system/js/'
JHTML::script('sample.js', 'templates/custom/js/');
?>

API has changed in 3.x, so the second parameter cannot be a string. If you really need to use this method, you must include the absolute link to your JavaScript file:

<?php
JHtml::script(Juri::base() . 'templates/custom/js/sample.js');
?>

You can use options in a third parameter. This example shows the options version and relative . The file example should be saved in the folder media/com_example/js/example.min.js. So you do NOT need to insert the js in the path you insert as second parameter.

<?php
JHtml::_('script', 'com_example/example.min.js', array('version' => 'auto', 'relative' => true));
?>

Description[edit]

The Joomla API's JDocument::addScriptDeclaration, JDocument::addScript and script methods embed JavaScript into Joomla's index.php via the jdoc head tag:

<jdoc:include type="head"/>

Using the JDocument::addScript or script methods to embed JavaScript includes would result in the index.php rendering the following HTML:

<head>
...
<script type="text/javaScript" src="/media/system/js/sample.js"></script>
...
</head>

Calling the class method JDocument::addScriptDeclaration would render the following HTML:

<head>
...
<script type="text/javaScript">
window.addEvent("domready", function() {
    alert("Embedded block of JS here");
});
</script>
...
</head>

Using these methods is highly recommended as it clearly differentiates another scripting language (JavaScript) from the main PHP code, ensures all JavaScript is correctly embedded between the <head></head> tags and, in the case of JDocument::addScript and JHTML::script ensures that a JavaScript file is included only once (I.e. there is no .js file duplication).

Using a JavaScript Framework[edit]

A Javascript framework provides developers with generic functionality for handling various coding tasks in a familiar, consistent and platform-independent way. A framework enables the developer to forget about the intricacies of implementing a certain function in different web browsers and focus on the requirements of the software.

Two Javascript Frameworks are provided as part of Joomla 3.x; jQuery and Mootools. jQuery is a newly introduced framework which integrates with Joomla's new Bootstrap HTML framework; Mootools is Joomla's legacy Javascript library which is now superseded by jQuery and is included for backwards compatibility with 3rd party extensions.

In nearly all cases you should use a framework when developing Javascript in your extensions or templates and including one is very simple with Joomla's API.

Joomla 3.x jQuery[edit]

Please see the guide on Javascript Frameworks in Joomla 3.x for information about including a framework in Joomla 3.x

Joomla 1.5/2.5 Mootools[edit]

Unless you are maintaining Javascript code which leverages Mootools or you are developing an extension for Joomla 2.5 or earlier it is recommended you use jQuery instead.

Firstly, you will need to include the Mootools code in your extension. To include the Mootools framework in your extension, you add the following code to your view.html.php or tmpl file:

FOR JOOMLA 1.5

JHTML::_('behavior.mootools');

FOR JOOMLA 2.5

JHtml::_('behavior.framework');

The above code results in the same outcome as the similar jQuery framework statement; that is it ensures Mootools is included correctly and only once.

Then using Mootools is almost identical to jQuery:

JFactory::getDocument()->addScriptDeclaration('
window.addEvent("domready", function() {
    alert($("list").getElements("li").length);
});
');

More information about Mootools is available at http://mootools.net/. For API documentation, visit http://mootools.net/docs/core.

Important notes for 3rd party developers[edit]

If you are creating a custom template override or extension that needs to add a custom JS file, make sure to add important dependencies such as Jquery or Mootools before your custom JS files. JS framework files must always be loaded before any other files to make sure they get executed first, otherwise other files that load before the frameworks they need are likely to end in JS exceptions.

Some templates like Protostar or Beez insert all the dependencies you need using functions like

JHtml::_('bootstrap.framework');

to load Jquery + Bootstrap, but you should not rely in this fact on your extensions or custom templates overrides. Always make sure your extension or custom override load the dependencies you need before the template does it, I will explain why later:

For example if you got a custom template override that needs to insert a JS file with some Jquery scripts that does fancy things on all the pages where that template override is being used. In that case you should declare this on the top section of that override file:

JHtml::_('jquery.framework');
$doc->addScript('templates/'.$this->template.'/js/fancy-script.js');

If you are developing a 3rd party extension that you plan to put on the Joomla! extension directory you should do something like this:

if($params->get('add_extension_resources', false))
{
    JHtml::_('jquery.framework');
    $doc->addScript('media/com_fancy/js/fancy-script.js');
}

The conditional clause to decide whether to add or not the extension resources is strongly encouraged and considered a good practice because it gives flexibility to 3rd party developers who don't want to use your extension resources and use custom/modified files without having to battle with Joomla! using workarounds and hacks to be able to remove your original extensions resources in order to avoid duplicates and conflicts.

Explanation[edit]

If you check the source code of the index.php from the Protostar template, you can see that the statements

JHtml::_('bootstrap.framework');

is added way before the statement

<jdoc:include type="head" />

this can make you think that the framework files and your 3rd party files using methods like

$doc->addScript('templates/'.$this->template.'/js/fancy-script.js');
$doc->addScript('media/com_fancy/js/fancy-script.js');

will be added in the right order at the right spot, but that is not the case, because extension files and template override files are processed first and the index.php file of your current template is processed the last. This will cause that your custom JS files get inserted first and the framework files inserted from the template get inserted after.

This happens because the Joomla! API (such as $doc->addScript) uses an array to store the JS files paths and they get rendered in the document in the same order they where inserted into that array (FIFO stack). Also, once a file path is inserted on the array and another API call tries to insert the same file this action is ignored to avoid duplicates. It also means that the order of the files is not altered when the same files is attempted to be inserted several times.

Having said that doing this

JHtml::_('jquery.framework');
$doc->addScript('templates/'.$this->template.'/js/fancy-script.js');

at your custom templates overrides and extension, is required and does not cause harm or conflict with the call

JHtml::_('bootstrap.framework');

at your template index.php file.

External Links[edit]

Joomla 2.5 https://api.joomla.org/cms-2.5/classes/JHtmlBehavior.html#method_framework

Joomla 3.x https://api.joomla.org/cms-3/classes/JHtmlBehavior.html#method_framework

http://en.wikipedia.org/wiki/JavaScript

http://www.w3schools.com/js/default.asp

http://mootools.net/

http://jquery.com/