[TikiWiki-commits] [Git][tikiwiki/tiki][master] [FIX] Comments: Fix copy comment link action

"Victor Emanouilov \(@kroky\) via TikiWiki-cvs" <[email protected]> Tue, 14 Jul 2026 12:02:54 +0000
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a56256e74209_3819c08099097@gitlab-sidekiq-low-urgency-cpu-bound-v2-6d75fbfbb4-nxm6d.mail>

Victor Emanouilov pushed to branch master at Tiki Wiki CMS Groupware / Tiki


Commits:
6a0d0f1f by UshindiG at 2026-07-14T11:43:57+00:00
[FIX] Comments: Fix copy comment link action
---
* [FIX] Comments: Fix copy comment link action

See merge request tikiwiki/tiki!10601

- - - - -


2 changed files:

- lib/jquery_tiki/tiki-jquery.js
- templates/comment/list_inner.tpl


Changes:

=====================================
lib/jquery_tiki/tiki-jquery.js
=====================================
@@ -1068,46 +1068,53 @@ $.fn.tiki = function(func) {
              *     eg. $(document).tiki('copy', () => 'content to copy', successCallback, errorCallback, '.copy-btn')
              */
             return (getText, onSuccess, onError, selector) => {
-                if (typeof ClipboardJS === 'undefined' || !ClipboardJS.isSupported()) return this;
                 if (!this.length && !selector) return this;
 
-                const initializeClipboard = (elementSelector) => {
-                    const clipboard = new ClipboardJS(elementSelector, {
-                        text: typeof getText === "function" ? getText : (trigger) => {
-                            const target = $(trigger).data('clipboard-target');
-                            return $(target).text();
-                        },
-                        /**
-                         * For use in Bootstrap Modals or with any other library that changes the
-                         * focus we want to set the focused element as the container value
-                        */
-                        container: document.body
-                    });
+                const initializeCopy = () => {
+                    if (typeof ClipboardJS === 'undefined' || !ClipboardJS.isSupported()) return this;
+                    const getClipboardText = typeof getText === "function" ? getText : (trigger) => $($(trigger).data('clipboard-target')).text();
+                    const initializeClipboard = (elementSelector) => {
+                        const clipboard = new ClipboardJS(elementSelector, {
+                            text: getClipboardText,
+                            /**
+                             * For use in Bootstrap Modals or with any other library that changes the
+                             * focus we want to set the focused element as the container value
+                            */
+                            container: document.body
+                        });
 
-                    if (typeof onSuccess === "function") clipboard.on('success', onSuccess.bind(this));
-                    if (typeof onError === "function") clipboard.on('error', onError.bind(this));
+                        if (typeof onSuccess === "function") clipboard.on('success', onSuccess.bind(this));
+                        if (typeof onError === "function") clipboard.on('error', onError.bind(this));
+                    };
+
+                    /**
+                    * If a selector is provided, we use ClipboardJS's built-in delegation.
+                    * This ensures functionality for elements added to the DOM after the initial load
+                    */
+                    if (selector) {
+                        initializeClipboard(selector);
+                        return this;
+                    }
+
+                    /**
+                     * Used when the plugin is called directly on existing DOM elements.
+                     * We ensure each element has a unique ID to allow ClipboardJS to target it specifically.
+                    */
+                    return this.each(function() {
+                        const $el = $(this);
+                        if (!$el.attr('id')) {
+                            $el.attr('id', 'copy-' + Math.random().toString(16).slice(2));
+                        }
+                        initializeClipboard('#' + $el.attr('id'));
+                    });
                 };
 
-                /**
-                * If a selector is provided, we use ClipboardJS's built-in delegation.
-                * This ensures functionality for elements added to the DOM after the initial load
-                */
-                if (selector) {
-                    initializeClipboard(selector);
+                if (typeof ClipboardJS === 'undefined' || !ClipboardJS.isSupported()) {
+                    $(window).one('load', initializeCopy);
                     return this;
                 }
 
-                /**
-                 * Used when the plugin is called directly on existing DOM elements.
-                 * We ensure each element has a unique ID to allow ClipboardJS to target it specifically.
-                */
-                return this.each(function() {
-                    const $el = $(this);
-                    if (!$el.attr('id')) {
-                        $el.attr('id', 'copy-' + Math.random().toString(16).slice(2));
-                    }
-                    initializeClipboard('#' + $el.attr('id'));
-                });
+                return initializeCopy();
             };
     }    // end switch(func)
 };
@@ -1121,6 +1128,9 @@ $(document).tiki('copy')(
         }
 
         const url = new URL(window.location.href);
+        const threadId = fragment.replace(/^threadId=?/, '');
+        url.searchParams.set('threadId', threadId);
+        url.searchParams.set('comzone', 'show');
         url.hash = fragment;
 
         return url.toString();


=====================================
templates/comment/list_inner.tpl
=====================================
@@ -14,7 +14,7 @@
                             <div class="comment-title">
                                 {$comment.title}
                                 {if $prefs.comments_heading_links eq 'y'}
-                                    <button type="button" class="heading-link copy-comment-link tips btn btn-link p-0" title="|{tr}Click to copy the comment link{/tr}" aria-label="{tr}Heading link{/tr}" data-thread-id="{if $comment.threadId neq $comments_parentId}threadId{$comment.threadId}{/if}">{icon name="link" _class="me-1"}</button>
+                                    <button type="button" class="heading-link copy-comment-link tips btn btn-link p-0" title="|{tr}Click to copy the comment link{/tr}" aria-label="{tr}Heading link{/tr}" data-thread-id="threadId{$comment.threadId|escape}">{icon name="link" iclass="me-1"}</button>
                                 {/if}
                             </div>
                         {/if}
@@ -24,7 +24,7 @@
                             {/if}
                             {tr _0=$comment.userName|userlink}%0{/tr}{if $prefs.comments_threshold_indent neq '0' && $level && $level gte $prefs.comments_threshold_indent}>{tr _0=$repliedTo.userName|userlink}%0{/tr}{/if} <small class="date">{tr _0=$comment.commentDate|tiki_short_datetime}%0{/tr}</small>
                             {if $prefs.comments_heading_links eq 'y' and  $prefs.comments_notitle eq 'y'}
-                                <button type="button" class="heading-link copy-comment-link tips btn btn-link p-0" title="|{tr}Click to copy the comment link{/tr}" aria-label="{tr}Heading link{/tr}" data-thread-id="{if $comment.threadId neq $comments_parentId}threadId{$comment.threadId}{/if}">{icon name="link" _class="me-1"}</button>
+                                <button type="button" class="heading-link copy-comment-link tips btn btn-link p-0" title="|{tr}Click to copy the comment link{/tr}" aria-label="{tr}Heading link{/tr}" data-thread-id="threadId{$comment.threadId|escape}">{icon name="link" iclass="me-1"}</button>
                             {/if}
                         </div>
                     </h4>



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/6a0d0f1f2bd665f541474554962e09d8fa0c4a01

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/6a0d0f1f2bd665f541474554962e09d8fa0c4a01
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs