PageRenderTime 28ms CodeModel.GetById 20ms RepoModel.GetById 2ms app.codeStats 0ms

/res/js/scripts.js

https://bitbucket.org/nirbhasa/wp-plugin-sitepress-multilingual-cms
JavaScript | 780 lines | 680 code | 95 blank | 5 comment | 90 complexity | fa9389aeabf0b43ce9b6bc9186b958c1 MD5 | raw file
  1. jQuery(document).ready(function(){
  2. if(jQuery('#category-adder').html()){
  3. jQuery('#category-adder').prepend('<p>'+icl_cat_adder_msg+'</p>');
  4. }
  5. jQuery('select[name="icl_post_language"]').change(iclPostLanguageSwitch);
  6. jQuery('#noupdate_but input[type="button"]').click(iclSetDocumentToDate);
  7. jQuery('select[name="icl_translation_of"]').change(function(){jQuery('#icl_translate_options').fadeOut();});
  8. jQuery('#icl_dismiss_help').click(iclDismissHelp);
  9. jQuery('#icl_dismiss_upgrade_notice').click(iclDismissUpgradeNotice);
  10. jQuery('#icl_dismiss_page_estimate_hint').click(iclDismissPageEstimateHint);
  11. jQuery('#icl_show_page_estimate_hint').click(iclShowPageEstimateHint);
  12. jQuery('a.icl_toggle_show_translations').live('click', iclToggleShowTranslations);
  13. icl_tn_initial_value = jQuery('#icl_post_note textarea').val();
  14. jQuery('#icl_post_add_notes h4 a').live('click', iclTnOpenNoteBox);
  15. jQuery('#icl_post_note textarea').live('keyup', iclTnClearButtonState);
  16. jQuery('#icl_tn_clear').live('click', function(){jQuery('#icl_post_note textarea').val('');jQuery(this).attr('disabled','disabled')});
  17. jQuery('#icl_tn_save').live('click', iclTnCloseNoteBox);
  18. jQuery('#icl_pt_hide').click(iclHidePTControls);
  19. jQuery('#icl_pt_show').click(iclShowPTControls);
  20. jQuery('#icl_pt_controls ul li :checkbox').live('change', function(){
  21. if(jQuery('#icl_pt_controls ul li :checkbox:checked').length){
  22. jQuery('#icl_pt_send').removeAttr('disabled');
  23. }else{
  24. jQuery('#icl_pt_send').attr('disabled', 'disabled');
  25. }
  26. iclPtCostEstimate();
  27. });
  28. jQuery('#icl_pt_send').live('click', iclPTSend);
  29. /* needed for tagcloud */
  30. oldajaxurl = false;
  31. jQuery("#icl_make_translatable_submit").live('click', icl_make_translatable);
  32. icl_admin_language_switcher();
  33. jQuery('#addtag').ajaxSuccess(function(evt, request, settings) {
  34. if(settings.data == undefined) return;
  35. if(settings.data.search('action=add-tag') != -1 && settings.data.search('source_lang%3D') != -1) {
  36. var taxonomy = '';
  37. var vars = settings.data.split("&");
  38. for (var i=0; i<vars.length; i++) {
  39. var pair = vars[i].split("=");
  40. if (pair[0] == 'taxonomy') {
  41. taxonomy = pair[1];
  42. break;
  43. }
  44. }
  45. jQuery('#icl_tax_'+taxonomy+'_lang .inside').html(icl_ajxloaderimg);
  46. jQuery.ajax({
  47. type:'GET',
  48. url : location.href.replace(/&trid=([0-9]+)/, ''),
  49. success: function(msg){
  50. jQuery('#icl_tax_adding_notice').fadeOut();
  51. jQuery('#icl_tax_'+taxonomy+'_lang .inside').html(jQuery(msg).find('#icl_tax_'+taxonomy+'_lang .inside').html());
  52. }
  53. })
  54. }
  55. });
  56. jQuery('a.icl_user_notice_hide').click(icl_hide_user_notice);
  57. jQuery('#icl_translate_independent').click(function(){
  58. jQuery(this).attr('disabled', 'disabled').after(icl_ajxloaderimg);
  59. jQuery.ajax({type: "POST",url: icl_ajx_url,data: "icl_ajx_action=reset_duplication&post_id="+jQuery('#post_ID').val(),success: function(msg){location.reload()}});
  60. });
  61. jQuery('#icl_set_duplicate').click(function(){
  62. if(confirm(jQuery(this).next().html())){
  63. jQuery(this).attr('disabled', 'disabled').after(icl_ajxloaderimg);
  64. jQuery.ajax({type: "POST",url: icl_ajx_url,data: "icl_ajx_action=set_duplication&post_id="+jQuery('#post_ID').val(),success: function(msg){location.reload()}});
  65. }
  66. });
  67. jQuery('#post input[name="icl_dupes[]"]').change(function(){
  68. if(jQuery('#post input[name="icl_dupes[]"]:checked').length > 0){
  69. jQuery('#icl_make_duplicates').show().removeAttr('disabled');
  70. }else{
  71. jQuery('#icl_make_duplicates').hide().attr('disabled', 'disabled');
  72. }
  73. })
  74. jQuery('#icl_make_duplicates').click(function(){
  75. var langs = new Array();
  76. jQuery('#post input[name="icl_dupes[]"]:checked').each(function(){langs.push(jQuery(this).val())});
  77. langs = langs.join(',');
  78. jQuery(this).attr('disabled', 'disabled').after(icl_ajxloaderimg);
  79. jQuery.ajax({type: "POST",url: icl_ajx_url,data: "icl_ajx_action=make_duplicates&post_id=" + jQuery('#post_ID').val() + '&langs=' + langs ,success: function(msg){location.reload()}});
  80. })
  81. icl_popups.attach_listeners();
  82. });
  83. var icl_tn_initial_value = '';
  84. window.onbeforeunload = function() {
  85. if(icl_tn_initial_value != jQuery('#icl_post_note textarea').val()){
  86. return jQuery('#icl_tn_cancel_confirm').val();
  87. }
  88. }
  89. function fadeInAjxResp(spot, msg, err){
  90. if(err != undefined){
  91. col = jQuery(spot).css('color');
  92. jQuery(spot).css('color','red');
  93. }
  94. jQuery(spot).html('<span>'+msg+'<span>');
  95. jQuery(spot).fadeIn();
  96. window.setTimeout(fadeOutAjxResp, 3000, spot);
  97. if(err != undefined){
  98. jQuery(spot).css('color',col);
  99. }
  100. }
  101. function fadeOutAjxResp(spot){
  102. jQuery(spot).fadeOut();
  103. }
  104. var icl_ajxloaderimg = '<img src="'+icl_ajxloaderimg_src+'" alt="loading" width="16" height="16" />';
  105. var iclHaltSave = false; // use this for multiple 'submit events'
  106. var iclSaveForm_success_cb = new Array();
  107. function iclSaveForm(){
  108. if(iclHaltSave){
  109. return false;
  110. }
  111. var formname = jQuery(this).attr('name');
  112. jQuery('form[name="'+formname+'"] .icl_form_errors').html('').hide();
  113. ajx_resp = jQuery('form[name="'+formname+'"] .icl_ajx_response').attr('id');
  114. fadeInAjxResp('#'+ajx_resp, icl_ajxloaderimg);
  115. jQuery.ajax({
  116. type: "POST",
  117. url: icl_ajx_url,
  118. data: "icl_ajx_action="+jQuery(this).attr('name')+"&"+jQuery(this).serialize(),
  119. success: function(msg){
  120. spl = msg.split('|');
  121. if(parseInt(spl[0]) == 1){
  122. fadeInAjxResp('#'+ajx_resp, icl_ajx_saved);
  123. for(i=0;i<iclSaveForm_success_cb.length;i++){
  124. iclSaveForm_success_cb[i](jQuery('form[name="'+formname+'"]'), spl);
  125. }
  126. }else{
  127. jQuery('form[name="'+formname+'"] .icl_form_errors').html(spl[1]);
  128. jQuery('form[name="'+formname+'"] .icl_form_errors').fadeIn()
  129. fadeInAjxResp('#'+ajx_resp, icl_ajx_error,true);
  130. }
  131. }
  132. });
  133. return false;
  134. }
  135. function iclPostLanguageSwitch(){
  136. var lang = jQuery(this).attr('value');
  137. var ajx = location.href.replace(/#(.*)$/,'');
  138. if(-1 == location.href.indexOf('?')){
  139. url_glue='?';
  140. }else{
  141. url_glue='&';
  142. }
  143. document.cookie= "_icl_current_language=" + lang;
  144. if(icl_this_lang != lang){
  145. jQuery('#icl_translate_options').fadeOut();
  146. }else{
  147. jQuery('#icl_translate_options').fadeIn();
  148. }
  149. if(jQuery('#parent_id').length > 0){
  150. jQuery('#parent_id').load(ajx+url_glue+'lang='+lang + ' #parent_id option',{lang_switch:jQuery('#post_ID').attr('value')}, function(resp){
  151. tow1 = resp.indexOf('<div id="translation_of_wrap">');
  152. tow2 = resp.indexOf('</div><!--//translation_of_wrap-->');
  153. jQuery('#translation_of_wrap').html(resp.substr(tow1+31, tow2-tow1-31));
  154. if(-1 == jQuery('#parent_id').html().indexOf('selected="selected"')){
  155. jQuery('#parent_id').attr('value','');
  156. }
  157. });
  158. }else if(jQuery('#categorydiv').length > 0){
  159. jQuery('.categorydiv').hide();
  160. var ltlhlpr = document.createElement('div');
  161. ltlhlpr.setAttribute('style','display:none');
  162. ltlhlpr.setAttribute('id','icl_ltlhlpr');
  163. jQuery(this).after(ltlhlpr);
  164. jQuery('#categorydiv').slideUp();
  165. jQuery('#icl_ltlhlpr').load(ajx+url_glue+'icl_ajx=1&lang='+lang + ' #categorydiv',{}, function(resp){
  166. tow1 = resp.indexOf('<div id="translation_of_wrap">');
  167. tow2 = resp.indexOf('</div><!--//translation_of_wrap-->');
  168. jQuery('#translation_of_wrap').html(resp.substr(tow1+31, tow2-tow1-31));
  169. jQuery('#icl_ltlhlpr').html(jQuery('#icl_ltlhlpr').html().replace('categorydiv',''));
  170. jQuery('#categorydiv').html(jQuery('#icl_ltlhlpr div').html());
  171. jQuery('#categorydiv').slideDown();
  172. jQuery('#icl_ltlhlpr').remove();
  173. jQuery('#category-adder').prepend('<p>'+icl_cat_adder_msg+'</p>');
  174. var tx = '';
  175. jQuery('.categorydiv').each(function(){
  176. var id = jQuery(this).attr('id');
  177. var tx = id.replace(/^taxonomy-/,'');
  178. if(id != 'taxonomy-category'){
  179. jQuery('#'+tx+'div').html(jQuery(resp).find('#'+tx+'div').html());
  180. }
  181. /* WP scrap */
  182. jQuery(".categorydiv").each(function () {
  183. var this_id = jQuery(this).attr("id"),
  184. noSyncChecks = false,
  185. syncChecks, catAddAfter, taxonomyParts, taxonomy, settingName;
  186. taxonomyParts = this_id.split("-");
  187. taxonomyParts.shift();
  188. taxonomy = taxonomyParts.join("-");
  189. settingName = taxonomy + "_tab";
  190. if (taxonomy == "category") {
  191. settingName = "cats"
  192. }
  193. jQuery("a", "#" + taxonomy + "-tabs").click(function () {
  194. var t = jQuery(this).attr("href");
  195. jQuery(this).parent().addClass("tabs").siblings("li").removeClass("tabs");
  196. jQuery("#" + taxonomy + "-tabs").siblings(".tabs-panel").hide();
  197. jQuery(t).show();
  198. if ("#" + taxonomy + "-all" == t) {
  199. deleteUserSetting(settingName)
  200. } else {
  201. setUserSetting(settingName, "pop")
  202. }
  203. return false
  204. });
  205. if (getUserSetting(settingName)) {
  206. jQuery('a[href="#' + taxonomy + '-pop"]', "#" + taxonomy + "-tabs").click()
  207. }
  208. jQuery("#new" + taxonomy).one("focus", function () {
  209. jQuery(this).val("").removeClass("form-input-tip")
  210. });
  211. jQuery("#" + taxonomy + "-add-submit").click(function () {
  212. jQuery("#new" + taxonomy).focus()
  213. });
  214. syncChecks = function () {
  215. if (noSyncChecks) {
  216. return
  217. }
  218. noSyncChecks = true;
  219. var th = jQuery(this),
  220. c = th.is(":checked"),
  221. id = th.val().toString();
  222. jQuery("#in-" + taxonomy + "-" + id + ", #in-" + taxonomy + "-category-" + id).attr("checked", c);
  223. noSyncChecks = false
  224. };
  225. catAddBefore = function (s) {
  226. if (!jQuery("#new" + taxonomy).val()) {
  227. return false
  228. }
  229. s.data += "&" + jQuery(":checked", "#" + taxonomy + "checklist").serialize();
  230. return s
  231. };
  232. catAddAfter = function (r, s) {
  233. var sup, drop = jQuery("#new" + taxonomy + "_parent");
  234. if ("undefined" != s.parsed.responses[0] && (sup = s.parsed.responses[0].supplemental.newcat_parent)) {
  235. drop.before(sup);
  236. drop.remove()
  237. }
  238. };
  239. jQuery("#" + taxonomy + "checklist").wpList({
  240. alt: "",
  241. response: taxonomy + "-ajax-response",
  242. addBefore: catAddBefore,
  243. addAfter: catAddAfter
  244. });
  245. jQuery("#" + taxonomy + "-add-toggle").click(function () {
  246. jQuery("#" + taxonomy + "-adder").toggleClass("wp-hidden-children");
  247. jQuery('a[href="#' + taxonomy + '-all"]', "#" + taxonomy + "-tabs").click();
  248. return false
  249. });
  250. jQuery("#" + taxonomy + "checklist li.popular-category :checkbox, #" + taxonomy + "checklist-pop :checkbox").live("click", function () {
  251. var t = jQuery(this),
  252. c = t.is(":checked"),
  253. id = t.val();
  254. if (id && t.parents("#taxonomy-" + taxonomy).length) {
  255. jQuery("#in-" + taxonomy + "-" + id + ", #in-popular-" + taxonomy + "-" + id).attr("checked", c)
  256. }
  257. })
  258. });
  259. /* WP scrap - end */
  260. });
  261. jQuery('.categorydiv').show();
  262. /* tagcloud */
  263. if (oldajaxurl == false) {
  264. oldajaxurl = ajaxurl;
  265. }
  266. if(-1 == ajaxurl.indexOf('?')){
  267. temp_url_glue='?';
  268. } else {
  269. temp_url_glue='&';
  270. }
  271. if (lang == icl_this_lang) {
  272. ajaxurl = oldajaxurl;
  273. } else if (-1 == ajaxurl.indexOf('lang')) {
  274. ajaxurl = ajaxurl+temp_url_glue+'lang='+lang;
  275. } else {
  276. ajaxurl = oldajaxurl+temp_url_glue+'lang='+lang;
  277. }
  278. jQuery('div[id^=tagsdiv-]').each(function(){
  279. jQuery(this).slideUp();
  280. jQuery(this).find('.the-tagcloud').remove();
  281. jQuery(this).find('.tagchecklist span').remove();
  282. jQuery(this).find('.the-tags').val('');
  283. tag_tax = jQuery(this).attr('id').substring(8);
  284. tagBox.get('link-'+tag_tax);
  285. jQuery(this).find('a.tagcloud-link').unbind().click(function(){
  286. jQuery(this).siblings('.the-tagcloud').toggle();
  287. return false;
  288. });
  289. jQuery(this).slideDown();
  290. });
  291. ajaxurl = oldajaxurl;
  292. });
  293. }
  294. }
  295. function iclSetDocumentToDate(){
  296. var thisbut = jQuery(this);
  297. if(!confirm(jQuery('#noupdate_but_wm').html())) return;
  298. thisbut.attr('disabled','disabled');
  299. thisbut.css({'background-image':"url('"+icl_ajxloaderimg_src+"')", 'background-position':'center right', 'background-repeat':'no-repeat'});
  300. jQuery.ajax({
  301. type: "POST",
  302. url: icl_ajx_url,
  303. data: "icl_ajx_action=set_post_to_date&post_id="+jQuery('#post_ID').val(),
  304. success: function(msg){
  305. spl = msg.split('|');
  306. thisbut.removeAttr('disabled');
  307. thisbut.css({'background-image':'none'});
  308. thisbut.parent().remove();
  309. var st = jQuery('#icl_translations_status td.icl_translation_status_msg');
  310. st.each(function(){
  311. jQuery(this).html(jQuery(this).html().replace(spl[0],spl[1]))
  312. })
  313. jQuery('#icl_minor_change_box').fadeIn();
  314. }
  315. });
  316. }
  317. function iclDismissHelp(){
  318. var thisa = jQuery(this);
  319. jQuery.ajax({
  320. type: "POST",
  321. url: icl_ajx_url,
  322. data: "icl_ajx_action=dismiss_help",
  323. success: function(msg){
  324. thisa.closest('#message').fadeOut();
  325. }
  326. });
  327. return false;
  328. }
  329. function iclDismissUpgradeNotice(){
  330. var thisa = jQuery(this);
  331. jQuery.ajax({
  332. type: "POST",
  333. url: icl_ajx_url,
  334. data: "icl_ajx_action=dismiss_upgrade_notice",
  335. success: function(msg){
  336. thisa.parent().parent().fadeOut();
  337. }
  338. });
  339. return false;
  340. }
  341. var iclShowPageEstimateHint_img = false;
  342. function iclDismissPageEstimateHint(){
  343. var thisa = jQuery(this);
  344. if(!iclShowPageEstimateHint_img){
  345. iclShowPageEstimateHint_img = jQuery('#icl_dismiss_page_estimate_hint').parent().find('img').attr('src');
  346. }
  347. jQuery('#icl_show_page_estimate_hint').find('img').attr('src', iclShowPageEstimateHint_img);
  348. jQuery.ajax({
  349. type: "POST",
  350. url: icl_ajx_url,
  351. data: "icl_ajx_action=dismiss_page_estimate_hint",
  352. success: function(msg){
  353. thisa.parent().fadeOut(function(){jQuery('#icl_show_page_estimate_hint').fadeIn()});
  354. }
  355. });
  356. return false;
  357. }
  358. function iclShowPageEstimateHint(){
  359. var thisa = jQuery(this);
  360. iclShowPageEstimateHint_img = thisa.find('img').attr('src');
  361. thisa.find('img').attr('src', icl_ajxloaderimg_src);
  362. jQuery.ajax({
  363. type: "POST",
  364. url: icl_ajx_url,
  365. data: "icl_ajx_action=dismiss_page_estimate_hint",
  366. success: function(msg){
  367. thisa.fadeOut(function(){jQuery('#icl_dismiss_page_estimate_hint').parent().fadeIn();});
  368. }
  369. });
  370. return false;
  371. }
  372. function iclToggleShowTranslations(){
  373. jQuery('a.icl_toggle_show_translations').toggle();
  374. jQuery('#icl_translations_table').toggle();
  375. jQuery.ajax({
  376. type: "POST",
  377. url: icl_ajx_url,
  378. data: "icl_ajx_action=toggle_show_translations"
  379. });
  380. return false;
  381. }
  382. function iclTnOpenNoteBox(){
  383. jQuery('#icl_post_add_notes #icl_post_note').slideDown();
  384. jQuery('#icl_post_note textarea').focus();
  385. return false;
  386. }
  387. function iclTnClearButtonState(){
  388. if(jQuery.trim(jQuery(this).val())){
  389. jQuery('#icl_tn_clear').removeAttr('disabled');
  390. }else{
  391. jQuery('#icl_tn_clear').attr('disabled', 'disabled');
  392. }
  393. }
  394. function iclTnCloseNoteBox(){
  395. jQuery('#icl_post_add_notes #icl_post_note').slideUp('fast', function(){
  396. if(icl_tn_initial_value != jQuery('#icl_post_note textarea').val()){
  397. jQuery('#icl_tn_not_saved').fadeIn();
  398. }else{
  399. jQuery('#icl_tn_not_saved').fadeOut();
  400. }
  401. });
  402. }
  403. function iclShowPTControls(){
  404. var thisa = jQuery(this);
  405. jQuery.ajax({
  406. type: "POST",
  407. url: icl_ajx_url,
  408. data: "icl_ajx_action=toggle_pt_controls&value=0",
  409. success: function(msg){
  410. jQuery('#icl_pt_controls').slideDown();
  411. thisa.fadeOut(function(){jQuery('#icl_pt_hide').fadeIn();});
  412. }
  413. });
  414. return false;
  415. }
  416. function iclHidePTControls(){
  417. var thisa = jQuery(this);
  418. jQuery.ajax({
  419. type: "POST",
  420. url: icl_ajx_url,
  421. data: "icl_ajx_action=toggle_pt_controls&value=1",
  422. success: function(msg){
  423. thisa.fadeOut(function(){
  424. jQuery('#icl_pt_controls').slideUp(function(){
  425. jQuery('#icl_pt_show').fadeIn()
  426. });
  427. });
  428. }
  429. });
  430. return false;
  431. }
  432. function iclPtCostEstimate(){
  433. var estimate = 0;
  434. var words = parseInt(jQuery('#icl_pt_wc').val());
  435. jQuery('#icl_pt_controls ul li :checkbox:checked').each(
  436. function(){
  437. lang = jQuery(this).attr('id').replace(/^icl_pt_to_/,'');
  438. rate = jQuery('#icl_pt_rate_'+lang).val();
  439. estimate += words * rate;
  440. }
  441. )
  442. if(estimate < 1){
  443. precision = Math.floor(estimate).toString().length + 1;
  444. }else{
  445. precision = Math.floor(estimate).toString().length + 2;
  446. }
  447. jQuery('#icl_pt_cost_estimate').html(estimate.toPrecision(precision));
  448. }
  449. function iclPTSend(){
  450. jQuery('#icl_pt_error, #icl_pt_success').hide();
  451. jQuery('#icl_pt_send').attr('disabled', 'disabled');
  452. if(jQuery('#icl_pt_controls ul li :checkbox:checked').length==0) return false;
  453. target_languages = new Array();
  454. jQuery('#icl_pt_controls ul li :checkbox:checked').each(function(){
  455. target_languages.push(jQuery(this).val());
  456. });
  457. jQuery.ajax({
  458. type: "POST",
  459. url: icl_ajx_url,
  460. dataType: 'json',
  461. data: "icl_ajx_action=send_translation_request&post_ids=" + jQuery('#icl_pt_post_id').val()
  462. + '&icl_post_type['+ jQuery('#icl_pt_post_id').val() + ']=' + jQuery('#icl_pt_post_type').val()
  463. + '&target_languages='+target_languages.join('#')
  464. + '&service=icanlocalize'
  465. + '&tn_note_'+jQuery('#icl_pt_post_id').val()+'=' + jQuery('#icl_pt_tn_note').val(),
  466. success: function(msg){
  467. for(i in msg){
  468. p = msg[i];
  469. }
  470. if(p.status > 0){
  471. location.href = location.href.replace(/#(.+)/,'')+'&icl_message=success';
  472. }else{
  473. jQuery('#icl_pt_error').fadeIn();
  474. }
  475. }
  476. });
  477. }
  478. function icl_pt_reload_translation_box(){
  479. jQuery.ajax({
  480. type: "POST",
  481. url: icl_ajx_url,
  482. dataType: 'json',
  483. data: "icl_ajx_action=get_translator_status",
  484. success: function(){
  485. jQuery('#icl_pt_hide').hide();
  486. jQuery('#icl_pt_controls').html(icl_ajxloaderimg+'<br class="clear" />');
  487. jQuery.get(location.href, {rands:Math.random()}, function(data){
  488. jQuery('#icl_pt_controls').html(jQuery(data).find('#icl_pt_controls').html());
  489. icl_tb_init('a.icl_thickbox');
  490. icl_tb_set_size('a.icl_thickbox');
  491. jQuery('#icl_pt_hide').show();
  492. })
  493. }
  494. });
  495. }
  496. function icl_pt_reload_translation_options(){
  497. jQuery.ajax({
  498. type: "POST",
  499. url: icl_ajx_url,
  500. dataType: 'json',
  501. data: "icl_ajx_action=get_translator_status",
  502. success: function(){
  503. jQuery('#icl-tr-opt').html(icl_ajxloaderimg+'<br class="clear" />');
  504. jQuery.get(location.href, {rands:Math.random()}, function(data){
  505. jQuery('#icl-tr-opt').html(jQuery(data).find('#icl-tr-opt').html());
  506. icl_tb_init('a.icl_thickbox');
  507. icl_tb_set_size('a.icl_thickbox');
  508. })
  509. }
  510. });
  511. }
  512. function icl_copy_from_original(lang, trid){
  513. jQuery('#icl_cfo').after(icl_ajxloaderimg).attr('disabled', 'disabled');
  514. if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {
  515. var editor_type = 'rich';
  516. }else{
  517. var editor_type = 'html';
  518. }
  519. jQuery.ajax({
  520. type: "POST",
  521. dataType: 'json',
  522. url: icl_ajx_url,
  523. data: "icl_ajx_action=copy_from_original&lang="+lang+'&trid='+trid+'&editor_type='+editor_type,
  524. success: function(msg){
  525. if(msg.error){
  526. alert(msg.error);
  527. }else{
  528. try{ // we may not have the content edtiro
  529. if ( typeof tinyMCE != 'undefined' && ( ed = tinyMCE.activeEditor ) && !ed.isHidden() ) {
  530. ed.focus();
  531. if (tinymce.isIE)
  532. ed.selection.moveToBookmark(tinymce.EditorManager.activeEditor.windowManager.bookmark);
  533. ed.execCommand('mceInsertContent', false, msg.body);
  534. } else {
  535. if(typeof wpActiveEditor == 'undefined') wpActiveEditor = 'content';
  536. edInsertContent(edCanvas, msg.body);
  537. }
  538. }catch(err){;}
  539. }
  540. jQuery('#icl_cfo').next().fadeOut();
  541. }
  542. });
  543. return false;
  544. }
  545. function icl_make_translatable(){
  546. var that = jQuery(this);
  547. jQuery(this).attr('disabled', 'disabled');
  548. jQuery('#icl_div_config .icl_form_success').hide();
  549. var translate = jQuery('#icl_make_translatable').attr('checked') ? 1 : 0;
  550. var cusotm_post = jQuery('#icl_make_translatable').val();
  551. var custom_taxs_on = new Array();
  552. var custom_taxs_off = new Array();
  553. jQuery(".icl_mcs_custom_taxs").each(function(){
  554. if(jQuery(this).attr('checked')){
  555. custom_taxs_on.push(jQuery(this).val());
  556. }else{
  557. custom_taxs_off.push(jQuery(this).val());
  558. }
  559. });
  560. var cfnames = new Array();
  561. var cfvals = new Array();
  562. jQuery('.icl_mcs_cfs:checked').each(function(){
  563. if(!jQuery(this).attr('disabled')){
  564. cfnames.push(jQuery(this).attr('name').replace(/^icl_mcs_cf_/,''));
  565. cfvals.push(jQuery(this).val())
  566. }
  567. })
  568. jQuery.post(location.href,
  569. {
  570. 'post_id' : jQuery('#post_ID').val(),
  571. 'icl_action' : 'icl_mcs_inline',
  572. 'custom_post' : cusotm_post,
  573. 'translate' : translate,
  574. 'custom_taxs_on[]' : custom_taxs_on,
  575. 'custom_taxs_off[]' : custom_taxs_off,
  576. 'cfnames[]' : cfnames,
  577. 'cfvals[]' : cfvals
  578. },
  579. function(data){
  580. that.removeAttr('disabled');
  581. if(translate){
  582. if(jQuery('#icl_div').length > 0){
  583. icl_div_update = true;
  584. jQuery('#icl_div').remove();
  585. }else{
  586. icl_div_update = false;
  587. }
  588. var prependto = false;
  589. if(jQuery('#side-sortables').html()){
  590. prependto = jQuery('#side-sortables');
  591. }else{
  592. prependto = jQuery('#normal-sortables');
  593. }
  594. prependto.prepend(
  595. '<div id="icl_div" class="postbox">' + jQuery(data).find('#icl_div').html() + '</div>'
  596. )
  597. jQuery('#icl_mcs_details').html(jQuery(data).find('#icl_mcs_details').html());
  598. if(!icl_div_update){
  599. location.href='#icl_div';
  600. }
  601. }else{
  602. jQuery('#icl_div').hide();
  603. jQuery('#icl_mcs_details').html('');
  604. }
  605. jQuery('#icl_div_config .icl_form_success').fadeIn();
  606. }
  607. );
  608. return false;
  609. }
  610. function icl_admin_language_switcher(){
  611. jQuery('#icl-als-inside').width( jQuery('#icl-als-actions').width() - 4 );
  612. jQuery('#icl-als-toggle, #icl-als-inside').bind('mouseenter', function() {
  613. jQuery('#icl-als-inside').removeClass('slideUp').addClass('slideDown');
  614. setTimeout(function() {
  615. if ( jQuery('#icl-als-inside').hasClass('slideDown') ) {
  616. jQuery('#icl-als-inside').slideDown(100);
  617. jQuery('#icl-als-first').addClass('slide-down');
  618. }
  619. }, 200);
  620. }).bind('mouseleave', function() {
  621. jQuery('#icl-als-inside').removeClass('slideDown').addClass('slideUp');
  622. setTimeout(function() {
  623. if ( jQuery('#icl-als-inside').hasClass('slideUp') ) {
  624. jQuery('#icl-als-inside').slideUp(100, function() {
  625. jQuery('#icl-als-first').removeClass('slide-down');
  626. });
  627. }
  628. }, 300);
  629. });
  630. }
  631. function icl_hide_user_notice(){
  632. var notice = jQuery(this).attr('href').replace(/^#/, '');
  633. var thisa = jQuery(this);
  634. jQuery.ajax({
  635. type: "POST",
  636. dataType: 'json',
  637. url: icl_ajx_url,
  638. data: "icl_ajx_action=save_user_preferences&user_preferences[notices]["+notice+"]=1",
  639. success: function(msg){
  640. thisa.parent().parent().fadeOut();
  641. }
  642. });
  643. return false;
  644. }
  645. function icl_cf_translation_preferences_submit(cf, obj) {
  646. jQuery.ajax({
  647. type: 'POST',
  648. url: ajaxurl,
  649. data: 'action=wpml_ajax&icl_ajx_action=wpml_cf_translation_preferences&translate_action='+obj.parent().children('input:[name="wpml_cf_translation_preferences['+cf+']"]:checked').val()+'&'+obj.parent().children('input:[name="wpml_cf_translation_preferences_data_'+cf+'"]').val(),
  650. cache: false,
  651. error: function(html){
  652. jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html('Error occured');
  653. },
  654. beforeSend: function(html){
  655. jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html(icl_ajxloaderimg);
  656. },
  657. success: function(html){
  658. jQuery('#wpml_cf_translation_preferences_ajax_response_'+cf).html(html);
  659. },
  660. dataType: 'html'
  661. });
  662. }
  663. /* icl popups */
  664. var icl_popups = {
  665. attach_listeners: function(){
  666. jQuery('.icl_pop_info_but').click(function(){
  667. jQuery('.icl_pop_info').hide();
  668. var pop = jQuery(this).next();
  669. pop.show(function(){
  670. var animate = {};
  671. var fold = jQuery(window).width() + jQuery(window).scrollLeft();
  672. if(fold < pop.offset().left + pop.width()){
  673. animate.left = '-=' + pop.width();
  674. };
  675. if(parseInt(jQuery(window).height() + jQuery(window).scrollTop()) < parseInt(pop.offset().top) + pop.height()){
  676. animate.top = '-=' + pop.height();
  677. }
  678. if(animate) pop.animate(animate);
  679. });
  680. });
  681. jQuery('.icl_pop_info_but_close').click(function(){
  682. jQuery(this).parent().fadeOut();
  683. });
  684. }
  685. }