/*! Custom Sidebars - v2.1.08 * http://premium.wpmudev.org/project/the-pop-over-plugin/ * Copyright (c) 2016; * Licensed GPLv2+ */ function trim(e){e=e.replace(/^\s\s*/,"");for(var i=e.length-1;i>=0;i--)if(/\S/.test(e.charAt(i))){e=e.substring(0,i+1);break}return e}function CsSidebar(e,i){var t;this.id=e.split("%").join("\\%"),this.type=i,this.sb=jQuery("#"+this.id),this.widgets="",this.name=trim(this.sb.find(".sidebar-name h3").text()),this.description=trim(this.sb.find(".sidebar-description").text()),t="custom"===i?window.csSidebars.extras.find(".cs-custom-sidebar").clone():window.csSidebars.extras.find(".cs-theme-sidebar").clone(),this.sb.parent().append(t),t.find("label").each(function(){var i=jQuery(this);window.csSidebars.addIdToLabel(i,e)})}CsSidebar.prototype.getID=function(){return this.id.split("\\").join("")},window.csSidebars=null,function(){window.csSidebars={sidebars:[],sidebar_prefix:"cs-",edit_form:null,delete_form:null,export_form:null,location_form:null,right:null,extras:null,action_handlers:{},init:function(){"undefined"!=typeof csSidebarsData&&csSidebars.initControls().initTopTools().initSidebars().initToolbars().initColumns()},initControls:function(){return csSidebars.right=jQuery("#widgets-right"),csSidebars.extras=jQuery("#cs-widgets-extra"),null===csSidebars.edit_form&&(csSidebars.edit_form=csSidebars.extras.find(".cs-editor").clone(),csSidebars.extras.find(".cs-editor").remove()),null===csSidebars.delete_form&&(csSidebars.delete_form=csSidebars.extras.find(".cs-delete").clone(),csSidebars.extras.find(".cs-delete").remove()),null===csSidebars.export_form&&(csSidebars.export_form=csSidebars.extras.find(".cs-export").clone(),csSidebars.extras.find(".cs-export").remove()),null===csSidebars.location_form&&(csSidebars.location_form=csSidebars.extras.find(".cs-location").clone(),csSidebars.extras.find(".cs-location").remove()),jQuery("#cs-title-options").detach().prependTo(csSidebars.right),csSidebars},initColumns:function(){function e(){var e=jQuery(this),i=e.closest(".sidebars-column-1, .sidebars-column-2"),t=i.data("sort-dir");t="asc"===t?"desc":"asc",csSidebars.sort_sidebars(i,t)}var i=csSidebars.right.find(".sidebars-column-1"),t=csSidebars.right.find(".sidebars-column-2"),s=jQuery('

'),a=csSidebars.right.find(".widgets-holder-wrap");t.length||(t=jQuery(''),t.appendTo(csSidebars.right)),s.find("h3").append('').css({cursor:"pointer"}),s.clone().prependTo(i).click(e).find(".cs-title-val").text(csSidebarsData.custom_sidebars),s.clone().prependTo(t).click(e).find(".cs-title-val").text(csSidebarsData.theme_sidebars),i=jQuery('
').appendTo(i),t=jQuery('
').appendTo(t),a.each(function(){var e=jQuery(this),s=e.find(".widgets-sortables");csSidebars.isCustomSidebar(s)?e.appendTo(i):e.appendTo(t)})},initSidebars:function(){return csSidebars.right.find(".widgets-sortables").each(function(){var e,i,t=!1,s=jQuery(this),a=s.attr("id");if(s.data("cs-init")!==!0)if(s.data("cs-init",!0),csSidebars.isCustomSidebar(this))i=csSidebars.add(a,"custom");else{i=csSidebars.add(a,"theme");for(e in csSidebarsData.replaceable)if(csSidebarsData.replaceable.hasOwnProperty(e)&&csSidebarsData.replaceable[e]===a){t=!0;break}csSidebars.setReplaceable(i,t,!1)}}),csSidebars},initTopTools:function(){var e=jQuery(".btn-create-sidebar"),i=jQuery(".btn-export"),t=jQuery(".cs-options"),s=jQuery(''),a={};return e.click(function(){a.id="",a.title=csSidebarsData.title_new,a.button=csSidebarsData.btn_new,a.description="",a.name="",csSidebars.showEditor(a)}),i.click(csSidebars.showExport),s.appendTo(t).attr("placeholder",csSidebarsData.filter).keyup(csSidebars.filter_sidebars).on("search",csSidebars.filter_sidebars),csSidebars},initToolbars:function(){function e(e){var i=jQuery(e.target).closest(".cs-tool"),t=i.data("action"),s=csSidebars.getIdFromEditbar(i),a=csSidebars.find(s);return!csSidebars.handleAction(t,a)}return csSidebars.registerAction("edit",csSidebars.showEditor),csSidebars.registerAction("location",csSidebars.showLocations),csSidebars.registerAction("delete",csSidebars.showRemove),csSidebars.registerAction("replaceable",csSidebars.setReplaceable),csSidebars.right.on("click",".cs-tool",e),csSidebars},handleAction:function(e,i){return"function"==typeof csSidebars.action_handlers[e]?!!csSidebars.action_handlers[e](i):!1},registerAction:function(e,i){csSidebars.action_handlers[e]=i},showAjaxError:function(e){var i={};i.message=csSidebarsData.ajax_error,i.details=e,i.parent="#widgets-right",i.insert_after="#cs-title-options",i.id="editor",i.type="err",wpmUi.message(i)},sort_sidebars:function(e,i){var t=e.find(".widgets-holder-wrap"),s=e.find(".cs-title .cs-icon");t.sortElements(function(e,t){var s=jQuery(e).find(".sidebar-name h3").text(),a=jQuery(t).find(".sidebar-name h3").text();return"asc"===i?s>a?1:-1:a>s?1:-1}),e.data("sort-dir",i),"asc"===i?s.removeClass("dashicons-arrow-down dashicons-sort").addClass("dashicons-arrow-up"):s.removeClass("dashicons-arrow-up dashicons-sort").addClass("dashicons-arrow-down")},filter_sidebars:function(){var e=jQuery("input.cs-filter").val().toLowerCase(),i=csSidebars.right.find(".widgets-holder-wrap");i.each(function(){var i=jQuery(this),t=i.find(".sidebar-name h3").text();-1!==t.toLowerCase().indexOf(e)?i.show():i.hide()}),jQuery(window).trigger("cs-resize")},showEditor:function(e){function i(){o.$().removeClass("csb-has-more"),o.size(782,215)}function t(){o.$().addClass("csb-has-more"),o.size(782,545)}function s(){jQuery(this).prop("checked")?t():i()}function a(e,i){return o.loading(!1),e?i?(e.sidebar&&(e=e.sidebar),e.id&&o.$().find("#csb-id").val(e.id),e.name&&o.$().find("#csb-name").val(e.name),e.description&&o.$().find("#csb-description").val(e.description),e.before_title&&o.$().find("#csb-before-title").val(e.before_title),e.after_title&&o.$().find("#csb-after-title").val(e.after_title),e.before_widget&&o.$().find("#csb-before-widget").val(e.before_widget),e.after_widget&&o.$().find("#csb-after-widget").val(e.after_widget),e.button&&o.$().find(".btn-save").text(e.button),void 0):(o.destroy(),csSidebars.showAjaxError(e),!1):!1}function r(e,i){var t,s={};o.loading(!1),o.destroy(),s.message=e.message,s.parent="#widgets-right",s.insert_after="#cs-title-options",s.id="editor",i?"update"===e.action?(t=csSidebars.find(e.data.id),csSidebars.updateSidebar(t,e.data)):"insert"===e.action&&csSidebars.insertSidebar(e.data):s.type="err",wpmUi.message(s)}function n(){var e=o.$().find("form");return o.loading(!0),d.reset().data(e).ondone(r).load_json(),!1}var o=null,d=null;return e instanceof CsSidebar&&(e={id:e.getID(),title:csSidebarsData.title_edit.replace("[Sidebar]",e.name),button:csSidebarsData.btn_edit}),o=wpmUi.popup().modal(!0).title(e.title).onshow(i).content(csSidebars.edit_form),i(),a(e,!0,null),d=wpmUi.ajax(null,"cs-ajax"),e.id&&(o.loading(!0),d.reset().data({"do":"get",sb:e.id}).ondone(a).load_json()),o.show(),o.$().find("#csb-name").focus(),o.$().on("click","#csb-more",s),o.$().on("click",".btn-save",n),o.$().on("click",".btn-cancel",o.destroy),!0},updateSidebar:function(e,i){return e.sb.find(".sidebar-name h3").text(i.name),e.sb.find(".sidebar-description").html('

').find(".description").text(i.description),csSidebars},insertSidebar:function(e){var i=jQuery('
'),t=jQuery('
'),s=jQuery(''),a=jQuery(''),r=csSidebars.right.find(".sidebars-column-1 > .inner:first");return t.attr("id",e.id),s.find("h3").text(e.name),a.html('

').find(".description").text(e.description),s.appendTo(t),a.appendTo(t),t.appendTo(i),i.prependTo(r),jQuery("#widgets-right .sidebar-name").unbind("click"),jQuery("#widgets-left .sidebar-name").unbind("click"),jQuery(document.body).unbind("click.widgets-toggle"),jQuery(".widgets-chooser").off("click.widgets-chooser").off("keyup.widgets-chooser"),jQuery("#available-widgets .widget .widget-title").off("click.widgets-chooser"),jQuery(".widgets-chooser-sidebars").empty(),window.wpWidgets.init(),csSidebars.initSidebars(),csSidebars},showExport:function(){function e(e){var i=jQuery(this).closest("form");return o.reset().data(i).load_http(),n.destroy(),e.preventDefault(),!1}function i(e,i){var t={};n.loading(!1),i?n.size(900,600).content(e.html):(t.message=e.message,t.parent=n.$().find(".wpmui-wnd-content"),t.insert_after=!1,t.id="export",t["class"]="wpmui-wnd-err",t.type="err",wpmUi.message(t))}function t(e){var t=jQuery(this).closest("form");return n.loading(!0),o.reset().data(t).ondone(i).load_json("cs-ajax"),e.preventDefault(),!1}function s(){var e=jQuery(this),i=e.prop("checked"),t=n.$().find(".column-widgets, .import-widgets");i?t.show():t.hide()}function a(){n.size(782,480),n.content(csSidebars.export_form)}function r(){var e=n.$().find(".frm-import");n.loading(!0),o.reset().data(e).load_http("_self")}var n=null,o=null;return n=wpmUi.popup().modal(!0).size(782,480).title(csSidebarsData.title_export).content(csSidebars.export_form).show(),o=wpmUi.ajax(null,"cs-ajax"),n.$().on("submit",".frm-export",e),n.$().on("submit",".frm-preview-import",t),n.$().on("change","#import-widgets",s),n.$().on("click",".btn-cancel",a),n.$().on("click",".btn-import",r),!0},showRemove:function(e){function i(e){e.find(".name").text(d)}function t(){r.loading(!1),r.destroy()}function s(e,i){var t={};r.loading(!1),r.destroy(),t.message=e.message,t.parent="#widgets-right",t.insert_after="#cs-title-options",t.id="editor",i?(csSidebars.right.find("#"+o).closest(".widgets-holder-wrap").remove(),csSidebars.remove(o)):t.type="err",wpmUi.message(t)}function a(){r.loading(!0),n.reset().data({"do":"delete",sb:o}).ondone(s).load_json()}var r=null,n=null,o=e.getID(),d=e.name;return r=wpmUi.popup().modal(!0).size(560,160).title(csSidebarsData.title_delete).content(csSidebars.delete_form).onshow(i).show(),n=wpmUi.ajax(null,"cs-ajax"),r.$().on("click",".btn-cancel",t),r.$().on("click",".btn-delete",a),!0},showLocations:function(e){function i(e,i){function t(e,i,t){var s=jQuery("");s.attr("value",t).text(e.name),i.append(s)}function s(e,i,t,s){var a=s.closest(".cs-replaceable").filter("."+i),r=a.find('option[value="'+t+'"]'),n=a.find("optgroup.used"),o=a.find(".detail-toggle");e===d?(r.prop("selected",!0),!0!==o.prop("checked")&&(o.prop("checked",!0),a.addClass("open"),wpmUi.upgrade_multiselect(a))):(n.length||(n=jQuery('').attr("label",a.data("lbl-used")).appendTo(a.find(".details select"))),r.detach().appendTo(n))}var a,n,o;if(r.loading(!1),!i)return r.destroy(),csSidebars.showAjaxError(e),void 0;r.$().find(".sb-name").text(e.sidebar.name);var d=e.sidebar.id,c=r.$().find(".cs-replaceable");c.hide(),e.replaceable=wpmUi.obj(e.replaceable);for(var l in e.replaceable)e.replaceable.hasOwnProperty(l)&&c.filter("."+e.replaceable[l]).show();var u=r.$().find(".cs-datalist.cs-cat"),f=r.$().find(".cs-datalist.cs-arc-cat"),b=e.categories;f.empty(),u.empty();for(var p in b)t(b[p],f,p),t(b[p],u,p);for(var h in b){if(b[h].single)for(a in b[h].single)s(b[h].single[a],a,h,u);if(b[h].archive)for(a in b[h].archive)s(b[h].archive[a],a,h,f)}var g=r.$().find(".cs-datalist.cs-pt"),v=e.posttypes;g.empty();for(var w in v)n=jQuery(""),o=v[w].name,n.attr("value",w).text(o),g.append(n);for(var m in v)if(v[m].single)for(a in v[m].single)s(v[m].single[a],a,m,g);var y=r.$().find(".cs-datalist.cs-arc"),S=e.archives;y.empty();for(var j in S)n=jQuery(""),o=S[j].name,n.attr("value",j).text(o),y.append(n);for(var Q in S)if(S[Q].archive)for(a in S[Q].archive)s(S[Q].archive[a],a,Q,y);var _=r.$().find(".cs-datalist.cs-arc-aut"),x=e.authors;_.empty();for(var k in x)n=jQuery(""),o=x[k].name,n.attr("value",k).text(o),_.append(n);for(var C in x)if(x[C].archive)for(a in x[C].archive)s(x[C].archive[a],a,C,_)}function t(){var e=jQuery(this),i=e.closest(".cs-replaceable"),t=i.find("select");e.prop("checked")?(i.addClass("open"),wpmUi.upgrade_multiselect(i),t.trigger("change.select2")):(i.removeClass("open"),t.val([]))}function s(e,i){var t={};r.loading(!1),r.destroy(),t.message=e.message,t.parent="#widgets-right",t.insert_after="#cs-title-options",t.id="editor",i||(t.type="err"),wpmUi.message(t)}function a(){r.loading(!0),n.reset().data(o).ondone(s).load_json()}var r=null,n=null,o=null,d=e.getID();return r=wpmUi.popup().modal(!0).size(782,560).title(csSidebarsData.title_location).content(csSidebars.location_form).show(),r.loading(!0),o=r.$().find(".frm-location"),o.find(".sb-id").val(d),n=wpmUi.ajax(null,"cs-ajax"),n.reset().data({"do":"get-location",sb:d}).ondone(i).load_json(),r.$().on("click",".detail-toggle",t),r.$().on("click",".btn-save",a),r.$().on("click",".btn-cancel",r.destroy),!0},setReplaceable:function(e,i,t){function s(e){e instanceof Object&&"object"==typeof e.replaceable&&(csSidebarsData.replaceable=wpmUi.obj(e.replaceable),r.find(".widgets-sortables").each(function(){var e=!1,i=jQuery(this),t=i.attr("id"),s=csSidebars.find(t);for(var a in csSidebarsData.replaceable)if(csSidebarsData.replaceable.hasOwnProperty(a)&&csSidebarsData.replaceable[a]===t){e=!0;break}csSidebars.setReplaceable(s,e,!1)})),r.find(".cs-toolbar .chk-replaceable").prop("disabled",!1),r.find(".cs-toolbar .btn-replaceable").removeClass("wpmui-loading")}var a,r=csSidebars.right.find(".sidebars-column-2 .widgets-holder-wrap"),n=jQuery(e.sb).closest(".widgets-holder-wrap"),o=n.find(".cs-toolbar .chk-replaceable"),d=n.find(".replace-marker");return n.find(".cs-toolbar .btn-replaceable"),void 0===i&&(i=o.prop("checked")),void 0===t&&(t=!0),o.data("active")===i?!1:(o.data("active",i),o.prop("checked",i),i?(d.length||jQuery("
").appendTo(n).attr("data-label",csSidebarsData.lbl_replaceable).addClass("replace-marker"),n.addClass("replaceable")):(d.remove(),n.removeClass("replaceable")),t&&(r.find(".cs-toolbar .chk-replaceable").prop("disabled",!0),r.find(".cs-toolbar .btn-replaceable").addClass("wpmui-loading"),a=wpmUi.ajax(null,"cs-ajax"),a.reset().data({"do":"replaceable",state:i,sb:e.getID()}).ondone(s).load_json()),!1)},find:function(e){return csSidebars.sidebars[e]},add:function(e,i){return csSidebars.sidebars[e]=new CsSidebar(e,i),csSidebars.sidebars[e]},remove:function(e){delete csSidebars.sidebars[e]},isCustomSidebar:function(e){var i=jQuery(e).attr("id"),t=i.substr(0,csSidebars.sidebar_prefix.length);return t===csSidebars.sidebar_prefix},addIdToLabel:function(e,i){if(!0!==e.data("label-done")){var t=e.attr("for");e.attr("for",t+i),e.find(".has-label").attr("id",t+i),e.data("label-done",!0)}},getIdFromEditbar:function(e){var i=e.closest(".widgets-holder-wrap"),t=i.find(".widgets-sortables:first"),s=t.attr("id");return s}},jQuery(function(e){e("#csfooter").hide(),e("#widgets-right").length>0&&csSidebars.init(),e(".defaultsContainer").hide(),e("#widgets-right .widgets-sortables").on("sort",function(i,t){e("#widgets-right").top,t.position.top=-e("#widgets-right").css("top")})})}(jQuery),jQuery.fn.sortElements=function(){var e=[].sort;return function(i,t){t=t||function(){return this};var s=this.map(function(){var e=t.call(this),i=e.parentNode,s=i.insertBefore(document.createTextNode(""),e.nextSibling);return function(){if(i===this)throw Error("You can't sort elements if any one is a descendant of another.");i.insertBefore(this,s),i.removeChild(s)}});return e.call(this,i).each(function(e){s[e].call(t.call(this))})}}();