Changeset 322


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.

Location:
trunk
Files:
1 added
4 edited
2 moved

Legend:

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

    r319 r322  
    33    boolean transactional = false
    44
    5     def js = new JavascriptService()
     5    def js = new JsUtilService()
    66
    77    def g = new org.codehaus.groovy.grails.plugins.web.taglib.ApplicationTagLib()
     
    8484
    8585                div(class: paneCloseHtmlClass()) {
    86                     a( href: js.hrefToggle(paneHtmlId()) ) {
     86                    a( href: js.toggle(paneHtmlId()) ) {
    8787                        img(src: closeImg())
    8888                    }
     
    106106                div( class: 'buttons') {
    107107                    span(class: 'button') {
    108                         input( type: 'button', value: g.message(code: 'default.close.text'), onclick: js.onclickToggle(paneHtmlId()) )
     108                        input( type: 'button', value: g.message(code: 'default.close.text'), onclick: js.toggle(paneHtmlId(), "onclick") )
    109109                    }
    110110                } // button div
     
    132132                                li() {
    133133                                    if(site.sections) {
    134                                         a(href: hrefToggleBranch(nextDivId()) ) {
     134                                        a(href: toggleBranch(nextDivId()) ) {
    135135                                            img( src: branchImg(divId), id: divId+'img' )
    136136                                        }
     
    152152                                                li() {
    153153                                                    if(section.assets) {
    154                                                         a( href: hrefToggleBranch(nextDivId()) ) {
     154                                                        a( href: toggleBranch(nextDivId()) ) {
    155155                                                            img(src: branchImg(divId), id: divId+'img' )
    156156                                                        }
     
    173173                                                                li() {
    174174                                                                    if(asset.assetSubItems) {
    175                                                                         a( href: hrefToggleBranch(nextDivId()) ) {
     175                                                                        a( href: toggleBranch(nextDivId()) ) {
    176176                                                                            img(src: branchImg(divId), id: divId+'img' )
    177177                                                                        }
     
    197197                                                                                li() {
    198198                                                                                    if(assetSubItemL1.subItems) {
    199                                                                                         a( href: hrefToggleBranch(nextDivId()) ) {
     199                                                                                        a( href: toggleBranch(nextDivId()) ) {
    200200                                                                                            img(src: branchImg(divId), id: divId+'img' )
    201201                                                                                        }
     
    218218                                                                                                li() {
    219219                                                                                                    if(assetSubItemL2.subItems) {
    220                                                                                                         a( href: hrefToggleBranch(nextDivId()) ) {
     220                                                                                                        a( href: toggleBranch(nextDivId()) ) {
    221221                                                                                                            img( src: branchImg(divId), id: divId+'img' )
    222222                                                                                                        }
     
    239239                                                                                                                li() {
    240240                                                                                                                    if(assetSubItemL3.subItems) {
    241                                                                                                                         a( href: hrefToggleBranch(nextDivId()) ) {
     241                                                                                                                        a( href: toggleBranch(nextDivId()) ) {
    242242                                                                                                                            img( src: branchImg(divId), id: divId+'img' )
    243243                                                                                                                        }
     
    260260                                                                                                                                li() {
    261261            //                                                                                                                         if(assetSubItemL4.subItems) {
    262             //                                                                                                                             a( href: hrefToggleBranch(nextDivId()) ) {
     262            //                                                                                                                             a( href: toggleBranch(nextDivId()) ) {
    263263            //                                                                                                                                 img( src: branchImg(divId), id: divId+'img' )
    264264            //                                                                                                                             }
     
    365365    }
    366366
    367     def hrefToggleBranch(divId) {
    368        'javascript: toggleBranch(\"' + divId + '\", \"' + divId + 'img' +'\", \"' + bulletTreeMinusImg() +'\", \"' + bulletTreePlusImg() + '\");'
     367    def toggleBranch(divId) {
     368        js.toggleWithImg(divId, divId + 'img', bulletTreeMinusImg(), bulletTreePlusImg())
    369369    }
    370370
  • 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
  • trunk/grails-app/taglib/AssetTreeTagLib.groovy

    r312 r322  
    66    static namespace = 'gnuMims'
    77
    8     def js = new JavascriptService()
     8    def js = new JsUtilService()
    99    def ts = new AssetTreeService()
    1010
     
    3737        mkp.div(class: ts.paneHtmlClass(), id: ts.paneHtmlId(), style: 'display:none;') {
    3838            div(class: ts.paneCloseHtmlClass()) {
    39                 a( href: js.hrefToggle(ts.paneHtmlId()) ) {
     39                a( href: js.toggle(ts.paneHtmlId()) ) {
    4040                    img(src: ts.closeImg())
    4141                }
  • trunk/grails-app/views/layouts/main.gsp

    r313 r322  
    1111        <g:javascript library="prototype/effects" />
    1212        <g:javascript src="overlayPane.js" />
    13         <g:javascript src="util.js" />
     13        <jsUtil:resources />
    1414        <gnuMims:resources />
    1515    </head>
  • trunk/web-app/js/assetTree.js

    r316 r322  
    44    Effect.Appear(paneDivId,{duration:0.4});
    55
    6     // Pulsing loadingImg blocks the default grails animated gif till complete.
    7     // After which the default will show as normal.
    8     new Effect.Pulsate($(loadingImg), { pulses: 200, duration: 133 });
     6    // Disabled since pulsing effect blocks other javascript till complete.
     7    // The effect may be stopped with e.cancel() but we will use the default Grails spinner for now.
     8    // def e = new Effect.Pulsate($(loadingImg), { pulses: 200, duration: 133 });
    99
    10     // The updater is only called once per page refresh.
    1110    new Ajax.Updater({ success: paneDivId }, url, {asynchronous:true,evalScripts:true});
    1211}
     
    3433    new Ajax.Request(saveUrl, {parameters: params, asynchronous: false});
    3534}
    36 
    37 function toggleBranch(divId, imageId, openImgUrl, closedImgUrl) {
    38 
    39     $(divId).toggle();
    40 
    41     if( $(divId).visible() ) {
    42         $(imageId).src= openImgUrl;
    43     }
    44     else {
    45         $(imageId).src= closedImgUrl;
    46     }
    47 
    48 }
  • trunk/web-app/js/jsUtil.js

    r314 r322  
    22function toggleUtil(id) {
    33    $(id).toggle();
     4}
     5
     6function toggleWithImgUtil(id, imageId, openImgUrl, closedImgUrl) {
     7
     8    $(id).toggle();
     9
     10    if( $(id).visible() ) {
     11        $(imageId).src= openImgUrl;
     12    }
     13    else {
     14        $(imageId).src= closedImgUrl;
     15    }
    416}
    517
Note: See TracChangeset for help on using the changeset viewer.