var ProcessWireAdminTheme={init:function(){this.setupInputfields();this.setupTooltips();this.checkLayout()},ready:function(){this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupSideNav();var $body=$("body");$(document).on("wiretabclick opened",function(e){$("body").addClass("pw-fake-resize");$(window).resize();setTimeout(function(){$("body").removeClass("pw-fake-resize")},100)});$("a.notice-remove","#notices").click(function(){$("#notices").slideUp("fast",function(){$(this).remove()});return false});$("a.pw-logo-link").click(this.logoClickEvent);$("#_ProcessPageEditView").click(function(e){e.stopPropagation()});var resizeTimer=null;$(window).resize(function(){if(resizeTimer)return;resizeTimer=setTimeout(function(){ProcessWireAdminTheme.windowResized();resizeTimer=null},250)});this.setupMasthead();this.setupWireTabs();$body.removeClass("pw-init").addClass("pw-ready")},setupWireTabs:function(){var $tabs=$(".WireTabs");if($tabs.length){$(document).on("wiretabclick",function(event,$newTabContent){ProcessWireAdminTheme.wireTabClick($newTabContent)});setTimeout(function(){var $activeTab=$tabs.children(".uk-active");if($activeTab.length){var href=$activeTab.find("a").attr("href");if(href.indexOf("#")===0){var $activeContent=$(href);if($activeContent.length)ProcessWireAdminTheme.wireTabClick($activeContent)}}},500)}},wireTabClick:function($newTabContent){if(!$newTabContent.length)return;var $header=null;var $inputfield=null;if($newTabContent.hasClass("InputfieldWrapper")){$inputfield=$newTabContent.children(".Inputfields").children(".Inputfield:eq(0)");$header=$inputfield.children(".InputfieldHeader")}else if($newTabContent.hasClass("Inputfield")){$inputfield=$newTabContent;$header=$newTabContent.children(".InputfieldHeader")}if(!$header||!$header.length)return;var skip=false;var skipClasses=["InputfieldIsPrimary","InputfieldIsWarning","InputfieldIsError","InputfieldIsHighlight","InputfieldIsSuccess"];for(var n=0;n-1){href=href.replace(/([?&]layout)=[-_a-zA-Z0-9]+/,"$1=sidenav-init")}else{href+=(href.indexOf("?")>0?"&":"?")+"layout=sidenav-init"}window.location.href=href}},windowResized:function(){if($("body").hasClass("pw-fake-resize"))return;this.setupMasthead()},setupMasthead:function(){var $masthead=$("#pw-masthead");var $mastheadMobile=$("#pw-masthead-mobile");var width=$(window).width();var height=0;var maxHeight=0;if(width>767){maxHeight=parseInt($masthead.data("pw-height"));height=$masthead.children(".pw-container").height()}else{height=999}if($masthead.hasClass("uk-hidden"))$masthead.removeClass("uk-hidden");if(height>maxHeight){if(!$masthead.hasClass("pw-masthead-hidden")){$masthead.addClass("pw-masthead-hidden").css({position:"absolute",top:"-9999px"});$mastheadMobile.removeClass("uk-hidden");$("#offcanvas-toggle").removeClass("uk-hidden")}}else{if($masthead.hasClass("pw-masthead-hidden")){$mastheadMobile.addClass("uk-hidden");$masthead.removeClass("pw-masthead-hidden").css({position:"relative",top:0});$("#offcanvas-toggle").addClass("uk-hidden")}}},setupCloneButton:function(){if($("body").is(".modal"))return;var $buttons=$("button.pw-head-button, button.head_button_clone");if($buttons.length==0)return;var $head=$("#pw-content-head-buttons");var $lastToggle=null;var $lastButton=null;var toggles={};$buttons.each(function(){var $t=$(this);var $a=$t.parent("a");var $button;if($a.length>0){$button=$t.parent("a").clone(true);$head.prepend($button)}else if($t.hasClass("pw-head-button")||$t.hasClass("head_button_clone")){$button=$t.clone(true);$button.attr("data-from_id",$t.attr("id")).attr("id",$t.attr("id")+"_copy").addClass("pw-head-button");$button.click(function(){$("#"+$(this).attr("data-from_id")).click();return false});if($button.hasClass("pw-button-dropdown-toggle")){var id=$button.attr("id").replace("pw-dropdown-toggle-","");toggles[id]=$button}else if($button.hasClass("pw-button-dropdown-main")){var $wrap=$("").addClass("pw-button-dropdown-wrap");$wrap.append($button).addClass("uk-float-right");$head.prepend($wrap)}else{$button.addClass("uk-float-right");$head.prepend($button)}}});for(var id in toggles){var $toggle=toggles[id];var $button=$("#"+id);$button.after($toggle)}},setupSearch:function(){$.widget("custom.adminsearchautocomplete",$.ui.autocomplete,{_renderMenu:function(ul,items){var that=this;var currentType="";ul.addClass("pw-dropdown-menu-shorter uk-nav uk-nav-default");ul.css("z-index",9999);$.each(items,function(index,item){if(item.type!=currentType){if(currentType.length){$("
  • ").appendTo(ul)}$("
  • "+item.type+"
  • ").addClass("uk-nav-header").appendTo(ul);currentType=item.type}that._renderItemData(ul,item)})},_renderItem:function(ul,item){if(item.label==item.template)item.template="";var $label=$("").text(item.label).css("margin-right","3px");if(item.unpublished)$label.css("text-decoration","line-through");if(item.hidden)$label.addClass("ui-priority-secondary");if(item.icon.length){var $icon=$("").addClass("fa fa-fw fa-"+item.icon).css("margin-right","2px");$label.prepend($icon)}var $a=$("").attr("href",item.edit_url).attr("title",item.tip).append($label).append($("").text(item.template));if(item.edit_url=="#"||!item.edit_url.length){$a.removeAttr("href")}return $("
  • ").append($a).appendTo(ul)}});$(".pw-search-form").each(function(){var $form=$(this);var $input=$form.find(".pw-search-input");var position={my:"right top",at:"right bottom"};if($form.closest(".uk-offcanvas-bar").length){position.my="left top";position.at="left bottom"}$input.click(function(event){event.stopPropagation()});$input.adminsearchautocomplete({minLength:2,position:position,search:function(event,ui){$form.find(".pw-search-icon").addClass("uk-hidden");$form.find(".pw-spinner-icon").removeClass("uk-hidden")},open:function(event,ui){},close:function(event,ui){},source:function(request,response){if(request.term===$input.attr("data-help-term"))request.term="help";var url=$input.parents("form").attr("data-action")+"?q="+request.term;$.getJSON(url,function(data){var len=data.matches.length;if(len");$ul.append($spinner);$.getJSON(url,function(data){var $a2=$a.clone();var $icon2=$a2.find("i");if(!$icon2.length){$icon2=$("");$a2.prepend($icon2)}$icon2.attr("class","fa fa-fw fa-arrow-circle-right pw-nav-icon");$a2.removeAttr("data-json").removeAttr("class");$a2.find("small").remove();var $li=$("
  • ").addClass("pw-nav-dup").append($a2);$ul.append($li);if(data.add){var $li2=$("
  • "+""+""+data.add.label+""+"
  • ");$ul.append($li2)}$.each(data.list,function(i){if(this.label.indexOf("-1){this.label=this.label.replace(/<\/?span[^>]*>/g,"")}var icon="";var $label=$("
    "+this.label+"
    ");var label=$label.text();if(label.length>30){var $small=$label.find("small");if($small.length)$small.remove();label=$label.text();label=label.substring(0,30);var n=label.lastIndexOf(" ");if(n>3)label=label.substring(0,n)+"… ";$label.html(label);if($small.length)$label.append($small)}label=$label.html().replace(" "," ");if(this.icon)icon="";var url=this.url.indexOf("/")===0?this.url:data.url+this.url;var $a=$(""+icon+label+"");var $li=$("
  • ").append($a);if(this.navJSON!="undefined"&&this.navJSON){$a.addClass("pw-has-items pw-has-ajax-items").attr("data-json",this.navJSON);var $ul2=$("
      ");$li.addClass("uk-parent").append($ul2);UIkit.nav($ul2,{multiple:true})}if(typeof this.className!="undefined"&&this.className&&this.className.length){$li.addClass(this.className)}if($li.hasClass("pw-nav-add")||$li.hasClass("pw-pagelist-show-all")){$ul.children(".pw-nav-dup").after($li.removeClass("separator").addClass("pw-nav-add"))}else{$ul.append($li)}});$spinner.remove();$ul.addClass("navJSON").addClass("length"+parseInt(data.list.length)).hide();if($ul.children().length)$ul.css("opacity",1).fadeIn("fast")});return false})},setupInputfields:function(){var noGrid=$("body").hasClass("AdminThemeUikitNoGrid");function initFormMarkup($target){$("form.uk-form-horizontal").each(function(){$(this).find(".InputfieldContent > .Inputfields").each(function(){var $content=$(this);$content.addClass("uk-form-vertical");$content.find(".uk-form-label").removeClass("uk-form-label");$content.find(".uk-form-controls").removeClass("uk-form-controls")});$(this).find(".InputfieldSubmit, .InputfieldButton").each(function(){$(this).find(".InputfieldContent").before("
       
      ")})});$(".InputfieldNoBorder.uk-card").removeClass("uk-card uk-card-default");$(".InputfieldIsOffset.InputfieldColumnWidthFirst").each(function(){var $t=$(this);var $f;do{$f=$t.next(".InputfieldColumnWidth");if(!$f.length||$f.hasClass("InputfieldColumnWidthFirst"))break;$f.addClass("InputfieldIsOffset");$t=$f}while(true)});$(".Inputfields").each(function(){identifyFirstLastRows($(this))});$(".ui-widget.Inputfield, .ui-widget-header.InputfieldHeader, .ui-widget-content.InputfieldContent").removeClass("ui-widget ui-widget-header ui-widget-content");$(".MarkupPagerNav:not(.uk-pagination)").each(function(){$(this).addClass("uk-pagination")});if(typeof $target=="undefined")$target=$(".InputfieldForm");var $selects=$("select:not([multiple]):not(.uk-select)",$target);$selects.addClass("uk-select")}function identifyFirstLastRows($inputfields){$(".InputfieldRowFirst",$inputfields).removeClass("InputfieldRowFirst");$(".InputfieldRowLast",$inputfields).removeClass("InputfieldRowLast");var $in=$inputfields.children(".Inputfield:not(.InputfieldStateHidden):eq(0)");if(!$in.length)return;do{$in.addClass("InputfieldRowFirst");$in=$in.next(".Inputfield:not(.InputfieldStateHidden)")}while($in.hasClass("InputfieldColumnWidth")&&!$in.hasClass("InputfieldColumnWidthFirst"));$in=$inputfields.children(".Inputfield:last-child");while($in.length&&$in.hasClass("InputfieldStateHidden")){$in=$in.prev(".Inputfield")}do{$in.addClass("InputfieldRowLast");if(!$in.hasClass("InputfieldColumnWidth")||$in.hasClass("InputfieldColumnWidthFirst"))break;$in=$in.prev(".Inputfield:not(.InputfieldStateHidden)")}while($in.hasClass("InputfieldColumnWidth"))}var ukGridClassCache=[];function ukGridClass(width,$in){if(noGrid&&typeof $in!="undefined"){if(typeof width=="string"){$in.addClass(width)}else{$in.css("width",width+"%")}return""}var ukGridClassDefault="uk-width-1-1";var ukGridClass=ukGridClassDefault;var widthIsClass=false;if(typeof width=="string"&&typeof $in!="undefined"){ukGridClass=width;widthIsClass=true}else if(!width||width>=100){ukGridClass=ukGridClassDefault}else if(typeof ukGridClassCache[width]!="undefined"){ukGridClass="uk-width-"+ukGridClassCache[width]}else{for(var pct in ProcessWire.config.ukGridWidths){var cn=ProcessWire.config.ukGridWidths[pct];pct=parseInt(pct);if(width>=pct){ukGridClass=cn;break}}if(ukGridClass.length){ukGridClassCache[width]=ukGridClass;ukGridClass="uk-width-"+ukGridClass}}if(!widthIsClass&&ukGridClass&&ukGridClass!=ukGridClassDefault){ukGridClass+="@m"}if(typeof $in!="undefined"){if(ukGridClass&&$in.hasClass(ukGridClass)){}else{removeUkGridClass($in);if(ukGridClass)$in.addClass(ukGridClass)}}return ukGridClass}function removeUkGridClass(str){var $in=null;if(typeof str!="string"){$in=str;str=$in.attr("class")}if(str.indexOf("uk-width-")>-1){var cls=str.replace(/uk-width-(\d-\d|expand)[@smxl]*\s*/g,"");if($in!==null)$in.attr("class",cls)}return str}function updateInputfieldRow($inputfield){if(!$inputfield)return;var $inputfields=$inputfield.parent().children(".Inputfield");var $lastInputfield=null;var width=0;var widthHidden=0;var w=0;var lastW=0;var debug=false;function consoleLog(msg,$in){if(!debug)return;if(typeof $in=="undefined")$in=$inputfield;var id=$in.attr("id");id=id.replace("wrap_Inputfield_","");console.log(id+" (combined width="+width+", w="+w+"): "+msg)}function expandLastInputfield($in){if(typeof $in=="undefined")$in=$lastInputfield;if($in){if(noGrid){$in.addClass("InputfieldColumnWidthLast")}else{ukGridClass("InputfieldColumnWidthLast uk-width-expand",$in)}}}function applyHiddenInputfield(){if(debug)consoleLog("A: hidden",$inputfield);lastW+=w;width+=w;if($lastInputfield&&width>=95){if(debug)consoleLog("Updating last visible Inputfield to width="+lastW,$lastInputfield);ukGridClass(lastW,$lastInputfield);width=0;lastW=0;widthHidden=0;$lastInputfield=null}else{widthHidden+=w}}function applyFullWidthInputfield(){if(debug)consoleLog("Skipping because full-width",$inputfield);if(width<100&&$lastInputfield)expandLastInputfield($lastInputfield);$lastInputfield=null;widthHidden=0;lastW=0;width=0}$inputfields.each(function(){$inputfield=$(this);var isLastColumn=false;var isFirstColumn=false;var hasWidth=$inputfield.hasClass("InputfieldColumnWidth");var isNewRow=!hasWidth||$inputfield.hasClass("InputfieldColumnWidthFirst");if(isNewRow&&$lastInputfield&&width<100){expandLastInputfield($lastInputfield)}w=hasWidth?parseInt($inputfield.attr("data-colwidth")):0;if(!w||w>=95){applyFullWidthInputfield();return}if($inputfield.hasClass("InputfieldStateHidden")){applyHiddenInputfield();return}if(!width||width>=100){width=0;isFirstColumn=true;isLastColumn=false;if(debug)consoleLog("B: starting new row",$inputfield)}else if(width+w>100){if($lastInputfield)expandLastInputfield($lastInputfield);width=0;isFirstColumn=true;if(debug)consoleLog("C: start new row because width would exceed 100%",$inputfield)}else if(width+w==100){isLastColumn=true;if(debug)consoleLog("D: width is exactly 100%, so this is the last column",$inputfield)}else if(width+w>=95){isLastColumn=true;w=100-width;if(debug)consoleLog("D2: width is close enough to 100%, so this is the last column",$inputfield)}else{if(debug)consoleLog("E: not first or last column",$inputfield)}if(isLastColumn){$inputfield.addClass("InputfieldColumnWidthLast")}else{$inputfield.removeClass("InputfieldColumnWidthLast")}if(isFirstColumn){$inputfield.addClass("InputfieldColumnWidthFirst");widthHidden=0}else{$inputfield.removeClass("InputfieldColumnWidthFirst")}if(isLastColumn){$lastInputfield=null;width=0;lastW=0;if(widthHidden)w+=widthHidden;widthHidden=0}else{$lastInputfield=$inputfield;width+=w;lastW=w}ukGridClass(w,$inputfield)});if(width<100&&$lastInputfield)expandLastInputfield($lastInputfield)}var showHideInputfieldTimer=null;var showHideInputfield=function(event,inputfield){var $inputfield=$(inputfield);if(event.type=="showInputfield"){$inputfield.removeClass("uk-hidden")}else{$inputfield.show();$inputfield.addClass("uk-hidden")}updateInputfieldRow($inputfield);if(showHideInputfieldTimer)return;showHideInputfieldTimer=setTimeout(function(){identifyFirstLastRows($inputfield.closest(".Inputfields"));var $inputfields=$inputfield.find(".Inputfields");if($inputfields.length){$inputfields.each(function(){identifyFirstLastRows($(this))})}showHideInputfieldTimer=null},100)};$(document).on("reloaded",function(){initFormMarkup($(this))});$(document).on("hideInputfield",showHideInputfield);$(document).on("showInputfield",showHideInputfield);$(document).on("columnWidth",".Inputfield",function(e,width){ukGridClass(width,$(this));return false});$("body").addClass("InputfieldColumnWidthsInit");Inputfields.toggleBehavior=ProcessWire.config.adminTheme.toggleBehavior;initFormMarkup()},setupTooltips:function(){$(".tooltip, .pw-tooltip").each(function(){$(this).removeClass("tooltip pw-tooltip");UIkit.tooltip($(this))})},linkTargetMainMouseoverEvent:function(){var $a=$(this);var href=$a.attr("href");if(href.length<2)return;if($a.attr("target"))return;if($a.parent("li").hasClass("PageListActionView")){$a.attr("target","_top")}else{$a.attr("target","main")}},logoClickEvent:function(){if($("body").hasClass("pw-layout-sidenav-init")){if($("#pw-admin-side").length){toggleSidebarPane()}else{UIkit.toggle("#offcanvas-nav").toggle()}}else if(ProcessWire.config.adminTheme.logoAction==1){UIkit.toggle("#offcanvas-nav").toggle()}else{return true}return false}};$(document).ready(function(){ProcessWireAdminTheme.ready()});