(function($, undefined) {
"use strict";
window.VAMTAM = window.VAMTAM || {};
$(function() {
$('body').vamtamColorPicker().vamtamBackgroundOption();
window.VAMTAM.upload.init();
$(document).on('change select', '[data-field-filter]', function() {
var prefix = $(this).attr('data-field-filter');
var selected = $(':checked', this).val();
var others = $(this).closest('.vamtam-config-group').find('.' + prefix).filter(':not(.hidden)');
others.show().filter(':not(.' + prefix + '-' + selected + ')').hide();
});
$('[data-field-filter]').change();
$(document).on('change', '.social_icon_select_sites', function() {
var wrap = $(this).closest('p').siblings('.social_icon_wrap');
wrap.children('p').hide();
$('option:selected', this).each(function() {
wrap.find('.social_icon_' + $(this).val()).show();
});
});
$(document).on('change', '.num_shown', function() {
var wrap = $(this).closest('p').siblings('.hidden_wrap');
wrap.children('div').hide();
$('.hidden_el:lt(' + $(this).val() + ')', wrap).show();
});
$('.metabox').each(function() {
var meta_tabs = $('
').addClass('vamtam-meta-tabs');
$('.config-separator:first', this).before(meta_tabs);
$('.config-separator', this).each(function() {
var id = $(this).text().replace(/[\s\n]+/g, '').toLowerCase();
$(this).nextUntil('.config-separator').wrapAll('');
$(this).css('cursor', 'pointer');
if ($(this).next().is('.vamtam-meta-part')) {
meta_tabs.append('- ' + $(this).text() + '
');
}
$(this).remove();
});
if(meta_tabs.children().length > 1) {
meta_tabs.closest('.metabox').tabs();
} else {
meta_tabs.hide();
}
});
$('#vamtam-config').tabs({
activate: function(event, ui) {
var hash = ui.newTab.context.hash;
var element = $(hash);
element.attr('id', '');
window.location.hash = hash;
element.attr('id', hash.replace('#', ''));
$('.save-vamtam-config').show();
if (ui.newTab.hasClass('nosave')) $('.save-vamtam-config').hide();
},
create: function(event, ui) {
if (ui.tab.hasClass('nosave')) $('.save-vamtam-config').hide();
}
});
$('body').on('click', '.info-wrapper > a', function(e) {
var other = $(this).attr('data-other');
$(this).attr('data-other', $(this).text()).text(other);
$(this).siblings('.desc').slideToggle(200);
e.preventDefault();
});
});
})(jQuery);