aboutsummaryrefslogtreecommitdiff
path: root/app/src/web/assets/js/context_a.js
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-03-04 16:08:55 -0500
committerAllan Wang <me@allanwang.ca>2019-03-04 16:08:55 -0500
commitf77c652e612241e046d16690ca239cce44a00b07 (patch)
tree396621890c2929058eb01b73e66a621643f2630b /app/src/web/assets/js/context_a.js
parentdc4910e1e9b26eb71bb7a663cb2994b277be40ac (diff)
downloadfrost-f77c652e612241e046d16690ca239cce44a00b07.tar.gz
frost-f77c652e612241e046d16690ca239cce44a00b07.tar.bz2
frost-f77c652e612241e046d16690ca239cce44a00b07.zip
Improve context click logic
Diffstat (limited to 'app/src/web/assets/js/context_a.js')
-rw-r--r--app/src/web/assets/js/context_a.js20
1 files changed, 13 insertions, 7 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;