jQuery(document).ready(function($) { 'use strict'; var customize = wp.customize; /*icon type switch*/ function icon_type_switch(icon_type,row) { if(!row.length) return false; if (icon_type === 'icon') { row.find('.repeater-field-image').hide(); row.find('.repeater-field-iconpicker').show(); } else { row.find('.repeater-field-image').show(); row.find('.repeater-field-iconpicker').hide(); } } $('select[data-field="icon_type"]').each(function(index, element) { var icon_type = $(this).val(); var row = $(this).parents('li.repeater-row'); icon_type_switch(icon_type,row); }); $(document).on('change', 'select[data-field="icon_type"]', function(){ var icon_type = $(this).val(); var row = $(this).parents('li.repeater-row'); icon_type_switch(icon_type,row); }); $(document).on('click', 'button.repeater-add', function(){ var newRow = $(this).parent('.customize-control-repeater').find('li.repeater-row:last'); setTimeout(function(){ var icon_type = newRow.find('select[data-field="icon_type"]').val(); if(icon_type !== 'undefined'){ icon_type_switch(icon_type,newRow); } }, 100); }); /*Top Bar Left tpl*/ function astore_topbar_left_tpl() { var html = ''; $('#customize-control-astore-topbar_left .repeater-fields > li').each(function(index, element) { var icon = $(this).find('input[data-field="icon"]').val(); var text = $(this).find('input[data-field="text"]').val(); var link = $(this).find('input[data-field="link"]').val(); var target = $(this).find('input[data-field="target"]').val(); html += ''; }); customize.previewer.send('topbar_left', html); } wp.customize('astore[topbar_left]', function(value) { value.bind(function(to) { astore_topbar_left_tpl(); }); }); $(document).on('click', '#customize-control-astore-topbar_left .repeater-row-remove', function() { $(this).parents('li.repeater-row').remove(); astore_topbar_left_tpl(); }); /*Top Bar Icons tpl*/ function astore_topbar_icons_tpl() { var html = ''; $('#customize-control-astore-topbar_icons .repeater-fields > li').each(function(index, element) { var icon = $(this).find('input[data-field="icon"]').val(); var link = $(this).find('input[data-field="link"]').val(); var target = $(this).find('input[data-field="target"]').val(); html += ''; }); customize.previewer.send('topbar_icons', html); } wp.customize('astore[topbar_icons]', function(value) { value.bind(function(to) { astore_topbar_icons_tpl(); }); }); $(document).on('click', '#customize-control-astore-topbar_icons .repeater-row-remove', function() { $(this).parents('li.repeater-row').remove(); astore_topbar_icons_tpl(); }); /*Top Bar Right tpl*/ function astore_topbar_right_tpl() { var html = ''; $('#customize-control-astore-topbar_right .repeater-fields > li').each(function(index, element) { var icon = $(this).find('input[data-field="icon"]').val(); var text = $(this).find('input[data-field="text"]').val(); var link = $(this).find('input[data-field="link"]').val(); var target = $(this).find('input[data-field="target"]').val(); html += ''; }); customize.previewer.send('topbar_right', html); } wp.customize('astore[topbar_right]', function(value) { value.bind(function(to) { astore_topbar_right_tpl(); }); }); $(document).on('click', '#customize-control-astore-topbar_right .repeater-row-remove', function() { $(this).parents('li.repeater-row').remove(); astore_topbar_right_tpl(); }); /*menu tpl*/ function astore_menu_tpl() { var html = ''; $('#customize-control-astore-frontpage_menu .repeater-fields > li').each(function(index, element) { var title = $(this).find('input[data-field="title"]').val(); var link = $(this).find('input[data-field="link"]').val(); var icon = $(this).find('input[data-field="icon"]').val(); var icon_str = ''; if(icon !=='') icon_str = ' ' ; if (title !== '') html += '