//**************************************** // CLASSE JS_floatingbox // Floating Box // Autore: Massimiliano Cuttini // Versione: 1.2 //**************************************** var JS_floatingBox_assoc = new Array(); var JS_floatingBox_init = false; function JS_floatingBox(div_id) { //costruzione di un ID associativo autonomo this.ID = JS_floatingBox_assoc.length; this.opened = false; JS_floatingBox_assoc[this.ID] = this; this.autoclose = true; this.speed = "fast"; this.div_inner = $("#"+div_id); this.div = this.div_inner.show().wrap("
").parent().attr('class', 'floatingBox'); this.div.css({ position: 'fixed' }); this.div_inner.css({ overflow: 'auto', margin: '5px' }); if (!JS_floatingBox_init) { var o = document.body.appendChild(document.createElement('div')); o.id = "floatingBox_lock"; } var t = this; $(window).resize(function() { t.center(); }); } JS_floatingBox.prototype.center = function () { if (this.opened) { var mH = this.div.outerHeight()-this.div.height(); var mW = this.div.outerWidth()-this.div.width(); var sH = (($(window).height()-(this.div_inner.prop("scrollHeight")+mH))>10); var sW = (($(window).width()-(this.div_inner.prop("scrollWidth")+mW))>10); this.div_inner.height((sH) ? "auto" : $(window).height()-(mH)-10-18); this.div_inner.width((sW) ? "auto" : $(window).width()-(mW)-10-18); this.div_inner.css({ paddingBottom:((sH && sW) ? "5" : "18") + 'px', paddingRight:((sH && sW) ? "5" : "18") + 'px' }); this.div.offset({ top: Math.max(0, (($(window).height() - this.div.outerHeight()) / 2) + $(window).scrollTop()), left: Math.max(0, (($(window).width() - this.div.outerWidth()) / 2) + $(window).scrollLeft()) }); } }; JS_floatingBox.prototype.setAutoClose = function(autoclose) { this.autoclose = autoclose; }; JS_floatingBox.prototype.open = function() { this.opened=true; this.div.fadeIn(this.speed); this.center(); $("#floatingBox_lock").fadeIn(this.speed); $("#floatingBox_lock").unbind("click"); if (this.autoclose) { $("#floatingBox_lock").click(function() { for (var c in JS_floatingBox_assoc) JS_floatingBox_assoc[c].close(); }); } }; JS_floatingBox.prototype.close = function() { this.opened=false; this.div.fadeOut(this.speed); $("#floatingBox_lock").fadeOut(this.speed); };