Ignore:
Timestamp:
Feb 8, 2010, 2:51:23 AM (14 years ago)
Author:
gav
Message:

Move JavascriptService to JsUtilService.
Consolidate similar JsUtilService methods.
Create JsUtilTagLib?.
Disable pulsing of asset tree loading image.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/services/JsUtilService.groovy

    r314 r322  
    11/**
    22* 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.
    84*/
    9 class JavascriptService {
     5class JsUtilService {
    106
    117    boolean transactional = false
     
    1612    * Toggle the visibility of an html element.
    1713    * @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.
    1916    */
    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
    2223    }
    2324
    2425    /**
    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.
    2833    */
    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
    3142    }
    3243
     
    3445    * Show an html element by slowly increasing the visibility.
    3546    * @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.
    3749    */
    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
    4956    }
    5057
     
    5259    * Hide an html element by slowly decreasing the visibility.
    5360    * @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.
    5563    */
    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
    6770    }
    6871
Note: See TracChangeset for help on using the changeset viewer.