码迷,mamicode.com
首页 > 其他好文 > 详细

Bootbox 封装

时间:2018-10-19 18:45:33      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:extend   信息   关闭按钮   static   label   strong   gettime   点击   关闭   

(function ($) {
$.systemBootBox = function (options) {
var opts = $.extend({}, $.systemBootBox.defaults, options);
var tokenTime = new Date().getTime();
$.cookie(‘hf_token‘, tokenTime); //设置cookie
if (opts.boxType == ‘alert‘) {
bootbox.alert({
size: opts.size,
title: opts.title,
message: opts.message,
callback: function (data) { opts.boxCallback(data); },
//buttons: {
// OK: {
// label: ‘<i class="fa fa-check"></i> 确定‘,
// className: ‘btn-info‘, //按钮颜色
// }
//}
});
}
if (opts.boxType == ‘confirm‘) {
bootbox.confirm({
size: opts.size,
message: opts.message,
buttons: {
cancel: {
label: ‘<i class="fa fa-times"></i> 取消‘,
className: ‘btn-danger‘,
},
confirm: {
label: ‘<i class="fa fa-check"></i> 确定‘,
className: ‘btn-info‘, //按钮颜色

}
},
callback: function (data) { opts.boxCallback(data); }
})
}
if (opts.boxType == ‘dialog‘) {
bootbox.dialog({
size: opts.size,
title: opts.title,
message: ‘<form id="DataForm" action="" class="form-style">‘ + opts.message + ‘<input name="token" type="hidden" value="‘ + tokenTime + ‘"/></form>‘,
complete: function () {
opts.onComplete();
},
buttons: {
cancel: {
label: ‘<i class="fa fa-times"></i> 取消‘,
className: ‘btn-danger‘,
callback: function () {
// Example.show(‘Custom cancel clicked‘);
}
},
ok: {
label: ‘<i class="fa fa-check"></i> 确定‘,
className: ‘btn-info‘, //按钮颜色
callback: function (data) {
opts.boxCallback(data);
if (opts.closeOrShow == false) {
return false;
}
}
}
}
});
}
}
$.hideModel = function () {
$(‘.bootbox‘).modal(‘hide‘);
}
$.systemBootBox.defaults = {
boxType: ‘‘,//alert ,confirm,diolog 弹出框 ,警告框,自定义对话框
size: null, // large ,small
title: "标题演示",
message: "标题信息演示",
onComplete: function () { },
onEscape: true, //Esc 关闭对话框
show: false,//立即显示对话框
closeButton: false, //关闭按钮
boxCallback: function (data) { alert(data); }, //回调函数
closeOrShow: false, //true 关闭 false 不关
dialogInt: function () { }, //初始化执行函数
};
})(jQuery);

 调用

$.systemBootBox({
title: titleMsg,
boxType: ‘dialog‘,
message: $(‘#hf_window‘).html(),
boxCallback: function (data) {
edit();
}
});

关闭模态框;    $.hideModel();    默认点击确定不关闭模态框,可修改封装里面为True

修改源码 bootbox.js 

var defaults = {
// default language
locale: "en",
// show backdrop or not. Default to static so user has to interact with dialog
backdrop: "static",
// animate the modal in/out
animate: true,
// additional class string applied to the top level dialog
className: null,
// whether or not to include a close button
closeButton: true,
// show the dialog immediately by default
show: true,
complete: function () { },
// dialog container
container: "body"
};

添加模态框加载完成事件

Bootbox 封装

标签:extend   信息   关闭按钮   static   label   strong   gettime   点击   关闭   

原文地址:https://www.cnblogs.com/soulice/p/9818076.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!