!function(e,t){e.customize.SocialButtonsControl=e.customize.Control.extend({ready:function(){function o(e){var o=[];t(".social-button",e).each(function(){var e,i;i=t("select.social",this).val(),"custom"==i&&(i=t(".custom-social input",this).val()),css_class=t("input.css-class",this).val(),e=t("input.url",this).val(),o.push({social:i,css_class:css_class,url:e})}),i.setting.set(o)}var i=this,s=t(".social-buttons",this.container),n=t(".add-social-button",this.container),r=this.setting.get(),l=this.params.socials,a=e.template("social-button");t.each(r,function(e,t){var o,i=t.social,n=t.url,r=t.css_class;o="custom",l[i]&&(o=i),s.append(a({social:o,social_value:i,url:n,css_class:r,editing:!1}))}),n.on("click",function(e){e.preventDefault();var o=t(".social-buttons",t(this).closest(".customize-control-content")),i=t(a({social:"",social_value:"",url:"",css_class:"",editing:!0}));i.appendTo(o).find(".fields select.social").trigger("change"),t(".wp-full-overlay-sidebar-content").animate({scrollTop:t(".social-button:last-of-type",o).offset().top},500)}),s.on("change",".social-button select.social",function(){var e=t(".custom-social",t(this).closest(".social-button"));e.hide(),"custom"==t(this).val()&&e.show()}),s.on("change","select, input",function(){var e,i,s=t(this).closest(".social-button"),n=s.closest(".social-buttons"),r=t(".fields select.social",s).val(),d=t(".fields input.url",s).val();e="custom",l[r]&&(e=r),i=e,i.replace(/[^a-z0-9]/g,function(e){var t=e.charCodeAt(0);return 32==t?"-":t>=65&&90>=t?e.toLowerCase():"__"+("000"+t.toString(16)).slice(-4)}),s.replaceWith(a({social:e,social_value:r,url:d,css_class:i,editing:!0})),o(n)}),s.on("click",".social-button .preview .social-button-preview",function(e){e.preventDefault();var o=t(this).closest(".social-button"),i=t(".fields",o);i.toggle()}),s.on("click",".social-button .preview .remove-button",function(e){e.preventDefault();var i=t(this).closest(".social-button"),s=i.closest(".social-buttons");i.remove(),o(s)}),s.on("click",".social-button .preview .reorder-button",function(e){e.preventDefault();var i=t(this).closest(".social-button"),s=t(this).hasClass("move-up")?!0:!1,n=i.closest(".social-buttons");if(!(s&&i.is(":first-of-type")||!s&&i.is(":last-of-type"))){if(s){var r=i.prev(".social-button");r.before(i.clone())}else{var l=i.next(".social-button");l.after(i.clone())}i.remove(),o(n)}})}}),t.extend(e.customize.controlConstructor,{"social-buttons":e.customize.SocialButtonsControl})}(wp,jQuery);