Changeset 117


Ignore:
Timestamp:
03/29/2009 02:52:42 AM (3 years ago)
Author:
ofer
Message:

Another attempt at #24, seems much better this time

Location:
trunk/WordPress/plugin/transposh
Files:
5 edited

Legend:

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

    r113 r117  
    5959//Ajax translation 
    6060function ajax_translate(original,translation,source,segment_id) { 
    61         var token = jQuery("#tr_" + segment_id).attr('token'); 
    62         var query = 'token=' +  token + 
    63     '&translation=' + escape(translation) + 
    64     '&lang=' + transposh_params['lang'] + 
    65     '&source=' + source + 
    66     '&translation_posted=1'; 
    67          
    6861    jQuery.ajax({   
    6962        type: "POST", 
    7063        url: transposh_params['post_url'], 
    71         data: query,   
     64        data: {token: jQuery("#tr_" + segment_id).attr('token'), 
     65                                translation: translation, 
     66                                lang: transposh_params['lang'], 
     67                                source: source, 
     68                                translation_posted: "1"}, 
    7269        success: function(req) { 
    7370                var pre_translated = jQuery("#tr_" + segment_id).html(); 
     
    8380                    //current img  
    8481                    var img = jQuery("#tr_img_" + img_segment_id).attr('src'); 
    85  
    86                     //rewrite onclick function - in case of re-edit 
    87                     jQuery("#tr_img_" + img_segment_id).click(function () { 
    88                         translate_dialog(original, translation, img_segment_id); 
    89                     }); 
    90  
    91                     // handle image 
    92                     if(jQuery.trim(translation).length == 0) { 
     82                    if (img != undefined) { 
     83                        //rewrite onclick function - in case of re-edit 
     84                        jQuery("#tr_img_" + img_segment_id).click(function () { 
     85                                translate_dialog(original, translation, img_segment_id); 
     86                        }); 
     87                        img = img.substr(0,img.lastIndexOf("/")) + "/"; 
     88                        // handle image 
     89                        if(jQuery.trim(translation).length == 0) { 
    9390                        //switch to the edit img 
    94                         img = img.replace(/translate_fix.png/, "translate.png"); 
    95                         img = img.replace(/translate_auto.png/, "translate.png"); 
    96                     } else { 
    97                         if (source == 1) { 
    98                                 //switch to the auto img 
    99                                 img = img.replace(/translate.png/, "translate_auto.png");                                
     91                                img += "translate.png"; 
    10092                        } else { 
    101                                 //switch to the fix img 
    102                                 img = img.replace(/translate.png/, "translate_fix.png"); 
    103                                 img = img.replace(/translate_auto.png/, "translate_fix.png"); 
     93                                if (source == 1) { 
     94                                        //switch to the auto img 
     95                                        img += "translate_auto.png";                             
     96                                } else { 
     97                                //      switch to the fix img 
     98                                        img += "translate_fix.png"; 
     99                                } 
    104100                        } 
    105                     } 
    106                     //rewrite image 
    107                     jQuery("#tr_img_" + img_segment_id).attr('src', img); 
     101                        //      rewrite image 
     102                        jQuery("#tr_img_" + img_segment_id).attr('src', img); 
     103                    }; 
    108104                                 
    109105                        }); 
    110106                 
    111107            //close dialog 
    112             cClick(); 
     108                if (typeof cClick == 'function' && source == 0) { 
     109                        cClick(); 
     110                } 
    113111        }, 
    114112                 
     
    119117        } 
    120118    }); 
    121  
    122119} 
    123120 
  • trunk/WordPress/plugin/transposh/transposh.css

    r95 r117  
    8181.olraisedBlue { 
    8282    text-align:center;  
    83     background:#33aaff url(raised_blue.gif) repeat-x bottom left;} 
     83    background:#33aaff url(js/overlibmws/raised_blue.gif) repeat-x bottom left;} 
    8484 
    8585table.olraisedBlue { 
     
    9393 
    9494input.olinput { 
    95     background:white url(inputText.gif) repeat-x bottom left;  
     95    background:white url(js/overlibmws/inputText.gif) repeat-x bottom left;  
    9696    min-height:16px; 
    9797    font-family:Verdana,Arial,Helvetica,sans-serif;  
  • trunk/WordPress/plugin/transposh/transposh.php

    r116 r117  
    145145 
    146146        $url = html_entity_decode($url, ENT_NOQUOTES); 
    147          
     147 
    148148        if(!$enable_permalinks_rewrite) 
    149149        { 
     
    183183        $url = preg_replace("/&$/", "", $url); 
    184184        $url = preg_replace("/\?$/", "", $url); 
    185                  
     185 
    186186        $url = htmlentities($url, ENT_NOQUOTES); 
    187          
     187 
    188188        return $url; 
    189189} 
     
    483483                return; 
    484484        } 
     485 
     486        $lang = $wp_query->query_vars[LANG_PARAM]; 
     487        $editable_langs = get_option(EDITABLE_LANGS); 
     488 
     489        if(strpos($editable_langs, $lang) === FALSE) 
     490        { 
     491                //not an editable language - no need for any css. 
     492                return; 
     493        } 
     494 
    485495        //include the transposh.css 
    486496        wp_enqueue_style("transposh","$plugin_url/transposh.css",array(),'1.0.1'); 
     
    499509                return; 
    500510        } 
    501          
    502511        $lang = $wp_query->query_vars[LANG_PARAM]; 
    503512        $editable_langs = get_option(EDITABLE_LANGS); 
    504          
     513 
    505514        if(strpos($editable_langs, $lang) === FALSE) 
    506515        { 
    507                 //not an editable language - no need for any js.         
    508                 return; 
    509         } 
    510          
     516                //not an editable language - no need for any js. 
     517                return; 
     518        } 
     519 
    511520        $is_edit_param_enabled = $wp_query->query_vars[EDIT_PARAM]; 
    512          
     521 
    513522        if (!$is_edit_param_enabled && ! $enable_auto_translate) 
    514523        { 
  • trunk/WordPress/plugin/transposh/transposh_db.php

    r114 r117  
    9999 
    100100/* 
    101 * Helper function for annoying strings from php escape (%u2019) 
    102 */ 
    103 function utf8_urldecode($str) { 
    104     $str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($str)); 
    105     return html_entity_decode($str,null,'UTF-8');; 
    106 } 
    107  
    108 /* 
    109101 * A new translation has been posted, update the translation database. 
    110102 */ 
     
    115107        $ref=getenv('HTTP_REFERER'); 
    116108        $original =  base64_url_decode($_POST['token']); 
    117         $translation = utf8_urldecode($_POST['translation']); 
     109        $translation = $_POST['translation']; 
    118110        $lang = $_POST['lang']; 
    119111        $source = $_POST['source']; 
    120112 
     113        logger("Enter " . __FILE__ . " Params: $original , $translation, $lang," . $ref, 3); 
    121114        if(!isset($original) || !isset($translation) || !isset($lang)) 
    122115        { 
  • trunk/WordPress/plugin/transposh/transposh_widget.php

    r115 r117  
    4545                        $is_edit = $_POST[EDIT_PARAM]; 
    4646                        $ref = rewrite_url_lang_param($ref, $lang, $is_edit); 
    47                          
     47 
    4848                        //ref is generated with html entities encoded, needs to be 
    4949                        //decoded when used in the http header (i.e. 302 redirect) 
     
    210210    $url = preg_replace("/$home_url_quoted\/(..\/)/", "$home_url/",  $url); 
    211211 
     212    //some more cleans 
     213    $url = preg_replace("/&$/", "", $url); 
     214        $url = preg_replace("/\?$/", "", $url); 
     215 
    212216    return $url; 
    213217} 
Note: See TracChangeset for help on using the changeset viewer.