- Timestamp:
- 01/30/2010 01:17:04 AM (2 years ago)
- File:
-
- 1 edited
-
trunk/WordPress/plugin/transposh/js/transposh.js (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/js/transposh.js
r370 r372 18 18 /*global Date, Math, Microsoft, alert, clearTimeout, document, google, jQuery, setTimeout, t_jp, window */ 19 19 // fetch translation from google translate... 20 (function () { // closure 20 // We first try to avoid conflict with other frameworks 21 jQuery.noConflict(); 22 23 (function ($) { // closure 21 24 var langLoaded, loadLang, getMSN, 22 25 // number of phrases that might be translated … … 39 42 function fix_page(token, translation) { 40 43 // Todo - Probably not needed, but in case we get bad stuff 41 if ( jQuery.trim(translation).length === 0) {44 if ($.trim(translation).length === 0) { 42 45 return; 43 46 } … … 47 50 // edit script will fix this 48 51 var fix_image = function () { // handle the image changes 49 var img_segment_id = jQuery(this).attr('id').substr(jQuery(this).attr('id').lastIndexOf('_') + 1),50 img = jQuery("#" + t_jp_prefix + "img_" + img_segment_id);51 jQuery("#" + t_jp_prefix + img_segment_id).attr('source', 1); // source is 152 var img_segment_id = $(this).attr('id').substr($(this).attr('id').lastIndexOf('_') + 1), 53 img = $("#" + t_jp_prefix + "img_" + img_segment_id); 54 $("#" + t_jp_prefix + img_segment_id).attr('source', 1); // source is 1 52 55 img.removeClass('tr-icon-yellow').removeClass('tr-icon-green').addClass('tr-icon-yellow'); 53 56 }; 54 57 55 58 // rewrite text for all matching items at once 56 jQuery("*[token='" + token + "'][hidden!='y']")59 $("*[token='" + token + "'][hidden!='y']") 57 60 .html(translation) 58 61 .each(fix_image); 59 62 60 63 // TODO - FIX hidden elements too (need to update father's title) 61 jQuery("*[token='" + token + "'][hidden='y']")64 $("*[token='" + token + "'][hidden='y']") 62 65 .attr('trans', translation) 63 66 .each(fix_image); 64 67 } 65 68 69 // function to move the progress bars (if needed) 70 function make_progress(id, value) { 71 if (t_jp.progress) { 72 $('#' + id).progressbar('value', value); 73 } 74 } 75 66 76 // we have four params, here two are implicit (source =1 auto translate, lang = target language) 67 77 function ajax_translate(token, translation) { … … 86 96 // We are pre-accounting the progress bar here - which is not very nice 87 97 //if (source > 0) { 88 done_posted += jQuery("*[token='" + tokens[i] + "']").size();98 done_posted += $("*[token='" + tokens[i] + "']").size(); 89 99 //} 90 100 } 91 jQuery.ajax({101 $.ajax({ 92 102 type: "POST", 93 103 url: t_jp.post_url, … … 95 105 success: function () { 96 106 // Success now only updates the save progress bar (green) 97 jQuery('#' + progressbar_posted_id).progressbar('value', done_posted / possibly_translateable * 100); 107 make_progress(progressbar_posted_id, done_posted / possibly_translateable * 100); 108 //$('#' + progressbar_posted_id).progressbar('value', done_posted / possibly_translateable * 100); 98 109 } 99 110 // we removed the error function, as there is no alert for automated thing, this will silently fail … … 110 121 function create_progress_bar() { 111 122 // progress bar is for alteast 5 items 112 jQuery("#" + t_jp_prefix + "credit").css({123 $("#" + t_jp_prefix + "credit").css({ 113 124 'overflow': 'auto' 114 125 }).append('<div style="float: left;width: 90%;height: 10px" id="' + progressbar_id + '"/><div style="margin-bottom:10px;float:left;width: 90%;height: 10px" id="' + progressbar_posted_id + '"/>'); 115 jQuery('#' + progressbar_id).progressbar({126 $('#' + progressbar_id).progressbar({ 116 127 value: 0 117 128 }); 118 jQuery('#' + progressbar_posted_id).progressbar({129 $('#' + progressbar_posted_id).progressbar({ 119 130 value: 0 120 131 }); 121 132 // color the "save" bar 122 jQuery('#' + progressbar_posted_id + " > div").css({133 $('#' + progressbar_posted_id + " > div").css({ 123 134 'background': '#28F828', 124 135 'border' : "#08A908 1px solid" … … 130 141 // auto_translated_previously... 131 142 var auto_translated_phrases = [], binglang = t_jp.lang; 132 jQuery("." + t_jp_prefix + '[source=""]').each(function (i) {143 $("." + t_jp_prefix + '[source=""]').each(function (i) { 133 144 // not needed! 134 //var translated_id = jQuery(this).attr('id'),135 var token = jQuery(this).attr('token'),145 //var translated_id = $(this).attr('id'), 146 var token = $(this).attr('token'), 136 147 //alert(translated_id); 137 148 // we only have orig if we have some translation,? 138 to_trans = jQuery(this).attr('orig');149 to_trans = $(this).attr('orig'); 139 150 if (to_trans === undefined) { 140 to_trans = jQuery(this).html();151 to_trans = $(this).html(); 141 152 } 142 153 if (auto_translated_phrases[to_trans] !== 1) { … … 151 162 try { 152 163 Microsoft.Translator.translate(to_trans, "", binglang, function (translation) { 153 ajax_translate(token, jQuery("<div>" + translation + "</div>").text()); 154 jQuery('#' + progressbar_id).progressbar('value', (possibly_translateable - jQuery("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 164 ajax_translate(token, $("<div>" + translation + "</div>").text()); 165 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 166 //$('#' + progressbar_id).progressbar('value', (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 155 167 }); 156 168 } … … 167 179 //var segment_id = translated_id.substr(translated_id.lastIndexOf('_') + 1); 168 180 // No longer need because now included in the ajax translate 169 //fix_page( jQuery("<div>" + result.translation + "</div>").text(), 1, segment_id);181 //fix_page($("<div>" + result.translation + "</div>").text(), 1, segment_id); 170 182 // ???? 171 //to_trans = jQuery(this).attr('orig');172 ajax_translate(token, jQuery("<div>" + result.translation + "</div>").text());183 //to_trans = $(this).attr('orig'); 184 ajax_translate(token, $("<div>" + result.translation + "</div>").text()); 173 185 // update the regular progress bar 174 // done = possibly_translateable - jQuery("." + t_jp_prefix + '[source=""]').size(); 175 jQuery('#' + progressbar_id).progressbar('value', (possibly_translateable - jQuery("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 186 // done = possibly_translateable - $("." + t_jp_prefix + '[source=""]').size(); 187 make_progress(progressbar_id, (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 188 //$('#' + progressbar_id).progressbar('value', (possibly_translateable - $("." + t_jp_prefix + '[source=""]').size()) / possibly_translateable * 100); 176 189 } 177 190 }); … … 181 194 } 182 195 183 // We first try to avoid conflict with other frameworks184 jQuery.noConflict();185 186 196 loadLang = function () { 187 197 google.load("language", "1", { … … 190 200 }; 191 201 192 jQuery(document).ready(202 $(document).ready( 193 203 function () { 194 204 // this is the set_default_language function 195 205 // attach a function to the set_default_language link if its there 196 jQuery('#' + t_jp_prefix + 'setdeflang').click(function () {197 jQuery.get(t_jp.post_url + "?tr_cookie=" + Math.random());198 jQuery(this).hide("slow");206 $('#' + t_jp_prefix + 'setdeflang').click(function () { 207 $.get(t_jp.post_url + "?tr_cookie=" + Math.random()); 208 $(this).hide("slow"); 199 209 return false; 200 210 }); … … 204 214 //var translationstats, possibly_translateable, now; 205 215 // now lets check if auto translate is needed 206 //translationstats = jQuery("meta[name=translation-stats]").attr("content");216 //translationstats = $("meta[name=translation-stats]").attr("content"); 207 217 // Logic borrowed from jquery and http://json.org/json2.js - Didn't see the reason for that, if someone can modify the html, he can probably do any script he wants too... 208 218 /*if (/^[\],:{}\s]*$/.test(translationstats.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, "@") … … 222 232 }*/ 223 233 224 // var translationstats = window["eval"]("(" + jQuery("meta[name=translation-stats]").attr("content") + ")"), possibly_translateable, now;234 // var translationstats = window["eval"]("(" + $("meta[name=translation-stats]").attr("content") + ")"), possibly_translateable, now; 225 235 //if (translationstats !== undefined) { 226 236 //possibly_translateable = (translationstats.total_phrases - translationstats.translated_phrases - (translationstats.meta_phrases - translationstats.meta_translated_phrases)); 227 possibly_translateable = jQuery("." + t_jp_prefix + '[source=""]').size();237 possibly_translateable = $("." + t_jp_prefix + '[source=""]').size(); 228 238 229 239 now = new Date(); 230 240 // we make sure script sub loaded are cached 231 jQuery.ajaxSetup({241 $.ajaxSetup({ 232 242 cache: true 233 243 }); … … 239 249 if (t_jp.progress) { 240 250 var loaduiandtranslate = function () { 241 jQuery.xLazyLoader({251 $.xLazyLoader({ 242 252 js: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js', 243 253 css: 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css', … … 248 258 }); 249 259 }; 250 if (typeof jQuery.xLazyLoader === 'function') {260 if (typeof $.xLazyLoader === 'function') { 251 261 loaduiandtranslate(); 252 262 } else { 253 jQuery.getScript(t_jp.plugin_url + '/js/lazy.js', loaduiandtranslate);263 $.getScript(t_jp.plugin_url + '/js/lazy.js', loaduiandtranslate); 254 264 } 255 265 } else { … … 262 272 source = 2; 263 273 getMSN = function () { 264 jQuery.getScript('http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=' + t_jp.msnkey, langLoaded);274 $.getScript('http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=' + t_jp.msnkey, langLoaded); 265 275 }; 266 276 // don't know why, but that's how it works 267 277 if (t_jp.edit && t_jp.progress) { 268 jQuery.getScript(t_jp.plugin_url + '/js/lazy.js', getMSN);278 $.getScript(t_jp.plugin_url + '/js/lazy.js', getMSN); 269 279 } else { 270 280 getMSN(); 271 281 } 272 282 } else { 273 jQuery.getScript('http://www.google.com/jsapi', loadLang);283 $.getScript('http://www.google.com/jsapi', loadLang); 274 284 } 275 285 } … … 278 288 // this is the part when we have editor support 279 289 if (t_jp.edit) { 280 jQuery.getScript(t_jp.plugin_url + '/js/transposhedit.js');281 } 282 }); 283 }( )); // end of closure290 $.getScript(t_jp.plugin_url + '/js/transposhedit.js'); 291 } 292 }); 293 }(jQuery)); // end of closure
Note: See TracChangeset
for help on using the changeset viewer.
