alert.js 1.91 KB
/*
 * alert.js - javascript alert replacement v1.0
 *
 * (c) 2009 Naden Badalgogtapeh - http://www.naden.de/blog/javascript-alert
 *
 */
window.alert=function(){var E=document.getElementById("alert");if(E){document.body.removeChild(E)}E=document.createElement("DIV");E.id=E.className="alert";document.body.appendChild(E);if(arguments.length==1){arguments=["",arguments[0]]}E.innerHTML=(arguments[0]==""?"":'<div class="title">'+arguments[0]+"</div>")+'<div class="body">'+arguments[1]+'</div><div class="button"><a href="" onclick="document.body.removeChild(document.getElementById(\'alert\'));return( false );">ok</a></div>';var D=A(),C=(Math.max(B(arguments[0]),B(arguments[1]))*6);E.style.width=C+"px";E.style.left=parseInt((D[0]+D[2]-C)/2)+"px";E.style.top=parseInt((D[1]+D[3]-(E.offsetHeight||E.pixelHeight))/2)+"px";E.style.display="block";function B(I){var J=I.split("<br />");if(J.length<=1){J=I.split("<br>")}if(J.length<=1){return(I.replace(/<(?:.|\s)*?>/g,"").length)}var F=0;for(var H=0;H<J.length;H++){var G=J[H].replace(/<(?:.|\s)*?>/g,"");if(G.length>F){F=G.length}}return(F)}function A(){var G=0,H=0,F=0,I=0;if(typeof (window.innerWidth)=="number"){G=window.innerWidth;H=window.innerHeight}else{if(document.documentElement&&(document.documentElement.clientWidth||document.documentElement.clientHeight)){G=document.documentElement.clientWidth;H=document.documentElement.clientHeight}else{if(document.body&&(document.body.clientWidth||document.body.clientHeight)){G=document.body.clientWidth;H=document.body.clientHeight}}}if(typeof (window.pageYOffset)=="number"){I=window.pageYOffset;F=window.pageXOffset}else{if(document.body&&(document.body.scrollLeft||document.body.scrollTop)){I=document.body.scrollTop;F=document.body.scrollLeft}else{if(document.documentElement&&(document.documentElement.scrollLeft||document.documentElement.scrollTop)){I=document.documentElement.scrollTop;F=document.documentElement.scrollLeft}}}return([F,I,G,H])}};