var Modalbox = jQuery.Class({ 'defaults':{ content:'' }, 'init':function(options){ var self = this; this.options = jQuery.extend({},this.defaults,options); // console.log(this.options); this.$blanket = jQuery("
").prependTo('body'); this.$modalcontainer = jQuery(""); this.$modalcontainer.data('modalobj',self); this.$modalclose = jQuery("").prependTo(this.$modalcontainer); this.$modalcontent = jQuery("").appendTo(this.$modalcontainer); this.$modalclose.click(function(){ self.close(); }); this.$blanket.click(function(){ self.close(); }); this.setcontents(this.options.content); this.$modalcontainer.prependTo('body'); }, 'open':function(){ }, 'close':function(){ this.$modalcontainer.remove(); this.$blanket.remove(); }, 'setcontents':function(content){ this.$modalcontent.html(content); this.adjustposition(); }, 'ajaxcontents':function(obj){ var self = this; jQuery.ajax({ 'url':obj.url, 'data':obj.data?obj.data:{}, 'type':obj.method?obj.method:'get', 'success':function(data){ self.setcontents(data); if (obj.success){ obj.success(); } } }) }, 'adjustposition':function(){ var position = this.$modalcontainer.position(); // console.log(position); var winheight = jQuery(window).height(); var winwidth = jQuery(window).width(); var elemheight = this.$modalcontainer.height(); var elemwidth = this.$modalcontainer.width(); // console.log(winheight); // console.log(winwidth); var newtop = Math.floor(winheight/2) - Math.floor(elemheight/2); var newleft = Math.floor(winwidth/2) - Math.floor(elemwidth/2); // console.log(newtop); // console.log(newleft); this.$modalcontainer.css({'top':newtop,'left':newleft}); } });