Files
SIGE-WEB-snapshot/wp-content/plugins/conditional-menus/assets/admin.js

1 line
5.3 KiB
JavaScript

!function($,t,i){"use strict";var n,e,c,o=[],a="";function m(i=t.body){let n=i.getElementsByClassName("themify_cm_loader")[0];n||(n=t.createElement("div"),n.className="themify_cm_loader",i.prepend(n)),n.classList.add("busy")}function s(i=t.body){const n=i.getElementsByClassName("themify_cm_loader")[0];n&&n.classList.remove("busy")}function l(t){t||(t=e);const i=t.querySelectorAll('input[type="checkbox"]');for(let t=0;t<i.length;t++)i[t].checked=a.includes(i[t].name+"=on")}function r(){var i=t;return Math.max(Math.max(i.body.scrollHeight,i.documentElement.scrollHeight),Math.max(i.body.offsetHeight,i.documentElement.offsetHeight),Math.max(i.body.clientHeight,i.documentElement.clientHeight))}function y(t,n,e,c){var a=t.clone().removeClass("cm-location");a.find(".menu-location-title").empty();var m=a.find("select").attr("name").match(/menu-locations\[(.*)\]/)[1];null==n&&(void 0===o[m]&&(o[m]=parseInt($(function(t){var i=[];for(var n in t)t.hasOwnProperty(n)&&i.push(n);return i}(i.options[m])).last()[0]),$.isNumeric(o[m])||(o[m]=1)),n=o[m]++),a.find("select").find('option[value="0"]').text(i.lang.disable_menu).before('<option value=""></option>').end().val(e).attr("name","themify_cm["+m+"]["+n+"][menu]"),(a=function(t,n,e,c){return c=c||"",t.find(".locations-row-links").empty().html('<input type="hidden" data-id="'+e+'" name="'+n+"\" value='"+c+'\' /><a href="#" class="themify-cm-conditions">'+i.lang.conditions+'</a> <a class="themify-cm-remove" href="#">x</a>'),t}(a,"themify_cm["+m+"]["+n+"][condition]",n,c)).insertBefore(jQuery('.menu-locations tr[data-menu="'+m+'"]'));var s=$(".menu-location-menus select").length,l=$(".cm-replacement-button").length+1;a.find(".menu-location-menus").attr("data-item",m+n),s===l&&$(".themify-cm-conditions-container:first").addClass("themify-cm-conditions-container-"+m+n).data("item",m+n),s>l&&$(".themify-cm-conditions-container:first").clone().removeClass().addClass("themify-cm-conditions-container themify-admin-lightbox tf_clearfix themify-cm-conditions-container-"+m+n).data("item",m+n).insertAfter(".themify-cm-conditions-container:last")}$(".menu-locations .locations-row-links").empty(),$("body").on("click",".themify-cm-conditions",(function(o){o.preventDefault(),a=decodeURI((n=this.previousElementSibling).value);var y=$(t).scrollTop()+80;return e||(m(),$.ajax({type:"POST",url:ajaxurl,async:!1,data:{action:"themify_cm_get_conditions",nonce:i.nonce},success(i){s();const n=t.createElement("template");n.innerHTML=i,t.body.appendChild(n.content)}}),e=t.getElementById("themify-cm-conditions"),c=t.getElementById("themify-cm-overlay")),l(),c.style.display="block",$(e).show().css("top",r()).animate({top:y},800),$("#visibility-tabs",e).tabs(),$("#visibility-tabs .themify-visibility-inner-tabs",e).tabs(),!1})).on("click","#visibility-tabs .themify_cm_load_ajax, #visibility-tabs .inline-tabs a",(function(t){let n=this.dataset.type,c=e.querySelector(this.getAttribute("href"));n?c.getElementsByClassName("themify-visibility-items-page-1")[0]||$.ajax({url:ajaxurl,type:"post",data:{action:"themify_cm_create_inner_page",nonce:i.nonce,type:n},beforeSend(){m()},success(t){s(),c.firstElementChild.innerHTML=t,l(c)}}):c.querySelector(".inline-tabs .ui-tabs-active a").click()})).on("click",".themify-visibility-pagination a.page-numbers",(function(n){n.preventDefault();const c=parseInt(this.getAttribute("href")),o=this.closest(".themify-visibility-items-inner"),a=o.getElementsByClassName("themify-visibility-items-page");o.getElementsByClassName("themify-visibility-items-page-"+c)[0]||$.ajax({url:ajaxurl,async:!1,type:"post",data:{action:"themify_cm_create_inner_page",type:(this.closest(".themify-visibility-inner-tab")?this.closest(".themify-visibility-inner-tabs"):e).querySelector(".ui-tabs-active a").dataset.type,paged:c,nonce:i.nonce},beforeSend(){m()},success(i){s();const n=t.createElement("template");n.innerHTML=i,l(n.content),o.appendChild(n.content)}});for(let t=0;t<a.length;t++)a[t].style.display=a[t].classList.contains("themify-visibility-items-page-"+c)?"block":"none"})).on("change",'.themify-cm-conditions-container input[type="checkbox"]',(function(){this.checked?a+="&"+this.name+"=on":a=a.replace(this.name+"=on","")})).on("click",".themify-cm-close, #themify-cm-overlay",(t=>(t.preventDefault(),$(e).animate({top:r()},800,(()=>{c.style.display="none",e.style.display="none",a="",l()})),!1))).on("click",".themify-mc-add-assignment",(function(){return y($("#locations-"+$(this).closest("tr").attr("data-menu")).closest("tr")),!1})).on("click",".themify-cm-save",(()=>(n.value=a,$(".menu-location-menus[data-item="+n.dataset.id+"]").val(a),c.click(),!1))).on("click",".themify-cm-remove",(function(){return $(this).closest("tr").fadeOut((function(){$(this).remove()})),!1})).on("click",".themify-cm-conditions-container .uncheck-all",(t=>{t.preventDefault(),a="",l()})).on("click",".themify-cm-conditions-container .themify_apply_all_conditions",(()=>{})),window.addEventListener("load",(()=>{$.each(i.nav_menus,((t,n)=>{$("#locations-"+n).closest("tr").after('<tr class="cm-replacement-button" data-menu="'+n+'"><td>&nbsp;</td><td><a href="#" class="themify-mc-add-assignment">'+i.lang.add_assignment+"</a></td></tr>")})),$.each(i.options,((t,i)=>{"object"==typeof i&&$.each(i,((i,n)=>{y($("#locations-"+t).closest("tr"),i,n.menu,n.condition),o[t]=++i}))})),$("#themify_cm_nonce").appendTo($(".menu-locations").closest("form"))}))}(jQuery,document,themify_cm);