aboutsummaryrefslogtreecommitdiff
path: root/app/src/web/assets/js
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2019-02-05 23:02:50 -0500
committerAllan Wang <me@allanwang.ca>2019-02-05 23:02:50 -0500
commitddfc310fde5f50ba52ef930287449c2e08faaca8 (patch)
treed96d38769b841f55e493a84805b99a294d7bc0ac /app/src/web/assets/js
parent8b850711ceb7c38f9368ce840831c1c0bdb4ba74 (diff)
downloadfrost-ddfc310fde5f50ba52ef930287449c2e08faaca8.tar.gz
frost-ddfc310fde5f50ba52ef930287449c2e08faaca8.tar.bz2
frost-ddfc310fde5f50ba52ef930287449c2e08faaca8.zip
Add ability to copy comments, resolves #454
Diffstat (limited to 'app/src/web/assets/js')
-rw-r--r--app/src/web/assets/js/context_a.js13
-rw-r--r--app/src/web/assets/js/context_a.ts28
2 files changed, 30 insertions, 11 deletions
diff --git a/app/src/web/assets/js/context_a.js b/app/src/web/assets/js/context_a.js
index d0f5c622..410553bd 100644
--- a/app/src/web/assets/js/context_a.js
+++ b/app/src/web/assets/js/context_a.js
@@ -1,6 +1,15 @@
"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;
@@ -55,12 +64,12 @@
Frost.contextMenu(url, text);
return true;
};
- var handlers = [_frostCopyPost, _frostImage];
+ 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 Element)) {
+ if (!(target instanceof HTMLElement)) {
console.log("No element found");
return;
}
diff --git a/app/src/web/assets/js/context_a.ts b/app/src/web/assets/js/context_a.ts
index 2a079f39..4751bbdc 100644
--- a/app/src/web/assets/js/context_a.ts
+++ b/app/src/web/assets/js/context_a.ts
@@ -9,7 +9,17 @@
/**
* Given event and target, return true if handled and false otherwise.
*/
- type EventHandler = (e: Event, target: Element) => Boolean
+ type EventHandler = (e: Event, target: HTMLElement) => Boolean
+
+ const _frostCopyComment: EventHandler = (e, target) => {
+ if (!target.hasAttribute('data-commentid')) {
+ return false;
+ }
+ const text = target.innerText;
+ console.log(`Copy comment ${text}`);
+ Frost.contextMenu(null, text);
+ return true;
+ };
/**
* Posts should click a tag, with two parents up being div.story_body_container
@@ -26,7 +36,7 @@
if (!parent2 || !parent2.classList.contains('story_body_container')) {
return false;
}
- const url = target.getAttribute('href')!;
+ const url = target.getAttribute('href');
const text = parent1.innerText;
console.log(`Copy post ${url} ${text}`);
Frost.contextMenu(url, text);
@@ -42,11 +52,11 @@
}
}
if (element.tagName !== 'A') {
- return false
+ return false;
}
const url = element.getAttribute('href');
if (!url || url === '#') {
- return false
+ return false;
}
const text = (<HTMLElement>element.parentElement).innerText;
// Check if image item exists, first in children and then in parent
@@ -58,7 +68,7 @@
const imageUrl = (<String>window.getComputedStyle(image, null).backgroundImage).trim().slice(4, -1);
console.log(`Context image: ${imageUrl}`);
Frost.loadImage(imageUrl, text);
- return true
+ return true;
}
// Check if true img exists
const img = element.querySelector("img[src*=scontent]");
@@ -66,14 +76,14 @@
const imgUrl = img.src;
console.log(`Context img: ${imgUrl}`);
Frost.loadImage(imgUrl, text);
- return true
+ return true;
}
console.log(`Context content ${url} ${text}`);
Frost.contextMenu(url, text);
- return true
+ return true;
};
- const handlers = [_frostCopyPost, _frostImage];
+ const handlers = [_frostCopyComment, _frostCopyPost, _frostImage];
const _frostAContext = (e: Event) => {
Frost.longClick(true);
@@ -83,7 +93,7 @@
* Commonality; check for valid target
*/
const target = e.target || e.currentTarget || e.srcElement;
- if (!(target instanceof Element)) {
+ if (!(target instanceof HTMLElement)) {
console.log("No element found");
return
}