Implementing jQuery UI in a Web Application
A lot of people thought I was crazy for wanting to develop my own PHP framework, and 1400 hours of discovery and development later, they may have a point. At the end of the day, though, I have an extremely powerful and flexible framework for making database-driven web applications. Where even I drew the line, however, was with javascript. I made the decision to use jQuery because its design philosophy seems similar to my own.
My plan is to integrate jQuery into my PHP framework, but I need to learn a lot more about how jQuery works and refactor some of my core structural components to accommodate it. In the meantime, I can start to implement jQuery in individual applications.
Downloading jQuery
To enable jQuery requires only one javascript file, available from jquery.com. I chose to copy down the latest minimized version (jquery.min.js) to my web server to have as a local file. Almost everything is driven through events.
To have all the interface elements available, both javascript and stylesheets are required, available as themes from http://jqueryui.com/themeroller. I again downloaded the relevant files to my web server: When you select a theme from the gallery, there is an option to download the package (and you can fine tune which parts of a theme you want or need). Themes are also customizable.
When you download a theme, there a number of directories and files, but there are only two important ones: the theme folder (which contains the base stylesheet and all the supporting images) and jquery-ui javascript file.
Making jQuery Available
Now, you need only reference the downloaded javascript and stylesheets. In the applications I build, I tend to use abstract application modules that handle the common tasks (like loading libraries and content necessary for most of the modules in the application).
Partial Listing: rsrc/master/ApplicationModule
abstract class ApplicationModule extends IWModule{ . . . function pageDidLoad( $page) { $page-> addJavascript( 'js/jquery.min.js') ; $page-> addJavascript( 'js/jquery-ui-1.8.14.custom.min.js') ; $page-> addStylesheet( 'css/smoothness/jquery-ui-1.8.14.custom.css') ; } . . . }
The rendered page for any ApplicationModule subclass has a header block with the appropriate references.
& lt; ! DOCTYPE html> & lt; html lang= "en"> & lt; head> & lt; link rel= "stylesheet" type= "text/css" href= "/pod/lib/css/public.css" /> <link rel="stylesheet" type="text/css" href="/pod/lib/css/editor.css" /> <link rel="stylesheet" type="text/css" href="/pod/lib/css/smoothness/jquery-ui-1.8.14.custom.css" /> <script src="/pod/lib/js/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script src="/pod/lib/js/jquery-ui-1.8.14.custom.min.js" type="text/javascript" charset="utf-8"> </script> </head> <body> ... </body> </html>
Now, my application is ready for some jQuery UI goodness (to be presented in later articles).