2017-03-08 75 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(); 
 
}