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); |
| 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 | |
| 15 | export function isEmpty(obj) { |
| 16 | return Object.keys(obj).length === 0; |
| 17 | } |
Adrià Vilanova Martínez | e777047 | 2021-10-17 00:02:37 +0200 | [diff] [blame] | 18 | |
| 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. |
| 22 | export function createImmuneLink() { |
| 23 | var a = document.createElement('a'); |
| 24 | a.addEventListener('click', e => e.stopPropagation(), false); |
| 25 | return a; |
| 26 | } |
Adrià Vilanova Martínez | 54964a5 | 2022-10-26 23:53:29 +0200 | [diff] [blame] | 27 | |
| 28 | export 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 | } |