Changeset 322 for trunk/grails-app/services/JsUtilService.groovy
- Timestamp:
- Feb 8, 2010, 2:51:23 AM (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/services/JsUtilService.groovy
r314 r322 1 1 /** 2 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. 3 * For use with JsUtilTagLib. 8 4 */ 9 class J avascriptService {5 class JsUtilService { 10 6 11 7 boolean transactional = false … … 16 12 * Toggle the visibility of an html element. 17 13 * @param id The html id of the element. 18 * @returns A javascript string that can be assigned to an onclick action. 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. 19 16 */ 20 def onclickToggle(id) { 21 'return toggleUtil(\"' + id + '\");' 17 def toggle(id, type="href") { 18 def s = 'toggleUtil(\"' + id + '\");' 19 if(type == "onclick") 20 s + ' return false;' 21 else 22 'javascript: ' + s 22 23 } 23 24 24 25 /** 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. 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. 28 33 */ 29 def hrefToggle(id) { 30 'javascript: toggleUtil(\"' + id + '\");' 34 def toggleWithImg(toggleId, imageid, openImgUrl, closedImgUrl, type="href") { 35 36 def s = 'toggleWithImgUtil(\"' + toggleId +'\", \"' + imageid +'\", \"' + openImgUrl +'\", \"' + closedImgUrl +'\");' 37 if(type == "onclick") 38 s + ' return false;' 39 else 40 'javascript: ' + s 41 31 42 } 32 43 … … 34 45 * Show an html element by slowly increasing the visibility. 35 46 * @param id The html id of the element. 36 * @returns A javascript string that can be assigned to an onclick action. 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. 37 49 */ 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 + '\");' 50 def show(id) { 51 def s = 'showUtil(\"' + id + '\");' 52 if(type == "onclick") 53 s + ' return false;' 54 else 55 'javascript: ' + s 49 56 } 50 57 … … 52 59 * Hide an html element by slowly decreasing the visibility. 53 60 * @param id The html id of the element. 54 * @returns A javascript string that can be assigned to an onclick action. 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. 55 63 */ 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 + '\");' 64 def hide(id) { 65 def s = 'hideUtil(\"' + id + '\");' 66 if(type == "onclick") 67 s + ' return false;' 68 else 69 'javascript: ' + s 67 70 } 68 71
Note: See TracChangeset
for help on using the changeset viewer.