Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions assets/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,40 @@
.addon-url-data-table .label-default {
background: #ccc;
}

/* Copy-to-clipboard code elements */
.url-copy-code {
cursor: pointer;
transition: all 0.2s ease;
position: relative;
}

.url-copy-code:hover {
background-color: #e6f3ff !important;
color: #0066cc !important;
border-left: 3px solid #0066cc;
padding-left: 5px !important;
}

.url-copy-code.copied {
background-color: #d4edda !important;
color: #155724 !important;
border-left: 3px solid #28a745;
padding-left: 5px !important;
}

.url-copy-feedback {
position: absolute;
background: #28a745;
color: white;
padding: 2px 6px;
border-radius: 3px;
font-size: 10px;
top: -25px;
left: 50%;
transform: translateX(-50%);
white-space: nowrap;
z-index: 1000;
opacity: 0;
transition: opacity 0.3s ease;
}
98 changes: 96 additions & 2 deletions fragments/url/profiles/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ class="btn btn-primary btn-xs pull-right"
?>
<p class="help-block rex-note" style="font-size: 0.8em;">
Aufruf via
<code>rex_getUrl('', '', ['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])</code>
<code class="url-copy-code"
data-copy="rex_getUrl('', '', ['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])"
title="Klicken zum Kopieren">rex_getUrl('', '', ['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])</code>
oder via Artikel
<code>rex_article::get(<?= $article->getId() ?>)->getUrl(['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])</code><br>
<code class="url-copy-code"
data-copy="rex_article::get(<?= $article->getId() ?>)->getUrl(['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])"
title="Klicken zum Kopieren">rex_article::get(<?= $article->getId() ?>)->getUrl(['<?= htmlspecialchars($profile['namespace'] ?? '') ?>' => {id}])</code><br>


</p>
Expand Down Expand Up @@ -209,3 +213,93 @@ class="btn btn-danger pull-right"
</a>
</div>
</div>

<script type="text/javascript">

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline JavaScript should be moved to external files for better separation of concerns and maintainability. Consider creating a separate JS file for the copy functionality.

Copilot uses AI. Check for mistakes.
(function($) {
// Copy to clipboard functionality
function copyToClipboard(text) {
if (navigator.clipboard && window.isSecureContext) {
// Modern clipboard API
return navigator.clipboard.writeText(text);
} else {
// Fallback for older browsers
return new Promise(function(resolve, reject) {
var textArea = document.createElement("textarea");
textArea.value = text;
textArea.style.position = "fixed";
textArea.style.left = "-999999px";
textArea.style.top = "-999999px";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();

try {
var successful = document.execCommand('copy');
document.body.removeChild(textArea);
if (successful) {
resolve();
} else {
reject(new Error('Copy failed'));
}
} catch (err) {
document.body.removeChild(textArea);
reject(err);
}
});
}
}

function showCopyFeedback(element) {
var feedback = $('<span class="url-copy-feedback">Kopiert!</span>');
Comment on lines +252 to +253

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code duplicates the feedback creation and styling logic between success and error cases. Consider extracting this into a reusable function to reduce duplication.

Suggested change
function showCopyFeedback(element) {
var feedback = $('<span class="url-copy-feedback">Kopiert!</span>');
/**
* Shows feedback message near the element.
* @param {jQuery} element - The element to attach feedback to.
* @param {string} message - The feedback message.
* @param {string} [background] - Optional background color.
* @param {number} [duration] - Duration in ms before feedback disappears.
*/
function showCopyFeedback(element, message, background, duration) {
var feedback = $('<span class="url-copy-feedback"></span>').text(message);
if (background) {
feedback.css('background', background);
}

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you create a new issue from this?

element.css('position', 'relative').append(feedback);

setTimeout(function() {
feedback.css('opacity', '1');
}, 10);

setTimeout(function() {
feedback.css('opacity', '0');
setTimeout(function() {
feedback.remove();
}, 300);
}, 1500);
}

// Event handler for copy buttons
$(document).on('click', '.url-copy-code', function(e) {
e.preventDefault();
var $this = $(this);
var textToCopy = $this.data('copy');

if (!textToCopy) {
return;
}

copyToClipboard(textToCopy).then(function() {
// Success feedback
$this.addClass('copied');
showCopyFeedback($this);

setTimeout(function() {
$this.removeClass('copied');
}, 2000);
}).catch(function(err) {
// Error feedback

var feedback = $('<span class="url-copy-feedback url-copy-feedback-error">Fehler beim Kopieren</span>');
$this.css('position', 'relative').append(feedback);

setTimeout(function() {
feedback.css('opacity', '1');
}, 10);

setTimeout(function() {
feedback.css('opacity', '0');
setTimeout(function() {
feedback.remove();
}, 300);
}, 2000);
});
});
})(jQuery);
</script>