/** * 提示信息. * * user: sunhao * date: 13-4-29 * time: 上午5:22 * * @author sunhao(sunhao.java@gmail.com) */ (function($){ //定义整个msgbox对象 $.msgbox = $.msgbox || {}; //定义默认属性值 $.msgbox.defaults = { icon: 'ok', //图标(ok:成功信息,no:错误信息,warn:警告,clear:什么都没有) i18n: false, //是否使用国际化:如果是,message指定为code,否则message为要显示的值 message: '', //同上 timeout: 3000, //多长时间之后消失 beforehide: null //消失前执行的方法 } $.msgbox.show = function(p){ p = $.extend({}, $.msgbox.defaults, p || {}); var f = { show: function(){ var msgbox; var isfirst = true; //是否是第一次显示 if($('.msgbox_layout_wrap').length > 0){ msgbox = $('.msgbox_layout_wrap')[0]; isfirst = false; } else { msgbox = $(f.gethtml()); } //设置top $('.msgbox_layout_wrap', msgbox).css('top', f.gettop() + 'px'); //设置文本 f.settext(f.getmessage(), msgbox); //设置图标 f.seticon(f.getstyle(), msgbox); //添加事件 f.addevent(); //显示 f.render(msgbox, isfirst); }, getmessage: function(){ if(p.i18n){ var message_ = $.util.getmessage(p.message); if(!message_ || "" == message_) message_ = p.message; return message_; } return p.message; }, getstyle: function(){ var class_; if(p.icon != 'ok' && p.icon != 'no' && p.icon != 'warn' && p.icon != 'clear'){ class_ = "icon_clear"; } else { class_ = "icon_" + p.icon; } return class_; }, gethtml: function(){ var html = []; html.push('
'); html.push(' '); html.push(' '); html.push(' '); html.push(' '); html.push(' '); html.push('
'); return html.join(""); }, gettop: function(){ //可视区域高度 var viewheight = $(window).height(); return viewheight - 27; }, settext: function(text, msgbox){ var icon = $('#txtpan', $(msgbox)); icon.html(text); }, seticon: function(iconstyle, msgbox){ var icon = $('#iconspan', $(msgbox)); var classname = icon.attr('class'); icon.removeclass(classname); icon.addclass(iconstyle); }, addevent: function(){ var inerval = setinterval(function () { if(p.beforehide){ p.beforehide(); } $('#m_mgbox').hide(); cleartimeout(inerval); }, p.timeout); }, render: function(msgbox, isfirst){ if(isfirst){ $('body').append(msgbox); } else { $(msgbox).show(); } } } f.show(); } })(jquery)