source: trunk/grails-app/taglib/JsUtilTagLib.groovy

Last change on this file was 918, checked in by gav, 14 years ago

Small taglib fix, mkp is now a special namespace in groovy.xml.MarkupBuilder? so using 'mb'.

File size: 1.8 KB
RevLine 
[322]1
2/**
3* JsUtil tags.
4* Javascript Utility tags.
5*/
6class JsUtilTagLib {
7    static namespace = 'jsUtil'
8
9    def js = new JsUtilService()
10
11    /**
12    * Resources.
13     * To be included in the page head tag.
14    */
15    def resources = { attrs ->
16        out << g.javascript(src: "jsUtil.js")
17    }
18
19    /**
20    * Toggle the visibility of an html element and update an image.
21    * @param toggleId The html id of the element to toggle.
22    * @param imageId The html id to apply to the image.
23    * @param openImgUrl The url to apply as the image src when toggled element is visible.
24    * @param closedImgUrl The url to apply as the image src when toggled element is hidden.
[323]25    * @param effect The effect to apply, 'fade' uses the fade/appear effect while the default is to just toggle.
[322]26    * @param text The text, if any, to display.
[568]27    * @param useDiv Whether or not to use a wrapping div, default is 'true'.
[322]28    */
29    def toggleControl = { attrs ->
[918]30        def mb = new groovy.xml.MarkupBuilder(out)
[322]31
[323]32        def toggleJs
33
34        // Do we want to fade/appear or just toggle.
35        if(attrs.effect == "fade")
36            toggleJs = js.toggleWithImgAndEffect(attrs.toggleId, attrs.imageId, attrs.openImgUrl, attrs.closedImgUrl)
37        else
38            toggleJs = js.toggleWithImg(attrs.toggleId, attrs.imageId, attrs.openImgUrl, attrs.closedImgUrl)
39
[568]40        if(attrs.useDiv == 'false') {
[918]41            mb.a( href: toggleJs ) {
42                    mkp.yieldUnescaped(attrs.text)
[568]43                    img(id: attrs.imageId, src: attrs.closedImgUrl, alt: "Show")
[918]44            }
[322]45
[568]46        }
47        else {
[918]48            mb.div() {
[568]49                a( href: toggleJs ) {
[918]50                    mkp.yieldUnescaped(attrs.text)
[568]51                    img(id: attrs.imageId, src: attrs.closedImgUrl, alt: "Show")
52                }
[918]53            }
[568]54        }
55
[322]56    } // hideShowControl
57
58} // end class
Note: See TracBrowser for help on using the repository browser.