PageRenderTime 47ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/wp-content/plugins/sitepress-multilingual-cms/res/js/scripts.js

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