praiadeseselle/wire/modules/AdminTheme/AdminThemeDefault/scripts/main.min.js

1 line
5 KiB
JavaScript
Raw Permalink Normal View History

var ProcessWireAdminTheme={init:function(){var $button=$("#head_button > button.pw-dropdown-toggle").hide();this.setupCloneButton();ProcessWireAdmin.init();this.setupSearch();this.setupMobile();var $body=$("body");if($body.hasClass("hasWireTabs")&&$("ul.WireTabs").length==0)$body.removeClass("hasWireTabs");$("#content").removeClass("pw-fouc-fix");$body.removeClass("pw-init").addClass("pw-ready");if($button.length>0)$button.show()},setupCloneButton:function(){if($("body").is(".modal"))return;var $buttons=$("button.pw-head-button, button.head_button_clone");if($buttons.length==0)return;var $head=$("#head_button");if($head.length==0)$head=$("<div id='head_button'></div>").prependTo("#breadcrumbs .pw-container");$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");$button.on("click",function(){$("#"+$(this).attr("data-from_id")).trigger("click");return false});$head.prepend($button)}});$head.show()},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.addClass("ui-priority-secondary");if(typeof item.icon!="undefined"&&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("<img src='"+ProcessWire.config.urls.modules+"Process/ProcessPageList/images/loading.gif'>")},open:function(event,ui){$("#topnav").hide()},close:function(event,ui){$("#topnav").show()},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("focus",function(){$(this).siblings("label").find("i").hide()}).on("blur",function(){$status.text("");$(this).siblings("label").find("i").show()})},setupMobile:function(){var collapsedTopnavAtBodyWidth=0;var collapsedTabsAtBodyWidth=0;var windowResize=function(){var $topnav=$("#topnav");var $body=$("body");var height=$topnav.height();if(height>50){if(!$body.hasClass("collapse-topnav")){$body.addClass("collapse-topnav");collapsedTopnavAtBodyWidth=$body.width()}}else if(collapsedTopnavAtBodyWidth>0){var width=$body.width();if($body.hasClass("collapse-topnav")&&widt