clipboard

master
km0 3 years ago
parent 7102ca7f4c
commit 343b843790

@ -1,15 +1,18 @@
import os
class Config(object):
DEBUG = False
TESTING = False
URL_PREFIX = ''
class ProductionConfig(Config):
DEBUG = False
URL_PREFIX = os.environ.get("URL_PREFIX")
class DevelopmentConfig(Config):
ENV = "development"
DEVELOPMENT = True
DEBUG = True

@ -1,7 +1,8 @@
import os
from flask import Flask
from flask import Flask, send_from_directory
from . import prefix
def create_app(test_config=None):
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
@ -26,6 +27,12 @@ def create_app(test_config=None):
from . import db
db.init_app(app)
@app.route("/favicon.ico")
def favicon():
return send_from_directory(
os.path.join(app.root_path, "static"), "favicon.ico", mimetype="image/vnd.microsoft.icon",
)
from . import draw
app.register_blueprint(draw.bp)
@ -38,8 +45,7 @@ def create_app(test_config=None):
from . import home
app.register_blueprint(home.bp)
app.wsgi_app = prefix.PrefixMiddleware(app.wsgi_app, prefix=os.environ.get("URL_PREFIX", ''))
app.wsgi_app = prefix.PrefixMiddleware(
app.wsgi_app, prefix=os.environ.get("URL_PREFIX", ''))
return app

@ -2,6 +2,7 @@ html,
body {
margin: 0;
background-color: var(--background);
font-size: 1.25rem;
}
* {

@ -0,0 +1,28 @@
.share {
width: 100vw;
height: 100vh;
line-height: 2;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
a {
color: currentColor;
text-decoration: none;
}
button.clipboard {
background: none;
border: none;
text-decoration: underline;
cursor: pointer;
font-size: 1rem;
}
button.clipboard:hover {
color: dodgerblue;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,22 @@
copies = document.querySelectorAll("[data-copy]");
Array.from(copies).forEach((copy) => {
clipboard = document.createElement("button");
clipboard.classList.add("clipboard");
clipboard.innerHTML = "Copy to clipboard";
insertAfter(clipboard, copy);
clipboard.addEventListener("click", (e) => {
navigator.clipboard.writeText(copy.dataset.copy).then(
function () {
clipboard.innerHTML = "Copied!";
},
function (err) {
console.error("Async: Could not copy text: ", err);
}
);
});
});
function insertAfter(newNode, referenceNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}

@ -8,12 +8,16 @@
<link rel="stylesheet" href="{{url_for('static', filename='css/variables.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/global.css')}}" />
<link rel="stylesheet" href="{{url_for('static', filename='css/share.css')}}" />
<script src="{{url_for('static', filename='js/copy.js')}}" defer></script>
</head>
<body>
<div class="share">
Send this link to your friends:
<a href="{{url_for('draw.draw', parent=branch)}}"
>{{url_for('draw.draw', parent=branch)}}</a
<a
href="{{url_for('draw.draw', parent=branch)}}"
data-copy="{{ request.url_root[:-1] + url_for('draw.draw', parent=branch)}}"
>{{ request.url_root[:-1] + url_for('draw.draw', parent=branch)}}</a
>
</div>
</body>

Loading…
Cancel
Save