Changeset 349


Ignore:
Timestamp:
01/07/2010 02:05:49 AM (2 years ago)
Author:
ofer
Message:

Async loading of transposh.js script, fix doc error, load scripts only as_needed with the help of lazyloader plugin. should improve page load speeds for translated pages quite nicely. work still needed on some edge cases + code linting

Location:
trunk/WordPress/plugin/transposh
Files:
1 added
3 edited

Legend:

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

    r346 r349  
    2020function getgt() 
    2121{ 
    22     jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled"); 
    23     google.language.translate(jQuery("#"+transposh_params.prefix+"original").val(), "", transposh_params.lang, function(result) { 
    24         if (!result.error) { 
    25             jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+result.translation+"</div>").text()) 
    26             .keyup(); 
    27         } 
    28     }); 
     22    if (typeof google == 'undefined') { 
     23        langLoaded = function() { 
     24            getgt(); 
     25        }; 
     26        jQuery.xLazyLoader({ 
     27            js: 'http://www.google.com/jsapi?callback=loadLang' 
     28        }); 
     29    } else { 
     30        jQuery(":button:contains('Suggest - Google')").attr("disabled","disabled").addClass("ui-state-disabled"); 
     31        google.language.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", _tr_p.lang, function(result) { 
     32            if (!result.error) { 
     33                jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+result.translation+"</div>").text()) 
     34                .keyup(); 
     35            } 
     36        }); 
     37    } 
    2938} 
    3039 
     
    3241function getbt() 
    3342{ 
    34     jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled"); 
    35     var binglang = transposh_params.lang; 
    36     if (binglang == 'zh') { 
    37         binglang = 'zh-chs' 
    38     } 
    39     if (binglang == 'zh-tw') { 
    40         binglang = 'zh-cht' 
    41     } 
    42     Microsoft.Translator.translate(jQuery("#"+transposh_params.prefix+"original").val(), "", binglang, function(translation) { 
    43         jQuery("#"+transposh_params.prefix+"translation").val(jQuery("<div>"+translation+"</div>").text()) 
    44         .keyup(); 
    45     }); 
     43    if (typeof Microsoft == 'undefined') { 
     44        jQuery.xLazyLoader({ 
     45            js: 'http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId='+_tr_p.msnkey, 
     46            success: function() { 
     47                getbt() 
     48            } 
     49        }); 
     50 
     51    } else { 
     52        jQuery(":button:contains('Suggest - Bing')").attr("disabled","disabled").addClass("ui-state-disabled"); 
     53        var binglang = _tr_p.lang; 
     54        if (binglang == 'zh') { 
     55            binglang = 'zh-chs' 
     56        } 
     57        if (binglang == 'zh-tw') { 
     58            binglang = 'zh-cht' 
     59        } 
     60        try { 
     61            Microsoft.Translator.translate(jQuery("#"+_tr_p.prefix+"original").val(), "", binglang, function(translation) { 
     62                jQuery("#"+_tr_p.prefix+"translation").val(jQuery("<div>"+translation+"</div>").text()) 
     63                .keyup(); 
     64            }); 
     65        } 
     66        catch (err) { 
     67            alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")"); 
     68        } 
     69    } 
    4670} 
    4771 
     
    5983    clearTimeout(timer); 
    6084    // push translations 
    61     tokens.push(jQuery("#"+transposh_params.prefix + segment_id).attr('token')); 
     85    tokens.push(jQuery("#"+_tr_p.prefix + segment_id).attr('token')); 
    6286    translations.push(translation); 
    6387    // This is a change - as we fix the pages before we got actual confirmation (worked well for auto-translation) 
     
    6589    timer = setTimeout(function() { 
    6690        var data = { 
    67             lang: transposh_params.lang, 
     91            lang: _tr_p.lang, 
    6892            source: source, 
    6993            translation_posted: "1", 
     
    80104        jQuery.ajax({ 
    81105            type: "POST", 
    82             url: transposh_params.post_url, 
     106            url: _tr_p.post_url, 
    83107            data: data, 
    84108            success: function() { 
    85109                // Success now only updates the save progress bar (green) 
    86                 if (transposh_params.progress) { 
     110                if (_tr_p.progress) { 
    87111                    if (togo > 4 && source > 0) { 
    88112                        jQuery("#progress_bar2").progressbar('value' , done_p/togo*100); 
     
    104128 
    105129function fix_page(translation,source,segment_id) { 
    106     var token = jQuery("#"+transposh_params.prefix + segment_id).attr('token'); 
     130    var token = jQuery("#"+_tr_p.prefix + segment_id).attr('token'); 
    107131    var new_text = translation; 
    108132    //reset to the original content - the unescaped version if translation is empty 
    109133    if(jQuery.trim(translation).length === 0) { 
    110         new_text = jQuery("#"+transposh_params.prefix + segment_id).attr('orig'); 
     134        new_text = jQuery("#"+_tr_p.prefix + segment_id).attr('orig'); 
    111135    } 
    112136    // rewrite text for all matching items at once 
     
    115139    .each(function (i) { // handle the image changes 
    116140        var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 
    117         jQuery("#"+transposh_params.prefix+img_segment_id).attr('source',source); 
    118         var img = jQuery("#"+transposh_params.prefix+"img_" + img_segment_id); 
     141        jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 
     142        var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 
    119143        img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 
    120144        if(jQuery.trim(translation).length !== 0) { 
     
    134158    .each(function (i) { // handle the image changes 
    135159        var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 
    136         jQuery("#"+transposh_params.prefix+img_segment_id).attr('source',source); 
    137         var img = jQuery("#"+transposh_params.prefix+"img_" + img_segment_id); 
     160        jQuery("#"+_tr_p.prefix+img_segment_id).attr('source',source); 
     161        var img = jQuery("#"+_tr_p.prefix+"img_" + img_segment_id); 
    138162        img.removeClass('tr-icon-yellow').removeClass('tr-icon-green'); 
    139163        if(jQuery.trim(translation).length !== 0) { 
     
    152176//function for auto translation 
    153177function do_auto_translate() { 
    154     if (transposh_params.progress) { 
    155         togo = jQuery("."+transposh_params.prefix+'[source=""]').size(); 
     178    if (_tr_p.progress) { 
     179        togo = jQuery("."+_tr_p.prefix+'[source=""]').size(); 
    156180        //alert(togo); 
    157181        // progress bar is for alteast 5 items 
    158182        if (togo > 4) { 
    159             jQuery("#"+transposh_params.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>') 
     183            jQuery("#"+_tr_p.prefix+"credit").append('<div style="float: left;width: 90%;height: 10px" id="progress_bar"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="progress_bar2"/>') 
    160184            jQuery("#progress_bar").progressbar({ 
    161185                value: 0 
     
    174198    // auto_translated_previously... 
    175199    var auto_t_p = new Array(); 
    176     jQuery("."+transposh_params.prefix+'[source=""]').each(function (i) { 
     200    jQuery("."+_tr_p.prefix+'[source=""]').each(function (i) { 
    177201        var translated_id = jQuery(this).attr('id'); 
    178202        //alert(translated_id); 
     
    181205        if (!(auto_t_p[to_trans] == 1)) { 
    182206            auto_t_p[to_trans] = 1; 
    183             google.language.translate(to_trans, "", transposh_params.lang, function(result) { 
     207            google.language.translate(to_trans, "", _tr_p.lang, function(result) { 
    184208                if (!result.error) { 
    185209                    var segment_id = translated_id.substr(translated_id.lastIndexOf('_')+1); 
     
    187211                    //fix_page(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 
    188212                    ajax_translate(jQuery("<div>"+result.translation+"</div>").text(),1,segment_id); 
    189                     if (transposh_params.progress) { 
    190                         done = togo - jQuery("."+transposh_params.prefix+'[source=""]').size(); 
     213                    if (_tr_p.progress) { 
     214                        done = togo - jQuery("."+_tr_p.prefix+'[source=""]').size(); 
    191215                        if (togo > 4) { 
    192216                            jQuery("#progress_bar").progressbar('value' , done/togo*100); 
     
    211235        buttons: { 
    212236            'Discard': function() { 
    213                 jQuery("#"+transposh_params.prefix+"translation").data("edit", { 
     237                jQuery("#"+_tr_p.prefix+"translation").data("edit", { 
    214238                    changed: false 
    215239                }); 
    216240                jQuery(this).dialog('close'); 
    217                 jQuery("#"+transposh_params.prefix+"d-tabs").dialog('close'); 
     241                jQuery("#"+_tr_p.prefix+"d-tabs").dialog('close'); 
    218242            }, 
    219243            Cancel: function() { 
     
    226250//Open translation dialog  
    227251function translate_dialog(segment_id) { 
    228     jQuery("#"+transposh_params.prefix+"d-tabs").remove(); 
    229     jQuery('<div id="'+transposh_params.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body"); 
    230     jQuery("#"+transposh_params.prefix+"d-tabs").append('<ul/>').tabs({ 
     252    jQuery("#"+_tr_p.prefix+"d-tabs").remove(); 
     253    jQuery('<div id="'+_tr_p.prefix+'d-tabs" title="Edit Translation"/>').appendTo("body"); 
     254    jQuery("#"+_tr_p.prefix+"d-tabs").append('<ul/>').tabs({ 
    231255        cache: true 
    232256    }) 
    233     .tabs('add',"#"+transposh_params.prefix+"d-tabs-1",'Translate') 
    234     .tabs('add',transposh_params.post_url+'?tr_token_hist='+jQuery("#"+transposh_params.prefix + segment_id).attr('token')+'&lang='+transposh_params.lang,'History') 
     257    .tabs('add',"#"+_tr_p.prefix+"d-tabs-1",'Translate') 
     258    .tabs('add',_tr_p.post_url+'?tr_token_hist='+jQuery("#"+_tr_p.prefix + segment_id).attr('token')+'&lang='+_tr_p.lang,'History') 
    235259    .css("text-align","left") 
    236260    .css("padding",0) 
     
    246270        jQuery("table tbody td[source='1']",ui.panel).append('<span title="computer" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-gear"></span>'); 
    247271        jQuery("table tbody td[source='0']",ui.panel).append('<span title="human" style="display: inline-block; margin-right: 0.3em;" class="ui-icon ui-icon-person"></span>'); 
    248     //jQuery("table tbody tr:first td:last",ui.panel).append('<span title="remove this translation" id="'+transposh_params.prefix+'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>'); 
    249     //jQuery("#"+transposh_params.prefix+"revert").click(function () { 
     272    //jQuery("table tbody tr:first td:last",ui.panel).append('<span title="remove this translation" id="'+_tr_p.prefix+'revert" style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-scissors"/>'); 
     273    //jQuery("#"+_tr_p.prefix+"revert").click(function () { 
    250274    //alert ('hi'); 
    251275    //}); 
     
    254278        // Change buttons 
    255279        if (jQuery(ui.tab).text() == 'Translate') { 
    256             jQuery("#"+transposh_params.prefix+"d-tabs").dialog('option', 'buttons', tButtons); 
     280            jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', tButtons); 
    257281        } else { 
    258             jQuery("#"+transposh_params.prefix+"d-tabs").dialog('option', 'buttons', hButtons); 
     282            jQuery("#"+_tr_p.prefix+"d-tabs").dialog('option', 'buttons', hButtons); 
    259283        } 
    260284    }) 
    261285    .bind('dialogbeforeclose', function(event, ui) { 
    262         if(jQuery("#"+transposh_params.prefix+"translation").data("edit").changed) { 
     286        if(jQuery("#"+_tr_p.prefix+"translation").data("edit").changed) { 
    263287            confirm_close(); 
    264288            return false; 
     
    267291    }); 
    268292    // fix for templates messing with li 
    269     jQuery("#"+transposh_params.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside"); 
    270     jQuery("#"+transposh_params.prefix+"d-tabs-1").css("padding", "1px").append( 
     293    jQuery("#"+_tr_p.prefix+"d-tabs li").css("list-style-type","none").css("list-style-position","outside"); 
     294    jQuery("#"+_tr_p.prefix+"d-tabs-1").css("padding", "1px").append( 
    271295        /*'<table><tr><td>'+*/ 
    272         '<form id="'+transposh_params.prefix+'form">' + 
     296        '<form id="'+_tr_p.prefix+'form">' + 
    273297        '<fieldset>' + 
    274298        '<label for="original">Original Text</label>' + 
    275         '<textarea cols="80" row="3" name="original" id="'+transposh_params.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/>' + 
     299        '<textarea cols="80" row="3" name="original" id="'+_tr_p.prefix+'original" class="text ui-widget-content ui-corner-all" readonly="y"/>' + 
    276300        '<label for="translation">Translate To</label>' + 
    277         '<textarea cols="80" row="3" name="translation" id="'+transposh_params.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/>' + 
     301        '<textarea cols="80" row="3" name="translation" id="'+_tr_p.prefix+'translation" value="" class="text ui-widget-content ui-corner-all"/>' + 
    278302        '</fieldset>' + 
    279303        '</form>'/*+ 
     
    287311        grabnext(segment_id); 
    288312    });*/ 
    289     jQuery("#"+transposh_params.prefix+"d-tabs-1 label").css("display","block"); 
    290     jQuery("#"+transposh_params.prefix+"d-tabs-1 textarea.text").css({ 
     313    jQuery("#"+_tr_p.prefix+"d-tabs-1 label").css("display","block"); 
     314    jQuery("#"+_tr_p.prefix+"d-tabs-1 textarea.text").css({ 
    291315        'margin-bottom':'12px', 
    292316        'width' : '95%', 
    293317        'padding' : '.4em' 
    294318    }); 
    295     jQuery("#"+transposh_params.prefix+"original").val(jQuery("#"+transposh_params.prefix + segment_id).attr('orig')); 
    296     jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix + segment_id).html()); 
    297     if (jQuery("#"+transposh_params.prefix + segment_id).attr('trans')) { 
    298         jQuery("#"+transposh_params.prefix+"translation").val(jQuery("#"+transposh_params.prefix + segment_id).attr('trans')); 
    299     } 
    300     jQuery("#"+transposh_params.prefix+"translation").data("edit", { 
     319    jQuery("#"+_tr_p.prefix+"original").val(jQuery("#"+_tr_p.prefix + segment_id).attr('orig')); 
     320    jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).html()); 
     321    if (jQuery("#"+_tr_p.prefix + segment_id).attr('trans')) { 
     322        jQuery("#"+_tr_p.prefix+"translation").val(jQuery("#"+_tr_p.prefix + segment_id).attr('trans')); 
     323    } 
     324    jQuery("#"+_tr_p.prefix+"translation").data("edit", { 
    301325        changed: false 
    302326    }); 
    303     jQuery("#"+transposh_params.prefix+"translation").keyup(function(e){ 
    304         if (jQuery("#"+transposh_params.prefix + segment_id).text() != jQuery(this).val()) { 
     327    jQuery("#"+_tr_p.prefix+"translation").keyup(function(e){ 
     328        if (jQuery("#"+_tr_p.prefix + segment_id).text() != jQuery(this).val()) { 
    305329            jQuery(this).css("background","yellow"); 
    306330            jQuery(this).data("edit", { 
     
    315339    }); 
    316340    var tButtons = {}; 
    317     if (binglangs.indexOf(transposh_params.lang+',',0) > -1) { 
     341    //only add button is bing support is defined for the language (and we got some key) 
     342    if (bing_langs.indexOf(_tr_p.lang) > -1 && _tr_p.msnkey != '') { 
    318343        //ar,zh-chs,zh-cht,nl,en,fr,de,he,it,ja,ko,pl,pt,ru,es 
    319344        tButtons['Suggest - Bing'] = function() { 
     
    322347    } 
    323348 
    324     if (google.language.isTranslatable(transposh_params.lang) || ext_langs.indexOf(transposh_params.lang) > -1) { 
     349    // Only add button if google supports said language 
     350    if ( google_langs.indexOf(_tr_p.lang) > -1) { 
    325351        tButtons['Suggest - Google'] = function() { 
    326352            getgt(); 
     
    332358            }, 
    333359            'Combine - Next': function() { 
    334                 getgt(); 
     360                something?(); 
    335361                //.next? .next all? 
    336362            },*/ 
    337363    tButtons['Ok'] = function() { 
    338         var translation = jQuery('#'+transposh_params.prefix+'translation').val(); 
    339         if(jQuery('#'+transposh_params.prefix+'translation').data("edit").changed) { 
     364        var translation = jQuery('#'+_tr_p.prefix+'translation').val(); 
     365        if(jQuery('#'+_tr_p.prefix+'translation').data("edit").changed) { 
    340366            ajax_translate(translation,0,segment_id); 
    341             jQuery("#"+transposh_params.prefix+"translation").data("edit", { 
     367            jQuery("#"+_tr_p.prefix+"translation").data("edit", { 
    342368                changed: false 
    343369            }); 
     
    351377        } 
    352378    }; 
    353     jQuery("#"+transposh_params.prefix+"d-tabs").dialog({ 
     379    jQuery("#"+_tr_p.prefix+"d-tabs").dialog({ 
    354380        bgiframe: true, 
    355381        modal: true, 
     
    360386} 
    361387 
    362 //to run at start 
     388// We first try to avoid conflict with other frameworks 
    363389jQuery.noConflict(); 
    364 //read parameters 
    365 var transposh_params = new Array(); 
    366 var ext_langs = 'he|zh-tw|pt|fa|af|be|is|ga|mk|ms|sw|ws|cy|yi'; 
    367 jQuery("script[src*='transposh.js']").each(function (j) { 
    368     var query_string = unescape(this.src.substring(this.src.indexOf('?')+1)); 
    369     var parms = query_string.split('&'); 
    370     for (var i=0; i<parms.length; i++) { 
    371         var pos = parms[i].indexOf('='); 
    372         if (pos > 0) { 
    373             var key = parms[i].substring(0,pos); 
    374             var val = parms[i].substring(pos+1); 
    375             transposh_params[key] = val; 
    376         } 
    377     } 
    378 }); 
    379  
    380 //console.log('hi'); 
    381  
    382 google.load("language", "1"); 
    383 // first we check if msn was even included 
    384 var binglangs = ''; 
    385 if (typeof(Microsoft) != 'undefined') { 
    386     try { 
    387         binglangs = String(Microsoft.Translator.GetLanguages())+',zh,zh-tw,';         
    388     } 
    389     catch (err) { 
    390         alert("There was an error using Microsoft.Translator - probably a bad key or URL used in key. ("+err+")"); 
    391     } 
     390// the languages supported externally 
     391// extracted using function above + he|zh-tw|pt that we know 
     392google_langs = 'af|sq|ar|be|bg|ca|zh|zh-CN|zh-TW|hr|cs|da|nl|en|et|tl|fi|fr|gl|de|el|iw|hi|hu|is|id|ga|it|ja|ko|lv|lt|mk|ms|mt|no|fa|pl|pt-PT|ro|ru|sr|sk|sl|es|sw|sv|tl|th|tr|uk|vi|cy|yi|he|zh-tw|pt'; 
     393// got this using Microsoft.Translator.GetLanguages() with added zh and zh-tw for our needs 
     394bing_langs = 'ar,bg,zh-chs,zh-cht,cs,da,nl,en,fi,fr,de,el,he,it,ja,ko,pl,pt,ru,es,sv,th,zh,zh-tw'; 
     395 
     396function loadLang() { 
     397    google.load("language", "1", { 
     398        "callback" : langLoaded 
     399    }); 
    392400} 
    393401 
    394402jQuery(document).ready( 
    395403    function() { 
    396         // an implicit param 
    397         if (typeof(jQuery().progressbar) != 'undefined') { 
    398             transposh_params.progress = true; 
    399         } 
    400         // attach a function to the set_defualt_language link if its there 
    401         jQuery('#'+transposh_params.prefix+'setdeflang').click(function () { 
    402             jQuery.get( transposh_params.post_url+"?tr_cookie="+Math.random()); 
     404        // this is the set_default_language function 
     405        // attach a function to the set_default_language link if its there 
     406        jQuery('#'+_tr_p.prefix+'setdeflang').click(function () { 
     407            jQuery.get( _tr_p.post_url+"?tr_cookie="+Math.random()); 
    403408            jQuery(this).hide("slow"); 
    404409            return false; 
    405410        }) 
    406         // TODO: he, iw? :) 
    407         if (google.language.isTranslatable(transposh_params.lang) || ext_langs.indexOf(transposh_params.lang) > -1) { 
    408             do_auto_translate(); 
    409         } 
    410         if (transposh_params.edit) { 
     411 
     412        // now lets check if auto translate is needed 
     413        translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"); 
     414        if (translationstats != undefined) { 
     415            possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases -(translationstats.meta_phrases - translationstats.meta_translated_phrases)); 
     416            now = new Date 
     417            // we'll only auto-translate and load the stuff if we either have more than 5 candidate translations, or more than one at 4am, and this language is supported... 
     418            if ((possibly_translateable > 5 || (now.getHours() == 4 && possibly_translateable > 0)) && google_langs.indexOf(_tr_p.lang) > -1) { 
     419                // TODO - FIX ME! (islands) 
     420                jQuery.ajaxSetup({ 
     421                    cache: true 
     422                }); 
     423                // if we have a progress bar, we need to load the jqueryui before the auto translate, after the google was loaded, otherwise we can just go ahead 
     424                langLoaded = function() { 
     425                    if (_tr_p.progress) { 
     426                        jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 
     427                            jQuery.xLazyLoader({ 
     428                                js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 
     429                                css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 
     430                                success: function () { 
     431                                    do_auto_translate() 
     432                                } 
     433                            }); 
     434                        }); 
     435                    } else { 
     436                        do_auto_translate() 
     437                    } 
     438                }; 
     439                // we now start the chain that leads to auto-translate (with or without progress) 
     440                jQuery.getScript('http://www.google.com/jsapi?callback=loadLang'); 
     441            } 
     442        } 
     443 
     444        // this is the part when we have editor support 
     445        if (_tr_p.edit) { 
    411446            // lets add the images 
    412             jQuery("."+transposh_params.prefix).each(function (i) { 
     447            jQuery("."+_tr_p.prefix).each(function (i) { 
    413448                var translated_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_')+1); 
    414                 jQuery(this).after('<span id="'+transposh_params.prefix+'img_'+translated_id+'" class="tr-icon" title="'+jQuery(this).attr('orig')+'"></span>'); 
    415                 var img = jQuery('#'+transposh_params.prefix+'img_'+translated_id); 
     449                jQuery(this).after('<span id="'+_tr_p.prefix+'img_'+translated_id+'" class="tr-icon" title="'+jQuery(this).attr('orig')+'"></span>'); 
     450                var img = jQuery('#'+_tr_p.prefix+'img_'+translated_id); 
    416451                img.click(function () { 
    417                     translate_dialog(translated_id); 
     452                    //  if we detect that jQuery.ui is missing (TODO - check tabs - etal) we load it first 
     453                    if (typeof jQuery.ui == 'undefined') { 
     454                        jQuery.ajaxSetup({ 
     455                            cache: true 
     456                        }); 
     457                        jQuery.getScript(_tr_p.plugin_url +'/js/lazy.js', function() { 
     458                            jQuery.xLazyLoader({ 
     459                                js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 
     460                                css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', 
     461                                success: function() { 
     462                                    translate_dialog(translated_id); 
     463                                } 
     464                            }); 
     465                        }); 
     466                    } else { 
     467                        translate_dialog(translated_id); 
     468                    } 
    418469                    return false; 
    419470                }).css({ 
     
    434485            }); 
    435486        } 
    436     } 
    437     ); 
     487    }); 
  • trunk/WordPress/plugin/transposh/transposh.php

    r348 r349  
    7878    /** @var string Saved search variables*/ 
    7979    private $search_s; 
    80     /** @var boolean If transposh.js is on the page*/ 
    81     public $js_included = false; 
    8280 
    8381    /** 
     
    118116        add_action('wp_print_styles', array(&$this,'add_transposh_css')); 
    119117        add_action('wp_print_scripts', array(&$this,'add_transposh_js')); 
     118        add_action('wp_head', array(&$this,'add_transposh_async')); 
    120119        add_action("sm_addurl",array(&$this,'add_sm_transposh_urls')); 
    121120        register_activation_hook(__FILE__, array(&$this,'plugin_activate')); 
     
    468467        wp_enqueue_style("transposh","{$this->transposh_plugin_url}/css/transposh.css",array(),TRANSPOSH_PLUGIN_VER); 
    469468        // we have to load the jquery-ui css just in some cases 
    470         if ($this->edit_mode || $this->options->get_widget_progressbar()) 
    471             wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0'); 
     469//        if ($this->edit_mode || $this->options->get_widget_progressbar()) 
     470//            wp_enqueue_style("jquery","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css",array(),'1.0'); 
    472471        logger("Added transposh_css",4); 
    473472    } 
     
    480479        if (!$this->edit_mode && !$this->is_auto_translate_permitted()) { 
    481480            return; 
    482         } 
    483  
    484         $edit_param = ""; 
    485         if($this->edit_mode) { 
    486             $edit_param = "&".EDIT_PARAM."=y"; 
    487         } 
    488  
    489         if($this->edit_mode || $this->options->get_widget_progressbar()) { 
    490             wp_enqueue_script("jqueryui","http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js",array("jquery"),'1.7.2',$this->options->get_enable_footer_scripts()); 
    491481        } 
    492482 
     
    497487            // toying around - for later... 
    498488            //wp_enqueue_script("jquery","http://code.jquery.com/jquery-1.4a2.min.js",array(),'1.4a2'); 
    499             // jQuery pushing below might cause issues 
    500             //wp_enqueue_script("jquery","http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js",array(),'1.3.2', $this->options->get_enable_footer_scripts()); 
    501             wp_enqueue_script("google","http://www.google.com/jsapi",array(),'1',$this->options->get_enable_footer_scripts()); 
    502             // Make sure msn translate is not needlessly loaded when we are only auto translating 
    503             if ($this->options->get_enable_msn_translate() && $this->edit_mode) { 
    504                 wp_enqueue_script("mstranslate","http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=".$this->options->get_msn_key(),array(),'1',$this->options->get_enable_footer_scripts()); 
    505             } 
    506             wp_enqueue_script("transposh","{$this->transposh_plugin_url}/js/transposh.js?post_url={$this->post_url}{$edit_param}&lang={$this->target_language}&prefix=".SPAN_PREFIX,array("jquery"),TRANSPOSH_PLUGIN_VER,$this->options->get_enable_footer_scripts()); 
    507             $this->js_included = true; 
    508         } 
    509     } 
    510  
     489        } 
     490    } 
     491 
     492 
     493    function add_transposh_async() { 
     494        if (!$this->edit_mode && !$this->is_auto_translate_permitted()) { 
     495            return; 
     496        } 
     497 
     498        echo "<script type=\"text/javascript\"> 
     499 
     500        var _tr_p=_tr_p || []; 
     501        _tr_p.post_url='{$this->post_url}'; 
     502        _tr_p.plugin_url='{$this->transposh_plugin_url}'; 
     503        _tr_p.edit=".($this->edit_mode? 'true' : 'false')."; 
     504        _tr_p.lang='{$this->target_language}'; 
     505        _tr_p.prefix='".SPAN_PREFIX."'; 
     506        _tr_p.msnkey='{$this->options->get_msn_key()}'; 
     507        _tr_p.progress=".($this->edit_mode || $this->options->get_widget_progressbar() ? 'true' : 'false')."; 
     508 
     509  (function() { 
     510    var tp = document.createElement('script'); tp.type = 'text/javascript'; tp.async = true; 
     511    tp.src = '{$this->transposh_plugin_url}/js/transposh.js?ver=".TRANSPOSH_PLUGIN_VER."'; 
     512    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(tp); 
     513  })(); 
     514 
     515</script>"; 
     516    } 
    511517 
    512518    /** 
     
    651657     * Also - priority is reduced by 0.2 
    652658     * And this requires the following line at the sitemap-core.php, add-url function (line 1509 at version 3.2.2) 
    653      * do_action('sm_addurl',$loc, &$page); 
     659     * do_action('sm_addurl', &$page); 
    654660     * @param GoogleSitemapGeneratorPage $sm_page Object containing the page information 
    655661     */ 
  • trunk/WordPress/plugin/transposh/wp/transposh_widget.php

    r346 r349  
    195195            if ($this->transposh->options->get_widget_allow_set_default_language()) { 
    196196                If ((isset($_COOKIE['TR_LNG']) && $_COOKIE['TR_LNG'] != $this->transposh->target_language) || (!isset($_COOKIE['TR_LNG']) && !$this->transposh->options->is_default_language($this->transposh->target_language))) { 
    197                     if ($this->transposh->js_included) { 
    198                         echo '<a href="#" id="'.SPAN_PREFIX.'setdeflang" onClick="return false;">Set as default language</a><br/>'; 
    199                     } else { 
    200                         echo '<a href="'.$this->transposh->post_url.'?tr_cookie_bck">Set as default language</a><br/>'; 
    201                     } 
     197                    echo '<a id="'.SPAN_PREFIX.'setdeflang" onClick="return false;" href="'.$this->transposh->post_url.'?tr_cookie_bck">Set as default language</a><br/>'; 
    202198                } 
    203199            } 
Note: See TracChangeset for help on using the changeset viewer.