/**
 * File customizer.js.
 * Theme Customizer extensions.
 */

(function($) {
	// $(document).on('ready', function() {
    $(function() {
		// init js
		woo_customizer.setup();
	});
})(jQuery);

var woo_customizer = new function() {

    this.setup = function() {

        this.bindSectionToLink('woo_general', local.shop_link);
        this.bindSectionToLink('woo_product_page', local.product_link);
        this.bindSectionToLink('woo_cart_page', local.cart_link);
        this.bindSectionToLink('woo_account_page', local.account_link);
        this.bindSectionToLink('woo_tables', local.cart_link);
        this.bindSectionToLink('woo_tabs', local.tabs_link);

    }
    
    // bind sections to pages
    this.bindSectionToLink = function(section=false, link=false) {
        if (section !== false && link !== false) {
            wp.customize.section( section, function( section ) {
                section.expanded.bind( function( isExpanded ) {
                    if ( isExpanded && customizer.reload === true ) {
                        wp.customize.previewer.previewUrl.set( link );
                    }
                } );
            });
        }
    }

}