2019-04-24 12:39:15 +02:00
|
|
|
export class HelperFunctions {
|
|
|
|
|
|
|
|
public static scroll() {
|
2020-05-21 15:17:28 +02:00
|
|
|
HelperFunctions.scrollTo(0,0);
|
|
|
|
}
|
|
|
|
public static scrollTo(x,y) {
|
2019-04-24 12:39:15 +02:00
|
|
|
if (typeof document !== 'undefined') {
|
2020-05-21 15:17:28 +02:00
|
|
|
window.scrollTo(x,y);
|
2019-04-24 12:39:15 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-06 12:51:39 +02:00
|
|
|
|
2020-05-21 15:17:28 +02:00
|
|
|
public static scrollToId(elementId:string) {
|
|
|
|
if (typeof document !== 'undefined' && document.getElementById(elementId)) {
|
|
|
|
document.getElementById(elementId).scrollIntoView();
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 12:51:39 +02:00
|
|
|
public static isTiny(url: string) {
|
|
|
|
return (url.indexOf('tinyurl.com') !== -1);
|
|
|
|
}
|
2019-11-11 14:27:18 +01:00
|
|
|
|
2019-11-22 09:51:17 +01:00
|
|
|
public static copy(obj: any): any {
|
|
|
|
let copy;
|
|
|
|
|
|
|
|
// Handle the 3 simple types, and null or undefined
|
|
|
|
if (null == obj || "object" != typeof obj) return obj;
|
|
|
|
|
|
|
|
// Handle Date
|
|
|
|
if (obj instanceof Date) {
|
|
|
|
copy = new Date();
|
|
|
|
copy.setTime(obj.getTime());
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Array
|
|
|
|
if (obj instanceof Array) {
|
|
|
|
copy = [];
|
|
|
|
for (let i = 0, len = obj.length; i < len; i++) {
|
|
|
|
copy[i] = HelperFunctions.copy(obj[i]);
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Map
|
|
|
|
if (obj instanceof Map) {
|
2019-11-24 17:28:25 +01:00
|
|
|
return new Map(obj.entries());
|
2019-11-22 09:51:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle Object
|
|
|
|
if (obj instanceof Object) {
|
|
|
|
copy = {};
|
|
|
|
for (let attr in obj) {
|
|
|
|
if (obj.hasOwnProperty(attr)) {
|
|
|
|
copy[attr] = HelperFunctions.copy(obj[attr]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
throw new Error("Unable to copy obj! Its type isn't supported.");
|
2019-11-11 14:27:18 +01:00
|
|
|
}
|
2019-11-12 16:54:03 +01:00
|
|
|
|
|
|
|
public static encodeArray(elements: string[]): string[] {
|
|
|
|
let encoded: string[] = [];
|
|
|
|
elements.forEach(element => {
|
|
|
|
encoded.push(encodeURIComponent(element));
|
|
|
|
});
|
|
|
|
return encoded;
|
|
|
|
}
|
2019-06-06 12:51:39 +02:00
|
|
|
}
|