<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.moodle.org/403/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rodrigomcol</id>
	<title>MoodleDocs - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.moodle.org/403/en/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Rodrigomcol"/>
	<link rel="alternate" type="text/html" href="https://docs.moodle.org/403/en/Special:Contributions/Rodrigomcol"/>
	<updated>2026-04-18T06:59:12Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://docs.moodle.org/403/en/index.php?title=Development:YUI&amp;diff=69291</id>
		<title>Development:YUI</title>
		<link rel="alternate" type="text/html" href="https://docs.moodle.org/403/en/index.php?title=Development:YUI&amp;diff=69291"/>
		<updated>2010-03-04T21:50:23Z</updated>

		<summary type="html">&lt;p&gt;Rodrigomcol: method name is onDOMReady (note uppercase R)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The &#039;&#039;&#039;Yahoo! User Interface&#039;&#039;&#039; (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. &lt;br /&gt;
&lt;br /&gt;
All components in the YUI Library have been released as open source under a BSD license and are free for all uses.&lt;br /&gt;
&lt;br /&gt;
Details of the YUI can be found at the [http://developer.yahoo.com/yui/index.html Yahoo Developer Website].&lt;br /&gt;
&lt;br /&gt;
==Note==&lt;br /&gt;
&lt;br /&gt;
Some of the following information will be out of date when Moodle 2.0 is released. Please see [[Development:JavaScript guidelines]] for the latest information.&lt;br /&gt;
&lt;br /&gt;
==Getting started==&lt;br /&gt;
&lt;br /&gt;
One approach is to find an example that is close to what you want, either in the Moodle code, or on the [http://developer.yahoo.com/yui/examples/slider/index.html Yahoo Developer Website]. Then adapt it to your needs.&lt;br /&gt;
&lt;br /&gt;
The entire YUI libraries are all part of a single YAHOO object, so they will not clash with other code. You then use them like this:&lt;br /&gt;
&amp;lt;code javascript&amp;gt;&lt;br /&gt;
YAHOO.util.Event.onDOMReady(...);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dependencies ===&lt;br /&gt;
&lt;br /&gt;
In order to make the &#039;&#039;onDOMReady&#039;&#039; method available to you, you first include a .js file that sets up the global object, then the events library .js file that adds all of the events methods to it. Moodle&#039;s way of doing this is with the &#039;&#039;require_js()&#039;&#039; function:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
require_js(array(&#039;yui_yahoo&#039;, &#039;yui_event&#039;)); &lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As you can see, you need only refer to the libraries by name. You don&#039;t need to know the full path. The [http://xref.moodle.org/lib/ajax/ajaxlib.php.source.html#l6 ajax_get_lib()] function in &#039;&#039;/lib/ajax/ajaxlib.php&#039;&#039; has the complete list of libraries. &lt;br /&gt;
&lt;br /&gt;
Once you have included the various .js dependency files with &#039;&#039;require_js()&#039;&#039; as outlined above, then write your own source .js file and add that to the require_js array &#039;&#039;&#039;after&#039;&#039;&#039; the other YUI ones. Many of the YUI files have other dependencies, so you&#039;ll often need to include more than one and the order matters for them too. Just follow the examples.&lt;br /&gt;
&lt;br /&gt;
=== Skinning ===&lt;br /&gt;
&lt;br /&gt;
For CSS, you include the css dependency files in either your theme styles.php or module/block styles.php using the standard PHP include() function. You will often need to apply the yui-skin-sam style to the body tag to get the skins to work right, so add something near the top of your script like:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
document.body.className += &#039; yui-skin-sam&#039;;&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As a caveat, the paths in the CSS files assume that yui is placed in the site&#039;s web root and have no reference to $CFG-&amp;gt;wwwroot, so none of the images work. The solution is to go through the CSS files, pulling out any that have&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
background: url(../../whatever.png);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and paste them into your styles.php below the css include you&#039;ve added, but looking like this:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
background: url(&amp;lt;?php echo $CFG-&amp;gt;wwwroot ?&amp;gt;/lib/yui/whatever.png);&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Performance ==&lt;br /&gt;
&lt;br /&gt;
Remember to use [http://developer.yahoo.com/yui/examples/event/event-delegation.html event bubbling] wherever possible so that instead of adding a drag-drop listener to every page element, you just add one to the content div which catches all of the events lower down the DOM tree and does what&#039;s needed.&lt;br /&gt;
&lt;br /&gt;
== Debugging ==&lt;br /&gt;
&lt;br /&gt;
* Ideally, you should use &#039;&#039;&#039;Firefox&#039;&#039;&#039;, with the [https://addons.mozilla.org/en-US/firefox/addon/60 Web Developer Toolbar], [https://addons.mozilla.org/en-US/firefox/addon/1843 Firebug] and [https://addons.mozilla.org/en-US/firefox/addon/5369 YSlow] extensions loaded (see also [[Development:Firebug]] and [[Web developer extension]]). &lt;br /&gt;
&lt;br /&gt;
* The &#039;&#039;&#039;YUI logger&#039;&#039;&#039; will need to be included as a dependency if you want to use the xxx-debug.js versions of the files, so you need to add it to require_js() before them.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [http://developer.yahoo.com/yui/ The official YUI documentation]&lt;br /&gt;
* [[JavaScript FAQ]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Javascript|YUI]]&lt;br /&gt;
[[Category:AJAX|YUI]]&lt;br /&gt;
{{CategoryDeveloper}}&lt;/div&gt;</summary>
		<author><name>Rodrigomcol</name></author>
	</entry>
</feed>