From 1d4380cee77fc049a54d280a27dcefa3fa6ff1fd Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 10 Dec 2017 14:25:29 -0500 Subject: theme (#546) * Update to coffee and use webstorm * Add chrome as well * Update all * Reinstall android 27 --- app/src/main/assets/js/context_a.js | 98 +++++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 41 deletions(-) (limited to 'app/src/main/assets/js/context_a.js') diff --git a/app/src/main/assets/js/context_a.js b/app/src/main/assets/js/context_a.js index dfc75a80..b39a6542 100644 --- a/app/src/main/assets/js/context_a.js +++ b/app/src/main/assets/js/context_a.js @@ -1,67 +1,83 @@ -//context menu for links -//largely mimics click_a.js -//we will also bind a listener here to notify the activity not to deal with viewpager scrolls -//since the long press is also associated witho -if (!window.hasOwnProperty('frost_context_a')) { - console.log('frost_context_a frost_click_a'); - window.frost_context_a = true; +"use strict"; - var longClick = false; +(function () { + // context menu for links + // largely mimics click_a.js + // we will also bind a listener here to notify the activity not to deal with viewpager scrolls + var _frostAContext, longClick; - var _frostAContext = function(e) { - if (typeof Frost !== 'undefined') Frost.longClick(true); - longClick = true; + longClick = false; + _frostAContext = function _frostAContext(e) { /* * Commonality; check for valid target */ - var element = e.target || e.currentTarget || e.srcElement; - if (!element) return; - if (element.tagName !== 'A') element = element.parentNode; + var element, image, imageUrl, img, imgUrl, text, url; + if (typeof Frost !== "undefined" && Frost !== null) { + Frost.longClick(true); + } + longClick = true; + element = e.target || e.currentTarget || e.srcElement; + if (!element) { + return; + } + if (element.tagName !== "A") { + element = element.parentNode; + } //Notifications is two layers under - if (element.tagName !== 'A') element = element.parentNode; - if (element.tagName === 'A' && element.getAttribute('href') !== '#') { - var url = element.getAttribute('href'); - if (!url) return; - var text = element.parentNode.innerText; - - //check if image item exists, first in children and then in parent - var image = element.querySelector('[style*="background-image: url("]'); - if (!image) image = element.parentNode.querySelector('[style*="background-image: url("]'); + if (element.tagName !== "A") { + element = element.parentNode; + } + if (element.tagName === "A" && element.getAttribute("href") !== "#") { + url = element.getAttribute("href"); + if (!url) { + return; + } + text = element.parentNode.innerText; + // check if image item exists, first in children and then in parent + image = element.querySelector("[style*=\"background-image: url(\"]"); + if (!image) { + image = element.parentNode.querySelector("[style*=\"background-image: url(\"]"); + } if (image) { - var imageUrl = window.getComputedStyle(image, null).backgroundImage.trim().slice(4, -1); - console.log('Context image: ' + imageUrl); - if (typeof Frost !== 'undefined') Frost.loadImage(imageUrl, text); + imageUrl = window.getComputedStyle(image, null).backgroundImage.trim().slice(4, -1); + console.log("Context image: " + imageUrl); + if (typeof Frost !== "undefined" && Frost !== null) { + Frost.loadImage(imageUrl, text); + } e.stopPropagation(); e.preventDefault(); return; } - - //check if true img exists - var img = element.querySelector('img[src*=scontent]') + // check if true img exists + img = element.querySelector("img[src*=scontent]"); if (img) { - var imgUrl = img.src; - console.log('Context img', imgUrl); - if (typeof Frost !== 'undefined') Frost.loadImage(imgUrl, text); + imgUrl = img.src; + console.log("Context img " + imgUrl); + if (typeof Frost !== "undefined" && Frost !== null) { + Frost.loadImage(imgUrl, text); + } e.stopPropagation(); e.preventDefault(); return; } - - console.log('Context Content', url, text); - if (typeof Frost !== 'undefined') Frost.contextMenu(url, text); - + console.log("Context Content " + url + " " + text); + if (typeof Frost !== "undefined" && Frost !== null) { + Frost.contextMenu(url, text); + } e.stopPropagation(); e.preventDefault(); } - } + }; - document.addEventListener('contextmenu', _frostAContext, true); + document.addEventListener("contextmenu", _frostAContext, true); - document.addEventListener('touchend', function _frostEnd(e) { + document.addEventListener("touchend", function (e) { if (longClick) { - if (typeof Frost !== 'undefined') Frost.longClick(false); + if (typeof Frost !== "undefined" && Frost !== null) { + Frost.longClick(false); + } longClick = false; } }, true); -} +}).call(undefined); \ No newline at end of file -- cgit v1.2.3