1 | |
---|
2 | /** |
---|
3 | * JsUtil tags. |
---|
4 | * Javascript Utility tags. |
---|
5 | */ |
---|
6 | class 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 | * @param useDiv Whether or not to use a wrapping div, default is 'true'. |
---|
28 | */ |
---|
29 | def toggleControl = { attrs -> |
---|
30 | def mkp = new groovy.xml.MarkupBuilder(out) //this line will be unnecessary in versions of Grails after version 1.2 |
---|
31 | |
---|
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 | |
---|
40 | if(attrs.useDiv == 'false') { |
---|
41 | mkp.a( href: toggleJs ) { |
---|
42 | yieldUnescaped(attrs.text) |
---|
43 | img(id: attrs.imageId, src: attrs.closedImgUrl, alt: "Show") |
---|
44 | } // mkp |
---|
45 | |
---|
46 | } |
---|
47 | else { |
---|
48 | mkp.div() { |
---|
49 | a( href: toggleJs ) { |
---|
50 | yieldUnescaped(attrs.text) |
---|
51 | img(id: attrs.imageId, src: attrs.closedImgUrl, alt: "Show") |
---|
52 | } |
---|
53 | } // mkp |
---|
54 | } |
---|
55 | |
---|
56 | } // hideShowControl |
---|
57 | |
---|
58 | } // end class |
---|