-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.ui.domwindow.min.js
6 lines (6 loc) · 12.6 KB
/
jquery.ui.domwindow.min.js
1
2
3
4
5
6
/*! jQuery.ui.domwindow (https://github.com/Takazudo/jQuery.ui.domwindow)
* lastupdate: 2013-12-25
* version: 0.3.5
* author: 'Takazudo' Takeshi Takatsudo <takazudo@gmail.com>
* License: MIT */
(function(){var e=[].slice;(function(i,t,n){var o,r,s,a,d,l,h,u,c,p,f,g,v,w,m,y;return r=i(t),o=i(n),g=Math.round,t.domwindowNs=u={},t.domwindowApi=a=null,y=u.widgets={$dialog:null,$overlay:null},u.ie6=function(){var e;return e=i("<div><!--[if IE 6]><i></i><![endif]--></div>"),e.find("i").length?!0:!1}(),u.isBlackListedMobile=function(){var e=window,i=navigator.userAgent,t=navigator.platform,n=i.match(/AppleWebKit\/([0-9]+)/),o=!!n&&n[1],r=i.match(/Fennec\/([0-9]+)/),s=!!r&&r[1],a=i.match(/Opera Mobi\/([0-9]+)/),d=!!a&&a[1];return(t.indexOf("iPhone")>-1||t.indexOf("iPad")>-1||t.indexOf("iPod")>-1)&&o&&534>o||e.operamini&&"[object OperaMini]"==={}.toString.call(e.operamini)||a&&7458>d||i.indexOf("Android")>-1&&o&&533>o||s&&6>s||"palmGetResource"in window&&o&&534>o||i.indexOf("MeeGo")>-1&&i.indexOf("NokiaBrowser/8.5.0")>-1?!0:!1},u.positionFixedUnavailable=u.ie6||u.isBlackListedMobile(),u.isQuirks=function(){return-1===navigator.userAgent.indexOf("MSIE")?!1:5===n.documentMode?!0:!1},f=function(){return i.Deferred(function(e){return e.resolve()})},v=u.viewportH=function(){return t.innerHeight||r.height()||n.body.offsetHeight},w=u.viewportW=function(){return r.width()||n.body.offsetWidth},p=u.offsetY=function(){return t.pageYOffset||n.documentElement.scrollTop||n.body.scrollTop},c=u.offsetX=function(){return t.pageXOffset||n.documentElement.scrollLeft||n.body.scrollLeft},m=function(e){return i.Deferred(function(i){return setTimeout(function(){return i.resolve()},e)})},i.widget("ui.hideoverlay",{options:{overlayfade:!0,spinnersrc:null,maxopacity:.8,bgiframe:!1,forceabsolute:u.positionFixedUnavailable||u.isQuirks()||!1,spinjs:!1,spinjs_options:{color:"#fff",lines:15,length:22,radius:40}},widgetEventPrefix:"hideoverlay.",_active:!1,_create:function(){return this.$el=this.element,this.$spinner=i(".ui-hideoverlay-spinner",this.$el),this.options.spinjs&&this.$spinner.css("background","none"),this.$bg=i(".ui-hideoverlay-bg",this.$el),this._preloadSpinner(),this._eventify(),this._handleLegacy(),this},_attachSpinjs:function(){return this._showDefer?this._spinning?(new Spinner(this.options.spinjs_options).spin(this.$spinner[0]),this):this:this},_handleLegacy:function(){return this.options.forceabsolute?(this.$el.css("position","absolute"),this._resize(),this.options.bgiframe&&i.fn.bgiframe&&this.$el.bgiframe(),this):this},_resize:function(){var e,i,t,n;return this.options.forceabsolute?(n=w(),e=v(),t=p(),i=c(),this.$el.css({width:n,height:e,top:t,left:i}),this.$bg.css({width:n,height:e}),this):this},_eventify:function(){var e=this;return this.options.forceabsolute?(r.bind("resize scroll orientationchange",function(){return e._resize()}),this):this},_showOverlayEl:function(e){var t,n,o,r=this;return o=i.Deferred(o),this.$spinner.hide(),this.$el.css("display","block"),n={opacity:0},t={opacity:this.options.maxopacity},this.options.overlayfade?i.when(this.$bg.stop().css(n).animate(t,200)).done(function(){return e||(r.options.spinjs&&(r.$spinner.show(),r._attachSpinjs()),r.$spinner.hide().fadeIn()),o.resolve()}):(this.$bg.css(t),e||(this.options.spinjs&&(this.$spinner.show(),this._attachSpinjs()),this.$spinner.show()),o.resolve()),o.promise()},_hideOverlayEl:function(){var e,t,n,o=this;return t=i.Deferred(t),e={opacity:0},n=function(){return o.$el.css("display","none"),o.$spinner.show(),t.resolve()},this.options.overlayfade?i.when(this.$bg.stop().animate(e,100)).done(function(){return n()}):(this.$bg.css(e),n()),t.promise()},_preloadSpinner:function(){var e;return(e=this.options.spinnersrc)?((new Image).src=e,this):this},show:function(e){var i=this;return this._showDefer?this._showDefer:this._active?f():(this._active=!0,e?this.hideSpinner():(this._spinning=!0,this.$spinner.show()),this._trigger("showstart"),this._showDefer=this._showOverlayEl(e),this._showDefer.done(function(){return i._showDefer=null,i._trigger("showend")}),this._showDefer)},hide:function(){var e=this;return this._showDefer?(this._showDefer.done(function(){return e.hide()}),this):this._active?(this._active=!1,this._trigger("hidestart"),this._hideDefer=this._hideOverlayEl(),this._hideDefer.done(function(){return e._hideDefer=null,e.$spinner&&e.$spinner.empty(),e._trigger("hideend")}),this._hideDefer):f()},hideSpinner:function(){return this._spinning=!1,this.$spinner.stop().empty().hide(),this}}),i.ui.hideoverlay.create=function(e){var t;return t='<div class="ui-hideoverlay" id="domwindow-hideoverlay">\n <div class="ui-hideoverlay-bg"></div>\n <div class="ui-hideoverlay-spinner"></div>\n</div>',i(t).hideoverlay(e)},i.ui.hideoverlay.destroy=function(){return y.$overlay?(y.$overlay.hideoverlay("destroy").remove(),y.$overlay=null,!0):!1},i.ui.hideoverlay.setup=function(e){var t;return i.ui.hideoverlay.destroy(),t=i.ui.hideoverlay.create(e).appendTo("body"),y.$overlay=t,t},i.widget("ui.domwindowdialog",{options:{spinjs:!1,height:500,width:500,fixedMinY:30,selector_open:".apply-domwindow-open",selector_close:".apply-domwindow-close",ajaxdialog:!0,ajaxdialog_avoidcache:!0,ajaxdialog_mindelay:300,iframedialog:!1,iddialog:!1,strdialog:!1,overlay:!0,overlayclickclose:!0,forceabsolute:u.positionFixedUnavailable||u.isQuirks()||!1,centeronresize:!0,centeronscroll:!1,tandbmargintodecideposition:50},widgetEventPrefix:"domwindowdialog.",_create:function(){return this.$el=this.element,this.$el.css({width:this.options.width,height:this.options.height}),this._eventify(),this},_eventify:function(){var e,i=this;return e=this,o.on("click",this.options.selector_open,function(i){var t;return i.preventDefault(),t=h(this),e.open.apply(e,t)}),o.on("click",this.options.selector_close,function(e){return e.preventDefault(),i.close()}),r.on("resize",function(){return i.options.centeronresize?i.center():void 0}),r.on("scroll",function(){return i.options.centeronscroll?i.center():void 0}),r.on("orientationchange",function(){return i.center()}),this},_appendFetchedData:function(e){return this.$el.empty().append(e),this},setOverlay:function(e){var i=this;return this.options.overlay?(this.$overlay=e,this.overlay=e.data("uiHideoverlay"),this.options.overlayclickclose&&this.$overlay.bind("click",function(){return i.close()}),this):this},center:function(){var e,i,t,n,o,r,s,a,d;return s={},e=this.$el.outerHeight(),i=this.$el.outerWidth(),d=w(),a=v(),r=p(),o=c(),n=i>d,t=e+this.options.tandbmargintodecideposition>a,n?(s.left=0,t?(s.position="absolute",s.top=this.options.fixedMinY+r):(s.position="absolute",s.top=g(a/2)-g(e/2)+r)):t?(s.position="absolute",s.top=this.options.fixedMinY+r,s.left=g(d/2)-g(i/2)+o):(s.top=g(a/2)-g(e/2),s.left=g(d/2)-g(i/2),this.options.forceabsolute?(s.position="absolute",s.top+=r,s.left+=o):s.position="fixed"),this.$el.css(s),this},open:function(t,n){var o,r,s,a,d,l,h,u,c,p,f,g,v,w,y,_=this;switch(this._isOpen=!0,null!=(p=this._currentOpen)&&p.kill(),this._currentOpen=s={},s.defer=i.Deferred(),u=this.options,s.restoreOriginalOptions=function(){return this.options=u},s.kill=function(){s.restoreOriginalOptions(),s.killed=!0},r=function(){return s.killed?void 0:(_.$el.fadeIn(200,function(){var e;return null!=(e=_.overlay)&&e.hideSpinner(),_._trigger("afteropen",{},{dialog:_.$el}),_._currentOpen=null}),m(0).done(function(){return _.center()}),s.defer.resolve())},l=null,i.isFunction(t)?l="deferred":0===t.indexOf("#")?(l="id",t=t.replace(/^#/,"")):(this.options.ajaxdialog&&(l="ajax"),this.options.iframedialog&&(l="iframe"),this.options.iddialog&&(l="id"),this.options.strdialog&&(l="str"),(null!=n?n.ajaxdialog:void 0)&&(l="ajax"),(null!=n?n.iframedialog:void 0)&&(l="iframe"),(null!=n?n.iddialog:void 0)&&(l="id"),(null!=n?n.strdialog:void 0)&&(l="str")),"id"===l?(o=i("#"+t),this.$lastIdTarget=o,o.is(":ui-domwindow")?n=i.extend({},o.domwindow("createApiOpenOptions"),n):this.$lastIdTarget=null):this.$lastIdTarget=null,n&&this._applyOneTimeOptions(n,s),this._attachOneTimeEvents(n,"open",s),c=this.options.width,h=this.options.height,this.$el.css({width:c,height:h}),this._trigger("beforeopen",{},{dialog:this.$el}),d=this.options.ajaxdialog_mindelay,l){case"deferred":null!=(f=this.overlay)&&f.show(),a=i.Deferred(),t.apply(this,[a]),i.when(a,m(d)).done(function(e){return _._appendFetchedData(e),r()});break;case"ajax":null!=(g=this.overlay)&&g.show(),i.when(this._ajaxGet(t),m(d)).done(function(){var i,t;return i=arguments.length>=1?e.call(arguments,0):[],t=i[0][0],_._appendFetchedData(t),r()});break;case"iframe":null!=(v=this.overlay)&&v.show(!0),this.$el.empty().append(this._createIframeSrc(t)),r();break;case"id":null!=(w=this.overlay)&&w.show(!0),this._appendFetchedData(o.html()),r();break;case"str":null!=(y=this.overlay)&&y.show(),this._appendFetchedData(t),r()}return s},close:function(e){var t,n,o=this;return t=i.Deferred(),this._isOpen?(this.$lastIdTarget&&(e=i.extend({},e,this.$lastIdTarget.domwindow("createApiCloseOptions"))),this._attachOneTimeEvents(e),null!=(n=this._currentOpen)&&n.kill(),this._isOpen=!1,this._trigger("beforeclose",{},{dialog:this.$el}),m(0).done(function(){var e;return null!=(e=o.overlay)&&e.hide(),o.$el.fadeOut(200,function(){return o._trigger("afterclose",{},{dialog:o.$el}),t.resolve()})}),t.promise()):this},_applyOneTimeOptions:function(e,t){var n,o;return e=i.extend({},e),o=["beforeclose","afterclose","beforeopen","afteropen"],i.each(o,function(i,t){return e[t]?delete e[t]:void 0}),n=this.options,this.options=i.extend({},this.options,e),this.$el.one(""+this.widgetEventPrefix+"afteropen",function(){return(null!=t?!t.killed:true)?t.restoreOriginalOptions():void 0}),this},_attachOneTimeEvents:function(t,n,o){var r,s=this;return t?(r=["beforeclose","afterclose"],"open"===n&&i.merge(r,["beforeopen","afteropen"]),i.each(r,function(i,n){return t[n]?s.$el.one(""+s.widgetEventPrefix+n,function(){var i;return i=arguments.length>=1?e.call(arguments,0):[],(null!=o?!o.killed:true)?t[n].apply(this.$el,i):void 0}):void 0}),this):this},_ajaxGet:function(e){var t;return t={url:e,dataType:"text"},this.options.ajaxdialog_avoidcache&&(t.cache=!1),i.ajax(t)},_createIframeSrc:function(e){var i;return i=l(),'<iframe\n frameborder="0" hspace="0" wspace="0" src="'+e+'" name="'+i+'"\n style="width:100%; height:100%; border:none; background-color:#fff"\n></iframe>'}}),i.ui.domwindowdialog.create=function(e){var t;return t='<div class="ui-domwindowdialog"></div>',i(t).domwindowdialog(e)},i.ui.domwindowdialog.destroy=function(){return y.$dialog?(y.$dialog.domwindowdialog("destroy").remove(),y.$dialog=null,!0):!1},i.ui.domwindowdialog.setup=function(e){var n,o;return i.ui.domwindowdialog.destroy(),n=i.ui.domwindowdialog.create(e),n.appendTo("body"),o=d(e),n.domwindowdialog("setOverlay",i.ui.hideoverlay.setup(o)),a=t.domwindowApi=new s(n),y.$dialog=n,n},d=function(e){var t;return t={},e?(i.each(i.ui.hideoverlay.prototype.options,function(i){return void 0!==e[i]?t[i]=e[i]:void 0}),t):t},h=u.getInfoFromOpener=function(e){var t,n,o,r;return t=i(e),o=[],r=t.data("domwindowUrl")||t.data("domwindowId"),r||(r=t.attr("href").replace(/^#/,"")),o.push(r),n={},t.data("domwindowAjaxdialog")&&(n.ajaxdialog=!0),t.data("domwindowIframedialog")&&(n.iframedialog=!0),t.data("domwindowIddialog")&&(n.iddialog=!0),function(){var e;return e=t.data("domwindowHeight"),e?n.height=e:void 0}(),function(){var e;return e=t.data("domwindowWidth"),e?n.width=e:void 0}(),o.push(n),o},l=function(){return"domwindow-uniqid-"+Math.round(1e3*Math.random())},s=function(){function i(e){this.$dialog=e,this.dialog=this.$dialog.data("uiDomwindowdialog")}return i.prototype.open=function(){var i;return i=arguments.length>=1?e.call(arguments,0):[],this.dialog.open.apply(this.dialog,i)},i.prototype.close=function(){var i;return i=arguments.length>=1?e.call(arguments,0):[],this.dialog.close.apply(this.dialog,i)},i}(),i.widget("ui.domwindow",{options:{iddialog:!0},widgetEventPrefix:"domwindow.",_create:function(){var e=this;return this.$el=this.element,this._id=this.$el.attr("id")||function(){var i;return i=l(),e.$el.attr("id",i),i}(),this},createApiOpenOptions:function(){var e,t;return t=this,e=i.extend({},this.options),delete e.beforeopen,delete e.afteropen,delete e.beforeclose,delete e.afterclose,i.extend(e,{beforeopen:function(e,i){return t._trigger("beforeopen",e,i)},afteropen:function(e,i){return t._trigger("afteropen",e,i)}})},createApiCloseOptions:function(){var e,t;return t=this,e={},delete e.beforeopen,delete e.afteropen,delete e.beforeclose,delete e.afterclose,i.extend(e,{beforeclose:function(e,i){return t._trigger("beforeclose",e,i)},afterclose:function(e,i){return t._trigger("afterclose",e,i)}})},open:function(){return a.open(this._id,this.createApiOpenOptions())},close:function(){return a.close()}})})(jQuery,window,document)}).call(this);