diff options
Diffstat (limited to 'app/src/main/assets/js')
-rw-r--r-- | app/src/main/assets/js/media.coffee | 47 | ||||
-rw-r--r-- | app/src/main/assets/js/media.js | 32 |
2 files changed, 39 insertions, 40 deletions
diff --git a/app/src/main/assets/js/media.coffee b/app/src/main/assets/js/media.coffee index 810c09b7..a15a5279 100644 --- a/app/src/main/assets/js/media.coffee +++ b/app/src/main/assets/js/media.coffee @@ -1,29 +1,30 @@ # we will handle media events _frostMediaClick = (e) -> - ### - # Commonality; check for valid target - ### + element = e.target or e.srcElement + if !element?.dataset.sigil?.toLowerCase().includes("inlinevideo") + return - element = e.target or e.srcElement - if !element.hasAttribute("data-sigil") or !element.getAttribute("data-sigil").toLowerCase().includes("inlinevideo") - return - console.log "Found inline video" - element = element.parentNode - if !element.hasAttribute("data-store") - return - dataStore = undefined - try - dataStore = JSON.parse(element.getAttribute("data-store")) - catch e - return - if !dataStore.src - return - console.log "Inline video #{dataStore.src}" - Frost?.loadVideo dataStore.src, dataStore.animatedGifVideo - e.stopPropagation() - e.preventDefault() - return + i = 0 + while !element.hasAttribute("data-store") + if ++i > 2 + return + element = element.parentNode -document.addEventListener "click", _frostMediaClick, true + try + dataStore = JSON.parse(element.dataset.store) + catch e + return + url = dataStore.src + + if !url || !url.startsWith("http") + return + + console.log "Inline video #{url}" + if Frost?.loadVideo url, dataStore.animatedGifVideo + e.stopPropagation() + e.preventDefault() + return + +document.addEventListener "click", _frostMediaClick, true
\ No newline at end of file diff --git a/app/src/main/assets/js/media.js b/app/src/main/assets/js/media.js index 5ec7f472..5b1a3776 100644 --- a/app/src/main/assets/js/media.js +++ b/app/src/main/assets/js/media.js @@ -5,35 +5,33 @@ var _frostMediaClick; _frostMediaClick = function _frostMediaClick(e) { - /* - * Commonality; check for valid target - */ - var dataStore, element; + var dataStore, element, i, ref, url; element = e.target || e.srcElement; - if (!element.hasAttribute("data-sigil") || !element.getAttribute("data-sigil").toLowerCase().includes("inlinevideo")) { + if (!(element != null ? (ref = element.dataset.sigil) != null ? ref.toLowerCase().includes("inlinevideo") : void 0 : void 0)) { return; } - console.log("Found inline video"); - element = element.parentNode; - if (!element.hasAttribute("data-store")) { - return; + i = 0; + while (!element.hasAttribute("data-store")) { + if (++i > 2) { + return; + } + element = element.parentNode; } - dataStore = void 0; try { - dataStore = JSON.parse(element.getAttribute("data-store")); + dataStore = JSON.parse(element.dataset.store); } catch (error) { e = error; return; } - if (!dataStore.src) { + url = dataStore.src; + if (!url || !url.startsWith("http")) { return; } - console.log("Inline video " + dataStore.src); - if (typeof Frost !== "undefined" && Frost !== null) { - Frost.loadVideo(dataStore.src, dataStore.animatedGifVideo); + console.log("Inline video " + url); + if (typeof Frost !== "undefined" && Frost !== null ? Frost.loadVideo(url, dataStore.animatedGifVideo) : void 0) { + e.stopPropagation(); + e.preventDefault(); } - e.stopPropagation(); - e.preventDefault(); }; document.addEventListener("click", _frostMediaClick, true); |