| Current Path : /home/lejardintz/www/media/foundry/3.1/scripts/ |
| Current File : /home/lejardintz/www/media/foundry/3.1/scripts/dialog.min.js |
!function(){var moduleFactory=function($){var module=this;$.require().script("ui/position","easing").done(function(){var exports=function(){$.template("dialog/default",'<div class="foundryDialog global"><div class="dialog-wrap"><div class="in"><div class="dialog-loader"><div class="loader-img"></div></div><div class="dialog-head"><span class="dialog-title"></span><a class="dialog-closeButton">Close</a></div><div class="dialog-body dialog-content"></div><div class="dialog-footer"><div class="dialog-loading"></div><div class="dialog-buttons"></div></div></div></div></div>'),$.Controller("Dialog",{pluginName:"dialog",defaultOptions:{title:"",content:void 0,buttons:{},customClass:"",width:"auto",height:"auto",css:{position:"absolute",width:"auto",height:"auto",zIndex:10001},position:{my:"center center",at:"center center",of:window},offset:100,showOverlay:!0,overlay:{css:{background:"#000",opacity:"0.4",position:"fixed",top:0,left:0,zIndex:1e4,width:"100%",height:"100%",display:"none"}},body:{css:{minWidth:0,minHeight:0,overflow:"auto"}},loader:{width:300,height:100},loading:"",iframe:{css:{width:"100%",height:"100%",border:"none"}},transition:{show:"zoom",hide:"zoom"},escapeKey:!0,beforeShow:function(){},afterShow:function(){},beforeHide:function(){},afterHide:function(){},dialogHead:".dialog-head",dialogBody:".dialog-body",dialogFooter:".dialog-footer",dialogTitle:".dialog-title",dialogContent:".dialog-content",dialogButtons:".dialog-buttons",dialogLoader:".dialog-loader",dialogLoading:".dialog-loading","{closeButton}":".dialog-closeButton"}},function(self){return{ready:!1,contentReady:!1,init:function(){self.setInitOptions(self.options),self.initElement=self.element.clone(),self.element.finalizeContent=function(){return self.finalizeContent.apply(self,arguments)
},$.each(["dialogHead","dialogBody","dialogFooter","dialogTitle","dialogContent","dialogButtons","dialogLoader","dialogLoading"],function(i,name){self[name]=self.find(self.options[name])}),void 0!==self.options.content&&self.display()},"{self} destroyed":function(){$(document).off("keydown.foundry.dialog")},setInitOptions:function(options){self.initOptions=$.extend(!0,{},options),$.each(["beforeShow","afterShow","beforeHide","afterHide"],function(i,name){self.initOptions[name]=function(){}}),$.each(["title","content","buttons","loading","selectors","bindings"],function(i,name){self.initOptions[name]=null
})},update:function(options){if(options){if(options.hasOwnProperty("{binder}"))return;var options=$.extend(!0,{},self.initOptions,options);self.setInitOptions(options),self.display(options)}return self},determineContentType:function(content){return/<dialog>(.*?)/.test(content)?"dialog":$.isUrl(content)?"iframe":$.isDeferred(content)?"deferred":"html"},displayQueue:[],display:function(options){if(self.resizing)return self.displayQueue.push(options);$.isPlainObject(options)&&(self.options=$.extend(!0,{},self.Class.defaults,options)),self.ready||self.options.showOverlay&&self.createOverlay();
var options=self.options,content=options.content;self.contentReady=null===content,self.contentType=self.determineContentType(content);var transition=options.transition;switch($.isString(transition)&&(options.transition={show:transition,hide:transition}),self.contentType){case"html":self.hideLoader(),self.show();break;case"iframe":var iframe=$(document.createElement("iframe")),iframeUrl=content,iframeCss=options.iframe.css,iframeButtons=options.buttons,dialogContent=self.dialogContent,iframeOptions=$.extend(!0,{},options,{content:iframe,buttons:iframeButtons});
self.showLoader(function(){onIframeLoaded=function(){return function(){try{iframe[0].contentWindow.parentDialog=self}catch(err){}self.update(iframeOptions)}}(),self.dialogBody.addClass("type-iframe"),iframe.appendTo(dialogContent).css(iframeCss).css({position:"absolute",visibility:"hidden"}).one("load",onIframeLoaded).attr("src",iframeUrl)});break;case"deferred":var ajax=content;self.showLoader(function(){ajax.done(function(html){if(html){var newOptions=$.isString(html)?{content:html}:html;newOptions.content&&self.update($.extend(!0,{},options,newOptions))
}}).fail(function(message,type){var title=$.isString(type)?$.String.capitalize(type):"Error",content=$.isString(message)?message:"There was an error loading content.";self.update({title:title,content:content})})});break;case"dialog":var xmlOptions=$.buildHTML(content),newOptions={};$.each(xmlOptions.children(),function(i,node){var node=$(node),key=$.String.camelize(this.nodeName.toLowerCase()),val=node.html(),type=node.attr("type");switch(type){case"json":try{val=$.parseJSON(val)}catch(e){}break;case"javascript":try{val=eval("(function($){ return "+$.trim(val)+" })("+$.globalNamespace+")")
}catch(e){}break;case"text":val=node.text()}$.isNumeric(val)&&(val=parseFloat(val)),newOptions[key]=val}),self.update($.extend(!0,{},options,newOptions))}},loading:function(flag){var el=self.element;return void 0===flag?el.hasClass("loading"):flag===!1?(el.removeClass("loading"),void 0):(flag===!0&&(flag=self.options.loading||""),$.isString(flag)&&(el.addClass("loading"),self.dialogLoading.html(flag)),void 0)},showLoader:function(callback){var originalWidth=self.options.width,originalHeight=self.options.height,showLoaderOverlay=function(){return self.dialogLoader.show().css({width:self.dialogBody.outerWidth(!0),height:self.dialogBody.outerHeight(!0)}).position({my:"top left",at:"top left",of:self.options.dialogContent}),self.options.width=originalWidth,self.options.height=originalHeight,callback&&callback()
};return self.ready?showLoaderOverlay():self.update($.extend({title:self.options.title,content:"",width:self.initOptions.body.css.minWidth,height:self.initOptions.body.css.minHeight,afterShow:showLoaderOverlay},self.options.loader))},hideLoader:function(){self.element.removeClass("loading"),self.dialogLoader.hide()},autoSize:function(){return"auto"==self.initOptions.css.width||"auto"==self.initOptions.css.height},finalizeContent:function(finale){var options=self.options,content=options.content;if(self.element.css(options.css),self.dialogContent.css(options.body.css),!self.refreshing){if(null!==options.title&&self.dialogTitle.html(options.title),null!==content){var isIframe=!$.isString(content)&&$(content).is("iframe");
if(self.dialogBody.toggleClass("type-iframe",isIframe),isIframe){for(var parent=content.parent()[0],i=0;parent.childNodes.length>1;){var node=parent.childNodes[i];node!==content[0]&&parent.removeChild(node),i++}content.css({position:"relative",visibility:"visible"})}else{var finalContent;finale?(finalContent=content,options.content=self.stripScript(finalContent)):finalContent=self.stripScript(content),self.dialogContent.html(finalContent)}}return self.contentReady||self.finalizeButtons(),self.element}},stripScript:function(html){if(!$.isString(html))return html;
var content=$($.parseHTML(html));return content.find("script").remove(),content},finalizeSize:function(fast){var refElement=self.refElement,options=self.options,body=options.body,content=options.content,css=options.css,bodyCss=body.css;if(void 0===refElement?refElement=self.refElement=self.initElement.clone().removeClass("global").insertAfter(self.element):refElement.insertAfter(self.element),!fast){refTitle=refElement.find(options.dialogTitle),refBody=refElement.find(options.dialogBody),refFooter=refElement.find(options.dialogFooter),refButtons=refElement.find(options.dialogButtons),refElement.css(self.initOptions.css).css({display:"block"}),refTitle.html(options.title),$.isEmptyObject(options.buttons)?refFooter.hide():(refFooter.show(),refButtons.append("<button>test</button>"));
var isIframe=!$.isString(content)&&$(content).is("iframe"),refContent=isIframe?document.createElement("div"):self.stripScript(content);bodyCss.width=isIframe&&"auto"==options.width?content.contents().width():options.width,bodyCss.height=isIframe&&"auto"==options.height?content.contents().height():options.height,refBody.css(bodyCss).toggleClass("type-iframe",isIframe).html(refContent);var refBodyWidth=refBody.width(),refBodyHeight=refBody.height();"border-box"!==refBody.css("boxSizing")&&(bodyCss.width=refBodyWidth,bodyCss.height=refBodyHeight),bodyCss.width<bodyCss.minWidth&&(bodyCss.width=bodyCss.minWidth),bodyCss.height<bodyCss.minHeight&&(bodyCss.height=bodyCss.minHeight);
var offset=options.offset,width=refElement.width(),height=refElement.height(),maxWidth=$(window).width()-offset,maxHeight=$(window).height()-offset,widthExceeded=width>maxWidth,heightExceeded=height>maxHeight;css.width=widthExceeded?maxWidth:width,css.height=heightExceeded?maxHeight:height,"auto"!==bodyCss.width&&(bodyCss.width-=width-css.width),bodyCss.width<=0&&(bodyCss.width="auto"),"auto"!==bodyCss.height&&(bodyCss.height-=height-css.height),bodyCss.height<=0&&(bodyCss.height="auto"),bodyCss.minWidth=bodyCss.minHeight="auto",refBody.css(bodyCss),bodyCss.overflowX=!widthExceeded||isIframe||refBody[0].scrollWidth<=bodyCss.width?"auto":"scroll",bodyCss.overflowY=!heightExceeded||isIframe||refBody[0].scrollHeight<=bodyCss.height?"auto":"scroll",refBody.html("")
}refElement.css(css).css("visibility","hidden").position(options.position),css.top=refElement.css("top"),css.left=refElement.css("left")},finalizeButtons:function(){var dialogFooter=self.dialogFooter,dialogButtons=self.dialogButtons;dialogButtons.empty();var buttons=self.options.buttons;return $.isEmptyObject(buttons)?(dialogFooter.hide(),void 0):($.isString(buttons)&&dialogButtons.html(buttons),$.isArray(buttons)&&$.each(buttons,function(i,button){var events=$.extend({},button),classNames=button.classNames?button.classNames:"";
delete events.name,delete events.classNames,$(document.createElement("button")).attr("type","button").addClass(classNames).html(button.name).bind(events).appendTo(dialogButtons)}),dialogFooter.show(),void 0)},show:function(callback){if(!self.ready||!self.resizing){var options=self.options;self.refElement&&self.refElement.remove(),self.contentReady||options.beforeShow.apply(self),$(document).off("keydown.foundry.dialog"),options.escapeKey&&$(document).on("keydown.foundry.dialog",function(event){27==event.keyCode&&self.close()
}),self.resizing=!0,self.finalizeSize(),self.element.addClass("resizing"),$(window).trigger("dialogTransitionStart"),self.transition[options.transition.show].show.apply(self,[function(){self.ready||(self.on("resize.dialog scroll.dialog",window,$._.debounce(function(){self.refresh()},150)),self.ready=!0),self.contentReady||(callback&&callback.apply(self),options.afterShow.apply(self)),self.refElement.detach(),self.element.removeClass("resizing"),self.contentReady=!0,self.element.css({width:"auto",height:"auto"}),self.removePlugin("binder");
var selectors=options.selectors,bindings=options.bindings;if(selectors&&bindings){var binder=$.Controller($.uid("dialogBinder"),{defaultOptions:selectors},function(){return bindings});self.addPlugin("binder",binder)}self.displayQueue.length>0?setTimeout(function(){self.resizing=!1,self.display(self.displayQueue.shift())},500):(self.resizing=!1,$(window).trigger("dialogTransitionEnd"))}])}},"{self} removePlugin":function(el,event,name,plugin){void 0!==plugin&&delete $.Controller[plugin.Class.fullName]},hide:function(callback){self.contentReady||self.options.beforeHide.apply(self),$(window).trigger("dialogTransitionStart"),self.transition[self.options.transition.hide].hide.apply(self,[function(){callback&&callback.apply(self),self.options.afterHide.apply(self),$(window).trigger("dialogTransitionEnd")
}])},refresh:function(){self.closing||self.resizing||(self.finalizeSize(!0),self.resizing=!0,self.refreshing=!0,$(window).trigger("dialogTransitionStart"),self.transition[self.options.transition.show].show.apply(self,[function(){$(window).trigger("dialogTransitionEnd"),self.resizing=!1,self.refreshing=!1,self.element.css({width:"auto",height:"auto"})}]))},transition:{none:{show:function(callback){self.ready||self.overlay.show(),self.element.finalizeContent().show(0,callback)},hide:function(callback){self.overlay.hide(),self.element.hide(0,callback)
}},fade:{show:function(callback){return self.ready||self.overlay.fadeOut(0).fadeIn("normal"),self.contentReady?(self.element.finalizeContent(),callback&&callback()):(self.element.fadeOut(self.contentReady?"fast":0,function(){self.element.finalizeContent().fadeIn("normal","easeInCubic",callback)}),void 0)},hide:function(callback){self.overlay.fadeOut("normal","easeOutCubic"),self.element.fadeOut("normal","easeOutCubic",callback)}},zoom:{show:function(callback){var dialogBody=self.dialogBody,dialogFooter=self.dialogFooter,css=self.options.css;
self.ready||(self.overlay.fadeIn("fast"),self.element.finalizeContent().css({top:parseInt(css.top)+parseInt(css.height)/2,left:parseInt(css.left)+parseInt(css.width)/2,width:0,height:0})),self.contentReady||(dialogBody.css({opacity:0}),dialogFooter.css({opacity:0})),self.element.animate({top:css.top,left:css.left,width:css.width,height:css.height},"normal","easeInCubic",function(){return self.element.finalizeContent(!0),dialogBody.css({opacity:1}),dialogFooter.css({opacity:1}),callback&&callback()})},hide:function(callback){var css=self.options.css;
self.element.animate({top:parseInt(css.top)+parseInt(css.height)/2,left:parseInt(css.left)+parseInt(css.width)/2,width:0,height:0},"normal","easeOutCubic",function(){return self.overlay.fadeOut("fast"),callback&&callback()})}}},overlay:$("<div></div>"),createOverlay:function(){self.overlay.css(self.options.overlay.css).click(function(){self.close()}).appendTo("body")},closing:!1,close:function(){return self.closing?void 0:(self.closing=!0,$(document).off("keydown.foundry.dialog"),self.hide(function(){self.removePlugin("binder"),self.element.remove(),self.refElement&&self.refElement.remove()
}),self)},"{closeButton} click":function(){self.close()},content:function(){var dialogContent=self.dialogContent,iframe=dialogContent.find("> iframe");return iframe.length>0?iframe.contents():dialogContent},messageGroup:function(){var dialogBody=self.dialogBody,messageGroup=dialogBody.find("> [data-message-group]");return messageGroup.length<1&&(messageGroup=$("<div data-message-group></div>").prependTo(dialogBody)),messageGroup}}}),$.dialog=function(options){if(window.parentDialog)return window.parentDialog.update(options);
var dialog=$(".foundryDialog.global"),controller=dialog.controllers("dialog")[0];if(arguments.length<1&&controller)return controller;if(dialog.length<1&&(dialog=$($.View("dialog/default")).addClass("global").addClass(options.customClass).appendTo("body")),"string"==typeof options||$.isDeferred(options)){var afterShow=arguments[1];options={content:options,afterShow:$.isFunction(afterShow)?afterShow:$.noop}}return controller?controller.update(options):controller=dialog.addController("Dialog",options),controller
}};exports(),module.resolveWith(exports)})};FD31.module("dialog",moduleFactory)}();