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

Last change on this file since 440 was 323, checked in by gav, 15 years ago

Add toggleWithImgAndEffect to JsUtil.
Replace control divs with our new JsUtil toggleControl taglib.
Small CSS adjustment to asset tree pane close.

File size: 1.6 KB
Line 
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.
25    * @param effect The effect to apply, 'fade' uses the fade/appear effect while the default is to just toggle.
26    * @param text The text, if any, to display.
27    */
28    def toggleControl = { attrs ->
29        def mkp = new groovy.xml.MarkupBuilder(out) //this line will be unnecessary in versions of Grails after version 1.2
30
31        def toggleJs
32
33        // Do we want to fade/appear or just toggle.
34        if(attrs.effect == "fade")
35            toggleJs = js.toggleWithImgAndEffect(attrs.toggleId, attrs.imageId, attrs.openImgUrl, attrs.closedImgUrl)
36        else
37            toggleJs = js.toggleWithImg(attrs.toggleId, attrs.imageId, attrs.openImgUrl, attrs.closedImgUrl)
38
39        mkp.div() {
40            a( href: toggleJs ) {
41                yieldUnescaped(attrs.text)
42                img(id: attrs.imageId, src: attrs.closedImgUrl, alt: "Show")
43            }
44        } // mkp
45
46    } // hideShowControl
47
48} // end class
Note: See TracBrowser for help on using the repository browser.