1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
|
var pwModalWindows=[];function pwModalWindowSettings(name){var modal=ProcessWire.config.modals[name];if(typeof modal=="undefined")modal=ProcessWire.config.modals["medium"];modal=modal.split(",");var options={modal:true,draggable:false,resizable:true,hide:250,show:100,hideOverflow:true,closeOnEscape:false};if(modal.length>=4){for(var n=4;n<modal.length;n++){var val=modal[n];if(val.indexOf("=")<1)continue;val=val.split("=");var key=val[0].toString().trim();val=val[1].toLowerCase().trim();if(typeof options[key]=="undefined")continue;if(val=="true"||val=="1"){val=true}else if(val=="false"||val=="0"){val=false}else{val=parseInt(val)}options[key]=val}}if(jQuery.ui.version==="1.10.4"){var position=[parseInt(modal[0]),parseInt(modal[1])]}else{var position={my:"left+"+modal[0]+" top+"+modal[1],at:"left top"}}var width=jQuery(window).width()-parseInt(modal[2]);var height=jQuery(window).height()-parseInt(modal[3]);var settings={modal:options.modal,draggable:options.draggable,resizable:options.resizable,position:position,width:width,height:height,hide:options.hide,show:options.show,closeOnEscape:options.closeOnEscape,closeText:"",create:function(event,ui){if(options.hideOverflow){if(typeof parent.jQuery!="undefined"){parent.jQuery("body").css("overflow","hidden")}else{parent.document.querySelector("body").style.overflow="hidden"}}var $widget=jQuery(this).dialog("widget");jQuery(".ui-dialog-titlebar-close",$widget).css("padding-top",0).addClass("ui-state-default").prepend("<i class='fa fa-times'></i>").find(".ui-icon").remove();if(frameElement){if(typeof parent.jQuery!=="undefined"){if(parent.jQuery(".ui-dialog").length){parent.jQuery(".ui-dialog .ui-button").addClass("pw-modal-hidden").hide();parent.jQuery(".ui-dialog-buttonpane").css("margin-top","-10px");jQuery("body").css("overflow","hidden")}}else{if(parent.document.querySelector(".ui-dialog")){var parentButtons=parent.document.querySelectorAll(".ui-dialog .ui-button");var i;for(i=0;i<parentButtons.length;i++){parentButtons[i].classList.add("pw-modal-hidden");parentButtons[i].style.display="none"}var parentPanes=parent.document.querySelectorAll(".ui-dialog-buttonpane");for(i=0;i<parentPanes.length;i++){parentPanes[i].style.marginTop="-10px"}document.querySelector("body").style.overflow="hidden"}}}},beforeClose:function(event,ui){if(typeof parent.jQuery!="undefined"){if(parent.jQuery(".ui-dialog").length){if(frameElement){parent.jQuery(".pw-modal-hidden").show();jQuery("body").css("overflow","")}else if(options.hideOverflow){parent.jQuery("body").css("overflow","")}}}else{if(frameElement){var parentModalHidden=parent.document.querySelector(".pw-modal-hidden");if(parentModalHidden)parentModalHidden.style.display="block";document.querySelector("body").style.overflow=""}else if(options.hideOverflow){parent.document.querySelector("body").style.overflow=""}}}};return settings}function pwModalWindow(href,options,size){var $iframe,url;for(var n=0;n<=pwModalWindows.length;n++){$iframe=pwModalWindows[n];if($iframe==null)continue;if($iframe.dialog("isOpen"))continue;$iframe.dialog("destroy").remove();pwModalWindows[n]=null}if(href.indexOf("modal=")>0){url=href}else{url=href+(href.indexOf("?")>-1?"&":"?")+"modal=1"}$iframe=jQuery('<iframe class="pw-modal-window" frameborder="0" src="'+url+'"></iframe>');$iframe.attr("id","pw-modal-window-"+(pwModalWindows.length+1));pwModalWindows[pwModalWindows.length]=$iframe;if(typeof size=="undefined"||size.length==0)size="large";var settings=pwModalWindowSettings(size);if(settings==null){alert("Unknown modal setting: "+size);return $iframe}if(typeof options!="undefined")jQuery.extend(settings,options);$iframe.on("dialogopen",function(event,ui){jQuery(document).trigger("pw-modal-opened",{event:event,ui:ui})});$iframe.on("dialogclose",function(event,ui){jQuery(document).trigger("pw-modal-closed",{event:event,ui:ui})});$iframe.dialog(settings);$iframe.data("settings",settings);$iframe.on("load",function(){if(typeof settings.title=="undefined"||!settings.title){var title=jQuery("<textarea />").text($iframe.contents().find("title").text()).html();$iframe.d
|