/* * bdAlertCustom - Sobre-escreve a função Alert() do javaScript * * Copyright (c) 2008 Tihh Gonçalves , http://www.bludata.com.br * Licensed under the MIT License: * http://www.opensource.org/licenses/mit-license.php * * $Version: 1.0.0 BETA * * Dependências: * - jQuery 1.2.6 * - jquery.jqModal * - jquery.tooltip */ var alertAberto = false; var _fnc = ''; function alert(msg, fnc) { _verificaAlert(msg, fnc); } function _verificaAlert(msg, fnc) { if(alertAberto == false) _alertOpen(msg, fnc); else setTimeout("_verificaAlert(msg, fnc)",1000); } function _alertOpen(msg, fnc) { alertAberto = true; //Adiciona tecla de atalho pra fechar alert (ESC) shortcut.add("Esc",function(){ $('#AlertOk').click(); }); //Trata as quebras de linha msg = msg.replaceAll("\n", '
'); //msg = msg + '[' + fnc + ']'; /** *Imprime Alert */ $('
').appendTo("body"); $('
').appendTo("body"); $('
' + msg + '
').appendTo("#AlertCustomForm"); _fnc = fnc; $('
').appendTo("#AlertCustomForm"); //Diz que AlertCustom é modal $('#AlertCustomForm').jqm({ overlay: 60, overlayClass: 'overlay', modal: true, trigger: false }); //Seta/cria tooltip do botão $(document).ready(function() { $("#AlertOk").tooltip({ bodyHandler: function() { return 'Tecle ESC para sair'; }, showURL: false }); }); /** * Mostra Alert */ //Faz aparecer alert $("#AlertCustom").fadeTo("normal", 0.8,function(){ var tamanho = _getPageSize(); var width = tamanho[0]; var height = tamanho[1]; var WindowWidth = tamanho[2]; var WindowHeight = tamanho[3]; var scroll = _getPageScroll(); var left = scroll[0] + (WindowWidth / 2) - ($("#AlertCustomForm").width() / 2); var top = scroll[1] + (WindowHeight / 2) - ($("#AlertCustomForm").height() / 2); $("#AlertCustom").width(width); $("#AlertCustom").height(height); $("#AlertCustomForm").css('left', left); $("#AlertCustomForm").css('top', top); $('#AlertCustom').fadeIn("fast",function(){ $('#AlertCustomForm').jqmShow(); $('#AlertOk').focus(); //esconde os 'selects' (só no ie) if($.browser.msie) $('select').hide(); //Move tooltip para final do body(depois do AlertModal) $("body").append( $("#tooltip") ); }); }); } function _alertClose(fnc) { var fnc = _fnc; /* * Esconde Alert */ $('#AlertCustomForm').jqmHide(); $('#AlertCustom').fadeOut("fast",function(){ /* * Exclui html da pagina */ $('#AlertCustomForm').remove(); $('#AlertCustom').remove(); //mostra os 'selects' (só se for ie) if($.browser.msie) $('select').show(); alertAberto = false; if(!(typeof fnc == 'undefined')) { fnc(); } //Remote tecla de atalho pra fechar alert() shortcut.remove("Esc"); ///////////// }); } /*** * Função que retorna tamanho da página no momento (ideal para fundo de tela) */ function _getPageSize() { var xScroll, yScroll; if (window.innerHeight && window.scrollMaxY) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if (self.innerHeight) { // all except Explorer windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; } else if (document.body) { // other Explorers windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } // for small pages with total height less then height of the viewport if(yScroll < windowHeight){ pageHeight = windowHeight; } else { pageHeight = yScroll; } // for small pages with total width less then width of the viewport if(xScroll < windowWidth){ pageWidth = windowWidth; } else { pageWidth = xScroll; } arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) return arrayPageSize; } /** * Função que retorna posição da página que está sendo exibido na tela (calcula o scrool) */ function _getPageScroll() { var xScroll, yScroll; if (self.pageYOffset) { yScroll = self.pageYOffset; xScroll = self.pageXOffset; } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict yScroll = document.documentElement.scrollTop; xScroll = document.documentElement.scrollLeft; } else if (document.body) {// all other Explorers yScroll = document.body.scrollTop; xScroll = document.body.scrollLeft; } arrayPageScroll = new Array(xScroll,yScroll); return arrayPageScroll; };