jQuery(document).ready(function ($) {
wp.customize('business_shuffle_about_sidebar', function (setting) {
var setupControlImage = function (control) {
var visibility = function () {
if ('single-image' === setting.get()) {
control.container.removeClass('customizer-hidden');
} else {
control.container.addClass('customizer-hidden');
}
};
visibility();
setting.bind(visibility);
};
var setupControlWidget = function (control) {
var visibility = function () {
if ('widget' === setting.get()) {
control.container.removeClass('customizer-hidden');
} else {
control.container.addClass('customizer-hidden');
}
};
visibility();
setting.bind(visibility);
};
wp.customize.control('business_shuffle_about_image', setupControlImage);
wp.customize.control('business_shuffle_about_widget', setupControlWidget);
});
var delay = (function () {
var timer = 0;
return function (callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
jQuery('html').addClass('colorpicker-ready');
$('#sub-accordion-panel-business_shuffle_home_panel').sortable({
axis: 'y',
helper: 'clone',
cursor: 'move',
items: '> li.control-section:not(#accordion-section-business_shuffle_slider_section)',
delay: 150,
update: function (event, ui) {
$('#sub-accordion-panel-business_shuffle_home_panel').find('.business-shuffle-drag-spinner').show();
business_shuffle_sections_order('#sub-accordion-panel-business_shuffle_home_panel');
$('.wp-full-overlay-sidebar-content').scrollTop(0);
}
});
// FontAwesome Icon Control JS
$('body').on('click', '.business-shuffle-customizer-icon-box .business-shuffle-icon-list li', function () {
var icon_class = $(this).find('i').attr('class');
$(this).closest('.business-shuffle-icon-box').find('.business-shuffle-icon-list li').removeClass('icon-active');
$(this).addClass('icon-active');
$(this).closest('.business-shuffle-icon-box').prev('.business-shuffle-selected-icon').children('i').attr('class', '').addClass(icon_class);
$(this).closest('.business-shuffle-icon-box').next('input').val(icon_class).trigger('change');
$(this).closest('.business-shuffle-icon-box').slideUp();
});
$('body').on('click', '.business-shuffle-customizer-icon-box .business-shuffle-selected-icon', function () {
$(this).next().slideToggle();
});
$('body').on('change', '.business-shuffle-customizer-icon-box .business-shuffle-icon-search select', function () {
var selected = $(this).val();
$(this).closest('.business-shuffle-icon-box').find('.business-shuffle-icon-search-input').val('');
$(this).closest('.business-shuffle-icon-box').find('.business-shuffle-icon-list li').show();
$(this).closest('.business-shuffle-icon-box').find('.business-shuffle-icon-list').hide().removeClass('active');
$(this).closest('.business-shuffle-icon-box').find('.' + selected).fadeIn().addClass('active');
});
$('body').on('keyup', '.business-shuffle-customizer-icon-box .business-shuffle-icon-search input', function (e) {
var $input = $(this);
var keyword = $input.val().toLowerCase();
search_criteria = $input.closest('.business-shuffle-icon-box').find('.business-shuffle-icon-list.active i');
delay(function () {
$(search_criteria).each(function () {
if ($(this).attr('class').indexOf(keyword) > -1) {
$(this).parent().show();
} else {
$(this).parent().hide();
}
});
}, 500);
});
// 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
$(".hs-chosen-select, .customize-control-typography select").chosen({
width: "100%"
});
// Image Selector JS
$('body').on('click', '.selector-labels label', function () {
var $this = $(this);
var value = $this.attr('data-val');
$this.siblings().removeClass('selector-selected');
$this.addClass('selector-selected');
$this.closest('.selector-labels').next('input').val(value).trigger('change');
});
$('body').on('change', '.business-shuffle-type-radio input[type="radio"]', function () {
var $this = $(this);
$this.parent('label').siblings('label').find('input[type="radio"]').prop('checked', false);
var value = $this.closest('.radio-labels').find('input[type="radio"]:checked').val();
$this.closest('.radio-labels').next('input').val(value).trigger('change');
});
// Range JS
$('.customize-control-range').each(function () {
var sliderValue = $(this).find('.slider-input').val();
var newSlider = $(this).find('.business-shuffle-slider');
var sliderMinValue = parseFloat(newSlider.attr('slider-min-value'));
var sliderMaxValue = parseFloat(newSlider.attr('slider-max-value'));
var sliderStepValue = parseFloat(newSlider.attr('slider-step-value'));
newSlider.slider({
value: sliderValue,
min: sliderMinValue,
max: sliderMaxValue,
step: sliderStepValue,
range: 'min',
slide: function (e, ui) {
$(this).parent().find('.slider-input').trigger('change');
},
change: function (e, ui) {
$(this).parent().find('.slider-input').trigger('change');
}
});
});
// Change the value of the input field as the slider is moved
$('.customize-control-range .business-shuffle-slider').on('slide', function (event, ui) {
$(this).parent().find('.slider-input').val(ui.value);
});
// Reset slider and input field back to the default value
$('.customize-control-range .slider-reset').on('click', function () {
var resetValue = $(this).attr('slider-reset-value');
$(this).parents('.customize-control-range').find('.slider-input').val(resetValue);
$(this).parents('.customize-control-range').find('.business-shuffle-slider').slider('value', resetValue);
});
// Update slider if the input field loses focus as it's most likely changed
$('.customize-control-range .slider-input').blur(function () {
var resetValue = $(this).val();
var slider = $(this).parents('.customize-control-range').find('.business-shuffle-slider');
var sliderMinValue = parseInt(slider.attr('slider-min-value'));
var sliderMaxValue = parseInt(slider.attr('slider-max-value'));
// Make sure our manual input value doesn't exceed the minimum & maxmium values
if (resetValue < sliderMinValue) {
resetValue = sliderMinValue;
$(this).val(resetValue);
}
if (resetValue > sliderMaxValue) {
resetValue = sliderMaxValue;
$(this).val(resetValue);
}
$(this).parents('.customize-control-range').find('.business-shuffle-slider').slider('value', resetValue);
});
// TinyMCE editor
$(document).on('tinymce-editor-init', function () {
$('.customize-control').find('.wp-editor-area').each(function () {
var tArea = $(this),
id = tArea.attr('id'),
input = $('input[data-customize-setting-link="' + id + '"]'),
editor = tinyMCE.get(id),
content;
if (editor) {
editor.onChange.add(function () {
this.save();
content = editor.getContent();
input.val(content).trigger('change');
});
}
tArea.css({
visibility: 'visible'
}).on('keyup', function () {
content = tArea.val();
input.val(content).trigger('change');
});
});
});
// Select Image Js
$('.select-image-control').on('change', function () {
var activeImage = $(this).find(':selected').attr('data-image');
$(this).next('.select-image-wrap').find('img').attr('src', activeImage);
});
// Date Picker Js
$(".ht-datepicker-control").datepicker({
dateFormat: "yy/mm/dd"
});
// Scroll to section
$('body').on('click', '#sub-accordion-panel-business_shuffle_home_panel .control-subsection .accordion-section-title', function (event) {
var section_id = $(this).parent('.control-subsection').attr('id');
scrollToSection(section_id);
});
// Set all variables to be used in scope
var frame;
// ADD IMAGE LINK
$('.customize-control-repeater').on('click', '.business-shuffle-upload-button', function (event) {
event.preventDefault();
var imgContainer = $(this).closest('.business-shuffle-fields-wrap').find('.thumbnail-image'),
placeholder = $(this).closest('.business-shuffle-fields-wrap').find('.placeholder'),
imgIdInput = $(this).siblings('.upload-id');
// Create a new media frame
frame = wp.media({
title: 'Select or Upload Image',
button: {
text: 'Use Image'
},
multiple: false // Set to true to allow multiple files to be selected
});
// When an image is selected in the media frame...
frame.on('select', function () {
// Get media attachment details from the frame state
var attachment = frame.state().get('selection').first().toJSON();
// Send the attachment URL to our custom image input field.
imgContainer.html('
');
placeholder.addClass('hidden');
// Send the attachment id to our hidden input
imgIdInput.val(attachment.url).trigger('change');
});
// Finally, open the modal on click
frame.open();
});
// DELETE IMAGE LINK
$('.customize-control-repeater').on('click', '.business-shuffle-delete-button', function (event) {
event.preventDefault();
var imgContainer = $(this).closest('.business-shuffle-fields-wrap').find('.thumbnail-image'),
placeholder = $(this).closest('.business-shuffle-fields-wrap').find('.placeholder'),
imgIdInput = $(this).siblings('.upload-id');
// Clear out the preview image
imgContainer.find('img').remove();
placeholder.removeClass('hidden');
// Delete the image id from the hidden input
imgIdInput.val('').trigger('change');
});
var ColorChange = false;
$('.business-shuffle-color-picker').wpColorPicker({
change: function (event, ui) {
if (jQuery('html').hasClass('colorpicker-ready') && ColorChange) {
business_shuffle_refresh_repeater_values();
}
}
});
ColorChange = true;
//MultiCheck box Control JS
$('body').on('change', '.business-shuffle-type-multicategory input[type="checkbox"]', function () {
var checkbox_values = $(this).parents('.business-shuffle-type-multicategory').find('input[type="checkbox"]:checked').map(function () {
return $(this).val();
}).get().join(',');
$(this).parents('.business-shuffle-type-multicategory').find('input[type="hidden"]').val(checkbox_values).trigger('change');
business_shuffle_refresh_repeater_values();
});
$('.color-tab-toggle').on('click', function () {
$(this).closest('.customize-control').find('.color-tab-wrap').slideToggle();
});
$('.color-tab-switchers li').on('click', function () {
if ($(this).hasClass('active')) {
return false;
}
var clicked = $(this).attr('data-tab');
$(this).parent('.color-tab-switchers').find('li').removeClass('active');
$(this).addClass('active');
$(this).closest('.color-tab-wrap').find('.color-tab-contents > div').hide();
$(this).closest('.color-tab-wrap').find('.' + clicked).fadeIn();
});
function scrollToSection(section_id) {
var preview_section_id = "bs-slider-section";
var $contents = $('#customize-preview iframe').contents();
switch (section_id) {
case 'accordion-section-business_shuffle_slider_section':
preview_section_id = "bs-slider-section";
break;
case 'accordion-section-business_shuffle_about_section':
preview_section_id = "about-section";
break;
case 'accordion-section-business_shuffle_progressbar_section':
preview_section_id = "progressbar-section";
break;
case 'accordion-section-business_shuffle_featured_section':
preview_section_id = "featured-section";
break;
case 'accordion-section-business_shuffle_portfolio_section':
preview_section_id = "ht-portfolio-section";
break;
case 'accordion-section-business_shuffle_highlight_section':
preview_section_id = "highlight-section";
break;
case 'accordion-section-business_shuffle_counter_section':
preview_section_id = "counter-section";
break;
case 'accordion-section-business_shuffle_logo_section':
preview_section_id = "logo-section";
break;
case 'accordion-section-business_shuffle_cta_section':
preview_section_id = "cta-section";
break;
case 'accordion-section-business_shuffle_blog_section':
preview_section_id = "blog-section";
break;
}
if ($contents.find('#' + preview_section_id).length > 0) {
$contents.find("html, body").animate({
scrollTop: $contents.find("#" + preview_section_id).offset().top
}, 1000);
}
}
// Homepage Section Sortable
function business_shuffle_sections_order(container) {
var sections = $(container).sortable('toArray');
var s_ordered = [];
$.each(sections, function (index, s_id) {
s_id = s_id.replace("accordion-section-", "");
s_ordered.push(s_id);
});
$.ajax({
url: ajaxurl,
type: 'post',
dataType: 'html',
data: {
'action': 'business_shuffle_order_sections',
'sections': s_ordered,
}
}).done(function (data) {
$.each(s_ordered, function (key, value) {
wp.customize.section(value).priority(key);
});
$(container).find('.business-shuffle-drag-spinner').hide();
wp.customize.previewer.refresh();
});
}
});
(function (api) {
// Class extends the UploadControl
api.controlConstructor['background-image'] = api.UploadControl.extend({
ready: function () {
// Re-use ready function from parent class to set up the image uploader
var image_url = this;
image_url.setting = this.settings.image_url;
api.UploadControl.prototype.ready.apply(image_url, arguments);
// Set up the new controls
var control = this;
control.container.addClass('customize-control-image');
control.container.on('click keydown', '.remove-button',
function () {
control.container.find('.background-image-fields').hide();
}
);
control.container.on('change', '.background-image-repeat select',
function () {
control.settings['repeat'].set(jQuery(this).val());
}
);
control.container.on('change', '.background-image-size select',
function () {
control.settings['size'].set(jQuery(this).val());
}
);
control.container.on('change', '.background-image-attach select',
function () {
control.settings['attach'].set(jQuery(this).val());
}
);
control.container.on('change', '.background-image-position select',
function () {
control.settings['position'].set(jQuery(this).val());
}
);
},
/**
* Callback handler for when an attachment is selected in the media modal.
* Gets the selected image information, and sets it within the control.
*/
select: function () {
var attachment = this.frame.state().get('selection').first().toJSON();
this.params.attachment = attachment;
this.settings['image_url'].set(attachment.url);
this.settings['image_id'].set(attachment.id);
},
});
// Tab Control
api.TotalTabs = [];
api.TotalTab = api.Control.extend({
ready: function () {
var control = this;
control.container.find('a.customizer-tab').click(function (evt) {
var tab = $(this).data('tab');
evt.preventDefault();
control.container.find('a.customizer-tab').removeClass('active');
$(this).addClass('active');
control.toggleActiveControls(tab);
});
api.TotalTabs.push(control.id);
},
toggleActiveControls: function (tab) {
var control = this,
currentFields = control.params.buttons[tab].fields;
_.each(control.params.fields, function (id) {
var tabControl = api.control(id);
if (undefined !== tabControl) {
if (tabControl.active() && $.inArray(id, currentFields) >= 0) {
tabControl.toggle(true);
} else {
tabControl.toggle(false);
}
}
});
}
});
$.extend(api.controlConstructor, {
'tab': api.TotalTab,
});
api.bind('ready', function () {
_.each(api.TotalTabs, function (id) {
var control = api.control(id);
control.toggleActiveControls(0);
});
});
// Alpha Color Picker Control
api.controlConstructor['alpha-color'] = api.Control.extend({
ready: function () {
var control = this;
var paletteInput = control.container.find('.alpha-color-control').data('palette');
if (true == paletteInput) {
palette = true;
} else if ((typeof (paletteInput) !== 'undefined') && paletteInput.indexOf('|') !== -1) {
palette = paletteInput.split('|');
} else {
palette = false;
}
control.container.find('.alpha-color-control').wpColorPicker({
change: function (event, ui) {
var color = ui.color.toString();
if (jQuery('html').hasClass('colorpicker-ready')) {
control.setting.set(color);
}
},
clear: function (event) {
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0];
var color = '';
if (element) {
control.setting.set(color);
}
},
palettes: palette
});
}
});
// Color Tab Control
api.controlConstructor['color-tab'] = api.Control.extend({
ready: function () {
var control = this;
control.container.find('.alpha-color-control').each(function () {
var $elem = $(this);
var paletteInput = $elem.data('palette');
var setting = $(this).attr('data-customize-setting-link');
if (true == paletteInput) {
palette = true;
} else if ((typeof (paletteInput) !== 'undefined') && paletteInput.indexOf('|') !== -1) {
palette = paletteInput.split('|');
} else {
palette = false;
}
$elem.wpColorPicker({
change: function (event, ui) {
var color = ui.color.toString();
if (jQuery('html').hasClass('colorpicker-ready')) {
wp.customize(setting, function (obj) {
obj.set(color);
});
}
},
clear: function (event) {
var element = jQuery(event.target).closest('.wp-picker-input-wrap').find('.wp-color-picker')[0];
var color = '';
if (element) {
wp.customize(setting, function (obj) {
obj.set(color);
});
}
},
palettes: palette
});
});
}
});
// Dimenstion Control
api.controlConstructor['dimensions'] = wp.customize.Control.extend({
ready: function () {
var control = this;
control.container.on('change keyup paste', '.dimension-desktop_top', function () {
control.settings['desktop_top'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-desktop_right', function () {
control.settings['desktop_right'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-desktop_bottom', function () {
control.settings['desktop_bottom'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-desktop_left', function () {
control.settings['desktop_left'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-tablet_top', function () {
control.settings['tablet_top'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-tablet_right', function () {
control.settings['tablet_right'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-tablet_bottom', function () {
control.settings['tablet_bottom'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-tablet_left', function () {
control.settings['tablet_left'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-mobile_top', function () {
control.settings['mobile_top'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-mobile_right', function () {
control.settings['mobile_right'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-mobile_bottom', function () {
control.settings['mobile_bottom'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.dimension-mobile_left', function () {
control.settings['mobile_left'].set(jQuery(this).val());
});
}
});
// Range Slider Control
api.controlConstructor['range-slider'] = wp.customize.Control.extend({
ready: function () {
var control = this,
desktop_slider = control.container.find('.business-shuffle-slider.desktop-slider'),
desktop_slider_input = desktop_slider.next('.business-shuffle-slider-input').find('input.desktop-input'),
tablet_slider = control.container.find('.business-shuffle-slider.tablet-slider'),
tablet_slider_input = tablet_slider.next('.business-shuffle-slider-input').find('input.tablet-input'),
mobile_slider = control.container.find('.business-shuffle-slider.mobile-slider'),
mobile_slider_input = mobile_slider.next('.business-shuffle-slider-input').find('input.mobile-input'),
slider_input,
$this,
val;
// Desktop slider
desktop_slider.slider({
range: 'min',
value: desktop_slider_input.val(),
min: +desktop_slider_input.attr('min'),
max: +desktop_slider_input.attr('max'),
step: +desktop_slider_input.attr('step'),
slide: function (event, ui) {
desktop_slider_input.val(ui.value).keyup();
},
change: function (event, ui) {
control.settings['desktop'].set(ui.value);
}
});
// Tablet slider
tablet_slider.slider({
range: 'min',
value: tablet_slider_input.val(),
min: +tablet_slider_input.attr('min'),
max: +tablet_slider_input.attr('max'),
step: +desktop_slider_input.attr('step'),
slide: function (event, ui) {
tablet_slider_input.val(ui.value).keyup();
},
change: function (event, ui) {
control.settings['tablet'].set(ui.value);
}
});
// Mobile slider
mobile_slider.slider({
range: 'min',
value: mobile_slider_input.val(),
min: +mobile_slider_input.attr('min'),
max: +mobile_slider_input.attr('max'),
step: +desktop_slider_input.attr('step'),
slide: function (event, ui) {
mobile_slider_input.val(ui.value).keyup();
},
change: function (event, ui) {
control.settings['mobile'].set(ui.value);
}
});
// Update the slider when the number value change
jQuery('input.desktop-input').on('change keyup paste', function () {
$this = jQuery(this);
val = $this.val();
slider_input = $this.parent().prev('.business-shuffle-slider.desktop-slider');
slider_input.slider('value', val);
});
jQuery('input.tablet-input').on('change keyup paste', function () {
$this = jQuery(this);
val = $this.val();
slider_input = $this.parent().prev('.business-shuffle-slider.tablet-slider');
slider_input.slider('value', val);
});
jQuery('input.mobile-input').on('change keyup paste', function () {
$this = jQuery(this);
val = $this.val();
slider_input = $this.parent().prev('.business-shuffle-slider.mobile-slider');
slider_input.slider('value', val);
});
// Save the values
control.container.on('change keyup paste', '.desktop input', function () {
control.settings['desktop'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.tablet input', function () {
control.settings['tablet'].set(jQuery(this).val());
});
control.container.on('change keyup paste', '.mobile input', function () {
control.settings['mobile'].set(jQuery(this).val());
});
}
});
// Sortable Control
api.controlConstructor['sortable'] = wp.customize.Control.extend({
ready: function () {
var control = this;
// Set the sortable container.
control.sortableContainer = control.container.find('ul.sortable').first();
// Init sortable.
control.sortableContainer.sortable({
// Update value when we stop sorting.
stop: function () {
control.updateValue();
}
}).disableSelection().find('li').each(function () {
// Enable/disable options when we click on the eye of Thundera.
jQuery(this).find('i.visibility').click(function () {
jQuery(this).toggleClass('dashicons-visibility-faint').parents('li:eq(0)').toggleClass('invisible');
});
}).click(function () {
// Update value on click.
control.updateValue();
});
},
/**
* Updates the sorting list
*/
updateValue: function () {
var control = this,
newValue = [];
this.sortableContainer.find('li').each(function () {
if (!jQuery(this).is('.invisible')) {
newValue.push(jQuery(this).data('value'));
}
});
control.setting.set(newValue);
}
});
})(wp.customize);
(function ($) {
wp.customize.bind('ready', function () {
wp.customize.section('business_shuffle_gdpr_section', function (section) {
section.expanded.bind(function (isExpanding) {
// Value of isExpanding will = true if you're entering the section, false if you're leaving it.
if (isExpanding) {
wp.customize.previewer.send('business-shuffle-gdpr-add-class', {
expanded: isExpanding
});
} else {
wp.customize.previewer.send('business-shuffle-gdpr-remove-class', {
home_url: wp.customize.settings.url.home
});
}
});
});
});
})(jQuery);
jQuery(document).ready(function ($) {
// Responsive switchers
$('.customize-control .responsive-switchers button').on('click', function (event) {
// Set up variables
var $this = $(this),
$devices = $('.responsive-switchers'),
$device = $(event.currentTarget).data('device'),
$control = $('.customize-control.has-switchers'),
$body = $('.wp-full-overlay'),
$footer_devices = $('.wp-full-overlay-footer .devices');
// Button class
$devices.find('button').removeClass('active');
$devices.find('button.preview-' + $device).addClass('active');
// Control class
$control.find('.control-wrap').removeClass('active');
$control.find('.control-wrap.' + $device).addClass('active');
$control.removeClass('control-device-desktop control-device-tablet control-device-mobile').addClass('control-device-' + $device);
// Wrapper class
$body.removeClass('preview-desktop preview-tablet preview-mobile').addClass('preview-' + $device);
// Panel footer buttons
$footer_devices.find('button').removeClass('active').attr('aria-pressed', false);
$footer_devices.find('button.preview-' + $device).addClass('active').attr('aria-pressed', true);
// Open switchers
if ($this.hasClass('preview-desktop')) {
$control.toggleClass('responsive-switchers-open');
}
});
// If panel footer buttons clicked
$('.wp-full-overlay-footer .devices button').on('click', function (event) {
// Set up variables
var $this = $(this),
$devices = $('.customize-control.has-switchers .responsive-switchers'),
$device = $(event.currentTarget).data('device'),
$control = $('.customize-control.has-switchers');
// Button class
$devices.find('button').removeClass('active');
$devices.find('button.preview-' + $device).addClass('active');
// Control class
$control.find('.control-wrap').removeClass('active');
$control.find('.control-wrap.' + $device).addClass('active');
$control.removeClass('control-device-desktop control-device-tablet control-device-mobile').addClass('control-device-' + $device);
// Open switchers
if (!$this.hasClass('preview-desktop')) {
$control.addClass('responsive-switchers-open');
} else {
$control.removeClass('responsive-switchers-open');
}
});
// Linked button
$('.business-shuffle-linked').on('click', function () {
// Set up variables
var $this = $(this);
// Remove linked class
$this.parent().parent('.dimension-wrap').prevAll().slice(0, 4).find('input').removeClass('linked').attr('data-element', '');
// Remove class
$this.parent('.link-dimensions').removeClass('unlinked');
});
// Unlinked button
$('.business-shuffle-unlinked').on('click', function () {
// Set up variables
var $this = $(this),
$element = $this.data('element');
// Add linked class
$this.parent().parent('.dimension-wrap').prevAll().slice(0, 4).find('input').addClass('linked').attr('data-element', $element);
// Add class
$this.parent('.link-dimensions').addClass('unlinked');
});
// Values linked inputs
$('.dimension-wrap').on('input', '.linked', function () {
var $data = $(this).attr('data-element'),
$val = $(this).val();
$('.linked[ data-element="' + $data + '" ]').each(function (key, value) {
$(this).val($val).change();
});
});
});