blob: 76a23d93422270477f4781542c709b8d42a8c9bf [file] [log] [blame]
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02001export function parseUrl(url) {
2 var forum_a = url.match(/forum\/([0-9]+)/i);
3 var thread_a = url.match(/thread\/([0-9]+)/i);
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +01004 var message_a = url.match(/message\/([0-9]+)/i);
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02005
6 if (forum_a === null || thread_a === null) {
7 return false;
8 }
9
10 return {
11 'forum': forum_a[1],
12 'thread': thread_a[1],
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +010013 'message': message_a !== null ? message_a[1] : null,
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020014 };
15}
16
17export function isEmpty(obj) {
18 return Object.keys(obj).length === 0;
19}
Adrià Vilanova Martíneze7770472021-10-17 00:02:37 +020020
21// Create a link element which isn't handled by the Community Console when
22// clicked. This is done by cancelling the event propagation in the beginning of
23// the bubbling phase.
24export function createImmuneLink() {
25 var a = document.createElement('a');
26 a.addEventListener('click', e => e.stopPropagation(), false);
27 return a;
28}
Adrià Vilanova Martínez54964a52022-10-26 23:53:29 +020029
30export function recursiveParentElement(el, tag) {
31 while (el !== document.documentElement) {
32 el = el.parentNode;
33 if (el.tagName == tag) return el;
34 }
35 return undefined;
36}
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010037
38/**
39 * Utility to indicate that a class method should be implemented (similarly to
40 * abstract methods in Java).
41 */
42export function shouldImplement(name) {
43 throw new Error(
44 `The ${name} method should be implemented by the extending class.`);
45}