var __Sender; var ModalPopup = { _Titulo: null, _Texto: null, _ModalType: undefined, _UrlNavegate: undefined, _ModalWidth: null, _ModalHeight: null, Navegate: function (Url, Width, Height) { this._ModalType = 'Navegate'; this._UrlNavegate = Url; this._ModalWidth = Width; this._ModalHeight = Height; this.Create.Navegate(); this.Show(); }, Confirm: function (Texto, Titulo, sender, e) { this._Titulo = Titulo; this._Texto = Texto; this._ModalType = 'Confirm'; this._ModalWidth = '350'; this._ModalHeight = '150'; if (sender._Confirmed) { sender._Confirmed = false; return true; } else { this.Create.Confirm(); __Sender = sender; //$get("__btnOk").OnOkScript = '__Sender._Confirmed = true; __Sender.click();'; ModalPopup.Execute(function () { document.getElementById("__btnOk").OnOkScript = '__Sender._Confirmed = true; __Sender.click();' }); this.Show(); try { ModalPopup.Execute(function () { document.getElementById("__btnCancelar").focus() }); } catch (e) { } e.returnValue = false; if (e.preventDefault) { e.preventDefault(); e.stopPropagation(); }; }; }, Alert: function (Texto, Titulo, ModalType) { this._Titulo = Titulo; this._Texto = Texto; this._ModalType = ModalType; this._ModalWidth = '350'; this._ModalHeight = '150'; this.Create.Alert(); this.Show(); ModalPopup.Execute(function () { document.getElementById("__btnAlertOk").focus() }); }, AlertAndRedirect: function (Texto, Titulo, Url, e, ModalType) { this._Titulo = Titulo; this._Texto = Texto; this._ModalType = ModalType; this._ModalWidth = '350'; this._ModalHeight = '150'; this.Create.AlertAndRedirect(); this.Show(); // so funcionava no IE //ModalPopup.Execute(function(){document.getElementById("__btnAlertAndRedirectOk").attachEvent('onclick',function(){location.href=Url})}); var buttonok = document.getElementById("__btnAlertAndRedirectOk"); if (buttonok.addEventListener) { // all browsers except IE before version 9 ModalPopup.Execute(function () { buttonok.addEventListener('click', function () { location.href = Url }, false) }); } else { if (buttonok.attachEvent) { // IE before version 9 ModalPopup.Execute(function () { buttonok.attachEvent('onclick', function () { location.href = Url }) }); } } ModalPopup.Execute(function () { document.getElementById("__btnAlertAndRedirectOk").focus() }); e.returnValue = false; }, Create: { _dvModalClassName: 'dvModal', _dvModalBackgroundClassName: 'dvModalBackground', _dvModalContainerClassName: 'dvModalContainer', _dvModalContentClassName: 'dvModalContent', Navegate: function () { this.Modal('Navegate'); }, Confirm: function () { this.Modal('Confirm'); }, Alert: function () { this.Modal('Alert'); }, AlertAndRedirect: function () { this.Modal('AlertAndRedirect'); }, Modal: function (Type) { var __dvModalBackground = document.createElement('div'); __dvModalBackground.id = 'dvModalBackground'; __dvModalBackground.className = this._dvModalBackgroundClassName; var __dvModalContainer = document.createElement('div'); __dvModalContainer.id = 'dvModalContainer'; __dvModalContainer.className = this._dvModalContainerClassName; __dvModalContainer.style.width = ModalPopup.GetModalWidth() + 'px'; __dvModalContainer.style.height = (ModalPopup.GetModalHeight()-20) + 'px'; __dvModalContainer.style.marginLeft = '-' + (ModalPopup.GetModalWidth() / 2) + 'px'; __dvModalContainer.style.marginTop = '-' + ((ModalPopup.GetModalHeight() / 2)) + 'px'; var __dvModalContent = document.createElement('div'); __dvModalContent.id = 'dvModalContent'; __dvModalContent.className = this._dvModalContentClassName; __dvModalContent.style.width = ModalPopup.GetModalWidth() + 'px'; __dvModalContent.innerHTML = this.ContentBox(Type); var __dvModal = document.createElement('div'); __dvModal.id = 'dvModal'; __dvModal.className = this._dvModalClassName; document.body.appendChild(__dvModal); document.getElementById("dvModal").appendChild(__dvModalContainer); document.getElementById("dvModal").appendChild(__dvModalBackground); document.getElementById("dvModalContainer").appendChild(__dvModalContent); }, ContentBox: function (BoxType) { var box; if (BoxType == 'Confirm' || BoxType == 'Alert' || BoxType == 'Navegate') { box = ''; } else { box = '
'; }; box += ' '; box += ' '; box += ' '; box += ' '; box += ' ' box += ' '; box += '
'; // CONTEÚDO DO MODAL if (BoxType == 'Navegate') { box += ' '; box += ' '; box += ' '; box += ' '; box += ' '; box += ' '; box += ' '; box += ' '; box += '
Fechar
'; box += ' '; box += '
'; } else { box += ' '; box += ' '; if (ModalPopup.GetModalType() != undefined) { box += ' '; }; box += ' '; box += ' '; box += '
'; box += '
' + ModalPopup.GetTitulo() + '

'; box += '
' + ModalPopup.GetTexto() + '


'; box += '
'; box += '
'; if (BoxType == 'Confirm') { box += ModalPopup.Create.ConfirmOptions(); } else if (BoxType == 'Alert') { box += ModalPopup.Create.AlertOptions(); } else if (BoxType == 'AlertAndRedirect') { box += ModalPopup.Create.AlertAndRedirectOptions(); }; }; // FIM DO CONTEÚDO box += '
'; return box; }, GetImagesUrl: function () { return "/img/modalpopup/"; }, ConfirmOptions: function () { var Options; Options = '   '; Options += ' '; return Options; }, AlertOptions: function () { var Options; Options = '   '; return Options; }, AlertAndRedirectOptions: function () { var Options; Options = '   '; return Options; } }, GetTitulo: function () { return this._Titulo; }, GetTexto: function () { return this._Texto; }, GetModalType: function () { return this._ModalType; }, GetUrlNavegate: function () { return this._UrlNavegate; }, GetModalWidth: function () { if (this._ModalWidth > ModalPopup.GetWindowWidth()) { this._ModalWidth = ModalPopup.GetWindowWidth(); } return this._ModalWidth; }, GetModalHeight: function () { if (this._ModalHeight > ModalPopup.GetWindowHeight()) { this._ModalHeight = ModalPopup.GetWindowHeight(); } return this._ModalHeight; }, GetWindowWidth: function () { var myWidth = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myWidth = window.innerWidth; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { //IE 6+ in 'standards compliant mode' myWidth = document.documentElement.clientWidth; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE 4 compatible myWidth = document.body.clientWidth; } return myWidth; }, GetWindowHeight: function () { var myHeight = 0; if (typeof (window.innerWidth) == 'number') { //Non-IE myHeight = window.innerHeight; } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) { //IE 6+ in 'standards compliant mode' myHeight = document.documentElement.clientHeight; } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) { //IE 4 compatible myHeight = document.body.clientHeight; } return myHeight; }, Show: function () { window.onscroll = function () { document.getElementById("dvModal").style.top = document.body.scrollTop; }; document.getElementById("dvModal").style.top = document.body.scrollTop; document.getElementById("dvModal").style.display = 'block'; document.getElementById("dvModalContent").focus(); }, Hide: function () { window.onscroll = null; document.getElementById("dvModal").style.display = 'none'; //var conteiner = document.getElementById("dvModalContainer"); //conteiner.removeChild(document.getElementById("dvModalContent")); var moda = document.getElementById("dvModal"); //moda.removeChild(document.getElementById("dvModalBackground")); //moda.removeChild(document.getElementById("dvModalContainer")); if (moda) { moda.parentNode.removeChild(moda); }; }, CancelClick: function () { this.Hide(); return false; }, OkClick: function (evt) { //setTimeout($get("__btnOk").OnOkScript,0); ModalPopup.Execute(document.getElementById("__btnOk").OnOkScript); this.Hide(); return false; }, Execute: function (act) { setTimeout(act, 100); } }; // Overriding o alert para exibir o modal function alert(Msg){ ModalPopup.Alert(Msg,'Atenção!'); }; // Faz um preload das imagens function PreLoadImgs(){ if (document.images) { pic1= new Image(19,19); pic1.src= ModalPopup.Create.GetImagesUrl() + 'canto_dir_inf.gif'; pic2= new Image(19,19); pic2.src= ModalPopup.Create.GetImagesUrl() + 'canto_dir_sup.gif'; pic3= new Image(19,19); pic3.src= ModalPopup.Create.GetImagesUrl() + 'canto_esq_inf.gif'; pic4= new Image(19,19); pic4.src= ModalPopup.Create.GetImagesUrl() + 'canto_esq_sup.gif'; pic5= new Image(19,1); pic5.src= ModalPopup.Create.GetImagesUrl() + 'linha_dir.gif'; pic6= new Image(19,1); pic6.src= ModalPopup.Create.GetImagesUrl() + 'linha_esq.gif'; pic7= new Image(1,19); pic7.src= ModalPopup.Create.GetImagesUrl() + 'linha_inf.gif'; pic8= new Image(1,19); pic8.src= ModalPopup.Create.GetImagesUrl() + 'linha_sup.gif'; }; }; function loadCss(cssPath) { if ($('link[href="' + cssPath + '"]').length == 0) { var s = document.createElement('link'); s.setAttribute('href', cssPath); s.setAttribute('type', 'text/css'); s.setAttribute('rel', 'stylesheet'); document.getElementsByTagName('head')[0].appendChild(s); } } $(document).ready(function () { loadCss("/css/modalpopup.css"); PreLoadImgs(); });