Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 1 | export 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ínez | 72a4ea4 | 2024-02-09 22:35:32 +0100 | [diff] [blame] | 4 | var message_a = url.match(/message\/([0-9]+)/i); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 5 | |
| 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ínez | 72a4ea4 | 2024-02-09 22:35:32 +0100 | [diff] [blame] | 13 | 'message': message_a !== null ? message_a[1] : null, |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 14 | }; |
| 15 | } |
| 16 | |
| 17 | export function isEmpty(obj) { |
| 18 | return Object.keys(obj).length === 0; |
| 19 | } |
Adrià Vilanova Martínez | e777047 | 2021-10-17 00:02:37 +0200 | [diff] [blame] | 20 | |
| 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. |
| 24 | export function createImmuneLink() { |
| 25 | var a = document.createElement('a'); |
| 26 | a.addEventListener('click', e => e.stopPropagation(), false); |
| 27 | return a; |
| 28 | } |
Adrià Vilanova Martínez | 54964a5 | 2022-10-26 23:53:29 +0200 | [diff] [blame] | 29 | |
| 30 | export 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ínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 37 | |
| 38 | /** |
| 39 | * Utility to indicate that a class method should be implemented (similarly to |
| 40 | * abstract methods in Java). |
| 41 | */ |
| 42 | export function shouldImplement(name) { |
| 43 | throw new Error( |
| 44 | `The ${name} method should be implemented by the extending class.`); |
| 45 | } |