(function ($) { $.modal = function (data, options) { return $.modal.impl.init(data, options); }; $.modal.close = function () { $.modal.impl.close(true); }; $.fn.modal = function (options) { return $.modal.impl.init(this, options); }; $.modal.defaults = { overlay: 50, overlayId: 'modalOverlay', overlayCss: {}, containerId: 'modalContainer', containerCss: {}, close: true, closeTitle: 'Close', closeClass: 'modalClose', persist: false, onOpen: null, onShow: null, onClose: null }; $.modal.impl = { opts: null, dialog: {}, init: function (data, options) { if (this.dialog.data) { return false; } this.opts = $.extend({}, $.modal.defaults, options); if (typeof data == 'object') { data = data instanceof jQuery ? data : $(data); if (data.parent().parent().size() > 0) { this.dialog.parentNode = data.parent(); if (!this.opts.persist) { this.dialog.original = data.clone(true); } } } else if (typeof data == 'string' || typeof data == 'number') { data = $('
').html(data); } else { if (console) { console.log('SimpleModal Error: Unsupported data type: ' + typeof data); } return false; } this.dialog.data = data.addClass('modalData'); data = null; this.create(); this.open(); if ($.isFunction(this.opts.onShow)) { this.opts.onShow.apply(this, [this.dialog]); } return this; }, create: function () { this.dialog.overlay = $('
') .attr('id', this.opts.overlayId) .addClass('modalOverlay') .css($.extend(this.opts.overlayCss, { opacity: this.opts.overlay / 100, height: '100%', width: '100%', position: 'fixed', left: 0, top: 0, zIndex: 3000 })) .hide() .appendTo('body'); this.dialog.container = $('
') .attr('id', this.opts.containerId) .addClass('modalContainer') .css($.extend(this.opts.containerCss, { position: 'absolute', zIndex: 3100 })) .append(this.opts.close ? '' : '') .hide() .appendTo('body'); if ($.browser.msie && ($.browser.version < 7)) { this.fixIE(); } this.dialog.container.append(this.dialog.data.hide()); }, bindEvents: function () { var modal = this; $('.' + this.opts.closeClass).click(function (e) { e.preventDefault(); modal.close(); }); }, unbindEvents: function () { $('.' + this.opts.closeClass).unbind('click'); }, fixIE: function () { var wHeight = $(document).height() + 'px'; var wWidth = $(document.body).width() + 'px'; this.dialog.overlay.css({position: 'absolute', height: wHeight, width: wWidth}); this.dialog.container.css({position: 'absolute'}); this.dialog.iframe = $('