artabro/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js
2024-08-27 11:35:37 +02:00

1 line
No EOL
9.8 KiB
JavaScript

var ProcessWireAdminTheme={init:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupDropdowns();this.setupSidebarNav();this.setupSideBarState();this.setupSideBarToggle();var $body=$("body");var $html=$("html");if($body.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0)$body.removeClass("hasWireTabs");$("#content").removeClass("pw-fouc-fix");$body.removeClass("pw-init").addClass("pw-ready");$html.removeClass("pw-init").addClass("pw-ready");$("a.notice-remove","#notices").on("click",function(){$("#notices").slideUp("fast",function(){$(this).remove();return false})})},setupSidebarNav:function(){var url=window.location.toString();$(document).on("mouseup",function(e){var quicklinks=$("ul.quicklinks");if(!quicklinks.is(e.target)&&quicklinks.has(e.target).length===0){quicklinks.hide();$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow")}});$(document).on("keydown",function(e){var type=e.target.tagName.toLowerCase();var firstClass=e.target.className.split(" ")[0];var state;if(type=="input"||type=="textarea"||firstClass=="InputfieldCKEditorInline")return;switch(e.which){case 37:state="open";break;case 39:state="closed";break;default:return}ProcessWireAdminTheme.setupSideBarState(true,state);e.preventDefault()});function closeOpenQuicklinks(){$("#main-nav > li > a.open:not(.hover-temp):not(.just-clicked)").each(function(){var $t=$(this);var $u=$t.next("ul:visible");if($u.length>0){if($u.find(".quicklinks-open").length>0)$u.find(".quicklink-close").trigger("click")}})}var clickTimer=null,numClicks=0;$("#main-nav a.parent").on("dblclick",function(e){e.preventDefault()}).on("click",function(){var $a=$(this);$a.addClass("just-clicked");numClicks++;if(numClicks===1){clickTimer=setTimeout(function(){closeOpenQuicklinks();$a.toggleClass("open").next("ul").slideToggle(200,function(){$a.removeClass("just-clicked")});numClicks=0},200)}else{clearTimeout(clickTimer);numClicks=0;window.location.href=$a.attr("href");return true}return false});var quicklinkTimer=null;$(".quicklink-open").on("click",function(event){closeOpenQuicklinks();var $this=$(this);$this.parent().addClass("quicklinks-open");$this.toggleClass("active").parent().next("ul.quicklinks").toggle();$this.parent().parent().siblings().find("ul.quicklinks").hide();$this.parent().parent().siblings().find(".quicklink-open").removeClass("active").parent("a").removeClass("quicklinks-open");$this.effect("pulsate",100);event.stopPropagation();$("#main-nav .current:not(.open)").addClass("no-arrow");var $ul=$(this).parent().next("ul.quicklinks");var jsonURL=$ul.attr("data-json");if(jsonURL.length>0&&!$ul.hasClass("json-loaded")){$ul.addClass("json-loaded");var $spinner=$ul.find(".quicklinks-spinner");var spinnerSavedClass=$spinner.attr("class");$spinner.removeClass(spinnerSavedClass).addClass("fa fa-fw fa-spin fa-spinner");$.getJSON(jsonURL,function(data){if(data.add){var $li=$("<li class='add'><a href='"+data.url+data.add.url+"'><i class='fa fa-fw fa-"+data.add.icon+"'></i>"+data.add.label+"</a></li>");$ul.append($li)}$.each(data.list,function(n){var icon="";var url=this.url.indexOf("/")===0?this.url:data.url+this.url;var $li=$("<li><a style='white-space:nowrap' href='"+url+"'>"+icon+this.label+"</a></li>");if(typeof this.className!="undefined"&&this.className&&this.className.length)$li.addClass(this.className);$ul.append($li)});$spinner.removeClass("fa-spin fa-spinner").addClass(spinnerSavedClass);if(data.icon.length>0)$spinner.removeClass("fa-bolt").addClass("fa-"+data.icon)})}return false}).on("mouseover",function(){var $this=$(this);if($this.parent().hasClass("quicklinks-open"))return;$this.addClass("hover-temp");clearTimeout(quicklinkTimer);quicklinkTimer=setTimeout(function(){if($this.parent().hasClass("quicklinks-open"))return;if($this.hasClass("hover-temp"))$this.trigger("click")},500)}).on("mouseout",function(){$(this).removeClass("hover-temp")});$(".quicklink-close").on("click",function(){$(this).parent().removeClass("quicklinks-open");$(this).closest("ul.quicklinks").hide().prev("a").removeClass("quicklinks-open");$(".quicklink-open").removeClass("active");$("#main-nav .current").removeClass("no-arrow");return false});$("#main-nav .parent").each(function(){var myHref=$(this).attr("href");if(url.match(myHref)){$(this).next("ul").show();$(this).addClass("open")}})},setupCloneButton:function(){if($("body").is(".modal"))return;var $buttons=$("button.pw-head-button, button.head_button_clone");if($buttons.length==0)return;var $head=$("<div id='head_button'></div>").prependTo("#headline").show();$buttons.each(function(){var $t=$(this);var $a=$t.parent("a");var $button;if($a.length){$button=$t.parent("a").clone();$head.append($button)}else if($t.hasClass("head_button_clone")||$t.hasClass("pw-head-button")){$button=$t.clone();$button.attr("data-from_id",$t.attr("id")).attr("id",$t.attr("id")+"_copy");$button.on("click",function(){$("#"+$(this).attr("data-from_id")).trigger("click");return false});$head.prepend($button)}})},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(ul,items){var that=this;var currentType="";ul.attr("id","ProcessPageSearchAutocomplete");$.each(items,function(index,item){if(item.type!=currentType){$("<li>"+item.type+"</li>").addClass("ui-widget-header").appendTo(ul);currentType=item.type}that._renderItemData(ul,item)})},_renderItem:function(ul,item){if(item.label==item.template)item.template="";var $label=$("<span></span>").text(item.label).css("margin-right","3px");if(item.unpublished)$label.css("text-decoration","line-through");if(item.hidden)$label.css("opacity",.7);if(item.icon.length){var $icon=$("<i></i>").addClass("fa fa-fw fa-"+item.icon).css("margin-right","2px");$label.prepend($icon)}var $a=$("<a></a>").attr("href",item.edit_url).attr("title",item.tip).append($label).append($("<small class='uk-text-muted'></small>").text(item.template));if(item.edit_url=="#"||!item.edit_url.length)$a.removeAttr("href");return $("<li></li>").append($a).appendTo(ul)}});var $input=$("#ProcessPageSearchQuery");var $status=$("#ProcessPageSearchStatus");$input.adminsearchautocomplete({minLength:2,position:{my:"right top",at:"right bottom"},search:function(event,ui){$status.html("<i class='fa fa-spinner fa-spin'></i>")},source:function(request,response){var url=$input.parents("form").attr("action")+"?q="+request.term;$.getJSON(url,function(data){var len=data.matches.length;if(len<data.total)$status.text(data.matches.length+"/"+data.total);else $status.text(len);response($.map(data.matches,function(item){return{label:item.title,value:item.title,page_id:item.id,template:item.template_label?item.template_label:"",edit_url:item.editUrl,type:item.type,tip:item.tip,unpublished:typeof item.unpublished!="undefined"?item.unpublished:false,hidden:typeof item.hidden!="undefined"?item.hidden:false,locked:typeof item.locked!="undefined"?item.locked:false,icon:typeof item.icon!="undefined"?item.icon:""}}))})},select:function(event,ui){if(typeof event.key!="undefined"){event.preventDefault();if(ui.item.edit_url=="#"||!ui.item.edit_url.length)return false;window.location=ui.item.edit_url}}}).on("blur",function(){$status.text("")});var $search=$("#search");$input.on("keypress keydown keyup",function(event){if(event.keyCode==13){event.preventDefault()}if(event.keyCode==40){$input.data("no-close",true)}if(event.keyCode==38&&!$input.data("no-close")){$search.removeClass("open");$(this).val();$input.trigger("blur");$("#ProcessPageSearchAutocomplete").hide().html("")}if(event.keyCode==8){if(ProcessWire.trim($(this).val())==""){$status.text("")}}});$(".search-toggle").on("click",function(){if(!$search.hasClass("open")){$("#masthead").find("ul.open").removeClass("open");$input.trigger("focus")}else{$input.trigger("blur")}$search.toggleClass("open");$input.val("");return false});$(".search-close").on("click",function(){$search.removeClass("open");$input.val("");$input.trigger("blur");return false});$("body").on("click",function(event){if(!$search.hasClass("open"))return;var hide=true;var exclude=["ProcessPageSearchAutocomplete","ProcessPageSearchForm","search"];if($.inArray(event.target.id,exclude)!=-1)return;$.each(exclude,function(key,val){if($(event.target).closest("#"+val).length)hide=false});if(hide){$search.removeClass("open");$input.val("");$input.trigger("blur")}})},setupDropdowns:function(){$("#masthead li.pw-dropdown > a").on("click",function(e){$(this).next("ul").toggleClass("open");$(this).parent().siblings().find("ul.open").removeClass("open");return false});$("#masthead li.pw-dropdown > ul li a").on("click",function(e){e.stopPropagation()});$(document).on("click",function(){$("#masthead li.pw-dropdown ul").removeClass("open")})},setupSideBarToggle:function(){$(".main-nav-toggle").on("click",function(){ProcessWireAdminTheme.setupSideBarState(true);return false})},setupSideBarState:function(click,state){if($("body").hasClass("id-23")||$("body").hasClass("modal"))return false;var name="pw_sidebar_state";var state=state||localStorage.getItem(name);var toggle=$(".main-nav-toggle");var sidebar=$("#sidebar");var main=$("#main");var masthead=$("#masthead");var branding=$("#branding");var bug=$("#NotificationBug");var elems=toggle.add(sidebar).add(main).add(masthead).add(branding).add(bug);if(state===null&&$(window).width()>=690)localStorage.setItem(name,"open");if(!click&&$(window).width()<690){localStorage.setItem(name,"closed");state="closed"}if(click==true){if(state=="open"){localStorage.setItem(name,"closed");elems.addClass("closed")}else if(state=="closed"){localStorage.setItem(name,"open");elems.removeClass("closed")}sidebar.removeClass("hide");branding.removeClass("hide");main.removeClass("full");masthead.removeClass("full");toggle.removeClass("full")}else if(state=="closed"){elems.addClass("closed");sidebar.addClass("hide");branding.addClass("hide");main.addClass("full");masthead.addClass("full");toggle.addClass("full")}},browserCheck:function(){}};$(document).ready(function(){ProcessWireAdminTheme.init()});