praiadeseselle/wire/modules/Jquery/JqueryUI/modal.min.js
2022-03-08 15:55:41 +01:00

1 line
No EOL
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.refresh=function(){lastWidth=0;lastHeight=0;updateWindowSize()};$iframe.setButtons=function(buttons){$iframe.dialog("option","buttons",buttons);$iframe.refresh()};$iframe.setTitle=function(title){$iframe.dialog("option","title",title)};return $iframe}function pwModalOpenEvent(e){var $a=jQuery(this);var _autoclose=$a.attr("data-autoclose");var autoclose=_autoclose!=null;var autocloseSelector=autoclose&&_autoclose.length>1?_autoclose:"";var closeSelector=$a.attr("data-close");var closeOnLoad=false;var modalSize="medium";if($a.hasClass("pw-modal-large"))modalSize="large";else if($a.hasClass("pw-modal-small"))modalSize="small";else if($a.hasClass("pw-modal-full"))modalSize="full";var settings={title:$a.attr("title"),close:function(e,ui){var abort=typeof e.originalEvent!="undefined"&&jQuery(e.originalEvent.target).closest(".ui-dialog-titlebar-close").length>0;var eventData={event:e,ui:ui,abort:abort};$a.trigger("modal-close",eventData);$a.trigger("pw-modal-closed",eventData);jQuery(document).trigger("pw-modal-closed",eventData);$spinner.remove()}};var buttonSelector=$a.attr("data-buttons");if(closeSelector==null)closeSelector="";closeSelector+=(closeSelector.length>0?", ":"")+".pw-modal-cancel";var $spinner=jQuery("<i class='fa fa-spin fa-spinner fa-2x ui-priority-secondary'></i>").css({position:"absolute",top:parseInt(jQuery(window).height()/2)-80+"px",left:parseInt(jQuery(window).width()/2)-20+"px","z-index":9999}).hide();var href=$a.attr("data-pw-modal-href");if(href&&href.length){}else if($a.is("button")){var $aparent=$a.closest("a");href=$aparent.length?$aparent.attr("href"):$a.attr("data-href");if(!href)href=$a.find("a").attr("href")}else if($a.is("a")){href=$a.attr("href")}else{href=$a.attr("data-href")}if(!href){alert("Unable to find href attribute for: "+$a.text());return false}var $iframe=pwModalWindow(href,settings,modalSize);jQuery("body").append($spinner.fadeIn("fast"));setTimeout(function(){$a.removeClass("ui-state-active")},500);$iframe.load(function(){var buttons=[];var $icontents=$iframe.contents();var n=0;$spinner.fadeOut("fast",function(){$spinner.remove()});if(closeOnLoad){var $errorItems=$icontents.find(".NoticeError, .ui-state-error");if($errorItems.length==0){if(typeof Notifications!="undefined"){var messages=[];$icontents.find(".NoticeMessage").each(function(){messages[messages.length]=jQuery(this).text()});if(messages.length>0)setTimeout(function(){for(var i=0;i<messages.length;i++){Notifications.message(messages[i])}},500)}$iframe.dialog("close");return}else{}}var $body=$icontents.find("body");$body.hide();if(buttonSelector){$icontents.find(buttonSelector).each(function(){var $button=jQuery(this);$button.find(".ui-button-text").removeClass("ui-button-text");var text=$button.html();var skip=false;for(var i=0;i<buttons.length;i++){if(buttons[i].text==text||text.length<1)skip=true}if(!skip){buttons[n]={html:text,class:$button.is(".ui-priority-secondary")?"ui-priority-secondary":"",click:function(e){$button.click();if(closeSelector.length>0&&$button.is(closeSelector)){$iframe.dialog("close")}if(autoclose){jQuery("body").append($spinner.fadeIn());if(autocloseSelector.length>1){closeOnLoad=$button.is(autocloseSelector)}else{closeOnLoad=true}}}};n++}if(!$button.hasClass("pw-modal-button-visible"))$button.hide()})}if(buttons.length>0)$iframe.setButtons(buttons);$body.fadeIn("fast",function(){$body.show()})});return false}(function($){$.event.special.pwdoubletap={bindType:"touchend",delegateType:"touchend",handle:function(event){var handleObj=event.handleObj,targetData=jQuery.data(event.target),now=(new Date).getTime(),delta=targetData.lastTouch?now-targetData.lastTouch:0,delay=delay==null?300:delay;if(delta<delay&&delta>30){targetData.lastTouch=null;event.type=handleObj.origType;["clientX","clientY","pageX","pageY"].forEach(function(property){event[property]=event.originalEvent.changedTouches[0][property]});handleObj.handler.apply(this,arguments)}else{targetData.lastTouch=now}}}})(jQuery);function pwModalDoubleClick(){var clicks=0,timer=null,allowClick=false;jQuery(document).on("click",".pw-modal-dblclick a",function(){var $a=jQuery(this);if(allowClick){allowClick=false;return true}clicks++;if(clicks===1){timer=setTimeout(function(){clicks=0;allowClick=true;$a[0].click();return true},700)}else{clearTimeout(timer);allowClick=false;clicks=0;jQuery(this).closest(".pw-modal-dblclick").trigger("dblclick")}return false});jQuery(document).on("dblclick",".pw-modal-dblclick a",function(e){e.stopPropagation();return false});var isTouch="ontouchstart"in window||navigator.MaxTouchPoints>0||navigator.msMaxTouchPoints>0;if(isTouch){jQuery(document).on("pwdoubletap",".pw-modal-dblclick",pwModalOpenEvent)}}jQuery(document).ready(function($){$.widget("ui.dialog",$.extend({},$.ui.dialog.prototype,{_title:function(title){if(!this.options.title){title.html("&#160;")}else{title.html(this.options.title)}}}));$(document).on("pwdblclick",".pw-modal-dblclick",pwModalOpenEvent);$(document).on("click",".pw-modal:not(.pw-modal-dblclick):not(.pw-modal-longclick)",pwModalOpenEvent);$(document).on("dblclick",".pw-modal-dblclick",pwModalOpenEvent);$(document).on("longclick",".pw-modal-longclick",pwModalOpenEvent);pwModalDoubleClick()});