61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
|
define(function (require, exports, module) {
|
|||
|
var modalTemplate = $("div.modal-dialog");
|
|||
|
var widget = require("./widget.js");
|
|||
|
|
|||
|
$.fn.showModalDialog = function (options) {
|
|||
|
if (!this.length || this.is(":visible"))
|
|||
|
return this;
|
|||
|
|
|||
|
options = $.extend({}, { buttons: [], cancelConfirm: null, title: "我是对话框", showCloseButton: true }, options);
|
|||
|
|
|||
|
var template = modalTemplate.clone();
|
|||
|
$(document.body).append(template);
|
|||
|
template.find(">div").append(this);
|
|||
|
template.find(">header>span").html(options.title);
|
|||
|
if (!options.showCloseButton) {
|
|||
|
template.find(">header>i").remove();
|
|||
|
}
|
|||
|
this.show();
|
|||
|
|
|||
|
var hideModalDialog = function (callback) {
|
|||
|
if (options.cancelConfirm && !options.cancelConfirm())
|
|||
|
return;
|
|||
|
|
|||
|
widget.hideFloatDialog(template, function () {
|
|||
|
$(document.body).append(template.find(">div").children().hide());
|
|||
|
template.remove();
|
|||
|
callback && callback();
|
|||
|
});
|
|||
|
};
|
|||
|
options.hide = hideModalDialog;
|
|||
|
//处理按钮
|
|||
|
var buttonContainer = template.find(">footer");
|
|||
|
$.each(options.buttons, function () {
|
|||
|
var btn = $("<button type='button' class='button button-" + (this.type || "default") + "'></button>");
|
|||
|
buttonContainer.append(btn);
|
|||
|
btn.text(this.text || "按钮");
|
|||
|
if (this.icon) {
|
|||
|
btn.prepend("<i class='fa fa-" + this.icons + "' />");
|
|||
|
}
|
|||
|
if (this.callback) {
|
|||
|
btn.click(function () {
|
|||
|
this.apply(template, [options]);
|
|||
|
}.bind(this.callback));
|
|||
|
}
|
|||
|
if (this.cancel) {
|
|||
|
btn.click(function () {
|
|||
|
hideModalDialog();
|
|||
|
});
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
template.find(".close").click(function () {
|
|||
|
widget.hideFloatDialog(template);
|
|||
|
});
|
|||
|
|
|||
|
widget.showFloatDialog(template);
|
|||
|
|
|||
|
return this;
|
|||
|
};
|
|||
|
});
|