Files
wordpress-theme-aksrt/assets/js/runtime/libs/clipboard.min.js
T
kate522andClaude Sonnet 4.6 63b5edd901 fix(runtime): use jQuery, not bare $, in the lazily loaded clipboard lib
WordPress runs jQuery in noConflict mode, so bare $ is undefined. The
clipboard module called $(this) on every click and $.isFunction on the
copy result, so any click on a [data-clipboard-text] button threw
"$ is not a function" and copied nothing.

This was latent: the only prior emitter was the paid card, and the click
path only ran when a user actually clicked it. Exposing the copy button on
the download box made it reachable on every resource, surfacing the error.

Bind through jQuery explicitly, guard notyf so a missing toast lib cannot
also throw, and drop the _win.bd dependency (that payload only gains .bd
once main.js runs). Contract-lock the module under simulated noConflict.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-09-24 21:13:24 +08:00

2 lines
932 B
JavaScript

function copyText(t,e,n,a){function c(t,e,n){if(t.createTextRange){var a=t.createTextRange();a.collapse(!0),a.moveStart("character",e),a.moveEnd("character",n-e),a.select()}else{t.setSelectionRange(e,n),t.select()}}var o=t.toString(),i=document.querySelector("#copy-input");if(!i){i=document.createElement("input");i.id="copy-input";i.readOnly="readOnly";i.style.position="fixed";i.style.left="-2000px";i.style.zIndex="-1000";a.parentNode.appendChild(i)}i.value=o;c(i,0,o.length);if(document.execCommand("copy")){if(typeof e==="function")e()}else{if(typeof n==="function")n()}i.blur()}window.jQuery("body").on("click","[data-clipboard-text]","clipboard",function(t){var e=jQuery(this),n=e.attr("data-clipboard-text"),a=e.attr("data-clipboard-tag")||"内容";copyText(n,function(){if(typeof notyf==="function")notyf(a+"已复制")},function(){if(typeof notyf==="function")notyf(a+"复制失败,请手动复制","danger")},this)});