Skip to content

Instantly share code, notes, and snippets.

@sergii
Forked from swanson/copy_html_controller.js
Created April 19, 2022 19:37
Show Gist options
  • Save sergii/90a57ab0c8d221a4559dd8f62c331678 to your computer and use it in GitHub Desktop.
Save sergii/90a57ab0c8d221a4559dd8f62c331678 to your computer and use it in GitHub Desktop.
import { Controller } from "stimulus";
export default class extends Controller {
static targets = ["source"];
copy() {
const range = document.createRange();
window.getSelection().removeAllRanges();
this.sourceTarget.classList.remove("hidden");
range.selectNode(this.sourceTarget);
window.getSelection().addRange(range);
document.execCommand("copy");
this.sourceTarget.classList.add("hidden");
window.getSelection().removeAllRanges();
}
}
%div(data-controller="copy-html")
%button.btn-teal(data-action="copy-html#copy")
Copy
.hidden(data-copy-html-target="source")
%div(style="background: white; font-size: 11pt; font-family: Calibri; color: black;")
%br
%b(style="border: none;") Recent Changes
%br
%table(style="width: 800px")
%thead
%tr(style="font-weight: bold; color: white; background: #9F5B94; text-align: center;")
%td(style="border: 1.5pt solid black;")
Author
%td(style="border: 1.5pt solid black;")
Comments
%tbody
- @changes.each do |change|
%tr(style="background: white;")
%td(style="width: 200px; border: 1.5pt solid black; padding: 2px 10px")
= change.author.display_name
%td(style="border: 1.5pt solid black; padding: 2px 10px")
%ul
- change.comments.each do |c|
%li(style="border: none; margin: 0;")= c
%br
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment