function zdialog(config)
{
this.id = config.id;
/* style class : begin */
if(typeof(config.cls_dlg) == "undefined") this.cls_dlg = 'dlg_frame';
else this.cls_dlg = config.cls_dlg;
if(typeof(config.cls_titlebox) == "undefined") this.cls_titlebox = 'dlg_titlebox';
else this.cls_titlebox = config.cls_titlebox;
if(typeof(config.cls_title) == "undefined") this.cls_title = 'dlg_title';
else this.cls_title = config.cls_title;
if(typeof(config.cls_close) == "undefined") this.cls_close = 'dlg_close';
else this.cls_close = config.cls_close;
if(typeof(config.cls_body) == "undefined") this.cls_body = 'dlg_body';
else this.cls_body = config.cls_body;
if(typeof(config.cls_dragbody) == "undefined") this.cls_dragbody = 'dlg_dragbody';
else this.cls_dragbody = config.cls_dragbody;
if(typeof(config.cls_modal) == "undefined") this.cls_modal = 'dlg_modal';
else this.cls_modal = config.cls_modal;
/* style class : end */
if(typeof(config.autorun) == "undefined") this.autorun = true;
else this.autorun = config.autorun;
if(typeof(config.modal) == "undefined") this.modal = true;
else this.modal = config.modal;
if(typeof(config.title) == "undefined") this.title = "Untitled";
else this.title = config.title;
if(typeof(config.width) == "undefined") this.width = 500;
else this.width = config.width;
if(typeof(config.height) == "undefined") this.height = 300;
else this.height = config.height;
if(typeof(config.askonclose) == "undefined") this.askonclose = false;
else this.askonclose = config.askonclose;
if(typeof(config.movable) == "undefined") this.movable = true;
else this.movable = config.movable;
if(typeof(config.closeaction) == "undefined") this.closeaction = "";
else this.closeaction = config.closeaction;
this.odlg = null;
this.modalobj = null;
this.otitle = null;
this.obody = null;
this.odragbody = null;
this.bodywidth = this.width;
this.bodyheight = this.height;
this.titlespace = 48;
if($.browser.msie && $.browser.version < 7.0) this.titlespace += 12; //¿Ö..±×·±Áø ³ªµµ Àß ¸ð¸£°ÚÀ½...
this.isdlgactive = false;
this.modalactive = false;
this.reload = false; // âÀ» ´ÝÀ»¶§ reloadÇØ¾ß ÇÏ´ÂÁö¸¦ ¼³Á¤ÇÑ´Ù.
if(this.autorun) this.run();
}
zdialog.prototype = {
run : function ()
{
var self = this;
this.odlg = document.createElement("DIV");
this.odlg.id = "dlg_" + this.id;
this.odlg.className = this.cls_dlg;
with(this.odlg.style) {
width = this.width + "px";
height = this.height + "px";
}
var otitlebox = document.createElement("DIV");
otitlebox.id = "dlgtitlebox_" + this.id;
otitlebox.className = this.cls_titlebox;
this.otitle = document.createElement("DIV");
this.otitle.id = "dlgtitle_" + this.id;
this.otitle.className = this.cls_title;
$(this.otitle).html(this.title);
$(this.otitle).width(this.width - this.titlespace); //set width of title bar
$(this.otitle).appendTo(otitlebox);
$(this.otitle).disableSelection();
var oclose = document.createElement("DIV");
oclose.id = "dlgclose_" + this.id;
oclose.className = this.cls_close;
$(oclose).appendTo(otitlebox);
$(oclose).mousedown(function () {
self.hideDlg();
});
this.obody = document.createElement("DIV");
this.obody.id = "dlgbody_" + this.id;
this.obody.className = this.cls_body;
this.odragbody = document.createElement("DIV");
this.odragbody.id = "dlgdragbody_" + this.id;
this.odragbody.className = this.cls_dragbody;
$(otitlebox).appendTo(this.odlg);
$(this.obody).appendTo(this.odlg);
$(this.odragbody).appendTo(this.odlg);
if(this.modal) {
this.modalobj = document.createElement("DIV");
this.modalobj.className = this.cls_modal;
$(this.modalobj).appendTo("body");
}
$(this.odlg).appendTo("body");
if(this.movable) {
$(this.odlg).draggable({
handle: "div." + self.cls_title,
start: function() {
$(self.obody).hide();
with(self.odragbody.style) {
width = self.bodywidth + "px";
height = self.bodyheight + "px";
display = "block";
}
//$(self.odragbody).show();
},
stop: function() {
$(self.odragbody).hide();
$(self.obody).show();
}
//containment: "body"
});
}
else {
$(this.otitle).css("cursor", "default");
}
$(window).resize(function () {
self.setModalSize(20);
//self.setPosition();
});
$(window).scroll(function () {
self.setModalSize(0);
//self.setPosition();
});
},
getTitleHeight : function ()
{
return $("#dlgtitlebox_" + this.id).outerHeight();
},
setModalSize : function (offset)
{
if(this.modalactive == false) return;
var self = this;
if(offset > 0) {
//resize ½Ã modal background ÀÇ width¿Í scroll bar¶§¹®¿¡ ¿ìÃø¿¡ ÀÌ»óÇÑ °ø°£ÀÌ »ý±ä´Ù.
//¸ÕÀú modal backgroundÀÇ width¸¦ -20 ÇÑ ÈÄ,ó¸®ÇÑ´Ù.
//1 microsecond ÈÄ Çì modal backgroundÀÇ Å©±â¸¦ º¸Á¤ÇÑ´Ù.
var winwidth = $(window).width() + $(window).scrollLeft() - offset;
var winheight = $(window).height() + $(window).scrollTop();
$(this.modalobj).width(winwidth);
$(this.modalobj).height(winheight);
setTimeout(function () {
var bodyheight = document.documentElement.scrollHeight;
if(bodyheight == 0) bodyheight = document.body.scrollHeight;
var bodywidth = document.documentElement.scrollWidth;
if(bodywidth == 0) bodywidth = document.body.scrollWidth;
var winwidth = $(window).width() + $(window).scrollLeft();
var winheight = $(window).height() + $(window).scrollTop();
var width = (winwidth < bodywidth)?winwidth:bodywidth;
var height = (winheight < bodyheight)?winheight:bodyheight;
$(self.modalobj).width(width);
$(self.modalobj).height(height);
}, 1);
}
else {
var winwidth = $(window).width() + $(window).scrollLeft();
var winheight = $(window).height() + $(window).scrollTop();
$(this.modalobj).width(winwidth);
$(this.modalobj).height(winheight);
}
},
//2010.10.11
//À§Ä¡±¸Çϱâ
getPosition : function ()
{
var left = parseInt($(window).width() / 2, 10) - parseInt(this.width / 2, 10) + $(window).scrollLeft();
var top = parseInt($(window).height() / 2, 10) - parseInt(this.height / 2, 10) + $(window).scrollTop();
if(left < 0) left = 0;
if(top < 0) top = 0;
return {left:left, top:top};
},
setPosition : function ()
{
if(this.isdlgactive == false) return;
//2010.10.11
//¿¹ÀüÄڵ带 ÇÔ¼öó¸®ÇÔ.
var pos = this.getPosition();
this.odlg.style.left = pos.left + "px";
this.odlg.style.top = pos.top + "px";
},
setSize : function (width, height, doanimation, callback)
{
if(typeof(doanimation) == "undefined") doanimation = false;
this.width = width;
this.height = height;
if(doanimation == false) {
this.odlg.style.width = width + "px";
this.odlg.style.height = height + "px";
$(this.otitle).width(this.width - this.titlespace); //set width of title bar
this.setBodySize(width, height);
}
else {
var self = this;
//2010.10.11
//À̵¿ÇÒ ÃÖÁ¾ À§Ä¡¸¦ ±¸ÇÑ´Ù.
var pos = this.getPosition();
$(this.odlg).animate({
width: self.width,
height: self.height,
left: pos.left, //À§Ä¡¸¦ µ¿½Ã¿¡ º¯°æÇϱâ À§ÇØ
top: pos.top
}, 300, function() {
$(self.otitle).width(self.width - self.titlespace); //set width of title bar
self.setBodySize(self.width, self.height);
if($.isFunction(callback)) callback();
});
$(this.obody).animate({
width: self.width,
height: self.height
}, 300);
}
},
setBodySize : function (width, height)
{
this.bodywidth = width - 0;
this.bodyheight = height - 23;
with(this.obody.style) {
width = this.bodywidth + "px";
height = this.bodywidth + "px";
}
with(this.odragbody.style) {
width = this.bodywidth + "px";
height = this.bodywidth + "px";
}
},
setBody : function (content, bframe, bscroll)
{
var str = "";
if(typeof(bframe) == "undefined") bframe = true;
if(typeof(bscroll) == "undefined") bscroll = true;
if(bframe) {
if(bscroll) str = '';
else str = '';
}
else {
str = content;
}
$(this.obody).html(str);
},
getAjaxContent : function (pageurl, succfunc, errfunc)
{
var today = new Date();
var dummy = today.getTime();
var url = "";
if(pageurl.indexOf('?')) url = pageurl + '&dummy=' + dummy;
else url = pageurl + '?dummy=' + dummy;
$.ajax({
url: url,
type: 'GET',
timeout: 1000,
error: function(xhr, status, error){
if($.isFunction(errfunc)) errfunc(error);
}, //error
success: function(data){
if($.isFunction(succfunc)) succfunc(data);
} //success
}); //ajax
},
setTitle : function (str)
{
$(this.otitle).html(str);
},
showDlg : function ()
{
if(this.modal) {
this.modalactive = true;
this.setModalSize(0);
$(this.modalobj).show();
}
this.setSize(this.width, this.height);
this.isdlgactive = true;
this.setPosition();
$(this.odlg).show();
},
setReload : function (flag, force)
{
if(typeof force == "undefined") force = false;
if(force) this.reload = flag; // °Á¦·Î reload ¼³Á¤À» º¯°æÇϴ°æ¿ì
else if(!this.reload) this.reload = flag; // ±âÁ¸¿¡ reload°¡ ¼³Á¤µÇ¾î ÀÖÀ¸³ª, false·Î ¼³Á¤µÉ °æ¿ì´Â ±âÁ¸¼³Á¤À» µû¸¥´Ù.
},
hideDlg : function ()
{
if(this.askonclose && !confirm("âÀ» ´ÝÀ¸½Ã°Ú½À´Ï±î?")) return;
if(this.modal) $(this.modalobj).hide();
$(this.odlg).hide();
this.isdlgactive = false;
this.modalactive = false;
if((this.closeaction || this.reload) && $.isFunction(this.closeaction)) this.closeaction();
}
};