summaryrefslogtreecommitdiffstats
path: root/src/wwwroot/scripts/utils.js
diff options
context:
space:
mode:
authorivar <i@oiee.no>2025-10-19 23:41:23 +0200
committerivar <i@oiee.no>2025-10-19 23:41:23 +0200
commit3f4c0720e1e3421431e7baa20882a4a4512a7fab (patch)
tree734ca81d7d0841d8863e3f523ebba14c282dc681 /src/wwwroot/scripts/utils.js
downloadfagprove-master.tar.xz
fagprove-master.zip
InitialHEADmaster
Diffstat (limited to 'src/wwwroot/scripts/utils.js')
-rw-r--r--src/wwwroot/scripts/utils.js91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/wwwroot/scripts/utils.js b/src/wwwroot/scripts/utils.js
new file mode 100644
index 0000000..f20ab78
--- /dev/null
+++ b/src/wwwroot/scripts/utils.js
@@ -0,0 +1,91 @@
+$.niceDate = function (date) {
+ return kendo.toString(date, "dddd, MMMM d").toUpperCase();
+};
+
+$.validateTimeInput = function (input) {
+ return $.isHourAndMinute(input.val());
+};
+
+$.timeInput = function (container, options) {
+ $('<input name="' + options.field + '"/>')
+ .appendTo(container)
+ .kendoMaskedTextBox({
+ mask: "00:00"
+ });
+};
+
+$.getTimeOfDay = function (date) {
+ return kendo.toString(new Date(date), "HH:mm");
+};
+
+$.handlePhoneInput = function (evt) {
+ let theEvent = evt || window.event;
+ let key;
+ if (theEvent.type === "paste") {
+ key = event.clipboardData.getData("text/plain");
+ } else {
+ let key = theEvent.keyCode || theEvent.which;
+ key = String.fromCharCode(key);
+ }
+ let regex = /[0-9|+]|\./;
+ if (!regex.test(key)) {
+ theEvent.returnValue = false;
+ if (theEvent.preventDefault) theEvent.preventDefault();
+ }
+};
+
+$.notificate = function (title, message, type, noautohide) {
+ $('body')
+ .toast({
+ title: title,
+ message: message,
+ class: type,
+ displayTime: noautohide ? 0 : 5000
+ });
+};
+
+$.isHourAndMinute = function (value) {
+ let r = /^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$/;
+ return r.test(value);
+};
+
+$.isEmail = function (email) {
+ let re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
+ return re.test(String(email).toLowerCase());
+};
+
+$.isIe = function () {
+ let ua = window.navigator.userAgent;
+ let msie = ua.indexOf("MSIE ");
+ return msie > 0;
+};
+
+$.isPhoneNumber = function (phone) {
+ if (phone.length < 8 || phone.length > 13) return false;
+ let re = /(0047|\\+47|47)?\d/;
+ return re.test(String(phone));
+};
+
+$.urlParam = function (name) {
+ let results = new RegExp("[?&]" + name + "=([^&#]*)").exec(
+ window.location.href
+ );
+ if (results == null) {
+ return 0;
+ }
+ return results[1] || 0;
+};
+
+$.isGuid = function (stringToTest) {
+ if (stringToTest[0] === "{") {
+ stringToTest = stringToTest.substring(1, stringToTest.length - 1);
+ }
+ let regexGuid = /^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$/gi;
+ return regexGuid.test(stringToTest);
+};
+
+$.isMobile = function () {
+ let x = window.matchMedia("(max-width: 700px)");
+ x.addEventListener("change", $.isMobile);
+ return x.matches;
+};