From 8ea13b46709dcf25b1e0b9f8b21812ef5baccce5 Mon Sep 17 00:00:00 2001 From: Armand Duijn Date: Thu, 16 Apr 2020 20:31:54 +0200 Subject: [PATCH 1/3] Add ability to copy LaTeX command --- source/javascripts/classify.coffee | 21 +++++++++++++++++++++ source/javascripts/shared/shared.coffee | 2 +- source/stylesheets/_symbol-list.sass | 12 ++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/source/javascripts/classify.coffee b/source/javascripts/classify.coffee index 014b6af..f49f37d 100644 --- a/source/javascripts/classify.coffee +++ b/source/javascripts/classify.coffee @@ -40,6 +40,27 @@ $ -> return + $(".symbol-list").on "click", "li", -> + command = $("code.command", this)[0] + + range = document.createRange() + range.selectNode(command) + + selection = window.getSelection() + selection.removeAllRanges() + selection.addRange(range) + + try + if document.execCommand("copy") + range.collapse() # Remove selection if copy succeeded + + $(this) + .addClass "flash" + .on "animationend", -> + $(this).removeClass("flash") + catch error + console.error("Your browser doesn't support the copy command. Use CTRL + V instead.") + # Canvas c = $.canvassify("#tafel", callback: classify diff --git a/source/javascripts/shared/shared.coffee b/source/javascripts/shared/shared.coffee index fc86727..877d46e 100644 --- a/source/javascripts/shared/shared.coffee +++ b/source/javascripts/shared/shared.coffee @@ -23,7 +23,7 @@ template = """ {{#symbols}} -
  • +
  • diff --git a/source/stylesheets/_symbol-list.sass b/source/stylesheets/_symbol-list.sass index 4eefa43..fdfef2f 100644 --- a/source/stylesheets/_symbol-list.sass +++ b/source/stylesheets/_symbol-list.sass @@ -12,6 +12,9 @@ ul.symbol-list padding: 0 overflow: hidden + &.flash + animation: flash 1s linear + .info display: table-cell vertical-align: middle @@ -39,7 +42,16 @@ ul.symbol-list &:hover background-color: whitesmoke + cursor: pointer &.active:hover, &.active background-color: cornsilk + +@keyframes flash + 0% + background-color: whitesmoke + 10% + background-color: #EEE + 100% + background-color: whitesmoke From 7c889d004a1dfb0ba1939cfc98730bc3bca75f9f Mon Sep 17 00:00:00 2001 From: Armand Duijn Date: Thu, 16 Apr 2020 20:44:03 +0200 Subject: [PATCH 2/3] Fix clearing selection for Safari --- source/javascripts/classify.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/javascripts/classify.coffee b/source/javascripts/classify.coffee index f49f37d..fea4539 100644 --- a/source/javascripts/classify.coffee +++ b/source/javascripts/classify.coffee @@ -52,14 +52,14 @@ $ -> try if document.execCommand("copy") - range.collapse() # Remove selection if copy succeeded + selection.collapse(null) # Remove selection if copy succeeded $(this) .addClass "flash" .on "animationend", -> $(this).removeClass("flash") catch error - console.error("Your browser doesn't support the copy command. Use CTRL + V instead.") + console.error("Your browser doesn't support the copy command. Use CTRL + V instead.", error) # Canvas c = $.canvassify("#tafel", From 6445153e26cf744fbaa2e235dcf5247384292bff Mon Sep 17 00:00:00 2001 From: Armand Duijn Date: Fri, 17 Apr 2020 10:57:06 +0200 Subject: [PATCH 3/3] Fix typo in error message --- source/javascripts/classify.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/javascripts/classify.coffee b/source/javascripts/classify.coffee index fea4539..f1a2961 100644 --- a/source/javascripts/classify.coffee +++ b/source/javascripts/classify.coffee @@ -59,7 +59,7 @@ $ -> .on "animationend", -> $(this).removeClass("flash") catch error - console.error("Your browser doesn't support the copy command. Use CTRL + V instead.", error) + console.error("Your browser doesn't support the copy command. Use CTRL + C instead.", error) # Canvas c = $.canvassify("#tafel",