jQuery(document).ready(function ($) { var template = $('.acf_flm_add_layout_section').attr('data-target'); //Show the select button if is not a new page/post/term or user if( (typeof template !== 'undefined') && (template != 'new') && (template != '') ){ $('.acf-flm-btn-select-layout').show(); } $('.acf-flm-btn-select-layout').click(function(){ //Get the current flexible name and the last flexible name open in the modal var currentFlexible = $(this).parent().attr('data-template-name'); var key = $(this).parent().attr('data-template-key'); var oldFlexible = $('#acf-flm-form-answer-custom-select-layout input[name="flexible_content"]').val(); //Open the modal tb_show("Import Layout(s)", "#TB_inline?width=600&height=600&inlineId=acf-flm-thickbox-select-layout"); //Remove loader and show the first table selection returnFirstStep(); //If the modal has no content or if the last flexible is not the same has the current => Reload post if( ($('#acf-flm-select-post-table').html().length < 1) || (typeof oldFlexible === 'undefined') || (currentFlexible != oldFlexible) ) { //Update hidden field with the current flexible $('#acf-flm-form-answer-custom-select-layout input[name="flexible_content"]').val(currentFlexible); //Add loader $('.boxcontent .content .load').addClass('is-active'); data = { action: 'acf_flm_get_all_posts_how_contains_current_flexible', flexible: currentFlexible, key: key }; $.post(ajaxurl, data, function(response){ if(response.success){ //Build the table structure var rows = 'Pages / Posts / Custom Posts'; $.each(response.data, function(index, value){ //Add row in the table with every post/page/user/term how have the same flexible rows += '' + '' + '' + '' + ''; }); //Update the table with the new data $('#acf-flm-select-post-table').html(rows); //Add the trigger on every item of the table triggerCLickPageID(); //Remove loader $('.boxcontent .content .load').removeClass('is-active'); } }); } }); //Remove loader and show the first table selection function returnFirstStep(){ $('.boxcontent .content #acf-flm-select-post-table').show(); $('#acf-flm-btn-nav-select-layout').hide(); $('.boxcontent .content .load').removeClass('is-active'); $('.boxcontent .content .acf-flm-select-layout-result').removeClass('is-active'); $('.boxcontent .content .acf-flm-select-layout-result #inputs-select').html(''); } $('#return-select-post').click(function(){ returnFirstStep(); }); //Click on one item of the table function triggerCLickPageID() { $('.page-id-click').click(function () { var pageLink = $(this); var divContent = pageLink.parents('.content'); var flexible = $(this).parents('.boxcontent').find('#acf-flm-form-answer-custom-select-layout input[name="flexible_content"]').val(); //Add loader divContent.find('.load').addClass('is-active'); data = { action: 'acf_flm_get_all_layout_templates', postid: pageLink.attr('data-post-id'), flexible: flexible }; $.post(ajaxurl, data, function (response) { if (response.success) { //Remove loader divContent.find('.load').removeClass('is-active'); //Hide table divContent.find('table').hide(); //Add post id cible in input hidden divContent.find('.acf-flm-select-layout-result input[type="hidden"][name="post_id_cible"]').val(pageLink.attr('data-post-id')); //Add title with the post name an the first checkbox to select all layouts var inputs = '

' + tradObject.selectTemplate + '