mirror of https://gitlab.com/tildes/tildes.git
Bauke
5 years ago
committed by
Deimos
12 changed files with 179 additions and 10 deletions
-
1tildes/package.json
-
4tildes/scss/modules/_comment.scss
-
9tildes/scss/modules/_dropdown.scss
-
2tildes/scss/modules/_topic.scss
-
8tildes/scss/themes/_theme_base.scss
-
44tildes/static/js/behaviors/copy-button.js
-
22tildes/static/js/behaviors/dropdown-toggle.js
-
30tildes/tildes/templates/intercooler/markdown_source.jinja2
-
22tildes/tildes/templates/macros/comments.jinja2
-
23tildes/tildes/templates/topic.jinja2
-
12tildes/tildes/views/api/web/comment.py
-
12tildes/tildes/views/api/web/topic.py
@ -0,0 +1,44 @@ |
|||
// Copyright (c) 2020 Tildes contributors <code@tildes.net>
|
|||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|||
|
|||
$.onmount("[data-js-copy-button]", function() { |
|||
$(this).click(function(event) { |
|||
event.preventDefault(); |
|||
|
|||
var textToCopy; |
|||
// If there are multiple inputs or textareas in a form with a copy button, you
|
|||
// can use `data-js-copy-target="#selector"` to specify which element should
|
|||
// get copied for that button. If this isn't defined, whatever input/textarea
|
|||
// element jQuery finds first in the form will be copied instead.
|
|||
if ($(this).attr("data-js-copy-target")) { |
|||
var $targetField = $($(this).attr("data-js-copy-target")); |
|||
$targetField.select(); |
|||
textToCopy = $targetField.val(); |
|||
} else { |
|||
var $parentForm = $(this).closest("form"); |
|||
var $firstFoundField = $parentForm.find("input,textarea").first(); |
|||
$firstFoundField.select(); |
|||
textToCopy = $firstFoundField.val(); |
|||
} |
|||
|
|||
Tildes.writeToClipboard(textToCopy); |
|||
}); |
|||
}); |
|||
|
|||
Tildes.writeToClipboard = function(text) { |
|||
// Minimal polyfill for writing to clipboard, by Lucas Garron
|
|||
// https://gist.github.com/lgarron/d1dee380f4ed9d825ca7
|
|||
return new Promise(function(resolve, reject) { |
|||
var success = false; |
|||
function listener(event) { |
|||
event.clipboardData.setData("text/plain", text); |
|||
event.preventDefault(); |
|||
success = true; |
|||
} |
|||
|
|||
document.addEventListener("copy", listener); |
|||
document.execCommand("copy"); |
|||
document.removeEventListener("copy", listener); |
|||
success ? resolve() : reject(); |
|||
}); |
|||
}; |
@ -0,0 +1,30 @@ |
|||
{# Copyright (c) 2020 Tildes contributors <code@tildes.net> #} |
|||
{# SPDX-License-Identifier: AGPL-3.0-or-later #} |
|||
|
|||
<form class="form-markdown-source"> |
|||
<label class="form-label" for="markdown-source"> |
|||
{% if post is topic %} |
|||
Topic Markdown (read-only) |
|||
{% elif post is comment %} |
|||
Comment Markdown (read-only) |
|||
{% endif %} |
|||
</label> |
|||
<textarea |
|||
class="form-input" |
|||
name="markdown-source" |
|||
placeholder="Text (Markdown)" |
|||
readonly |
|||
>{{ post.markdown }}</textarea> |
|||
<div class="form-buttons"> |
|||
<button |
|||
class="btn btn-primary" |
|||
data-js-copy-button |
|||
type="button" |
|||
>Copy Markdown</button> |
|||
<button |
|||
class="btn btn-link" |
|||
data-js-cancel-button |
|||
type="button" |
|||
>Hide</button> |
|||
</div> |
|||
</form> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue