Changeset 77


Ignore:
Timestamp:
03/19/2009 12:45:45 PM (3 years ago)
Author:
ofer
Message:

Fix for changing translations of multiple items at once

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/js/transposh.js

    r75 r77  
    6464    '&source=' + source + 
    6565    '&translation_posted=1'; 
    66  
     66    //$("span:contains("+translation+")").css("text-decoration", "underline"); 
    6767    $.ajax({   
    6868        type: "POST", 
     
    7070        data: query,   
    7171        success: function(req) { 
    72                 var text_rewrite = translation; 
     72                var pre_translated = $("#tr_" + segment_id).html(); 
     73                var new_text = translation; 
     74                //reset to the original content - the unescaped version if translation is empty 
     75            if(jQuery.trim(translation).length == 0) { 
     76                new_text = original; 
     77            } 
     78            // rewrite text for all matching items at once 
     79                $(".tr_t,.tr_u").filter(function() {return $(this).html() == pre_translated;}).html(new_text) 
     80                        .each(function (i) { // handle the image changes 
     81                                var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_')+1); 
     82                    //current img  
     83                    var img = $("#tr_img_" + img_segment_id).attr('src'); 
    7384 
    74                 //rewrite text 
    75                 $("#tr_" + segment_id).html(text_rewrite); 
    76  
    77                 //current img  
    78                 var img = $("#tr_img_" + segment_id).attr('src'); 
    79  
    80                 //rewrite onclick function - in case of re-edit 
    81                 $("#tr_img_" + segment_id).click(function () { 
    82                         translate_dialog(original, translation, segment_id); 
     85                    //rewrite onclick function - in case of re-edit 
     86                    $("#tr_img_" + img_segment_id).click(function () { 
     87                        translate_dialog(original, translation, img_segment_id); 
    8388                    }); 
    8489 
    85                 if(jQuery.trim(translation).length == 0) { 
    86                     //reset to the original content - the not escaped version 
    87                     text_rewrite = original; 
    88  
    89                     //switch to the edit img 
    90                     img = img.replace(/translate_fix.png/, "translate.png"); 
    91                     img = img.replace(/translate_auto.png/, "translate.png"); 
    92                 } 
    93                 else { 
    94                         if (source == 1) { 
    95                                 //switch to the auto img 
    96                                 img = img.replace(/translate.png/, "translate_auto.png");                                
    97                         } else { 
    98                                 //switch to the fix img 
    99                                 img = img.replace(/translate.png/, "translate_fix.png"); 
    100                                 img = img.replace(/translate_auto.png/, "translate_fix.png"); 
    101                         } 
    102                 } 
     90                    // handle image 
     91                    if(jQuery.trim(translation).length == 0) { 
     92                        //switch to the edit img 
     93                        img = img.replace(/translate_fix.png/, "translate.png"); 
     94                        img = img.replace(/translate_auto.png/, "translate.png"); 
     95                    } else { 
     96                        if (source == 1) { 
     97                                //switch to the auto img 
     98                                img = img.replace(/translate.png/, "translate_auto.png");                                
     99                        } else { 
     100                                //switch to the fix img 
     101                                img = img.replace(/translate.png/, "translate_fix.png"); 
     102                                img = img.replace(/translate_auto.png/, "translate_fix.png"); 
     103                        } 
     104                    } 
     105                    //rewrite image 
     106                    $("#tr_img_" + img_segment_id).attr('src', img); 
     107                                 
     108                        }); 
    103109                 
    104                  
    105                 //rewrite image 
    106                 $("#tr_img_" + segment_id).attr('src', img); 
    107  
    108                 //close dialog 
    109                 cClick(); 
    110                 }, 
     110            //close dialog 
     111            cClick(); 
     112        }, 
    111113                 
    112114        error: function(req) { 
    113                         if (source == 0) { 
    114                                 alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 
    115                         } 
    116                 } 
     115                if (source == 0) { 
     116                        alert("Error !!! failed to translate.\n\nServer's message: " + req.statusText); 
     117                } 
     118        } 
    117119    }); 
    118120 
Note: See TracChangeset for help on using the changeset viewer.