(src, attrs)
| 431 | * @returns {Promise<boolean>} promise |
| 432 | */ |
| 433 | export const loadScript = (src, attrs) => { |
| 434 | /** |
| 435 | * @type {HTMLScriptElement} |
| 436 | */ |
| 437 | let script = document.querySelector('script[src="' + src + '"]'); |
| 438 | |
| 439 | return new Promise((resolve) => { |
| 440 | if (script) |
| 441 | return resolve(true); |
| 442 | |
| 443 | script = createNode('script'); |
| 444 | |
| 445 | /** |
| 446 | * Add custom attributes |
| 447 | */ |
| 448 | if (isObject(attrs)) { |
| 449 | for (const key in attrs) { |
| 450 | setAttribute(script, key, attrs[key]); |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | script.onload = () => resolve(true); |
| 455 | script.onerror = () => { |
| 456 | /** |
| 457 | * Remove script from dom if error is thrown |
| 458 | */ |
| 459 | script.remove(); |
| 460 | resolve(false); |
| 461 | }; |
| 462 | |
| 463 | script.src = src; |
| 464 | |
| 465 | appendChild(document.head, script); |
| 466 | }); |
| 467 | }; |
| 468 | |
| 469 | /** |
| 470 | * Save custom data inside cookie |
nothing calls this directly
no test coverage detected
searching dependent graphs…