Hello again,
So here goes an example of "Jingoizing" jQuery and one of its plug-
ins:
Original jQuery.js:
/*!
* jQuery JavaScript Library v1.3.2
*
http://jquery.com/
*
* Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses.
*
http://docs.jquery.com/License
*
* Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
* Revision: 6246
*/
(function(){
/* ... jQuery source */
})();
Jingoized jQuery.js placed directly in the main script repository
directory (defaults to "scripts", see jingo.init docs on the getting
started page to find out how to override):
/*!
* jQuery JavaScript Library v1.3.2
*
http://jquery.com/
*
* Copyright (c) 2009 John Resig
* Dual licensed under the MIT and GPL licenses.
*
http://docs.jquery.com/License
*
* Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009)
* Revision: 6246
*/
jingo.declare({
name: 'jQuery',
as: function() {
/* ... jQuery source */
/*
it's safest for a module not to effect the global scope
other than under it's own namespace, therefore we
choose to disable the $ alias to the jQuery function
Note: this is optional
*/
jQuery.noConflict();
}
});
Now that jQuery is a full blown Jingo module we can Jingoize a
jQuery plugin that depends on it.
Original jquery.ajaxmanager.js:
/**
* @author alexander.farkas
*
* @version 2.1
*/
(function($){
/* ... jquery.ajaxmanager source */
})(jQuery);
Jingoized "ajaxmanager.js" placed in a "jquery" subdirectory of the
main script repository directory:
/**
* @author alexander.farkas
*
* @version 2.1
*/
jingo.declare({
require: [
'jQuery'
],
name: 'jquery.ajaxmanager',
as: function() {
var $ = jQuery;
/* ... jquery.ajaxmanager source */
}
});
From here its pretty simple to write an in-house module that depends
on jquery.ajaxmanager.
Internal Jingo module "module.js" in the "internal" subdirectory of
the main script repository directory:
jingo.declare({
require: [
'jquery.ajaxmanager'
],
name: 'internal.module',
as: function() {
/* ... some code that depends on jquery.ajaxmanager */
/*
This module does not have to list jQuery as a transitive
dependency, but if it uses jQuery directly it is good
practice to list it in the requires list since it is a
direct rather than transitive dependency at that point
*/
}
});
Now loading modules into our html, jsp, etc. becomes:
<html>
<head>
<title>Some Title</title>
<script src="scripts/jingo.js" type="text/javascript"
encoding="utf-8"></script>
<script type="text/javascript" encoding="utf-8">
jingo.anonymous({
require: [
'internal.module'
],
exec: function() {
/* some code that depends on internal.module */
}
});
</script>
</head>
<body>
<!-- ... page body content -->
</body>
</html>
As you can see "Jingoizing" a well written library or libraries is
fairly painless. A modularized system such as jQuery and its plug-ins
lends itself very well to becoming Jingo modules. However, it really
is up to the team to decide which approach to take for third-party
module dependencies ("jingoize" or "manual include").
I hope that helps. Let us know if there is anything we can clarify or
other questions we can answer.
It's also worth noting that there are some major features around the
corner in 0.9.0-beta release that help you run your javascript modules
optimized for debugging support while you are in development and
optimized for download performance when you go to production with zero
code changes. The current release of Jingo already does a great job
of optimizing the development experience. In 0.9.0-beta, with the
addition of static assembly (also referred to as concatenation) and
source code compaction (also called minification) projects that
leverage Jingo for dependency management can optimize for quick
response times in production. The static assembly process will be
packaged as an Ant task or Maven plugin for the Java folks and a
command line interface for folks on other platforms.
Take care,
P.S. As an aside I would also highly recommend JSLint (http://
www.jslint.com) as an invaluable tool to help find problems early and
avoid a whole lot of run-time JavaScript debugging marathons :)
-Sean