adding copy join link function
This commit is contained in:
@@ -79,6 +79,9 @@
|
||||
</div>
|
||||
|
||||
<div class="GameArea">
|
||||
<!-- Copy Join Link Section -->
|
||||
|
||||
|
||||
@if (Model.GameStarted)
|
||||
{
|
||||
@if(!Model.onlineMultiplayer || !Model.CurrentPlayer.name.Equals(Model.player.name)) {
|
||||
@@ -165,6 +168,28 @@
|
||||
<p>Join code: <span>@Model.joinCode</span></p>
|
||||
<p>Joined as: <span>@Model.player.name</span></p>
|
||||
}
|
||||
@if (Model.onlineMultiplayer)
|
||||
{
|
||||
<div class="mb-3 p-3 bg-light rounded">
|
||||
<div class="d-flex align-items-center justify-content-between">
|
||||
<div>
|
||||
<h6 class="mb-1">🎮 Share this game</h6>
|
||||
<small class="text-muted">Send this link to friends to join the game</small>
|
||||
</div>
|
||||
<div>
|
||||
<button id="copyJoinLink" class="btn btn-sm btn-info" onclick="copyJoinLink('@Model.gameID')">
|
||||
Copy Join Link
|
||||
</button>
|
||||
<span id="copySuccess" class="text-success ms-2" style="display: none;">✓ Copied!</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<input type="text" id="joinLinkInput" class="form-control form-control-sm"
|
||||
value="@(Context.Request.Scheme)://@(Context.Request.Host)/game/join/@Model.joinCode"
|
||||
readonly onclick="this.select()">
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
<div style="flex:1;"></div>
|
||||
@if(Model.player.Owner) {
|
||||
@if(Model.players.Count <= 0)
|
||||
@@ -274,4 +299,30 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function copyJoinLink(gameId) {
|
||||
const joinLinkInput = document.getElementById('joinLinkInput');
|
||||
const copyButton = document.getElementById('copyJoinLink');
|
||||
const successMessage = document.getElementById('copySuccess');
|
||||
|
||||
// Select and copy the text
|
||||
joinLinkInput.select();
|
||||
joinLinkInput.setSelectionRange(0, 99999); // For mobile devices
|
||||
|
||||
try {
|
||||
// Use the modern clipboard API if available
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(joinLinkInput.value).then(function() {
|
||||
});
|
||||
} else {
|
||||
// Fallback for older browsers
|
||||
fallbackCopy(joinLinkInput, copyButton, successMessage);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to copy: ', err);
|
||||
alert('Failed to copy link. Please copy it manually.');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user