aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/assets/js/media.js
blob: f1a5ac3c8d8d2cf13d8421cdc832578cde7ed0e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// we will media events
if (!window.hasOwnProperty('frost_media')) {
  console.log('Registering frost_media');
  window.frost_media = true;

  var _frostMediaClick = function(e) {

    /*
     * Commonality; check for valid target
     */
    var element = e.target || e.srcElement;
    if (!element.hasAttribute("data-sigil") || !element.getAttribute("data-sigil").toLowerCase().includes("inlinevideo")) return;
    console.log("Found inline video");
    element = element.parentNode;
    if (!element.hasAttribute("data-store")) return;
    var dataStore;
    try {
      dataStore = JSON.parse(element.getAttribute("data-store"));
    } catch (e) {
      return;
    }
    if (!dataStore.src) return;
    console.log("Inline video " + dataStore.src);
    if (typeof Frost !== 'undefined') Frost.loadVideo(dataStore.src, dataStore.animatedGifVideo);
    e.stopPropagation();
    e.preventDefault();
    return;
  }

  document.addEventListener('click', _frostMediaClick, true);
}