(function($){ $( document ).ready( function() { var url = window.location.href, tab_link = url.split( 'edit.php' )[1]; if ( typeof tab_link !== 'undefined' ) { var $menu_items = $( '#toplevel_page_et_divi_library' ).find( '.wp-submenu li' ); $menu_items.removeClass( 'current' ); $menu_items.find( 'a' ).each( function() { var $this_el = $( this ), this_href = $this_el.attr( 'href' ), full_tab_link = 'edit.php' + tab_link; if ( -1 !== full_tab_link.indexOf( this_href ) ) { $this_el.closest( 'li' ).addClass( 'current' ); } }); $( '#toplevel_page_et_divi_library' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu' ); $( 'a.toplevel_page_et_divi_library' ).removeClass( 'wp-not-current-submenu' ).addClass( 'wp-has-current-submenu wp-menu-open' ); } $( 'body' ).on( 'click', '.add-new-h2, a.page-title-action', function() { var all_cats = $.parseJSON( et_pb_new_template_options.layout_cats ), $modal = '', cats_selector = ''; if( ! $.isEmptyObject( all_cats ) ) { cats_selector += '
'; $.each( all_cats, function( i, single_cat ) { if ( ! $.isEmptyObject( single_cat ) ) { cats_selector += ''; } }); cats_selector += '
'; } cats_selector += ''; $modal = "
\
\

" + et_pb_new_template_options.modal_text + "

\
\ \ \ \ \
\ \ \ \ \
\ \ " + cats_selector + " \ \
\ \
\
\ \ \
"; $( 'body' ).append( $modal ); return false; } ); $( 'body' ).on( 'click', '.et_pb_prompt_dont_proceed', function() { $( this ).closest( '.et_pb_modal_overlay' ).remove(); } ); $( 'body' ).on( 'change', '#new_template_type', function() { var selected_type = $( this ).val(); if ( 'module' === selected_type || 'fullwidth_module' === selected_type ) { $( '.et_module_tabs_options' ).css( 'display', 'block' ); } else { $( '.et_module_tabs_options' ).css( 'display', 'none' ); } } ); $( 'body' ).on( 'click', '.et_pb_create_template:not(.clicked_button)', function() { var $this_button = $( this ), $this_form = $this_button.closest( '.et_pb_prompt_modal' ), template_name = $this_form.find( '#et_pb_new_template_name' ).val(); if ( '' === template_name ) { $this_form.find( '#et_pb_new_template_name' ).focus(); } else { var template_shortcode = '', layout_scope = $this_form.find( $( '#et_pb_template_global' ) ).is( ':checked' ) ? 'global' : 'not_global', layout_type = $this_form.find( '#new_template_type' ).val(), module_width = 'regular', template_built_for_post_type = '', selected_tabs = '', selected_cats = '', new_cat = $this_form.find( '#et_pb_new_cat_name' ).val(); if ( 'module' === layout_type || 'fullwidth_module' === layout_type ) { if ( ! $( '.et_module_tabs_options input' ).is( ':checked' ) ) { $( '.et_pb_error_message_save_template' ).css( "display", "block" ); return; } else { selected_tabs = ''; $( '.et_module_tabs_options input' ).each( function() { var this_input = $( this ); if ( this_input.is( ':checked' ) ) { selected_tabs += '' !== selected_tabs ? ',' + this_input.val() : this_input.val(); } }); selected_tabs = 'general,advanced,css' === selected_tabs ? 'all' : selected_tabs; } } if ( $( '.layout_cats_container input' ).is( ':checked' ) ) { $( '.layout_cats_container input' ).each( function() { var this_input = $( this ); if ( this_input.is( ':checked' ) ) { selected_cats += '' !== selected_cats ? ',' + this_input.val() : this_input.val(); } }); } switch ( layout_type ) { case 'row' : template_shortcode = '[et_pb_row template_type="row"][/et_pb_row]'; break; case 'section' : template_shortcode = '[et_pb_section template_type="section"][et_pb_row][/et_pb_row][/et_pb_section]'; break; case 'module' : template_shortcode = '[et_pb_module_placeholder selected_tabs="' + selected_tabs + '"]'; break; case 'fullwidth_module' : template_shortcode = '[et_pb_fullwidth_module_placeholder selected_tabs="' + selected_tabs + '"]'; module_width = 'fullwidth'; layout_type = 'module'; break; case 'fullwidth_section' : template_shortcode = '[et_pb_section template_type="section" fullwidth="on"][/et_pb_section]'; layout_type = 'section'; break; case 'specialty_section' : template_shortcode = '[et_pb_section template_type="section" specialty="on" skip_module="true" specialty_placeholder="true"][/et_pb_section]'; layout_type = 'section'; break; } $this_button.addClass( 'clicked_button' ); $this_button.closest( '.et_pb_prompt_buttons' ).find( '.spinner' ).addClass( 'et_pb_visible_spinner' ); $.ajax( { type: "POST", url: et_pb_new_template_options.ajaxurl, dataType: 'json', data: { action : 'et_pb_save_layout', et_load_nonce : et_pb_new_template_options.et_load_nonce, et_layout_name : template_name, et_layout_built_for_post_type: template_built_for_post_type, et_layout_content : template_shortcode, et_layout_scope : layout_scope, et_layout_type : layout_type, et_module_width : module_width, et_layout_cats : selected_cats, et_layout_new_cat : new_cat }, success: function( data ) { window.location.href = decodeURIComponent( unescape( data.edit_link ) ); } } ); } } ); $( '#et_show_export_section' ).click( function() { var this_link = $( this ), margin_value = this_link.hasClass( 'et_pb_opened' ) ? '-100%' : '0'; $( '.et_pb_export_section' ).animate( { marginTop: margin_value }, 500 ); this_link.toggleClass( 'et_pb_opened' ); }); }); })(jQuery)