This plugin provides integration with the Yahoo! UI Library. When installing the plugin, it downloads and installs automatically the latest YUI 2.5.2 distribution in your application, and registers itself to be used with the adapative AJAX tags. It also contains two helper tags to easily include additional YUI javascript and css files as well.
Installation
To install the YUI plugin type this command from your project's root folder:
grails install-plugin yui
Usage
To use Grails' adaptive AJAX support just add the folowing line in the head section:
<g:javascript library="yui" />
<yui:javascript dir="calendar" file="calendar-min.js" /> <yui:javascript dir="calendar" file="calendar-min.js" version="2.5.2" /> // version to be used in case multiple version installed <yui:stylesheet dir="calendar/assets" file="calendar.css" />
Overriding default javascript files
By default only yahoo-dom-event.js and connection-min.js are included when using <g:javascript library="yui" />. Adding additional libraries to the default list can be done in a BootStrap (+) class:
import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLibclass BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui += ["yui/2.5.2/calendar/calendar-min", "yui/2.5.2/container/container-min"] } def destroy = { } }
import grails.util.GrailsUtil import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLibclass BootStrap { def init = { servletContext -> if (GrailsUtil.isDevelopmentEnv()) { JavascriptTagLib.LIBRARY_MAPPINGS.yui = ["yui/2.5.2/yahoo/yahoo-debug", "yui/2.5.2/dom/dom-debug", "yui/2.5.2/event/event-debug", "yui/2.5.2/connection/connection-debug"] } } def destroy = { } }
Serving YUI Files from Yahoo! Servers
It's also possible to serve the javascript from the Yahoo! servers. First delete the yui folder from web-appjs after installing the plugin. Then, in a BootStrap class, override the mapping which contains the javascript files to include by default:
import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLibclass BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui = [] } def destroy = { } }
Upgrading
If you want to upgrade:
- Delete the plugin from the project's plugins folder
- (Optional) Delete the previous YUI version folder from web-appjsyui
- Re-install the plugin by executing grails install-plugin yui