mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-07 09:36:05 -08:00
Pi.Alert 3.00
This commit is contained in:
@@ -13,20 +13,98 @@ var modalCallbackFunction = '';
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function showModal (title, message, btnCancel, btnOK, callbackFunction) {
|
||||
function setCookie (cookie, value, expirationHours='') {
|
||||
// Calc expiration date
|
||||
var expires = '';
|
||||
if (typeof expirationHours === 'number') {
|
||||
expires = ';expires=' + new Date(Date.now() + expirationHours *60*60*1000).toUTCString();
|
||||
}
|
||||
|
||||
// Save Cookie
|
||||
document.cookie = cookie + "=" + value + expires;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function getCookie (cookie) {
|
||||
// Array of cookies
|
||||
var allCookies = document.cookie.split(';');
|
||||
|
||||
// For each cookie
|
||||
for (var i = 0; i < allCookies.length; i++) {
|
||||
var currentCookie = allCookies[i].trim();
|
||||
|
||||
// If the current cookie is the correct cookie
|
||||
if (currentCookie.indexOf (cookie +'=') == 0) {
|
||||
// Return value
|
||||
return currentCookie.substring (cookie.length+1);
|
||||
}
|
||||
}
|
||||
|
||||
// Return empty (not found)
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function deleteCookie (cookie) {
|
||||
document.cookie = cookie + '=;expires=Thu, 01 Jan 1970 00:00:00 UTC';
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function deleteAllCookies() {
|
||||
// Array of cookies
|
||||
var allCookies = document.cookie.split(";");
|
||||
|
||||
// For each cookie
|
||||
for (var i = 0; i < allCookies.length; i++) {
|
||||
var cookie = allCookies[i].trim();
|
||||
var eqPos = cookie.indexOf("=");
|
||||
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
|
||||
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function showModalDefault (title, message, btnCancel, btnOK, callbackFunction) {
|
||||
// set captions
|
||||
$('#modal-title').html (title);
|
||||
$('#modal-message').html (message);
|
||||
$('#modal-cancel').html (btnCancel);
|
||||
$('#modal-OK').html (btnOK);
|
||||
modalCallbackFunction = callbackFunction;
|
||||
$('#modal-default-title').html (title);
|
||||
$('#modal-default-message').html (message);
|
||||
$('#modal-default-cancel').html (btnCancel);
|
||||
$('#modal-default-OK').html (btnOK);
|
||||
modalCallbackFunction = callbackFunction;
|
||||
|
||||
// Show modal
|
||||
$('#modal-default').modal('show');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function showModalWarning (title, message, btnCancel, btnOK, callbackFunction) {
|
||||
// set captions
|
||||
$('#modal-warning-title').html (title);
|
||||
$('#modal-warning-message').html (message);
|
||||
$('#modal-warning-cancel').html (btnCancel);
|
||||
$('#modal-warning-OK').html (btnOK);
|
||||
modalCallbackFunction = callbackFunction;
|
||||
|
||||
// Show modal
|
||||
$('#modal-warning').modal('show');
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function modalOK () {
|
||||
function modalDefaultOK () {
|
||||
// Hide modal
|
||||
$('#modal-default').modal('hide');
|
||||
|
||||
// timer to execute function
|
||||
window.setTimeout( function() {
|
||||
window[modalCallbackFunction]();
|
||||
}, 100);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
function modalWarningOK () {
|
||||
// Hide modal
|
||||
$('#modal-warning').modal('hide');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user