aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/web/assets/js/context_a.js20
-rw-r--r--app/src/web/assets/js/context_a.ts23
2 files changed, 29 insertions, 14 deletions
diff --git a/app/src/web/assets/js/context_a.js b/app/src/web/assets/js/context_a.js
index 410553bd..61192b28 100644
--- a/app/src/web/assets/js/context_a.js
+++ b/app/src/web/assets/js/context_a.js
@@ -28,12 +28,22 @@
Frost.contextMenu(url, text);
return true;
};
+ var _getImageStyleUrl = function (el) {
+ var img = el.querySelector("[style*=\"background-image: url(\"]");
+ if (!img) {
+ return null;
+ }
+ return window.getComputedStyle(img, null).backgroundImage.trim().slice(4, -1);
+ };
var _frostImage = function (e, target) {
var element = target;
for (var i = 0; i < 2; i++) {
if (element.tagName !== 'A') {
element = element.parentElement;
}
+ else {
+ break;
+ }
}
if (element.tagName !== 'A') {
return false;
@@ -43,12 +53,8 @@
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);
+ var imageUrl = _getImageStyleUrl(element) || _getImageStyleUrl(element.parentElement);
+ if (imageUrl) {
console.log("Context image: " + imageUrl);
Frost.loadImage(imageUrl, text);
return true;
@@ -64,7 +70,7 @@
Frost.contextMenu(url, text);
return true;
};
- var handlers = [_frostCopyComment, _frostCopyPost, _frostImage];
+ var handlers = [_frostImage, _frostCopyComment, _frostCopyPost];
var _frostAContext = function (e) {
Frost.longClick(true);
longClick = true;
diff --git a/app/src/web/assets/js/context_a.ts b/app/src/web/assets/js/context_a.ts
index 4751bbdc..5eec7611 100644
--- a/app/src/web/assets/js/context_a.ts
+++ b/app/src/web/assets/js/context_a.ts
@@ -43,12 +43,25 @@
return true;
};
+ const _getImageStyleUrl = (el: Element): string | null => {
+ const img = el.querySelector("[style*=\"background-image: url(\"]");
+ if (!img) {
+ return null
+ }
+ return (<String>window.getComputedStyle(img, null).backgroundImage).trim().slice(4, -1);
+ };
+
+ /**
+ * Opens image activity for posts with just one image
+ */
const _frostImage: EventHandler = (e, target) => {
let element: Element = target;
// Notifications are two layers under
for (let i = 0; i < 2; i++) {
if (element.tagName !== 'A') {
element = <Element>element.parentElement;
+ } else {
+ break
}
}
if (element.tagName !== 'A') {
@@ -60,12 +73,8 @@
}
const text = (<HTMLElement>element.parentElement).innerText;
// Check if image item exists, first in children and then in parent
- let image = element.querySelector("[style*=\"background-image: url(\"]");
- if (!image) {
- image = (<Element>element.parentElement).querySelector("[style*=\"background-image: url(\"]")
- }
- if (image) {
- const imageUrl = (<String>window.getComputedStyle(image, null).backgroundImage).trim().slice(4, -1);
+ const imageUrl = _getImageStyleUrl(element) || _getImageStyleUrl(<Element>element.parentElement);
+ if (imageUrl) {
console.log(`Context image: ${imageUrl}`);
Frost.loadImage(imageUrl, text);
return true;
@@ -83,7 +92,7 @@
return true;
};
- const handlers = [_frostCopyComment, _frostCopyPost, _frostImage];
+ const handlers = [_frostImage, _frostCopyComment, _frostCopyPost];
const _frostAContext = (e: Event) => {
Frost.longClick(true);