1 | /** |
---|
2 | * Provides some javascript utility methods. |
---|
3 | * To use include the following in the gsp head: |
---|
4 | * <!-- |
---|
5 | * <g:javascript src="util.js" /> |
---|
6 | * --> |
---|
7 | * @todo: util.js could be placed a taglib resources closure. |
---|
8 | */ |
---|
9 | class JavascriptService { |
---|
10 | |
---|
11 | boolean transactional = false |
---|
12 | |
---|
13 | def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib() |
---|
14 | |
---|
15 | /** |
---|
16 | * Toggle the visibility of an html element. |
---|
17 | * @param id The html id of the element. |
---|
18 | * @returns A javascript string that can be assigned to an onclick action. |
---|
19 | */ |
---|
20 | def onclickToggle(id) { |
---|
21 | 'return toggleUtil(\"' + id + '\");' |
---|
22 | } |
---|
23 | |
---|
24 | /** |
---|
25 | * Toggle the visibility of an html element. |
---|
26 | * @param id The html id of the element. |
---|
27 | * @returns A javascript string that can be assigned to an anchor href. |
---|
28 | */ |
---|
29 | def hrefToggle(id) { |
---|
30 | 'javascript: toggleUtil(\"' + id + '\");' |
---|
31 | } |
---|
32 | |
---|
33 | /** |
---|
34 | * Show an html element by slowly increasing the visibility. |
---|
35 | * @param id The html id of the element. |
---|
36 | * @returns A javascript string that can be assigned to an onclick action. |
---|
37 | */ |
---|
38 | def onclickShow(id) { |
---|
39 | 'return showUtil(\"' + id + '\");' |
---|
40 | } |
---|
41 | |
---|
42 | /** |
---|
43 | * Show an html element by slowly increasing the visibility. |
---|
44 | * @param id The html id of the element. |
---|
45 | * @returns A javascript string that can be assigned to an anchor href. |
---|
46 | */ |
---|
47 | def hrefShow(id) { |
---|
48 | 'javascript: showUtil(\"' + id + '\");' |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Hide an html element by slowly decreasing the visibility. |
---|
53 | * @param id The html id of the element. |
---|
54 | * @returns A javascript string that can be assigned to an onclick action. |
---|
55 | */ |
---|
56 | def onclickHide(id) { |
---|
57 | 'return hideUtil(\"' + id + '\");' |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * Hide an html element by slowly decreasing the visibility. |
---|
62 | * @param id The html id of the element. |
---|
63 | * @returns A javascript string that can be assigned to an anchor href. |
---|
64 | */ |
---|
65 | def hrefHide(id) { |
---|
66 | 'javascript: hideUtil(\"' + id + '\");' |
---|
67 | } |
---|
68 | |
---|
69 | } // end class |
---|