source: trunk/grails-app/services/JsUtilService.groovy @ 897

Last change on this file since 897 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: 3.6 KB
RevLine 
[312]1/**
2* Provides some javascript utility methods.
[322]3* For use with JsUtilTagLib.
[312]4*/
[322]5class JsUtilService {
[312]6
7    boolean transactional = false
8
9    def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
10
11    /**
12    * Toggle the visibility of an html element.
13    * @param id The html id of the element.
[322]14    * @param type The type of html action the javascript will be applied to e.g 'onclick', defaults to 'href'.
15    * @returns A javascript string that can be assigned for example to an anchor href or onclick action.
[312]16    */
[322]17    def toggle(id, type="href") {
18        def s = 'toggleUtil(\"' + id + '\");'
19        if(type == "onclick")
20            s + ' return false;'
21        else
22            'javascript: ' + s
[312]23    }
24
25    /**
[322]26    * Toggle the visibility of an html element and update an image.
27    * @param toggleId The html id of the element to toggle.
28    * @param imageid The html id of the image to update.
29    * @param openImgUrl The url to apply as the image src when toggled element is visible.
30    * @param closedImgUrl The url to apply as the image src when toggled element is hidden.
31    * @param type The type of html action the javascript will be applied to e.g 'onclick', defaults to 'href'.
32    * @returns A javascript string that can be assigned for example to an anchor href or onclick action.
[312]33    */
[322]34    def toggleWithImg(toggleId, imageid, openImgUrl, closedImgUrl, type="href") {
[312]35
[322]36        def s = 'toggleWithImgUtil(\"' + toggleId +'\", \"' + imageid +'\", \"' + openImgUrl +'\", \"' + closedImgUrl +'\");'
37        if(type == "onclick")
38            s + ' return false;'
39        else
40            'javascript: ' + s
41
[312]42    }
43
44    /**
45    * Show an html element by slowly increasing the visibility.
46    * @param id The html id of the element.
[322]47    * @param type The type of html action the javascript will be applied to e.g 'onclick', defaults to 'href'.
48    * @returns A javascript string that can be assigned for example to an anchor href or onclick action.
[312]49    */
[322]50    def show(id) {
51        def s = 'showUtil(\"' + id + '\");'
52        if(type == "onclick")
53            s + ' return false;'
54        else
55            'javascript: ' + s
[312]56    }
57
58    /**
59    * Hide an html element by slowly decreasing the visibility.
60    * @param id The html id of the element.
[322]61    * @param type The type of html action the javascript will be applied to e.g 'onclick', defaults to 'href'.
62    * @returns A javascript string that can be assigned for example to an anchor href or onclick action.
[312]63    */
[322]64    def hide(id) {
65        def s = 'hideUtil(\"' + id + '\");'
66        if(type == "onclick")
67            s + ' return false;'
68        else
69            'javascript: ' + s
[312]70    }
71
[323]72    /**
73    * Toggle the visibility of an html element and update an image.
74    * @param toggleId The html id of the element to toggle.
75    * @param imageid The html id of the image to update.
76    * @param openImgUrl The url to apply as the image src when toggled element is visible.
77    * @param closedImgUrl The url to apply as the image src when toggled element is hidden.
78    * @param type The type of html action the javascript will be applied to e.g 'onclick', defaults to 'href'.
79    * @returns A javascript string that can be assigned for example to an anchor href or onclick action.
80    */
81    def toggleWithImgAndEffect(toggleId, imageid, openImgUrl, closedImgUrl, type="href") {
82
83        def s = 'toggleWithImgAndEffectUtil(\"' + toggleId +'\", \"' + imageid +'\", \"' + openImgUrl +'\", \"' + closedImgUrl +'\");'
84        if(type == "onclick")
85            s + ' return false;'
86        else
87            'javascript: ' + s
88
89    }
90
[312]91} // end class
Note: See TracBrowser for help on using the repository browser.