(function(){"use strict";var e=[];u8.Mobile.Popup=function(e){$.extend(this,e);this._create()};$.extend(u8.Mobile.Popup.prototype,{close:function(){this._removePopup();this._removeElement();if(e.length<=0){this._removeModal()}},confirm:function(){return $.Deferred().resolve().promise()},getView:function(){return this._view},_addPopup:function(){e.push(this)},_removePopup:function(){var t=e.indexOf(this);if(t>=0){e.splice(t,1)}},_addModal:function(){var e=document.createElement("div");e.className="u8-modal";document.body.insertBefore(e,document.body.firstChild);this._scrollPosition={documentElement:document.documentElement.scrollTop,body:document.body.scrollTop};document.body.classList.add("has-modal")},_removeModal:function(){var e=document.querySelector(".u8-modal");if(e){e.parentNode.removeChild(e);document.body.classList.remove("has-modal");if(this._scrollPosition){if(this._scrollPosition.documentElement){document.documentElement.scrollTop=this._scrollPosition.documentElement}else if(this._scrollPosition.body){document.body.scrollTop=this._scrollPosition.body}delete this._scrollPosition}}},_hasModal:function(){return!!document.querySelector(".u8-modal")},_addElement:function(){var e=document.createElement("div");e.className="u8-popup";document.body.insertBefore(e,document.body.firstChild);this.element=e},_removeElement:function(){if(this.element){this.element.parentNode.removeChild(this.element);this.element=null}},_create:function(){this._addPopup();if(!this._hasModal()){this._addModal()}this._addElement();this._createView()},_createView:function(){this._view=u8.create("View",this.element);var e=this.url;if(!e){return}e=new u8.Base.Uri(e);e.set("popup",true);e=e.toString_();var t=this;this._view.load(e).fail(function(){t.close()})}});$.extend(u8.Mobile.Popup,{close:function(){while(e.length>0){e[e.length-1].close()}},confirm:function(){var t=e.length;var o=$.Deferred();function n(){if(t--<0){return o.resolve()}var i=e[t];i.confirm.done(n).fail(function(e){o.reject(e)})}n();return o.promise()},create:function(e){return new u8.Mobile.Popup($.extend({},e,{parent:this}))},get:function(t){for(var o=0;o<e.length;o++){var n=e[o];if(n.element.contains(t)){return n}}return}});u8.Mobile.Popup.makeClass({name:"Popup"})})();