praiadeseselle/wire/modules/AdminTheme/AdminThemeReno/scripts/main.min.js
2022-03-08 15:55:41 +01:00

1 line
No EOL
8.7 KiB
JavaScript

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