April 23
so I love all the lightbox stuff out there, everyday there seems to be another one popup (pardon the pun) on ajaxian. What I dont like is there dependence on the relation tag, and how complicated they can get. So I made my own SimpleModal.js, basic gist is you call it from js, and you send it what ever content you want in it. This gives me more flexibility say to call some ajax to do a save on lightbox close.
heres the js
JAVASCRIPT:
-
function simpleModal(c,s,ci)
-
{
-
this.content = c;
-
this.closescript = s;
-
this.closeicon =ci;
-
}
-
simpleModal.prototype = {
-
openWindow:function()
-
{
-
this.getScroll();
-
this.setScroll(0,0);
-
-
this.hideSelects(true);
-
bod = document.getElementsByTagName('body')[0];
-
overlay = document.createElement('div');
-
overlay.id = 'modalOverlay';
-
lb = document.createElement('div');
-
lb.id = 'modal';
-
lb.innerHTML += '<div style="text-align:right"><a href="javascript:'+this.closescript+';" style="">'+(this.closeicon!=''?'<img src="' + this.closeicon + '" border="0" alt="close" />':'X') + '</a></div>'+this.content;
-
-
bod.appendChild(overlay);
-
bod.appendChild(lb);
-
-
document.getElementById('modal').style.marginLeft=((document.body.clientWidth - document.getElementById('modal').clientWidth)/2)+'px';
-
document.getElementById('modal').style.display='block';
-
-
}
-
,
-
closeWindow:function()
-
{
-
this.hideSelects(false);
-
document.getElementById('modal').style.display='none';
-
bod = document.getElementsByTagName('body')[0];
-
bod.removeChild(document.getElementById('modalOverlay'));
-
bod.removeChild(document.getElementById('modal'));
-
}
-
-
,
-
// borrowed from lightbox implementation found at http://www.huddletogether.com/projects/lightbox/
-
/*---------------------------------------------------------------------------------------------*/
-
hideSelects: function(visibility){
-
selects = document.getElementsByTagName('select');
-
for(i = 0; i <selects.length; i++) {
-
try{
-
selects[i].style.visibility = visibility;
-
}catch(err){}
-
}
-
},
-
-
getScroll: function(){
-
if (self.pageYOffset) {
-
this.yPos = self.pageYOffset;
-
} else if (document.documentElement && document.documentElement.scrollTop){
-
this.yPos = document.documentElement.scrollTop;
-
} else if (document.body) {
-
this.yPos = document.body.scrollTop;
-
}
-
},
-
-
setScroll: function(x, y){
-
window.scrollTo(x, y);
-
}
-
-
/*----------------------------------------------------------------------------------------------*/
-
-
}
heres the css
HTML:
-
#modalOverlay{
-
position:absolute;
-
top:0;
-
left:0;
-
width:100%;
-
height:100%;
-
z-index:5000;
-
background-color:#000;
-
-moz-opacity: 0.8;
-
opacity:.80;
-
filter: alpha(opacity=80);
-
}
-
-
#modalOverlay[id]{
-
position:fixed;
-
}
-
-
#modal{
-
position: absolute;
-
z-index:9999;
-
height:inherit;
-
border:10px solid #555555;
-
background:#FDFCE9;
-
text-align:left;
-
top: 40px;
-
left: 0;
-
width: inherit;
-
margin: 0 auto;
-
disply:none;
-
}
-
-
#modal[id]{
-
position:fixed;
-
}
and some implementation code
JAVASCRIPT:
-
var uploader = new simpleModal('<iframe src="uploadfile.aspx" width="300" height="200" />','CloseUploadFile()','images/close.gif');
-
-
function UploadFile()
-
{
-
uploader.openWindow();
-
}
-
-
function CloseUploadFile()
-
{
-
uploader.closeWindow();
-
<%=this.UpdateJS%>;
-
//in my case UpdateJS makes an Asp.Net Ajax postback
-
}
