jQuery(document).ready(function($) { //"use strict"; //FontAwesome Icon Control JS $('body').on('click', '.bizzoy-icon-list li', function(){ var icon_class = $(this).find('i').attr('class'); $(this).addClass('icon-active').siblings().removeClass('icon-active'); $(this).parent('.bizzoy-icon-list').prev('.bizzoy-selected-icon').children('i').attr('class','').addClass(icon_class); $(this).parent('.bizzoy-icon-list').next('input').val(icon_class).trigger('change'); }); $('body').on('click', '.bizzoy-selected-icon', function(){ $(this).next().slideToggle(); }); //Switch Control $('body').on('click', '.onoffswitch', function(){ var $this = $(this); if($this.hasClass('switch-on')){ $(this).removeClass('switch-on'); $this.next('input').val('off').trigger('change') }else{ $(this).addClass('switch-on'); $this.next('input').val('on').trigger('change') } }); // Gallery Control $('.upload_gallery_button').click(function(event){ var current_gallery = $( this ).closest( 'label' ); if ( event.currentTarget.id === 'clear-gallery' ) { //remove value from input current_gallery.find( '.gallery_values' ).val( '' ).trigger( 'change' ); //remove preview images current_gallery.find( '.gallery-screenshot' ).html( '' ); return; } // Make sure the media gallery API exists if ( typeof wp === 'undefined' || !wp.media || !wp.media.gallery ) { return; } event.preventDefault(); // Activate the media editor var val = current_gallery.find( '.gallery_values' ).val(); var final; if ( !val ) { final = '[gallery ids="0"]'; } else { final = '[gallery ids="' + val + '"]'; } var frame = wp.media.gallery.edit( final ); frame.state( 'gallery-edit' ).on( 'update', function( selection ) { //clear screenshot div so we can append new selected images current_gallery.find( '.gallery-screenshot' ).html( '' ); var element, preview_html = '', preview_img; var ids = selection.models.map( function( e ) { element = e.toJSON(); preview_img = typeof element.sizes.thumbnail !== 'undefined' ? element.sizes.thumbnail.url : element.url; preview_html = "
"; current_gallery.find( '.gallery-screenshot' ).append( preview_html ); return e.id; } ); current_gallery.find( '.gallery_values' ).val( ids.join( ',' ) ).trigger( 'change' ); } ); return false; }); //MultiCheck box Control JS $( '.customize-control-checkbox-multiple input[type="checkbox"]' ).on( 'change', function() { var checkbox_values = $( this ).parents( '.customize-control' ).find( 'input[type="checkbox"]:checked' ).map( function() { return $( this ).val(); } ).get().join( ',' ); $( this ).parents( '.customize-control' ).find( 'input[type="hidden"]' ).val( checkbox_values ).trigger( 'change' ); } ); //Chosen JS //Scroll to section $('body').on('click', '#sub-accordion-panel-bizzoy_home_panel .control-subsection .accordion-section-title', function(event) { var section_id = $(this).parent('.control-subsection').attr('id'); scrollToSection( section_id ); }); //Homepage Section Sortable function bizzoy_sections_order(container) { var sections = $(container).sortable('toArray'); var sec_ordered = []; $.each(sections, function (index, sec_id) { sec_id = sec_id.replace("accordion-section-", ""); sec_ordered.push(sec_id); }); $.ajax({ url: ajaxurl, type: 'post', dataType: 'html', data: { 'action': 'bizzoy_order_sections', 'sections': sec_ordered, } }).done(function (data) { $.each(sec_ordered, function (key, value) { wp.customize.section(value).priority(key); }); $(container).find( '.bizzoy-drag-spinner' ).hide(); wp.customize.previewer.refresh(); }); } $('#sub-accordion-panel-bizzoy_home_panel').sortable({ axis: 'y', helper: 'clone', cursor: 'move', items: '> li.control-section:not(#accordion-section-bizzoy_slider_section)', delay: 150, update: function (event, ui) { $('#sub-accordion-panel-bizzoy_home_panel').find( '.bizzoy-drag-spinner' ).show(); bizzoy_sections_order('#sub-accordion-panel-bizzoy_home_panel'); $( '.wp-full-overlay-sidebar-content' ).scrollTop( 0 ); } }); }); // Extends our custom section. ( function( api ) { api.sectionConstructor['pro-section'] = api.Section.extend( { // No events for this type of section. attachEvents: function () {}, // Always make the section active. isContextuallyActive: function () { return true; } } ); } )( wp.customize ); function scrollToSection( section_id ){ var preview_section_id = "ht-home-slider-section"; var $contents = jQuery('#customize-preview iframe').contents(); switch ( section_id ) { case 'accordion-section-bizzoy_header_section': preview_section_id = "header-one-section"; break; case 'accordion-section-bizzoy_slider_section': preview_section_id = "slide-one"; break; case 'accordion-section-bizzoy_about_section': preview_section_id = "about-one"; break; case 'accordion-section-bizzoy_service_section': preview_section_id = "service-one"; break; case 'accordion-section-bizzoy_blog_section': preview_section_id = "blog-one-section"; break; case 'accordion-section-bizzoy_cta_section': preview_section_id = "callout-one-section"; break; } if( $contents.find('#'+preview_section_id).length > 0 ){ $contents.find("html, body").animate({ scrollTop: $contents.find( "#" + preview_section_id ).offset().top }, 1000); } }