praiadeseselle/wire/modules/Jquery/JqueryUI/panel.min.js

1 line
No EOL
6.9 KiB
JavaScript

var pwPanels={qty:0,init:function(){var url=window.location.href;if(url.indexOf("pw_panel=1")>-1){$(document).on("mouseover","a",function(){var $a=$(this);var target=$a.attr("target");if(typeof target=="undefined"||target.length==0){$a.attr("target","_parent")}})}else if(url.indexOf("pw_panel=2")>-1){}else{$(".pw-panel").each(function(){var $toggler=$(this);pwPanels.addPanel($toggler)})}},addPanel:function($toggler){var panelURL=$toggler.attr("data-href");var panelID=$toggler.attr("data-panel-id");var panelContainerID="pw-panel-container-"+ ++pwPanels.qty;if(typeof panelURL=="undefined"||!panelURL.length)panelURL=$toggler.attr("href");if(typeof panelURL!="undefined"&&panelURL.length){var hash="";if(panelURL.indexOf("#")>-1){var parts=panelURL.split("#");panelURL=parts[0];hash="#"+parts[1]}panelURL+=(panelURL.indexOf("?")>-1?"&":"?")+"modal=panel&pw_panel=";if($toggler!==null&&$toggler.hasClass("pw-panel-links")){panelURL+="2"}else{panelURL+="1"}panelURL+=hash}var $icon=$("<i />").attr("class","pw-panel-icon fa fa-angle-double-left");var $span=$("<small />").attr("class","ui-button-text").append($icon);var $btn=$("<a />").attr("class","pw-panel-button pw-panel-button-closed ui-button ui-state-default").attr("href",panelURL).on("click",pwPanels.buttonClickEvent).on("mouseover",pwPanels.buttonMouseoverEvent).on("mouseout",pwPanels.buttonMouseoutEvent).append($span);var $panel=$("<div />").attr("id",panelContainerID).attr("class","pw-panel-container pw-panel-container-closed").append($btn);$("body").append($panel);if(typeof panelID!="undefined"&&panelID.length){$("#"+panelID).hide().addClass("pw-panel-element");$panel.addClass("pw-panel-container-element").attr("data-panel-id",panelID)}if($toggler!==null){pwPanels.initToggler($toggler,$btn,$panel)}else{$panel.addClass("pw-panel-left")}},initToggler:function($toggler,$btn,$panel){var panelSide=$toggler.hasClass("pw-panel-right")?"right":"left";var text=$toggler.attr("data-tab-text");var icon=$toggler.attr("data-tab-icon");var offset=$toggler.attr("data-tab-offset");var panelWidth=$toggler.attr("data-panel-width");var btnPos=panelSide=="right"?"left":"right";var btnExtraPx=1;$panel.addClass("pw-panel-tab pw-panel-"+panelSide);$panel.attr("data-href",$btn.attr("href"));if($toggler.hasClass("pw-panel-reload"))$panel.addClass("pw-panel-reload");if(typeof offset!="undefined"){offset=parseInt(offset);if(offset>-1){$btn.css("top",offset+"px")}else{$btn.css("top","auto");$btn.css("bottom",Math.abs(offset)+"px")}}if(typeof text!="undefined"&&text.length){var $btnText=$btn.children(".ui-button-text");var $text=$("<span />").text(text);$btnText.html("<span>"+$text.text()+"</span>");$btn.addClass("pw-panel-button-text");btnExtraPx=7}if(typeof icon!="undefined"&&icon.length){var $icon=$("<i />").addClass("fa fa-fw fa-"+icon);var $text=$btn.children(".ui-button-text");if($btn.hasClass("pw-panel-button-text")){$text.prepend($icon)}else{$text.empty().append($icon);$btn.css(btnPos,-1*$btn.outerWidth()+"px")}}if(typeof panelWidth!="undefined"&&panelWidth.length){$panel.css("width",panelWidth);$panel.css(panelSide,"-"+panelWidth)}if(panelSide=="right"){}else{$btn.css("right",-1*(btnExtraPx+$btn.height())+"px")}if(!$toggler.hasClass("pw-panel-tab")){$btn.addClass("pw-panel-button-hidden")}$toggler.on("click",function(){$btn.trigger("click");return false}).on("mouseover",function(){$btn.trigger("mouseover")}).on("mouseout",function(){$btn.trigger("mouseout")})},initPanelContent:function($panel){var $content=$panel.find(".pw-panel-content");var panelID=$panel.attr("data-panel-id");if($content.length){return $content}else if(typeof panelID!="undefined"){var $panelTarget=$("#"+panelID);if($panelTarget.length){$content=$("<div />").addClass("pw-panel-content").css("overflow","auto");$panel.append($content);$content.append($panelTarget);$panelTarget.show();$panelTarget.trigger("pw-panel-init")}}else{$content=$("<iframe />").addClass("pw-panel-content").attr("src",$panel.attr("data-href"));$panel.append($content)}return $content},windowResizeEvent:function(){$(".pw-panel-container-init").each(function(){var $panel=$(this);if($panel.hasClass("pw-panel-container-open"))return;var panelWidth=$panel.width();var px=-1*panelWidth+"px";if($panel.hasClass("pw-panel-right")){$panel.css("right",px)}else{$panel.css("left",px)}})},buttonClickEvent:function(){var $btn=$(this);var $panel=$btn.closest(".pw-panel-container");var $panelContent=$panel.find(".pw-panel-content");var isOpen=$panel.hasClass("pw-panel-container-open");var isLoaded=$panel.hasClass("pw-panel-container-loaded");var panelWidth=$panel.width();var panelSide=$panel.hasClass("pw-panel-right")?"right":"left";var hasJQUI=typeof jQuery.ui!="undefined";function animateFinished(){$panel.toggleClass("pw-panel-container-open pw-panel-container-closed");$btn.toggleClass("pw-panel-button-open pw-panel-button-closed")}if($(".pw-panel-container-init").length==0){$(window).on("resize",pwPanels.windowResizeEvent)}if(isOpen){var px=-1*panelWidth+"px";if(hasJQUI){if(panelSide=="left"){$panel.animate({left:px},150,animateFinished)}else{$panel.animate({right:px},150,animateFinished)}}else{$panel.css(panelSide,px);animateFinished()}$("body").css("overflow","");$("#pw-panel-shade").fadeOut("fast",function(){$(this).remove()});$btn.fadeOut("fast",function(){$btn.removeClass("ui-state-active");$btn.fadeIn("fast")});if(hasJQUI&&panelSide=="left")$panel.resizable("destroy");if($panel.hasClass("pw-panel-reload")){$panel.find("iframe.pw-panel-content").remove()}$(document).trigger("pw-panel-closed",$panel)}else{if($panel.hasClass("pw-panel-reload")||!isLoaded){pwPanels.initPanelContent($panel)}if(hasJQUI){if(panelSide=="left"){$panel.animate({left:0},150,animateFinished)}else{$panel.animate({right:0},150,animateFinished)}}else{$panel.css(panelSide,0);animateFinished()}var $shade=$("<div id='pw-panel-shade'>&nbsp;</div>");$panel.before($shade).fadeIn("fast");$("body").css("overflow","hidden");$shade.on("click",function(){var $panel=$(".pw-panel-container-open");if(!$panel.length)return false;$panel.find(".pw-panel-button").trigger("click")});if(hasJQUI&&panelSide=="left")$panel.resizable({handles:"e",start:function(event,ui){var $overlay=$("<div />").addClass("pw-panel-resizable-overlay").css({position:"absolute",top:0,left:0,width:"100%",height:"100%",zIndex:1001,display:"hidden"});$panel.append($overlay)},stop:function(event,ui){$(".pw-panel-resizable-overlay").remove()}});$panel.addClass("pw-panel-container-init");$(document).trigger("pw-panel-opened",$panel)}return false},buttonMouseoverEvent:function(){var $btn=$(this);var $panel=$btn.closest(".pw-panel-container");$btn.removeClass("ui-state-active").addClass("ui-state-hover");if($panel.hasClass("pw-panel-container-loaded"))return;$panel.addClass("pw-panel-container-loaded");if(!$panel.hasClass("pw-panel-reload")){pwPanels.initPanelContent($panel)}},buttonMouseoutEvent:function(){var $btn=$(this);var $panel=$btn.closest(".pw-panel-container");if($panel.hasClass("pw-panel-container-open"))$btn.addClass("ui-state-active")}};jQuery(document).ready(function(){pwPanels.init()});