diff options
author | Allan Wang <me@allanwang.ca> | 2019-02-05 23:16:29 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-05 23:16:29 -0500 |
commit | 8e3bfc168009c8682c4f6191d655f3ca10ae9f21 (patch) | |
tree | cf8419a06e193c08622ead5e6854b995a5eeba77 /app/src/web/assets/js/context_a.js | |
parent | 83fb36f666fbb934b74b5f763b8ffb2e56ca7761 (diff) | |
parent | ddfc310fde5f50ba52ef930287449c2e08faaca8 (diff) | |
download | frost-8e3bfc168009c8682c4f6191d655f3ca10ae9f21.tar.gz frost-8e3bfc168009c8682c4f6191d655f3ca10ae9f21.tar.bz2 frost-8e3bfc168009c8682c4f6191d655f3ca10ae9f21.zip |
Merge pull request #1334 from AllanWang/fix/offline-crash
Fix/offline crash
Diffstat (limited to 'app/src/web/assets/js/context_a.js')
-rw-r--r-- | app/src/web/assets/js/context_a.js | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/app/src/web/assets/js/context_a.js b/app/src/web/assets/js/context_a.js new file mode 100644 index 00000000..410553bd --- /dev/null +++ b/app/src/web/assets/js/context_a.js @@ -0,0 +1,92 @@ +"use strict"; +(function () { + var longClick = false; + var _frostCopyComment = function (e, target) { + if (!target.hasAttribute('data-commentid')) { + return false; + } + var text = target.innerText; + console.log("Copy comment " + text); + Frost.contextMenu(null, text); + return true; + }; + var _frostCopyPost = function (e, target) { + if (target.tagName !== 'A') { + return false; + } + var parent1 = target.parentElement; + if (!parent1 || parent1.tagName !== 'DIV') { + return false; + } + var parent2 = parent1.parentElement; + if (!parent2 || !parent2.classList.contains('story_body_container')) { + return false; + } + var url = target.getAttribute('href'); + var text = parent1.innerText; + console.log("Copy post " + url + " " + text); + Frost.contextMenu(url, text); + return true; + }; + var _frostImage = function (e, target) { + var element = target; + for (var i = 0; i < 2; i++) { + if (element.tagName !== 'A') { + element = element.parentElement; + } + } + if (element.tagName !== 'A') { + return false; + } + var url = element.getAttribute('href'); + if (!url || url === '#') { + return false; + } + var text = element.parentElement.innerText; + var image = element.querySelector("[style*=\"background-image: url(\"]"); + if (!image) { + image = element.parentElement.querySelector("[style*=\"background-image: url(\"]"); + } + if (image) { + var imageUrl = window.getComputedStyle(image, null).backgroundImage.trim().slice(4, -1); + console.log("Context image: " + imageUrl); + Frost.loadImage(imageUrl, text); + return true; + } + var img = element.querySelector("img[src*=scontent]"); + if (img instanceof HTMLMediaElement) { + var imgUrl = img.src; + console.log("Context img: " + imgUrl); + Frost.loadImage(imgUrl, text); + return true; + } + console.log("Context content " + url + " " + text); + Frost.contextMenu(url, text); + return true; + }; + var handlers = [_frostCopyComment, _frostCopyPost, _frostImage]; + var _frostAContext = function (e) { + Frost.longClick(true); + longClick = true; + var target = e.target || e.currentTarget || e.srcElement; + if (!(target instanceof HTMLElement)) { + console.log("No element found"); + return; + } + for (var _i = 0, handlers_1 = handlers; _i < handlers_1.length; _i++) { + var h = handlers_1[_i]; + if (h(e, target)) { + e.stopPropagation(); + e.preventDefault(); + return; + } + } + }; + document.addEventListener('contextmenu', _frostAContext, true); + document.addEventListener('touchend', function () { + if (longClick) { + Frost.longClick(false); + longClick = false; + } + }, true); +}).call(undefined); |