/*! Custom Sidebars - v3.0.5 * https://premium.wpmudev.org/project/custom-sidebars-pro/ * Copyright (c) 2017; * Licensed GPLv2+ */ jQuery(function(){var a=jQuery(document),b=jQuery("#widgets-right"),c=!1,d=function(a,b){var c=jQuery(b).closest(".widget"),d=c.find(".csb-clone-button"),e=c.find(".widget-control-actions .widget-control-save"),f=c.find(".widget-control-actions .spinner"),g=c.find(".widget-control-save");c.data("_csb_cloning")||(f.insertBefore(e).css({float:"left"}),d.insertBefore(e).click(k),g.click(m),c.data("_csb_cloning",!0))},e=function(a,d){if(c)return!1;for(var e=jQuery(d).closest(".widget"),g=e.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),f()},f=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)},g=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"))},h=function(a){jQuery(".widget.csb-marker").removeClass("csb-marker")},i=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(g,h).click(j))})},j=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),h()):(c.addClass("group-active"),d.addClass("dashicons-admin-links").removeClass("dashicons-editor-unlink"),e.val(e.data("group")),g.call(this,[a])),!1},k=function(a){var b=jQuery(this).closest(".widget"),d=jQuery("#widgets-left"),e=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(),e.slideUp(200,function(){e.hide(),g.append(this)});var h=b.find("input.id_base").val(),i=d.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 e.find(".widgets-chooser-selected").removeClass("widgets-chooser-selected"),e.find("li").each(function(){var a=jQuery(this);o===a.data("sidebarId")&&a.addClass("widgets-chooser-selected").focus()}),window.wpWidgets.addWidget(e),window.wpWidgets.clearWidgetSelection(),f(),c=!1,!1},l=function(a){"empty"===a.find("input.csb-clone-state").val()&&(a.addClass("wpmui-loading"),window.wpWidgets.save(a,0,1,0))},m=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)})},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]:"",j=g&&2===g.length?g[1]:"";if(j.length){var k=jQuery('.widget input.widget-id[value="'+j+'"]'),m=k.closest(".widget");switch(h){case"save-widget":m.removeClass("wpmui-loading"),d.length?d.match(/^deleted:/)?window.setTimeout(i,400):(i(),n()):l(m)}}};b.find(".widget").each(d),a.on("widget-added",d),a.on("widget-added",e),a.ajaxSuccess(o),i(),f()});