List for cgit developers and users
 help / color / mirror / Atom feed
From: andy at warmcat.com (Andy Green)
Subject: [PATCH v5 6/6] line-range-highlight: copy URL to clipboard UI
Date: Tue, 26 Jun 2018 19:25:45 +0800	[thread overview]
Message-ID: <153001234496.12484.8630216246879475297.stgit@mail.warmcat.com> (raw)
In-Reply-To: <153001215740.12484.13344875445662026876.stgit@mail.warmcat.com>

Clicking on the line numbers to control the highlight
now causes a clipboard icon to appear to the left of
the line for 5s.

Clicking this will copy the highlight URL to the
clipboard, and cause the icon to grow, blur and
fade to acknowledge the click.

After 5s the clipboard icon will fade out... you can
still collect the URL from the browser URL bar.

Clicking on other line  number links will remove any
clipboard icon and create a new one with a new 5s
lifetime.

This is an entirely clientside implementation in
cgit.css and cgit.js only.  The clipboard symbol is
from unicode.

Tested on Linux Chrome 67 + Firefox 60.

Signed-off-by: Andy Green <andy at warmcat.com>
---
 cgit.css |   20 ++++++++++++++
 cgit.js  |   87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 106 insertions(+), 1 deletion(-)

diff --git a/cgit.css b/cgit.css
index 13c0955..7c2bafe 100644
--- a/cgit.css
+++ b/cgit.css
@@ -377,6 +377,26 @@ div#cgit div.selected-lines {
 	transition: background-color 1.5s;
 }
 
+div#cgit div.selected-lines-popup {
+	position: absolute;
+	text-align: center;
+	font-size: 28px;
+	font-color: black;
+	left: 8px;
+	width: 32px;
+	height: 32px;
+	opacity: 0;
+	z-index: 2;
+	cursor: pointer;
+	filter: grayscale(100%);
+	background-color: rgba(255, 255, 255, 0.0);
+	transition: filter 1s, opacity 1.5s, font-size 1s;
+}
+
+div#cgit div.selected-lines-popup:hover {
+	filter: grayscale(0%);
+}
+
 div#cgit table.bin-blob {
 	margin-top: 0.5em;
 	border: solid 1px black;
diff --git a/cgit.js b/cgit.js
index ebc4e5b..cd7ea86 100644
--- a/cgit.js
+++ b/cgit.js
@@ -1,3 +1,7 @@
+var cgit_clipboard_popup_duration = 5000;
+
+var cgit_clipboard_popup, cgit_clipboard_popup_time;
+
 function cgit_collect_offsetTop(e1)
 {
 	var t = 0;
@@ -98,13 +102,94 @@ function cgit_line_range_highlight()
 	t.scrollIntoView(true);
 }
 
+function cgit_copy_clipboard(value)
+{
+	var inp = document.createElement("textarea");
+	var e = document.getElementById("linenumbers");
+
+	inp.type = "text";
+	inp.value = value;
+	/* hidden style stops it working for clipboard */
+	inp.setAttribute('readonly', '');
+	inp.style.position = "absolute";
+	inp.style.left = "-1000px";
+
+	e.appendChild(inp);
+
+	inp.select();
+
+	document.execCommand("copy");
+
+	inp.remove();
+}
+
+function cgit_line_popup_click(e) {
+	e.stopPropagation();
+	e.preventDefault();
+	cgit_copy_clipboard(window.location);
+	/* fade out, blur out, grow */
+	cgit_clipboard_popup.style.opacity = "0";
+	cgit_clipboard_popup.style.fontSize = "40px";
+	cgit_clipboard_popup.style.filter = "blur(2px)";
+}
+
+function cgit_line_popup_create(e)
+{
+	var e1 = e, etable, d = new Date;
+
+	if (cgit_clipboard_popup)
+		cgit_clipboard_popup.remove();
+
+	cgit_clipboard_popup = document.createElement("DIV");
+	cgit_clipboard_popup.className = "selected-lines-popup";
+
+	cgit_clipboard_popup.style.top = cgit_collect_offsetTop(e1) + "px";
+	cgit_clipboard_popup.innerHTML = "&#x1f4cb;";
+	/* event listener cannot override default browser #URL behaviour */
+	cgit_clipboard_popup.onclick = cgit_line_popup_click;
+
+	etable = cgit_find_parent_of_type(e, "table");
+	etable.insertBefore(cgit_clipboard_popup, etable.firstChild);
+	cgit_clipboard_popup_time = d.getTime();
+
+	setTimeout(function() {
+		cgit_clipboard_popup.style.opacity = "1";
+	}, 1);
+
+	setTimeout(function() {
+		var d = new Date;
+		if (!cgit_clipboard_popup)
+			return;
+		if (d.getTime() - cgit_clipboard_popup_time < cgit_clipboard_popup_duration)
+			return;
+		cgit_clipboard_popup.style.opacity = "0";
+		setTimeout(function() {
+			var d = new Date;
+			if (!cgit_clipboard_popup)
+				return;
+			if (d.getTime() - cgit_clipboard_popup_time < cgit_clipboard_popup_duration + 1000)
+				return;
+
+			cgit_clipboard_popup.remove();
+			cgit_clipboard_popup = null;
+		}, 1000);
+	}, cgit_clipboard_popup_duration);
+
+}
+
 function cgit_line_range_click(e) {
-	var t, m, n = window.location.href.length - window.location.hash.length;
+	var t, elem, m, n = window.location.href.length - window.location.hash.length;
 
 	/* disable passthru to stop needless scrolling by default browser #URL handler */
 	e.stopPropagation();
 	e.preventDefault();
 
+	elem = document.getElementById(e.target.id);
+	if (!elem)
+		return;
+
+	cgit_line_popup_create(elem);
+
 	if (!window.location.hash ||
 	    window.location.hash.indexOf("-") >= 0)
 		t = window.location.href.substring(0, n) +



  parent reply	other threads:[~2018-06-26 11:25 UTC|newest]

Thread overview: 73+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-20  9:39 Highlighting lines or line ranges in tree view andy
2018-06-21  5:42 ` [PATCH 1/3] ui-shared: introduce line range highlight javascript andy
2018-06-21  7:03   ` list
2018-06-21  7:30     ` andy
2018-06-21  5:42 ` [PATCH 2/3] ui-tree: use the line range highlight script andy
2018-06-21  5:43 ` [PATCH 3/3] ui-blame: " andy
2018-06-21  9:34 ` [PATCH v2 0/5] line range highlight andy
2018-06-21  9:34   ` [PATCH v2 1/5] config: add js andy
2018-06-23 10:20     ` john
2018-06-23 10:34       ` andy
2018-06-21  9:34   ` [PATCH v2 2/5] cgit.js: introduce andy
2018-06-23 10:18     ` john
2018-06-21  9:34   ` [PATCH v2 3/5] ui-shared: introduce line range highlight javascript andy
2018-06-23 10:17     ` john
2018-06-24  2:37       ` andy
2018-06-21  9:35   ` [PATCH v2 4/5] ui-tree: use the line range highlight script andy
2018-06-21  9:35   ` [PATCH v2 5/5] ui-blame: " andy
2018-06-22 23:01   ` [PATCH v2 1/2] cgit.js: make line range highlight responsive to url changes andy
2018-06-22 23:02   ` [PATCH v2 2/2] cgit.js: line range highlight: improve vertical scroll logic andy
2018-06-23  7:45   ` [PATCH v2] cgit.js: line range highlight: always hook hashchange in case hash added andy
2018-06-24  2:44 ` [PATCH v3 0/6] line range highlight andy
2018-06-24  2:44   ` [PATCH v3 1/6] config: add js andy
2018-06-24 11:01     ` john
2018-06-24  2:44   ` [PATCH v3 2/6] ui-shared: line range highlight: introduce javascript andy
2018-06-24 11:28     ` john
2018-06-25  2:04       ` andy
2018-06-24  2:44   ` [PATCH v3 3/6] cgit.js: line range highlight: make responsive to url changes andy
2018-06-24  2:44   ` [PATCH v3 4/6] cgit.js: line range highlight: improve vertical scroll logic andy
2018-06-24  2:44   ` [PATCH v3 5/6] line-range-highlight: onclick handler and range selection andy
2018-06-24 11:35     ` john
2018-06-25  2:07       ` andy
2018-06-24  2:44   ` [PATCH v3 6/6] line-range-highlight: copy URL to clipboard on click andy
2018-06-24 11:42     ` john
2018-06-24 12:00       ` andy
2018-06-24 13:39         ` john
2018-06-24 15:06           ` andy
2018-06-24 16:03             ` john
2018-06-25  0:46               ` andy
2018-06-25  5:49 ` [PATCH v4 0/6] line range highlight andy
2018-06-25  5:49   ` [PATCH v4 1/6] config: add js andy
2018-06-26  8:03     ` list
2018-06-25  5:49   ` [PATCH v4 2/6] cgit.js: line range highlight: introduce javascript andy
2018-06-25  5:49   ` [PATCH v4 3/6] cgit.js: line range highlight: make responsive to url changes andy
2018-06-25  5:50   ` [PATCH v4 4/6] cgit.js: line range highlight: improve vertical scroll logic andy
2018-06-25  5:50   ` [PATCH v4 5/6] line-range-highlight: onclick handler and range selection andy
2018-06-25  5:50   ` [PATCH v4 6/6] line-range-highlight: copy URL to clipboard UI andy
2018-06-26 11:25 ` [PATCH v5 0/6] line range highlight andy
2018-06-26 11:25   ` [PATCH v5 1/6] config: add js andy
2018-06-26 11:25   ` [PATCH v5 2/6] cgit.js: line range highlight: introduce javascript andy
2018-06-27 18:02     ` Jason
2018-06-27 21:45       ` andy
2018-06-28 23:58         ` [PATCH] cgit.css: add copyright lines andy
2018-06-26 11:25   ` [PATCH v5 3/6] cgit.js: line range highlight: make responsive to url changes andy
2018-06-26 11:25   ` [PATCH v5 4/6] cgit.js: line range highlight: improve vertical scroll logic andy
2018-06-26 11:25   ` [PATCH v5 5/6] line-range-highlight: onclick handler and range selection andy
2018-06-26 11:51     ` [PATCH v5-ninjaedit] " andy
2018-06-26 11:25   ` andy [this message]
2018-06-27 18:07     ` [PATCH v5 6/6] line-range-highlight: copy URL to clipboard UI Jason
2018-06-27 23:24       ` andy
2018-06-27 23:30         ` Jason
2018-06-27 23:38           ` andy
2018-06-29  1:39 ` [PATCH v6 0/7] line range highlight andy
2018-06-29  1:40   ` [PATCH v6 1/7] config: add js andy
2018-06-29  6:14     ` list
2018-06-29  6:16       ` [PATCH v6-ninjaedit] " andy
2018-06-29  6:31         ` [PATCH v6-ninjaedit2] " andy
2018-06-29  6:33         ` [PATCH v6-ninjaedit] " list
2018-06-29  1:40   ` [PATCH v6 2/7] cgit.js: line range highlight: introduce javascript andy
2018-06-29  1:40   ` [PATCH v6 3/7] cgit.js: line range highlight: make responsive to url changes andy
2018-06-29  1:40   ` [PATCH v6 4/7] cgit.js: line range highlight: improve vertical scroll logic andy
2018-06-29  1:40   ` [PATCH v6 5/7] line-range-highlight: onclick handler and range selection andy
2018-06-29  1:40   ` [PATCH v6 6/7] line-range-highlight: burger menu and popup menu andy
2018-06-29  1:40   ` [PATCH v6 7/7] line-range-highlight: copy text andy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=153001234496.12484.8630216246879475297.stgit@mail.warmcat.com \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).