jQuery( document ).ready( function( $ ) { var api = wp.customize; var tippyOptions = { zIndex: 99999999, theme: 'light', arrow: true }; /** * Open the parent dialog and show the tabs. * * @since 1.1.6 */ $( document ).on( 'click', '.sc-dialog-button', function() { if ( $( this ).prop( 'disabled' ) ) { return; } $( this ).addClass( 'active' ); var id = $( this ).data( 'dialog' ); var title = $( this ).text() + ' Settings'; $( '#' + id ).dialog( { title: title, dialogClass: 'sc-dialog sc-dialog-parent ' + id + '-dialog', width: 420, height: 550, resizable: false, position: { my: 'left+50 top+48', at: 'left top', }, create: function() { var dialog = $( this ); // Buttons. var closeBtn = $( '' ); }); /** * Reset part of the dialogs settings. If the customizer is dirty, it saves * then reset the settings. * * @since 1.1.6 */ $( document.body ).on( 'sc-dialog:reset', function( event, reset, button ) { if ( typeof reset === 'undefined' ) { return; } var userConfirm = confirm( 'Are you sure to reset the settings to default?' ); if ( ! userConfirm ) { return false; } button.addClass( 'sc-resetting' ); // If Customizer has unsaved state, save first then reset. if ( ! api.state( 'saved' ).get() ) { api.previewer.save(); api.bind( 'saved', function() { ScAjaxReset( reset ); } ); return false; } ScAjaxReset( reset ); return false; } ); /** * Build the tabs inside the parent dialog and append settings. * * @since 1.1.6 * @param string content Main content of the dialog. * @param string dialogId The parent dialog section id. * @return mixed Necessary markup. */ function scBuildTabs( content, dialogId ) { // Return if the dialog opened once. if ( content.find( 'ul' ).length ) { return; } var dialogs = {}; var tabs; var tabsId = dialogId + '-tabs'; // Filter sections for dialogs. api.section.each( function( section ) { // Check if type of the section is dialog. if ( section.params.type !== 'sc-dialog' ) { return; } // Return if tab parameter is false. if ( section.params.scTab === false ) { return; } // Return if section doesn't belong to this dialog. if ( section.params.scBelong !== dialogId ) { return; } dialogs[ section.id ] = section.params; }); // Sort based on priority. var dialogs = _.sortBy( dialogs, 'priority' ); // Group dialogs based on tabs. tabs = _.groupBy( dialogs, function ( dialog ) { return dialog.scTab['id'] + ':' + dialog.scTab['text']; } ); // Create tabs markup. content.append( '
\ \
' ); _.each( tabs, function( tab, index ) { // Tabs nav. var tab_nav = index.split( ':' ); $( '#' + tabsId + ' > ul' ).append( '
  • \ ' + tab_nav[1] + '\
  • ' ); $( '#' + tabsId ).append( '
    ' ); // Tabs content. _.each( tab, function( element, index ) { var tabId = element.scTab['id']; if ( element.scChild === false ) { return content.find( '#' + tabId ).append( scLoadSettings( element.id ) ); } if ( ! $( '#' + tabId, '#' + tabsId ).find( 'ul' ).length ) { $( '#' + tabId, '#' + tabsId ).append( '' ); } return $( '#' + tabId + ' > ul', '#' + tabsId ).append( '
  • ' + element.title + '
  • \
  • \ \
    \
  • ' ); }); } ); // Initialte the tabs. $( "#" + tabsId ).tabs(); } /** * Load a section of settings from Customizer. * * @since 1.1.6 * @param string sectionId ID of the section. * @return object An object contains of necessary markup. */ function scLoadSettings( sectionId ) { var settings = ''; if ( typeof api.section( sectionId ) === 'undefined' ) { return 'Invalid section ID.'; } settings = api.section( sectionId ).contentContainer; // Remove meta section which is useless. settings.children().remove( '.section-meta' ); // Remove all the class then add necessary class. settings.removeClass().addClass( 'sc-row' ); return settings[0]; } /** * Send an Ajax request to reset the settings. * * @since 1.1.6 * @param string reset ID of the reset section. */ function ScAjaxReset( reset ) { setTimeout( function () { wp.ajax.send( 'sc_customizer_reset', { data: { nonce: sc_cz.nonce, reset : reset, }, success: function( response ) { window.location.reload( true ); } }); }, 1000 ); } } ); // End of ready function.