Files

1 line
5.3 KiB
JavaScript

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