/** * 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); } } }); }