/*! Custom Sidebars - v3.2.2 * https://premium.wpmudev.org/project/custom-sidebars-pro/ * Copyright (c) 2018; * Licensed GPLv2+ */ jQuery(function(){var a=jQuery(document),b=jQuery("#widgets-right"),c=!1,d=function(){for(var a=jQuery("#widgets-left input.csb-clone-group"),c=parseInt(a.first().val());b.find('input.csb-clone-group[value="'+c+'"]').length;)c+=1;a.val(c)},e=function(a){var b=jQuery(this).closest(".widget"),e=jQuery("#widgets-left"),f=jQuery(".widgets-chooser"),g=jQuery("#wpbody-content");a.preventDefault(),c=!0,"new"===b.find("input.csb-clone-state").val()&&window.wpWidgets.save(b,0,0,0),window.wpWidgets.clearWidgetSelection(),f.slideUp(200,function(){f.hide(),g.append(this)});var h=b.find("input.id_base").val(),i=e.find('input.id_base[value="'+h+'"]'),j=i.closest(".widget");j.addClass("widget-in-question");var k=b.find("input.csb-clone-group").val(),l=(j.find(".widget-control-actions"),j.find("input.csb-clone-group")),m=j.find("input.csb-clone-state");l.val(k),m.val("empty");var n=b.closest(".widgets-sortables"),o=n.attr("id");return f.find(".widgets-chooser-selected").removeClass("widgets-chooser-selected"),f.find("li").each(function(){var a=jQuery(this);o===a.data("sidebarId")&&a.addClass("widgets-chooser-selected").focus()}),window.wpWidgets.addWidget(f),window.wpWidgets.clearWidgetSelection(),d(),c=!1,!1},f=function(a){var c=jQuery(this).closest(".widget"),d=c.find("input.csb-clone-group").val();b.find('input.csb-clone-group[value="'+d+'"]').closest(".widget").not(c).each(function(){var a=jQuery(this);a.find("input.csb-clone-state"),a.addClass("wpmui-loading").attr("data-reload",!0)})},g=function(a,b){var c=jQuery(b).closest(".widget"),d=c.find(".csb-clone-button"),g=c.find(".widget-control-actions .widget-control-save"),h=c.find(".widget-control-actions .spinner"),i=c.find(".widget-control-save");c.data("_csb_cloning")||(h.insertBefore(g).css({float:"left"}),d.insertBefore(g).click(e),i.click(f),c.data("_csb_cloning",!0))},h=function(a,e){if(c)return!1;for(var f=jQuery(e).closest(".widget"),g=f.find("input.csb-clone-group"),h=parseInt(g.val()),i=null;;){if(i=b.find('input.csb-clone-group[value="'+h+'"]'),!i.length||1===i.length&&i[0]===g[0])break;h+=1}g.val(h),d()},i=function(a){var c=jQuery(this).closest(".widget"),d=c.find("input.csb-clone-group").val(),e=b.find('input.csb-clone-group[value="'+d+'"]').closest(".widget");isNaN(d)||d<1||(e.addClass("csb-marker"),c.removeClass("csb-marker"))},j=function(a){jQuery(".widget.csb-marker").removeClass("csb-marker")},k=function(a){var b=jQuery(this).closest(".widget"),c=b.find(".widget-title h4"),d=c.find(".btn-clone-group"),e=b.find("input.csb-clone-group");return a.preventDefault(),a.stopPropagation(),c.hasClass("group-active")?(c.removeClass("group-active"),d.removeClass("dashicons-admin-links").addClass("dashicons-editor-unlink"),e.data("group",e.val()),e.val(0),j()):(c.addClass("group-active"),d.addClass("dashicons-admin-links").removeClass("dashicons-editor-unlink"),e.val(e.data("group")),i.call(this,[a])),!1},l=function(){b.find("input.csb-clone-group").each(function(){var a=jQuery(this).val(),c=b.find('input.csb-clone-group[value="'+a+'"]').closest(".widget"),d=c.find(".widget-title h4, .widget-title h3"),e="add";(isNaN(a)||a<1)&&(e="remove"),c.length<2&&(e="remove"),d.removeClass("csb-group group-active").find(".btn-clone-group").remove(),c.removeAttr("data-csb-icon"),"add"===e&&(d.addClass("csb-group group-active").prepend(' '),d.find(".btn-clone-group").hover(i,j).click(k))})},m=function(a){"empty"===a.find("input.csb-clone-state").val()&&(a.addClass("wpmui-loading"),window.wpWidgets.save(a,0,1,0))},n=function(a){b.find(".widget[data-reload]").each(function(){var a=jQuery(this);a.find("input.csb-clone-state").val("empty"),a.removeAttr("data-reload"),window.wpWidgets.save(a,0,0,0)})},o=function(a,b,c,d){var e="string"==typeof c.data?c.data:"",f=e.match(/^.*&action=([^&]+).*$/),g=e.match(/^.*&widget-id=([^&]+).*$/),h=f&&2===f.length?f[1]:"",i=g&&2===g.length?g[1]:"";if(i.length){var j=jQuery('.widget input.widget-id[value="'+i+'"]'),k=j.closest(".widget");switch(h){case"save-widget":k.removeClass("wpmui-loading"),d.length?d.match(/^deleted:/)?window.setTimeout(l,400):(l(),n()):m(k)}}};b.find(".widget").each(g),a.on("widget-added",g),a.on("widget-added",h),a.ajaxSuccess(o),l(),d()});