class Adminx {
fullScreen = function (obj) {
var event = document.querySelector(obj);
if (event.requestFullscreen) {
event.requestFullscreen().then(function () {
}).catch(function (error) {
});
} else {
event.mozRequestFullScreen().then(function () {
}).catch(function (error) {
});
}
};
exitFullScreen = function () {
if (document.exitFullscreen) {
document.exitFullscreen().then(function () {
}).catch(function (error) {
});
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
}
};
inArray = function (search, array) {
for (var i in array) {
if (array[i] == search) {
return true;
}
}
return false;
};
isEmpty = function (str) {
if (str == null || str == "") {
return true;
} else {
return false;
}
};
isEmptyStrv2 = function (s) {
if (s == null || s === '') {
return true;
}
return false;
};
isEmptyStr = function (s) {
if (s == undefined || s === '') {
return true;
}
return false;
};
isNotEmptyStr = function (s) {
if (typeof s == 'string' && s.length > 0) {
return true;
}
return false;
};
showNotification(title, options) {
const image = "/information-desk.svg";
const icon = "/hospitals.png";
const sound = "/sound.wav";
var options = {
body: undefined ? undefined : options.body,
dir: "" ? "rtl" : options.lang,
lang: "" ? "zh-cn" : options.lang,
tag: "Notification",
icon: this.isEmpty(options.icon) ? icon : options.icon,
image: this.isEmpty(options.image) ? image : options.image,
renotify: true,
requireInteraction: false,
silent: false,
sound: undefined ? sound : options.sound,
noscreen: false,
sticky: true
};
if (!("Notification" in window)) {
console.log("This browser does not support desktop notification!");
return;
} else if (Notification.permission === "granted") {
const n = new Notification(title, options);
console.log(typeof (n.icon));
} else if (Notification.permission !== "denied") {
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
new Notification(title, options);
}
});
}
};
showPageMask = function (options) { }
printPageObj = function (obj, options) { }
saveAsText = function (data, filename) {
const urlObject = window.URL || window.webkitURL || window;
const exportBlob = new Blob([data]);
const saveLink = document.createElementNS("http://www.w3.org/1999/xhtml", "a");
saveLink.href = urlObject.createObjectURL(exportBlob);
saveLink.download = filename;
saveLink.click();
};
saveAsImage = function (obj, filename) { }
saveAsCsv = function (obj, filename) { }
saveAsExcel = function (obj, filename) { }
saveAsWord = function (obj, filename) { }
saveAsPdf = function (obj, filename) { }
randomIP = () => Array(4).fill(0).map((_, i) => Math.floor(Math.random() * 255) + (i === 0 ? 1 : 0)).join('.');
randomHex = () => `#${Math.random().toString(16).slice(2, 8).padEnd(6, '0')}`;
randomColor = () => `#${(~~(Math.random() * (1 << 24))).toString(16)}`;
copyInputToClipboard = function (obj, msg) {
if (navigator.clipboard && window.isSecureContext) {
console.info(true);
navigator.clipboard.writeText().then(
cliptext => document.querySelector(obj).value = JSON.stringify(cliptext)
).catch(
error => console.error(error)
);
} else {
console.info(false);
const input = document.createElement('textarea');
input.style.position = 'fixed';
input.style.left = '-9999px';
input.style.top = '-9999px';
input.style.opacity = '0';
input.value = JSON.stringify(document.querySelector(obj).value);
document.body.appendChild(input);
input.select();
document.execCommand('copy');
document.body.removeChild(input);
}
};
lectureAudio = function (obj, url) {
const button = document.querySelector(obj);
button, addEventListener('click', (e) => {
e.preventDefault();
const audio = new Audio(url);
audio.play();
audio.remove();
});
};
playAudio = function (url) {
const audio = new Audio(url);
audio.play().then(() => {
audio.play();
audio.remove();
}).catch(error => {
let iframe = document.createElement('iframe');
iframe.src = url;
iframe.setAttribute('allow', "autoplay 'src';fullscreen");
document.body.appendChild(iframe);
setInterval(() => {
iframe.remove();
}, 5000);
}).finally(() => {
audio.remove();
});
};
documentPageLink = () => { return window.location.href; };
documentTitleScroll = function () { }
documentWatermark = function (str) {
if (str == '' || str == undefined || str == null) {
str = "Hygeia Group";
}
let can = document.createElement('canvas');
let box = document.createElement('div');
let now = new Date();
now = now.getFullYear() + '-' + (now.getMonth() + 1) + '-' + now.getDate() + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds();
box.style.position = 'fixed';
box.style.width = '100%';
box.style.height = '100%';
box.style.zIndex = '-9999';
document.body.appendChild(box);
box.appendChild(can);
can.width = 250;
can.height = 250;
can.style.display = 'none';
can.style.background = "transparent";
let ctx = can.getContext('2d');
ctx.fillStyle = 'rgba(17,17,17,0.1)';
ctx.rotate(-30 * Math.PI / 180);
ctx.font = '11px Arial';
ctx.textAlign = 'center';
ctx.textBaseline = 'middle';
ctx.fillText(str, can.width / 4, can.height / 2);
ctx.fillText(now, can.width / 4, can.width / 2.5);
box.removeChild(can);
const imageData = ctx.getImageData(0, 0, can.width, can.height);
box.style.background = 'transparent';
box.style.backgroundImage = 'url(' + can.toDataURL("image/png") + ')';
};
createMonthSelect = function (obj) {
let currentDate = new Date();
let currentMonth = currentDate.getMonth() + 1;
const select = document.querySelector(obj);
for (let i = 0; i < 12; i++) {
let option = document.createElement("option");
option.value = i + 1;
option.text = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][i];
if (i + 1 === currentMonth) {
option.selected = true;
}
select.appendChild(option);
}
};
createDateSelect = function (obj) {
let currentDate = new Date();
let currentMonth = currentDate.getMonth() + 1;
let days = new Date(currentDate.getFullYear(), currentMonth + 1, 0).getDate();
let currentDay = currentDate.getDate();
const select = document.querySelector(obj);
for (let i = 0; i < days; i++) {
let option = document.createElement("option");
option.value = i;
option.text = i;
if (i === currentDay) {
option.selected = true;
}
}
}
onkeydown = function (e) {
if (e.keycode === 13) {
document.activeElement.onclick(e);
}
};
async getClientLocation() {
if (!navigator.geolocation) {
throw new Error("Geolocation is not supported by your browser!");
}
try {
const options = {
enableHighAccuracy: true,
timeout: 5000,
maximumAge: 0,
};
const position = await new Promise((resolve, reject) => {
navigator.geolocation.getCurrentPosition(resolve, reject);
});
const longitude = position.coords.longitude;
const latitude = position.coords.latitude;
const accuracy = position.coords.accuracy;
return {
lng: longitude,
lat: latitude,
accuracy: accuracy
};
} catch (error) {
throw new Error(error.message);
}
};
getClientLocation2() {
return new Promise((resolve, reject) => {
if (!navigator.geolocation) {
reject("Geolocation is not supported by your browser!");
} else {
function success(position) {
let longitude = position.coords.longitude;
let latitude = position.coords.latitude;
let accuracy = position.coords.accuracy;
resolve({
lng: longitude,
lat: latitude,
accuracy: accuracy
});
}
function error(error) {
reject(error);
}
navigator.geolocation.getCurrentPosition(success, error);
}
});
};
getClientLocation3() {
if (!navigator.geolocation) {
console.log("Geolocation is not supported by your browser!");
return false;
} else {
function success(position) {
let longitude = position.coords.longitude;
let latitude = position.coords.latitude;
let accuracy = position.coords.accuracy;
console.log(longitude, latitude, accuracy);
return {
lng: longitude,
lat: latitude,
accuracy: accuracy
};
}
function error(error) {
console.log(error);
}
navigator.geolocation.getCurrentPosition(success, error);
}
};
disableContextMenu = function (obj) { }
dateToString = function (date, format) { }
layerOpen = function (title, url, w, h) { }
layerShow = function (title, url, w, h) { }
layerFull = function (title, url) { }
layerTable = function (title, url, w, h) { }
layerClose = function () { }
}
console