jQuery(document).ready(function($) { "use strict"; /*** Sortlist Control ***/ $('ul.hybridextend-control-sortlist').each(function(){ /** Prepare Sortlist **/ var $self = $(this), openstate = $self.data('openstate'), $listItems = $self.children('li'), $listItemHeads = $listItems.children('.hybridextend-sortlistitem-head'), $listItemVisibility = $listItemHeads.children('.sortlistitem-display'), $listItemOptions = $listItems.children('.hybridextend-sortlistitem-options'); $listItemHeads.on('click', function(e){ $(this).children('.sortlistitem-expand').toggleClass('options-open'); $(this).siblings('.hybridextend-sortlistitem-options').slideToggle('fast'); }); if ( openstate ) { if ( openstate != 'all' ) { $listItemOptions.hide(); $listItems.filter('[data-choiceid="' + openstate + '"]').children('.hybridextend-sortlistitem-head').click(); } } else $listItemOptions.hide(); $listItemVisibility.on('click', function(e){ e.stopPropagation(); var $liContainer = $(this).closest('li.hybridextend-control-sortlistitem'); $liContainer.toggleClass('deactivated'); var hideValue = ( $liContainer.is('.deactivated') ) ? '1' : '0'; $(this).siblings('input.hybridextend-control-sortlistitem-hide').val(hideValue).trigger('change'); }); /** Sortlist Control **/ var $optionsform = $self.find('input, textarea, select'), $input = $self.siblings('input.hybridextend-customize-control-sortlist'), updateSortable = function(){ $optionsform = $self.find('input, textarea, select'); // Get updated list item order // JSON.stringify( $optionsform.serializeArray() ) :: serializeArray does not create a multidimensional array. It simpy creates array with name/value pairs // Hence use $optionsform.serialize(). For more notes on this issue, see php file. $input.val( $optionsform.serialize() ).trigger('change'); }; $optionsform.on('change', updateSortable); if ( $self.is('.sortable') ) { $self.sortable({ handle: ".sortlistitem-sort", placeholder: "hybridextend-control-sortlistitem-placeholder", update: function(event, ui) { updateSortable(); }, // start: function(e, ui){ // ui.placeholder.height(ui.item.height()); // }, forcePlaceholderSize: true, }); } }); /*** Radioimage Control ***/ $('.customize-control-radioimage, .hybridextend-sortlistitem-option-radioimage').each(function(){ var $radios = $(this).find('input'), $labels = $(this).find('.hybridextend-customize-radioimage'); $radios.on('change',function(){ $labels.removeClass('radiocheck'); $(this).parent('.hybridextend-customize-radioimage').addClass('radiocheck'); }); }); /*** Icon Control ***/ if ( (typeof _hybridextend_customize_data != 'undefined') && (typeof _hybridextend_customize_data.iconslist != 'undefined') ) { /** Fly Icon **/ var $body = $('body'), $flyicon = $('#hybridextend-flyicon-content'); $body.on( "openflypanel", function() { var $flypanelbutton = $body.data('flypanelbutton'); if( $flypanelbutton && $flypanelbutton.data('flypaneltype')=='icon' && $flypanelbutton.data('flypanel')=='open' ) { $flyicon.html( _hybridextend_customize_data.iconslist ).data('controlgroup', $flypanelbutton); var $flyiconIcons = $flyicon.find('i'), $input = $flypanelbutton.siblings('input.hybridextend-customize-control-icon'), selected = $input.val(), $icondisplay = $flypanelbutton.children('i'); $flypanelbutton.addClass('flygroup-open'); if(selected) $flyicon.find('i.'+selected.replace(' ', '.')).addClass('selected'); $flyiconIcons.click( function(event){ var iconvalue = $(this).data('value'); $flyiconIcons.removeClass('selected'); $(this).addClass('selected'); $input.val( iconvalue ).trigger('change'); $icondisplay.removeClass().addClass(iconvalue ); $('.hybridextend-flypanel-back').trigger('click'); }); $body.addClass('hybridextend-displaying-flyicon'); $body.data('flypaneltype','icon'); } }); $body.on( "closeflypanel", function() { $body.removeClass('hybridextend-displaying-flyicon'); var controlGroup = $flyicon.data('controlgroup'); if (controlGroup) $(controlGroup).removeClass('flygroup-open'); if($body.data('flypaneltype')=='icon') { $body.data('flypaneltype',''); } }); $('.hybridextend-customize-control-icon-remove').click( function(event){ var input = $(this).siblings('input.hybridextend-customize-control-icon'), icondisplay = $(this).siblings('.hybridextend-customize-control-icon-picked').children('i'); input.val('').trigger('change'); icondisplay.removeClass(); // $('.hybridextend-flypanel-back').trigger('click'); // redundant }); } /*** Group Control ***/ /** Prepare Groups **/ $( ".hybridextend-customize-control-groupstart" ).each( function( index ) { var id = $(this).attr('id'), moveBlocks = $(this).nextUntil( '.hybridextend-customize-control-groupend', "li" ); moveBlocks.addClass('hybridextend-customize-control-group-blocks').attr('data-controlgroup', id); }); /** Fly Groups **/ var $body = $('body'); $body.on( "openflypanel", function() { var $flypanelbutton = $body.data('flypanelbutton'); if( $flypanelbutton && $flypanelbutton.data('flypaneltype')=='group' && $flypanelbutton.data('flypanel')=='open' ) { var $groupstart = $flypanelbutton.parent('.hybridextend-customize-control-groupstart'); $groupstart.addClass('flygroup-open'); var moveBlocks = $groupstart.nextUntil( '.hybridextend-customize-control-groupend', "li" ); $('#hybridextend-flygroup-content').html('').append(moveBlocks).wrapInner('