2017-03-08 76 views
0

我是一个在甜蜜戒备中的菜鸟。 是否有可能创建一个甜蜜的提示提示,其中有确认按钮,取消和计时器。带有确认和取消按钮的计时器

逻辑是如果警报没有确认,定时器自动执行与取消相同的功能。我试过并卡住了。即使警报已确认,定时器仍在计数并且调用取消功能。

sweetAlert({ 
    title: 'Stay in fullscreen', 
    text: "You will be logged out in 10 seconds or if you leave the fullscreen!", 
    type: 'warning', 
    showCancelButton: true, 
    confirmButtonColor: '#3085d6', 
    cancelButtonColor: '#ff0000', 
    confirmButtonText: 'Go fullscreen!', 
    cancelButtonText: 'Leave this page!', 
    confirmButtonClass: 'btn btn-success', 
    cancelButtonClass: 'btn btn-warning', 
    closeOnConfirm: 'true', 
    timer:'10000', 
    buttonsStyling: false 
},function(isConfirm) { 
    if (isConfirm) { 
     return launchIntoFullscreen(document.documentElement) // timer still still counting 
    } else { 
     return Redirect() 
    } 
}).then(function() { 
    swal(
     window.alert('teest') 
    ) 
}, function (dismiss) { 
    // dismiss can be 'cancel', 'overlay', 
    // 'close', and 'timer' 
    if (dismiss === 'timer') { 
     return Redirect() 
    } 
}) 
+0

表明你已经尝试和OP – guradio

回答

0

检查isConfirm论据空应该告诉你,如果回调是由定时器初始化整理。

swal({ 
    title: "Auto close alert!", 
    text: "I will close in 2 seconds.", 
    timer: 2000, 
    showConfirmButton: true, 
    showCancelButton: true 
    }, 
    function(isConfirm) { 
    if (isConfirm === null || isConfirm == false) 
     cancelFunction(); 
    else 
     confirmFunction(); 
    } 
); 

至于我能找到的,这种行为是没有记录,但我相信这是relevant bit of the source

+0

如此坚持,(isConfirm ===空)将忽略定时器,当确认按钮点击 – OldSport19

+0

也许我误解了这个问题。你能澄清你想要的行为吗? – CollinD

+0

确认:确认功能 取消:取消功能 超时:也取消功能 – OldSport19

0

swal({ 
 
    title: "Auto close alert!", 
 
    text: "I will close in 2 seconds.", 
 
    timer: 2000, 
 
    showConfirmButton: true, 
 
    showCancelButton: true 
 
    }, 
 
    function(isConfirm) { 
 
    if (isConfirm === null || isConfirm == false) 
 
     cancelFunction(); 
 
    else 
 
     confirmFunction(); 
 
    } 
 
);

上面的代码仍然执行cancelFunction(); 我在Confirmfunction前添加一行。

if (isConfirm !=null && isConfirm != false) { 
 
    closeInSeconds = Number.MAX_VALUE/1000; // this line extends timer time 
 
    document.documentElement); 
 
} 
 
else { 
 
    Redirect(); 
 
}