Yahoo! User Interface Library (YUI)

  • Authors: Marcel Overdijk
4 votes

3% of Grails users

Dependency:
compile ":yui:2.8.2.1"

 Documentation  Source  Issues

Summary

Provides integration with the Yahoo! UI Library

Description

Yahoo! UI Library (YUI) Plugin

This plugin provides integration with the Yahoo! UI Library. When installing the plugin, it downloads and installs automatically the latest YUI 2.7.0 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

As of version 2.8.2 of the plugin, the YUI distribution is included in the plugin. Prior to that, the complete YUI distribution was downloaded and installed under your project's /web-app/js/yui/<version> folder.

Usage

To use Grails' adaptive AJAX support just add the folowing line in the head section:

<g:javascript library="yui" />
If you want to include additional YUI javascript and css files include them using:
<yui:javascript dir="calendar" file="calendar-min.js" />
<yui:javascript dir="calendar" file="calendar-min.js" version="2.6.0" /> 
// version to be used in case multiple version installed
<yui:stylesheet dir="calendar/assets" file="calendar.css" />
Refer to the Ajax section of the Grails reference documentation for usage.

As of version 2.8.2 of the plugin, if you have the Resources plugin installed as well you can simply include the corresponding YUI modules:
<r:require module="yui-calendar,yui-datatable"/>
You can find the module definitions in the Subversion repository.

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.JavascriptTagLib

class BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui += ["yui/2.6.0/calendar/calendar-min", "yui/2.6.0/container/container-min"] } def destroy = { } }

It's also possible to replace all default included javascript libraries. For example if you want to use the YUI debug javascript files in development mode:
import grails.util.GrailsUtil
import org.codehaus.groovy.grails.plugins.web.taglib.JavascriptTagLib

class BootStrap { def init = { servletContext -> if (GrailsUtil.isDevelopmentEnv()) { JavascriptTagLib.LIBRARY_MAPPINGS.yui = ["yui/2.6.0/yahoo/yahoo-debug", "yui/2.6.0/dom/dom-debug", "yui/2.6.0/event/event-debug", "yui/2.6.0/connection/connection-debug"] } } def destroy = { } }

For version 2.8.2 of the plugin and upwards, you can define your own modules that depend on the appropriate YUI ones and then r:require those modules from your GSP pages.

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.JavascriptTagLib

class BootStrap { def init = { servletContext -> JavascriptTagLib.LIBRARY_MAPPINGS.yui = [] } def destroy = { } }

The only drawback is that you need to include the references to the javascript files manually. Probably the easiest way is to do this in the main.gsp layout.

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

Plugin version history

2.8.2 (June 1, 2011)

  • Updated to YUI 2.8.2
  • The YUI distribution is now part of the plugin
  • Resources plugin integration added

2.6.0 (Oct 25, 2008)

  • Updated to YUI 2.6.0

2.5.2 (June 2, 2008)

  • Updated to YUI 2.5.2

2.5.1 (March 24, 2008)

  • Updated to YUI 2.5.1
  • Updated to Grails 1.0.2
  • The YUI libraries files are now stored in a 'version' subfolder, allowing multiple versions of YUI in your application
  • Incorporated fix for GRAILS-2512
  • Now contains 89! integration tests covering various use cases

2.5.0 (February 23, 2008)

  • Updated to YUI 2.5.0