Using Javascript
MojoMotor relies on Javascript for part of its power and flexibility. This means that its possible that MojoMotor's own Javascript can get in the way of a developer who wants to introduce script as part of their own solution. This document outlines how to prevent conflicts, and even leverage the existing resources MojoMotor makes available to you.
The nitty gritty
When a page is loaded, MojoMotor renders its content, and then injects jQuery, jQuery UI, and its own system scripts directly before </body>. This content is controlled centrally by MojoMotor, meaning simply adding your own scripts above </body> in a layout will still result in MojoMotor loading its own script last.
If you want to inject your own content after Mojo's resources (usually your own jQuery script), you can do so by putting it anywhere inside your layout template, inside {mojo:layout:append_content}{/mojo:layout:append_content} tags. Any content found between it will be rendered in the bottom of the page.
Example of append_content
In the following example, we don't need to load the jQuery library, as MojoMotor has already loaded it for its own use.
{mojo:layout:append_content}
<script type="text/javascript">
jQuery(document).ready(function() {
alert("Waited for jQuery's ready() function before I did this.");
});
</script>
{/mojo:layout:append_content}
Using a different version of jQuery
Some plugins are reliant on a specific version of jQuery, that may be different from the version used within MojoMotor. In these cases, you'll want to use jQuery noConflict() to load your resources.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>
<script>
jQuery.noConflict();
(function($) {
$(document).ready(function() {
alert("This is using an older version of jQuery, specifically "+$().jquery);
});
})(jQuery);
</script>