| 1 |
(function($) { |
| 2 |
wp.customize.bind('ready', function() { |
| 3 |
wp.customize.section.each(function(section) { |
| 4 |
if (!$('#sub-accordion-section-' + section.id + ' .customize-section-description').length) { |
| 5 |
$('#sub-accordion-section-' + section.id + ' .customize-section-description-container').append($('<div class="description customize-section-description"></div>')); |
| 6 |
} |
| 7 |
sectionOK = false; |
| 8 |
_.each(wp.customize.section(section.id).controls(), function (control) { |
| 9 |
if (typeof wp.customize(control.id) !== 'undefined') { |
| 10 |
sectionOK = true; |
| 11 |
} |
| 12 |
}); |
| 13 |
if (sectionOK && $('#sub-accordion-section-' + section.id + ' .customize-section-description').length) { |
| 14 |
var $button; |
| 15 |
if (section.id.startsWith('sidebar-widgets-')) { |
| 16 |
$button = $('<input type="button" id="reset-' + section.id + '" class="button-secondary button" value="' + resetCustomizer.resetPrefix + $('#accordion-section-' + section.id + '>h3').clone().children().remove().end().text() + '">'); |
| 17 |
} else { |
| 18 |
$button = $('<input type="button" id="reset-' + section.id + '" class="button-secondary button" value="' + resetCustomizer.resetPrefix + $('#accordion-section-' + section.id + '>h3').clone().children().remove().end().text() + resetCustomizer.resetSuffix + '">'); |
| 19 |
} |
| 20 |
$button.on('click', function () { |
| 21 |
var controls = []; |
| 22 |
_.each(wp.customize.section(section.id).controls(), function (control) { |
| 23 |
if (typeof wp.customize(control.id) !== 'undefined' && !section.id.startsWith('sidebar-widgets-')) { |
| 24 |
controls.push(control.id); |
| 25 |
} |
| 26 |
}); |
| 27 |
if (controls.length > 0) { |
| 28 |
var data = { |
| 29 |
action: 'rc_get_control_defaults', |
| 30 |
_ajax_nonce: resetCustomizer.nonce, |
| 31 |
controls: controls, |
| 32 |
wp_customize: 'on' |
| 33 |
}; |
| 34 |
$.ajax({ |
| 35 |
url: ajaxurl, |
| 36 |
data: data, |
| 37 |
type: 'POST', |
| 38 |
success: function(data) { |
| 39 |
_.each(wp.customize.section(section.id).controls(), function (control) { |
| 40 |
if (typeof wp.customize(control.id) !== 'undefined' && section.id.startsWith('sidebar-widgets-')) { |
| 41 |
wp.customize(control.id).set([]); |
| 42 |
} else if (typeof wp.customize(control.id) !== 'undefined' && typeof data.data[control.id] != "undefined") { |
| 43 |
wp.customize(control.id).set(data.data[control.id]); |
| 44 |
} |
| 45 |
}); |
| 46 |
wp.customize.previewer.refresh(); |
| 47 |
}, |
| 48 |
error: function() { |
| 49 |
alert(resetCustomizer.errorNotice); |
| 50 |
} |
| 51 |
}); |
| 52 |
} |
| 53 |
}); |
| 54 |
if ($('#sub-accordion-section-' + section.id + ' .customize-section-description').text().length && !$('#sub-accordion-section-' + section.id + ' .customize-section-description p').length) { |
| 55 |
$('#sub-accordion-section-' + section.id + ' .customize-section-description').append($('<br /><br />')); |
| 56 |
} |
| 57 |
$('#sub-accordion-section-' + section.id + ' .customize-section-description').append($button); |
| 58 |
} |
| 59 |
}); |
| 60 |
}); |
| 61 |
})(jQuery); |
| 62 |
|