/**
* Created by Luker on 2016/10/31.
*/
if (typeof $ === 'function') {
$(function () {
var BeAlert = {
defaultConfig: {
width: 320,
height: 170,
timer: 0,
type: 'warning',
showConfirmButton: true,
showCancelButton: false,
confirmButtonText: '纭',
cancelButtonText: '鍙栨秷'
},
html: '
' +
'
' +
'
' +
'
' +
'
' +
'' +
'' +
'
' +
'
',
overlay: '',
open: function (title, message, callback, o) {
var opts = {}, that = this;
$.extend(opts, that.defaultConfig, o);
$('body').append(that.html).append(that.overlay);
var box = $('.BeAlert_box');
box.css({
'width': opts.width + 'px',
'min-height': opts.height + 'px',
'margin-left': -(opts.width / 2) + 'px'
});
$('.BeAlert_image').addClass(opts.type);
title && $('.BeAlert_title').html(title).show(),
message && $('.BeAlert_message').html(message).show();
var confirmBtn = $('.BeAlert_confirm'), cancelBtn = $('.BeAlert_cancel');
opts.showConfirmButton && confirmBtn.text(opts.confirmButtonText).show(),
opts.showCancelButton && cancelBtn.text(opts.cancelButtonText).show();
// $('.BeAlert_overlay').unbind('click').bind('click', function () {
// that.close();
// });
confirmBtn.unbind('click').bind('click', function () {
that.close();
typeof callback === 'function' && callback(true);
});
cancelBtn.unbind('click').bind('click', function () {
that.close();
typeof callback === 'function' && callback(false);
});
var h = box.height();
box.css({
'margin-top': -(Math.max(h, opts.height) / 2 + 100) + 'px'
});
},
close: function () {
$(".BeAlert_overlay,.BeAlert_box").remove();
}
};
window.alert = function (title, message, callback, opts) {
BeAlert.open(title, message, callback, opts);
};
var _confirm = window.confirm;
window.confirm = function (title, message, callback, opts) {
opts = $.extend({type: 'question', showCancelButton: true}, opts);
if (typeof callback === 'function') {
BeAlert.open(title, message, callback, opts);
} else {
return _confirm(title);
}
}
});
}