define(function (require, exports, module) { var modalTemplate = $("div.modal-dialog"); var widget = require("./widget.js"); $.showModalDialog = function (content, options) { options = $.extend({}, options, { destory: true }); $((options.image ? "" : "") + "

" + content + "

").showModalDialog(options); }; $.fn.showModalDialog = function (options) { if (!this.length || this.is(":visible")) return this; options = $.extend({}, { buttons: [], cancelConfirm: null, destory: false, title: "", showCloseButton: true, closeOnAction: true }, options); var template = modalTemplate.clone(); var closed = false; $(document.body).append(template); template.find(">div").append(this); if (options.title) template.find(">header>span").html(options.title); else template.addClass("modal-popup").find(">header").remove(); if (!options.showCloseButton) { template.find(">header>i").remove(); } this.show(); var hideModalDialog = function (callback) { if (closed || options.cancelConfirm && !options.cancelConfirm()) return; widget.hideFloatDialog(template, function () { if (options.destory) { template.find(">div").empty(); } else { $(document.body).append(template.find(">div").children().hide()); } template.remove(); callback && callback(); }); closed = true; }; options.hide = hideModalDialog; //处理按钮 var buttonContainer = template.find(">footer"); $.each(options.buttons, function () { var btn = $(""); buttonContainer.append(btn); btn.text(this.text || "按钮"); if (this.icon) { btn.prepend(""); } if (this.callback) { btn.click(function () { return this.apply(template, [options]); }.bind(this.callback)); } if (options.closeOnAction || this.cancel) { btn.click(function (e) { if (e.isDefaultPrevented) return; hideModalDialog(); }); } }); widget.showFloatDialog(template); return this; }; });