To participate you must create an account on apostrophenow.org. If you have already done so, click Login.

Changeset 2145

Show
Ignore:
Timestamp:
09/08/10 10:30:22 (17 months ago)
Author:
tboutell
Message:

Firefox and Chrome respond differently to nested JS functions. In Firefox the declaration of the function must be executed before the call to the function, in Chrome you don't have to do that. I refactored the nested function to be a private method of the Apostrophe object, which felt right and avoided the confusion of dealing with nested functions. (I could also have defined it inside the method that calls it, but before the first call to it.)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • plugins/apostrophePlugin/trunk/web/js/a.js

    r2144 r2145  
    497497                        // a loop variable does *not* get captured 
    498498                        // in the closure at its current value otherwise 
    499                         setButtons(slot, n, slots); 
    500                         function setButtons(slot, n, slots) 
    501                         { 
    502                                 if (n > 0) 
    503                                 { 
    504                                         // TODO: this is not sensitive enough to nested areas 
    505                                         $(slot).find('.a-arrow-up').show().unbind('click').click(function() { 
    506                                                 // It would be nice to confirm success here in some way 
    507                                                 $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 1 }); 
    508                                                 apostrophe.swapNodes(slot, slots[n - 1]); 
    509                                                 apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
    510                                                 return false; 
    511                                         }); 
    512                                 } 
    513                                 else 
    514                                 { 
    515                                   $(slot).find('.a-arrow-up').hide(); 
    516                                 } 
    517                                 if (n < (slots.length - 1)) 
    518                                 { 
    519                                         $(slot).find('.a-arrow-down').show().unbind('click').click(function() { 
    520                                                 // It would be nice to confirm success here in some way 
    521                                                 $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 0 }); 
    522                                                 apostrophe.swapNodes(slot, slots[n + 1]); 
    523                                                 apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
    524                                                 return false; 
    525                                         }); 
    526                                 } 
    527                                 else 
    528                                 { 
    529                                         $(slot).find('.a-arrow-down').hide(); 
    530                                 } 
    531                         } 
     499                        slotUpdateMoveButtons(id, name, slot, n, slots, updateAction); 
    532500                } 
    533501        } 
     
    537505                $("#a-slot-" + pageid + "-" + name + "-" + permid).removeClass('a-new-slot'); 
    538506        } 
     507         
     508        // Private methods callable only from the above (no this.foo = bar) 
     509        function slotUpdateMoveButtons(id, name, slot, n, slots, updateAction) 
     510        { 
     511                if (n > 0) 
     512                { 
     513                        // TODO: this is not sensitive enough to nested areas 
     514                        $(slot).find('.a-arrow-up').show().unbind('click').click(function() { 
     515                                // It would be nice to confirm success here in some way 
     516                                $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 1 }); 
     517                                apostrophe.swapNodes(slot, slots[n - 1]); 
     518                                apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
     519                                return false; 
     520                        }); 
     521                } 
     522                else 
     523                { 
     524                  $(slot).find('.a-arrow-up').hide(); 
     525                } 
     526                if (n < (slots.length - 1)) 
     527                { 
     528                        $(slot).find('.a-arrow-down').show().unbind('click').click(function() { 
     529                                // It would be nice to confirm success here in some way 
     530                                $.get(updateAction, { id: id, name: name, permid: $(slot).data('a-permid'), up: 0 }); 
     531                                apostrophe.swapNodes(slot, slots[n + 1]); 
     532                                apostrophe.areaUpdateMoveButtons(updateAction, id, name); 
     533                                return false; 
     534                        }); 
     535                } 
     536                else 
     537                { 
     538                        $(slot).find('.a-arrow-down').hide(); 
     539                } 
     540        } 
    539541}  
    540542