View file File name : astra-advanced-headers-admin-edit.min.js Content :!function(a){AstraPageTitleBarAdminEdit={_locationObjectCache:{},_init:function(){this._bind(),this._initNonce(),this._initLocationRules(),this._initUserRules()},_bind:function(){a(".ast-advanced-headers-saved-locations").delegate(".ast-advanced-headers-locations","change",this._locationSelectChanged),a(".ast-advanced-headers-saved-locations").delegate(".ast-advanced-headers-remove-location","click",this._removeLocationClicked),a(".ast-advanced-headers-add-location.button").on("click",this._addLocationClicked),a(".ast-advanced-headers-add-exclusion.button").on("click",this._addExclusionClicked),a(".ast-advanced-headers-saved-user-rules").delegate(".ast-advanced-headers-user-rule","change",this._userRuleSelectChanged),a(".ast-advanced-headers-add-user-rule.button").on("click",this._addUserRuleClicked),a(".ast-advanced-headers-saved-user-rules").delegate(".ast-advanced-headers-remove-user-rule","click",this._removeUserRuleClicked)},_initNonce:function(){a("#post").append('<input type="hidden" name="astra-advanced-headers-nonce" value="'+AstraAdvancedHeadersConfig.nonce+'" />')},_initLocationRules:function(){var b=a(".ast-advanced-headers-exclusion-rules"),c=a(".ast-advanced-headers-add-exclusion");a(".ast-advanced-headers-location-rules").each(this._initLocations),AstraAdvancedHeadersConfig.exclusions.saved.length>0&&(b.show(),c.hide())},_initLocations:function(){var b=a(this),c=b.find(".ast-advanced-headers-saved-locations"),d=wp.template("ast-advanced-headers-saved-location"),e=null,f=null,g=null,h=null,i=null,j=null,k=null,l=null,m=null,n=0;if(b.hasClass("ast-advanced-headers-exclusion-rules")?(e="exclusion",f=AstraAdvancedHeadersConfig.exclusions):(e="location",f=AstraAdvancedHeadersConfig.locations),0===f.saved.length)c.append(d({type:e})),"exclusion"==e&&c.find(".ast-advanced-headers-remove-rule-button").show();else{for(;n<f.saved.length;n++)c.append(d({type:e})),g=f.saved[n].split(":"),h=b.find(".ast-advanced-headers-saved-location").last(),i=h.find(".ast-advanced-headers-locations"),k=h.find(".ast-advanced-headers-location-objects"),"post"==g[0]||"taxonomy"==g[0]?g.length<=3?(j=g[0]+":"+g[1],l=f[g[0]][g[1]],m=3===g.length?g[2]:void 0):(j=g[0]+":"+g[1]+":"+g[2]+":"+g[3],l=f[g[2]][g[3]],m=5===g.length?g[4]:void 0):j=g[0]+":"+g[1],h.find('[data-location="'+j+'"]').attr("selected","selected"),"post"!=g[0]&&"taxonomy"!=g[0]||AstraPageTitleBarAdminEdit._showLocationObjectSelect(k.parent(),l,m);c.find(".ast-advanced-headers-remove-rule-button").show()}AstraPageTitleBarAdminEdit._removeLocationOptions(),AstraPageTitleBarAdminEdit._removeLocationObjectOptions()},_removeLocationOptions:function(){a(".ast-advanced-headers-locations-form").show(),a('.ast-advanced-headers-exclusion-rules option[data-location="general:site"]').remove(),a(".ast-advanced-headers-location optgroup").filter(function(){return""===a.trim(a(this).text())}).remove()},_removeLocationObjectOptions:function(){a(".ast-advanced-headers-location-objects").each(function(){var b=a(this),c=null,d=b.attr("data-location");/post:[a-zA-Z0-9_-]+:post:[a-zA-Z0-9_-]+$/.test(d)&&(c=b.find("option").eq(0),""===c.attr("value")&&c.remove())})},_locationSelectChanged:function(){var b=AstraPageTitleBarAdminEdit,c=a(this),d=c.closest(".ast-advanced-headers-location-rules"),e=c.parent(),f=d.find(".ast-advanced-headers-saved-location"),g=c.val(),h="",i=d.find(".ast-advanced-headers-saved-locations .ast-advanced-headers-remove-rule-button"),j="terms";""==g?(e.removeClass("ast-advanced-headers-rule-objects-visible"),1===f.length&&i.hide()):(g=JSON.parse(g),h=g.type+":"+g.id,"taxonomy"==g.type||"post"==g.type?"undefined"!=typeof b._locationObjectCache[h]?b._showLocationObjectSelect(e,b._locationObjectCache[h]):(b._showRowLoading(c),"post"==g.type&&(g.id.indexOf(":taxonomy")>-1?(j="terms",g.id=g.id.split(":taxonomy:")[1]):j="posts"),a.post(ajaxurl,{action:"astra_advanced_headers_get_location_"+j,id:g.id,nonce:AstraAdvancedHeadersConfig.nonce},function(a){AstraPageTitleBarAdminEdit._showLocationObjectSelect(e,JSON.parse(a))})):e.removeClass("ast-advanced-headers-rule-objects-visible"),i.show())},_showLocationObjectSelect:function(a,b,c){for(var d=a.find(".ast-advanced-headers-locations"),e=JSON.parse(d.val()),f=e.type+":"+e.id,g=a.find(".ast-advanced-headers-location-objects"),h=null,a=g.parent(),i=AstraAdvancedHeadersConfig.strings.allObjects.replace("%s",b.label),j='<option value="" data-location="'+f+'">'+i+"</option>",k=null,l=0;l<b.objects.length;l++)h=' data-location="'+f+":"+b.objects[l].id+'"',k="undefined"!=typeof c&&c==b.objects[l].id?" selected":"",j+="<option value='"+JSON.stringify(b.objects[l])+"'"+k+h+">"+b.objects[l].name+"</option>";g.html(j),g.attr("data-location",f),g.attr("data-type",b.type),a.addClass("ast-advanced-headers-rule-objects-visible"),this._locationObjectCache[f]=b,AstraPageTitleBarAdminEdit._hideRowLoading(d),"disabled"==g.find("option").eq(0).attr("disabled")&&g.find("option").eq(1).attr("selected","selected"),AstraPageTitleBarAdminEdit._removeLocationObjectOptions()},_addLocationClicked:function(b){var c=AstraPageTitleBarAdminEdit,d=a(this).closest(".ast-advanced-headers-location-rules"),e=d.find(".ast-advanced-headers-saved-locations"),f=wp.template("ast-advanced-headers-saved-location"),g=d.hasClass("ast-advanced-headers-exclusion-rules")?"exclusion":"location";e.append(f({type:g})),e.find(".ast-advanced-headers-remove-rule-button").show(),c._removeLocationOptions()},_removeLocationClicked:function(b){var c=a(b.target),d=c.closest(".ast-advanced-headers-location-rules"),e=c.parents(".ast-advanced-headers-saved-location"),f=e.find(".ast-advanced-headers-locations"),g=d.find(".ast-advanced-headers-saved-location"),h=d.find(".ast-advanced-headers-saved-locations .ast-advanced-headers-remove-rule-button"),i=!!c.closest(".ast-advanced-headers-exclusion-rules").length;g.length>1&&c.closest(".ast-advanced-headers-saved-location").remove(),1===g.length?(f.val("").parent().removeClass("ast-advanced-headers-rule-objects-visible"),i||h.hide(),i&&(a(".ast-advanced-headers-exclusion-rules").hide(),a(".ast-advanced-headers-add-exclusion").show())):i||2!==g.length||""!=d.find(".ast-advanced-headers-locations").eq(0).val()||h.hide()},_addExclusionClicked:function(b){var c=a(".ast-advanced-headers-add-exclusion"),d=a(".ast-advanced-headers-exclusion-rules");c.hide(),d.show()},_initUserRules:function(){var b=AstraAdvancedHeadersConfig.userRules,c=a(".ast-advanced-headers-saved-user-rules"),d=wp.template("ast-advanced-headers-saved-user-rule"),e=null,f=null,g=null,h=0;if(0===b.length)return c.append(d()),void c.find('[data-rule="general:all"]').attr("selected","selected");for(;h<b.length;h++)c.append(d()),parts=b[h].split(":"),e=a(".ast-advanced-headers-saved-user-rule").last(),f=e.find(".ast-advanced-headers-user-rule"),g=e.find('[data-rule="'+parts[0]+":"+parts[1]+'"]'),g.attr("selected","selected");c.find(".ast-advanced-headers-remove-rule-button").show()},_userRuleSelectChanged:function(b){var c=a(b.target).val(),d=a(".ast-advanced-headers-saved-user-rule"),e=a(".ast-advanced-headers-saved-user-rules .ast-advanced-headers-remove-rule-button");""==c?1===d.length&&e.hide():e.show()},_addUserRuleClicked:function(b){var c=a(".ast-advanced-headers-saved-user-rules"),d=wp.template("ast-advanced-headers-saved-user-rule");c.append(d()),c.find(".ast-advanced-headers-remove-rule-button").show()},_removeUserRuleClicked:function(b){var c=a(b.target),d=c.parents(".ast-advanced-headers-saved-user-rule"),e=d.find(".ast-advanced-headers-user-rule"),f=a(".ast-advanced-headers-saved-user-rule"),g=a(".ast-advanced-headers-saved-user-rules .ast-advanced-headers-remove-rule-button");f.length>1&&c.closest(".ast-advanced-headers-saved-user-rule").remove(),1===f.length?(e.val(""),g.hide()):2===f.length&&""==a(".ast-advanced-headers-user-rule").val()&&g.hide()},_showLoading:function(){var b=a("#astra_page_header_settings h2.hndle span");b.find(".spinner").length||b.append('<span class="spinner"></span>')},_hideLoading:function(){a("#astra_page_header_settings h2.hndle .spinner").remove()},_showRowLoading:function(a){a.closest(".ast-advanced-headers-row-content").prepend('<div class="spinner ast-advanced-headers-loading"></div>')},_hideRowLoading:function(a){a.closest(".ast-advanced-headers-row-content").find(".spinner.ast-advanced-headers-loading").remove()}},a(function(){AstraPageTitleBarAdminEdit._init()})}(jQuery);