Skip to content

Commit 554fc6a

Browse files
committed
Squashed 'CTFd/themes/core-beta/' changes from a3558313..08dad215
08dad215 Add share links UI to challenge.html (CTFd#59) 0a73a090 make notifications fade in and out (CTFd#60) git-subtree-dir: CTFd/themes/core-beta git-subtree-split: 08dad215be93f8af7622387ab24b9dde01f56fb1
1 parent f346a05 commit 554fc6a

File tree

6 files changed

+58
-9
lines changed

6 files changed

+58
-9
lines changed

assets/js/challenges.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import dayjs from "dayjs";
33

44
import CTFd from "./index";
55

6-
import { Modal, Tab } from "bootstrap";
6+
import { Modal, Tab, Tooltip } from "bootstrap";
77
import highlight from "./theme/highlight";
88

99
function addTargetBlank(html) {
@@ -62,6 +62,7 @@ Alpine.data("Challenge", () => ({
6262
tab: null,
6363
solves: [],
6464
response: null,
65+
share_url: null,
6566

6667
async init() {
6768
highlight();
@@ -134,6 +135,31 @@ Alpine.data("Challenge", () => ({
134135
modal.hide();
135136
},
136137

138+
async getShareUrl() {
139+
let body = {
140+
type: "solve",
141+
challenge_id: this.id,
142+
};
143+
const response = await CTFd.fetch("/api/v1/shares", {
144+
method: "POST",
145+
body: JSON.stringify(body),
146+
});
147+
const data = await response.json();
148+
const url = data["data"]["url"];
149+
this.share_url = url;
150+
},
151+
152+
copyShareUrl() {
153+
navigator.clipboard.writeText(this.share_url);
154+
let t = Tooltip.getOrCreateInstance(this.$el);
155+
t.enable();
156+
t.show();
157+
setTimeout(() => {
158+
t.hide();
159+
t.disable();
160+
}, 2000);
161+
},
162+
137163
async submitChallenge() {
138164
this.response = await CTFd.pages.challenge.submitChallenge(
139165
this.id,

static/assets/challenges.897809bc.js

-1
This file was deleted.

static/assets/challenges.d8a7ea63.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

static/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
]
3131
},
3232
"assets/js/challenges.js": {
33-
"file": "assets/challenges.897809bc.js",
33+
"file": "assets/challenges.d8a7ea63.js",
3434
"src": "assets/js/challenges.js",
3535
"isEntry": true,
3636
"imports": [

templates/challenge.html

+27-4
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,33 @@ <h3 class="challenge-value text-center">
162162
}" role="alert"
163163
>
164164
<strong x-text="response.data.message"></strong>
165-
<div x-show="(response.data.status == 'correct' || response.data.status == 'already_solved') && getNextId()">
166-
<button @click="nextChallenge()" class="btn btn-info mt-3">
167-
{% trans %}Next Challenge{% endtrans %}
168-
</button>
165+
<div x-show="(response.data.status == 'correct' || response.data.status == 'already_solved')">
166+
<div x-show="getNextId()">
167+
<button @click="nextChallenge()" class="btn btn-info mt-3">
168+
{% trans %}Next Challenge{% endtrans %}
169+
</button>
170+
</div>
171+
{% if Configs.social_shares != false %}
172+
<div>
173+
<button x-show="!share_url" @click="getShareUrl()" class="btn btn-sm btn-outline-info mt-3">
174+
{% trans %}Share{% endtrans %}
175+
</button>
176+
<div class="btn-group mt-3" role="group" x-show="share_url">
177+
<button type="button" class="btn btn-sm btn-outline-secondary" @click="copyShareUrl()" data-bs-toggle="tooltip" data-bs-title="Copied!">
178+
<i class="fa-solid fa-copy"></i>
179+
</button>
180+
<a :href="'https://twitter.com/intent/tweet?url=' + encodeURIComponent(share_url)" role="button" class="btn btn-sm btn-outline-secondary" target="_blank">
181+
<i class="fa-brands fa-twitter"></i>
182+
</a>
183+
<a :href="'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(share_url)" role="button" class="btn btn-sm btn-outline-secondary" target="_blank">
184+
<i class="fa-brands fa-facebook-f"></i>
185+
</a>
186+
<a :href="'http://www.linkedin.com/shareArticle?url=' + encodeURIComponent(share_url)" role="button" class="btn btn-sm btn-outline-secondary" target="_blank">
187+
<i class="fa-brands fa-linkedin-in"></i>
188+
</a>
189+
</div>
190+
{% endif %}
191+
</div>
169192
</div>
170193
</div>
171194
</template>

templates/components/notifications.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
<div x-data>
17-
<div class="modal" x-ref="modal" tabindex="-1">
17+
<div class="modal fade" x-ref="modal" tabindex="-1">
1818
<div class="modal-dialog">
1919
<div class="modal-content">
2020
<div class="modal-header">
@@ -30,4 +30,4 @@ <h5 class="modal-title" x-text="$store.modal.title"></h5>
3030
</div>
3131
</div>
3232
</div>
33-
</div>
33+
</div>

0 commit comments

Comments
 (0)