Jquery makes popover prompt window code sharing

  • 2020-03-30 02:11:37
  • OfStack


<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<!--[if IE 6]>
<script type="text/javascript" src="js/iepngfix_tilebg.js"></script>
<![endif]-->
<script type="text/javascript">
function position(elem,l,t){
    var isIE6 = !-[1,] && !window.XMLHttpRequest;
    if(isIE6){
        var style = elem.style,
        dom  = '(document.documentElement)',
        left = l - document.documentElement.scrollLeft,
        top  = t - document.documentElement.scrollTop;
        style.position = 'absolute';
        style.removeExpression('left');
        style.removeExpression('top');
        style.setExpression('left', 'eval(' + dom + '.scrollLeft + ' + left + ') + "px"');
        style.setExpression('top', 'eval(' + dom + '.scrollTop + ' + top + ') + "px"');
    }else{
        elem.style.position = 'fixed';
    }
}      
function scscms_alert(msg,sign,ok,can){
    var c_=false;//If the window has been closed, resolve the conflict between automatic closing and manual closing
    sign=sign||"";
    var s="<div id='mask_layer'></div><div id='scs_alert'><div id='alert_top'></div><div id='alert_bg'><table width='260' align='center' border='0' cellspacing='0' cellpadding='1'><tr>";
    if (sign!="")s+="<td width='45'><div id='inco_"+sign+"'></div></td>";
    s+="<td id='alert_txt'>"+msg+"</td></tr></table>";
    if (sign=="confirm"){
        s+="<a href='javascript:void(0)' id='confirm_ok'> indeed   set </a><a href='javascript:void(0)' id='confirm_cancel'> take   eliminate </a>";
    }else{
        s+="<a href='javascript:void(0)' id='alert_ok'> indeed   set </a>"
    }
    s+="</div><div id='alert_foot'></div></div>";
    $("body").append(s);
    $("#scs_alert").css("margin-top",-($("#scs_alert").height()/2)+"px"); //Center it vertically
    $("#scs_alert").focus(); //Gets focus in case the function cannot be triggered after hitting enter
    position(document.getElementById('mask_layer'),0,0);
    position(document.getElementById('scs_alert'),$(window).width()/2,$(window).height()/2);
    if (typeof can == "number"){
    //Timing off prompt
        setTimeout(function(){
            close_info();
        },can*1000);
    }
    function close_info(){
    //Close the prompt window
        if(!c_){
        $("#mask_layer").fadeOut("fast",function(){
            $("#scs_alert").remove();
            $(this).remove();
        });
        c_=true;
        }
    }
    $("#alert_ok").click(function(){
        close_info();
        if(typeof(ok)=="function")ok();
    });
    $("#confirm_ok").click(function(){
        close_info();
        if(typeof(ok)=="function")ok();
    });
    $("#confirm_cancel").click(function(){
        close_info();
        if(typeof(can)=="function")can();
    });
    function modal_key(e){
        e = e||event;
        close_info();
        var code = e.which||event.keyCode;
        if (code == 13 || code == 32){if(typeof(ok)=="function")ok()}
        if (code == 27){if(typeof(can)=="function")can()}       
    }
    //Bind carriage return with ESC key
    if (document.attachEvent)
        document.attachEvent("onkeydown", modal_key);
    else
        document.addEventListener("keydown", modal_key, true);
}
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = the following for the test function = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =//
function test1(){
    scscms_alert(" Default prompt ");
}
function test2(){
    scscms_alert(" Success message ","ok");
}
function test3(){
    scscms_alert(" Callback function after successful prompt ","ok",function(){alert(" Callback successful! ")});
}
function test4(){
    scscms_alert(" Failure message ","error");
}
function test5(){
    scscms_alert(" Failure message ","error",function(){alert(" Oh! no!")});
}
function test6(){
    scscms_alert(" Warning message ","warn");
}
function test7(){
    scscms_alert(" Warning message ","warn",function(){alert(" Oh! warning !")});
}
function test8(){
    scscms_alert(" Do you like this message prompt? ","confirm",function(){
        scscms_alert(" You chose to like, thank you! ","ok");
    },function(){
        scscms_alert(" You chose not to like, sweat! ","error");
    });
}
function test9(){
    scscms_alert(" This information 3 Automatic shutdown after seconds ","ok","",3);
}
function test10(){
    scscms_alert(" Ask information Timing off prompt information ,3 Automatically close after seconds, no cancel callback function . Not recommended. ","confirm",function(){alert(" Make sure to call back! ")},3);
}
</script>


Related articles: