blob: 5784da14d50c3925a3f75ddb71ec376759e91f9d [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}