jQuery(document).ready(function($){ 'use strict'; /** Script for switch option **/ $('.switch_button').each(function() { var obj = $(this); var switchPart = obj.children('.switch_part').attr('data-switch'); var input = obj.children('input'); var input_val = obj.children('input').val(); obj.children('.switch_part.'+input_val).addClass('selected'); obj.children('.switch_part').on('click', function(){ var switchVal = $(this).attr('data-switch'); obj.children('.switch_part').removeClass('selected'); $(this).addClass('selected'); $(input).val(switchVal).change(); }); }); /* Move Widget Area Into Cutomizer Pannel As section */ wp.customize.section( 'sidebar-widgets-allrounder-news-home-right-sidebar' ).panel( 'allrounder_news_home_panel' ); wp.customize.section( 'sidebar-widgets-allrounder-news-home-right-sidebar' ).priority( '10' ); wp.customize.section( 'sidebar-widgets-allrounder-news-home-no-sidebar' ).panel( 'allrounder_news_home_panel' ); wp.customize.section( 'sidebar-widgets-allrounder-news-home-no-sidebar' ).priority( '15' ); //Scroll to section $('body').on('click', '#sub-accordion-panel-allrounder_news_home_panel .control-subsection .accordion-section-title', function(event) { var section_id = $(this).parent('.control-subsection').attr('id'); allrounder_news_scroll_to( section_id ); }); /* Redirect Front Page */ wp.customize.panel( 'allrounder_news_home_panel', function( section ){ section.expanded.bind( function( isExpanded ) { if( isExpanded ){ wp.customize.previewer.previewUrl.set( allrounder_news_customize_data.home_url ); } }); }); }); function allrounder_news_scroll_to( container_id ){ var active_section = "banner_section"; var $preview_frame = jQuery('#customize-preview iframe').contents(); switch ( container_id ) { case 'accordion-section-allrounder_news_home_slider_section': active_section = "home-banner-section"; break; case 'accordion-section-sidebar-widgets-allrounder-news-home-right-sidebar': active_section = "home-right-sidebar-section"; break; case 'accordion-section-sidebar-widgets-allrounder-news-home-no-sidebar': active_section = "home-no-sidebar-section"; break; } if( $preview_frame.find('#'+active_section).length > 0 && $preview_frame.find('.home').length > 0 ){ $preview_frame.find("html, body").animate({ scrollTop: $preview_frame.find( "#" + active_section ).offset().top }, 1000); } } ( function( api ) { api.sectionConstructor['pro-section'] = api.Section.extend( { attachEvents: function () {}, isContextuallyActive: function () { return true; } } ); } )( wp.customize );