blob: 3e0be666f5cabd13d04ba54130c079580c646f25 [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);
4
5 if (forum_a === null || thread_a === null) {
6 return false;
7 }
8
9 return {
10 'forum': forum_a[1],
11 'thread': thread_a[1],
12 };
13}
14
15export function isEmpty(obj) {
16 return Object.keys(obj).length === 0;
17}
Adrià Vilanova Martíneze7770472021-10-17 00:02:37 +020018
19// Create a link element which isn't handled by the Community Console when
20// clicked. This is done by cancelling the event propagation in the beginning of
21// the bubbling phase.
22export function createImmuneLink() {
23 var a = document.createElement('a');
24 a.addEventListener('click', e => e.stopPropagation(), false);
25 return a;
26}
Adrià Vilanova Martínez54964a52022-10-26 23:53:29 +020027
28export function recursiveParentElement(el, tag) {
29 while (el !== document.documentElement) {
30 el = el.parentNode;
31 if (el.tagName == tag) return el;
32 }
33 return undefined;
34}
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +010035
36/**
37 * Utility to indicate that a class method should be implemented (similarly to
38 * abstract methods in Java).
39 */
40export function shouldImplement(name) {
41 throw new Error(
42 `The ${name} method should be implemented by the extending class.`);
43}