aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/assets/js/context_a.js
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-12-10 14:25:29 -0500
committerGitHub <noreply@github.com>2017-12-10 14:25:29 -0500
commit1d4380cee77fc049a54d280a27dcefa3fa6ff1fd (patch)
tree6aa222b3f88862a46c8ffd0e46bfb94755d54729 /app/src/main/assets/js/context_a.js
parent30eb51a44a271512e27c97aecc02f3a339f572bf (diff)
downloadfrost-1d4380cee77fc049a54d280a27dcefa3fa6ff1fd.tar.gz
frost-1d4380cee77fc049a54d280a27dcefa3fa6ff1fd.tar.bz2
frost-1d4380cee77fc049a54d280a27dcefa3fa6ff1fd.zip
theme (#546)
* Update to coffee and use webstorm * Add chrome as well * Update all * Reinstall android 27
Diffstat (limited to 'app/src/main/assets/js/context_a.js')
-rw-r--r--app/src/main/assets/js/context_a.js98
1 files changed, 57 insertions, 41 deletions
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