js 提示窗

/**
 * @Co.,Ltd.    北京酷伴科技郑州分公司
 * @authors     小石头([email protected])
 * @date        2014-12-22
 * @version     4.0
 */
 var jAlert=(function(){
     this.myalertin=function(text,color,time,fn){
        var text=text||‘‘;
        var color=color||‘default‘;
        var time=time||3000;
        var timer=500;
        var fn=fn||function(){};
        var cover=addJcover();
        cover.prepend(‘<div class="jbox ‘+color+‘"><div class="jtop"><span class="jtit">\u6d88\u606f\u63d0\u793a</span><span class="jclose">&times;</span></div><div class="jtxt">‘+text+‘</div></div>‘);
        var box = $(‘#jcover .jbox‘)
        box.delay(time).fadeOut(timer,function(){
            //终止动画队列
            $(this).dequeue();
            jRemoveBox($(this),fn);
        });
        box.on(‘mouseover‘,function(){
            //清除动画队列
            $(this).clearQueue();
        });
        box.on(‘mouseout‘,function(){
            $(this).delay(time).fadeOut(timer,function(){
                jRemoveBox($(this),fn);
            })
        });
        box.find(‘.jtop,.jtxt‘).delegate($(this),‘click‘,function(){
            jRemoveBox($(this).closest(‘.jbox‘),fn);
        });
    };
    this.myconfirm=function(text,fn){
        var text=text||‘‘;
        var fn=fn||function(){};
        var timer=300;
        var cover=addJcover();
        cover.append(‘<div class="jconfirm"><div class="confirm-text">‘+text+‘</div><div class="confirm-btns"><div class="confirm-btn ensure"><div class="default">\u53d6\u6d88</div></div><div class="confirm-btn sure"><div class="error">\u786e\u5b9a</div></div></div></div>‘);
        $(‘.confirm-btn‘).delegate($(this),‘click‘,function(){
            var _this=$(this);
            $(this).closest(‘.jconfirm‘).fadeOut(timer,function(){
                jRemoveBox($(this),fn);
                if (_this.hasClass(‘sure‘)) {
                    if(fn)fn(true);
                };
            })
        });
    };
    this.myalert=function(_data,_refresh,_fn,_show){
        var data,refresh=false,show=‘show‘,fn=function(){};
        $.each(arguments, function(index, val) {
            if (typeof val ==‘boolean‘) {
                refresh=val;
            }else if (typeof val==‘function‘) {
                fn=val;
            }else if (typeof val==‘object‘) {
                data=val;
            }else if (typeof val==‘string‘) {
                show=val;
            };
        });
        if (data.status==1) {
            if (show==‘hide‘) {
                fn();
                location.href=data.url;
            }else{
                mysuccess(data.info,function(){
                    fn();
                    if (refresh&&data.url!=‘‘) {
                        location.href=data.url;
                    }
                })
            }
        }else if (data.status==0){
            myerror(data.info,function(){
                fn();
            })
        }else{
            myerror(‘\u64cd\u4f5c\u5931\u8d25‘,function(){
                fn();
            });
        }
    };
    this.jaja=function(_btn,_data,_fn,_type,_url){
        var btn,data,fn=function(){},type=‘POST‘,url=‘‘;
        if (arguments[0].length==0||arguments.length<2) {
            return false;
        }
        btn=arguments[0];
        url=btn.data(‘action‘);
        
        $.each(arguments, function(index, val) {
            if (val instanceof jQuery) {
                btn=val;
                data=btn.closest(‘form‘).serialize();
                url=btn.data(‘action‘);
            }else if ((typeof val==‘object‘) && !(val instanceof jQuery)) {
                data=val;
            }else if (typeof val==‘function‘) {
                fn=val;
            }else if ((typeof val==‘string‘) && (val==‘GET‘||val==‘POST‘)){
                type=val;
            }else if ((typeof val==‘string‘) && (/\//g.test(val.toString())) ) {
                url=val;
            };
        });
        if(type==‘GET‘ && btn.closest(‘form‘).length==0){
            data=‘‘;
        }
        var html=btn.html();
        btn.prop(‘disabled‘, true).html(‘\u8bf7\u7a0d\u7b49\u002e\u002e\u002e‘);
        $.ajax({
            url:url,
            type: type,
            data:data,
            error:function(e){
                btn.prop(‘disabled‘, false).html(html);
                e.info=‘\u64cd\u4f5c\u5931\u8d25‘;
                fn(e);
            },
            success:function(data){
                btn.prop(‘disabled‘, false).html(html);
                fn(data);
            }
        });
    };
    this.mysuccess=function(t,f){myalertin(t,‘success‘,2000,f)};
    this.myerror=function(t,f){myalertin(t,‘error‘,2000,f)};
    this.mywarning=function(t,f){myalertin(t,‘warning‘,2000,f)};
    this.myinfo=function(t,f){myalertin(t,‘info‘,2000,f)};
    this.myprimary=function(t,f){myalertin(t,‘primary‘,2000,f)};
    this.mydefault=function(t,f){myalertin(t,‘‘,2000,f)};
    this.jStyle={
        error:‘#DA2F2F‘,
    };
    this.addJcover=function(){
         $(‘#jcover‘).length==0?$(‘body‘).append(‘<div id="jcover"></div>‘):0;
         return $(‘#jcover‘);
     };
     this.jRemoveBox=function(box,fn){
        box.remove();
        if (!$(‘#jcover‘).children().length) {
            $(‘#jcover‘).remove();
        }
        if(fn)fn();
    };
    this.alertStyle=(function(){
        $(‘head‘).append(‘<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"><meta name="renderer" content="webkit"><style type="text/css">#jcover{position:fixed;z-index:9999;top:25%;left:50%;margin-left:-180px;width:360px;font-family:"Microsoft yahei";word-wrap:break-word;}#jcover .jbox,#jcover .jconfirm{border-radius:2px;width:100%;background:#e4e4e4;margin:0 auto 5px auto;color:#555}#jcover .jtop{height:40px;line-height:50px;width:100%;padding-bottom:10px}#jcover .jtit{font-size:12px;height:40px;display:inline-block;line-height:40px;padding-left:20px;}#jcover .jclose{border-radius:2px;font-size:30px;position:absolute;right:0;right:0;top:0;background-color:rgba(0,0,0,0.1);cursor:pointer;height:40px;width:40px;line-height:40px;text-align:center;font-family:Simsun}@media (max-width:361px){#jcover {width:100%;left:0;margin-left:0}}#jcover .jtxt{font-size:16px;line-height:24px;padding:10px 20px 20px 20px;}#jcover .success,#jcover .error,#jcover .warning,#jcover .info,#jcover .primary{color:#fff}#jcover .success{background:#5CB85C}#jcover .error{background:#c00}#jcover .warning{background:#FFA028}#jcover .info{background:#5BC0DE}#jcover .primary{background:#428BCA}#jcover .default{background:#fff}#jcover .confirm-text{font-size:16px;padding:20px 10px;color:#c00}.confirm-btns{padding:20px 10px;}#jcover .confirm-btn{text-align:center;width:48%;display:inline-block;}#jcover .confirm-btn div{border-radius:3px;padding:10px;cursor:pointer;}#jcover .confirm-btn.sure{float:right;}</style>‘);
    })();
    return this;
})(jAlert);window.jAlert=jAlert;

技术分享

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。