1 line
9.1 KiB
JavaScript
1 line
9.1 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=jQuery.trim(val[0]);val=jQuery.trim(val[1].toLowerCase());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}}return{modal:options.modal,draggable:options.draggable,resizable:options.resizable,position:[parseInt(modal[0]),parseInt(modal[1])],width:jQuery(window).width()-parseInt(modal[2]),height:jQuery(window).height()-parseInt(modal[3]),hide:options.hide,show:options.show,closeOnEscape:options.closeOnEscape,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).prepend("<i class='fa fa-times'></i>").find(".ui-icon").remove();if(frameElement&&parent.jQuery!="undefined"&&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")}},beforeClose:function(event,ui){if(parent.jQuery!="undefined"&&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","")}}}}}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.load(function(){if(typeof settings.title=="undefined"||!settings.title){var title=jQuery("<textarea />").text($iframe.contents().find("title").text()).html();$iframe.dialog("option","title",title)}$iframe.contents().find("form").css("-webkit-backface-visibility","hidden")});var lastWidth=0;var lastHeight=0;function updateWindowSize(){var width=jQuery(window).width();var height=jQuery(window).height();if(width==lastWidth&&height==lastHeight||!$iframe.hasClass("ui-dialog-content"))return;var _size=size;if(width<=960&&size!="full"&&size!="large")_size="large";if(width<=700&&size!="full")_size="full";var _settings=pwModalWindowSettings(_size);var $dialog=$iframe.closest(".ui-dialog");if($dialog.length>0){var subtractHeight=$dialog.find(".ui-dialog-buttonpane").outerHeight()+$dialog.find(".ui-dialog-titlebar").outerHeight();_settings.height-=subtractHeight}$iframe.dialog("option","width",_settings.width);$iframe.dialog("option","height",_settings.height);$iframe.dialog("option","position",_settings.position);$iframe.width(_settings.width).height(_settings.height);lastWidth=width;lastHeight=height}updateWindowSize();jQuery(window).resize(updateWindowSize);$iframe.
|