alertIdArray = []; window.YT = typeof YT == "undefined" ? {} : YT; window.YT.Alert = { Success: null, Error: null, Tip: null }; YT.Alert.Success = function (text) { let ranId = Math.floor(Math.random() * 100000); $("body").append(`
`) //紀錄上一筆出現的alert alertIdArray.push("success-alert-" + ranId) alertIdArray.length > 2 ? alertIdArray.shift() : "" $("#success-alert-" + ranId).fadeIn(300); //判斷上一筆是否還存在頁面中 if (typeof ($("#" + alertIdArray[0]).css("bottom")) != "undefined" && $("#" + alertIdArray[0]).css("display") != "none" && (alertIdArray[1] != "" || alertIdArray[1] != null)) { //存在的話下一個alert出現在前一個alert上面 let newAlertWidth = parseInt($("#" + alertIdArray[0]).css("bottom").split('px')[0]) + parseInt($("#" + alertIdArray[0]).css("height")) + 10 + "px" $("#" + alertIdArray[1]).css("bottom", newAlertWidth); } $("#success-alert-" + ranId).click(function () { $("#success-alert-" + ranId).fadeOut(300); }) setTimeout(function () { $("#success-alert-" + ranId).fadeOut(300); }, 6000); setTimeout(function () { $("#success-alert-" + ranId).remove(); alertIdArray.splice($.inArray("#success-alert-" + ranId, alertIdArray), 1); }, 7000); } YT.Alert.Error = function (text) { let ranId = Math.floor(Math.random() * 100000); $("body").append(` ${text} `) alertIdArray.push("danger-alert-" + ranId); alertIdArray.length > 2 ? alertIdArray.shift() : "" $("#danger-alert-" + ranId).fadeIn(300); if (typeof ($("#" + alertIdArray[0]).css("bottom")) != "undefined" && $("#" + alertIdArray[0]).css("display") != "none" && (alertIdArray[1] != "" || alertIdArray[1] != null)) { let newAlertWidth = parseInt($("#" + alertIdArray[0]).css("bottom").split('px')[0]) + parseInt($("#" + alertIdArray[0]).css("height")) + 10 + "px" $("#" + alertIdArray[1]).css("bottom", newAlertWidth); } $("#danger-alert-" + ranId).click(function () { $("#danger-alert-" + ranId).fadeOut(300); }) setTimeout(function () { $("#danger-alert-" + ranId).fadeOut(300); alertIdArray.splice($.inArray("#danger-alert-" + ranId, alertIdArray), 1); }, 6000); setTimeout(function () { $("#danger-alert-" + ranId).remove(); }, 7000); } YT.Alert.Tip = function (text, type = null,isLoading = true, color = null) { let ranId = Math.floor(Math.random() * 100000); let iconHtml = ""; if (isLoading) { iconHtml = ` ${text}