diff options
| author | shu <nvcsadjkojf@outlook.com> | 2026-07-26 22:42:45 +0800 |
|---|---|---|
| committer | shu <nvcsadjkojf@outlook.com> | 2026-07-26 22:42:45 +0800 |
| commit | 338cc101f127e4841689c1f81227ee033e57ad28 (patch) | |
| tree | 490cfc2ca29dc28e116a979f5c19b0851c3ea32e /tiddlers/copy-codeblock.tid | |
| parent | 1888ff59743d83bd7776b0f16ef0bc20d68e3e10 (diff) | |
Add task board and organize local plugins
Diffstat (limited to 'tiddlers/copy-codeblock.tid')
| -rw-r--r-- | tiddlers/copy-codeblock.tid | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/tiddlers/copy-codeblock.tid b/tiddlers/copy-codeblock.tid deleted file mode 100644 index 2251c62..0000000 --- a/tiddlers/copy-codeblock.tid +++ /dev/null @@ -1,72 +0,0 @@ -title: $:/plugins/local/copy-codeblock/copy-codeblock.js -type: application/javascript -module-type: widget - -/*\ -title: $:/plugins/local/copy-codeblock/copy-codeblock.js -type: application/javascript -module-type: widget - -Adds a copy button to code blocks. -\*/ -(function() { -"use strict"; - -var CodeBlockWidget = require("$:/core/modules/widgets/codeblock.js").codeblock; - -var CopyCodeBlockWidget = function(parseTreeNode,options) { - this.initialise(parseTreeNode,options); -}; - -CopyCodeBlockWidget.prototype = new CodeBlockWidget(); -CopyCodeBlockWidget.prototype.constructor = CopyCodeBlockWidget; - -CopyCodeBlockWidget.prototype.postRender = function() { - var self = this, - preNode = this.domNodes[0], - previousNode, - button; - - // Preserve syntax highlighting supplied by the highlight plugin. - if(CodeBlockWidget.prototype.postRender) { - CodeBlockWidget.prototype.postRender.call(this); - } - - if(!$tw.browser || !preNode || preNode.isTiddlyWikiFakeDom) { - return; - } - - // The system code view already renders its own copy button. - previousNode = preNode.previousElementSibling; - if(previousNode && previousNode.querySelector && previousNode.querySelector(".tc-image-copy-clipboard")) { - return; - } - - preNode.style.position = "relative"; - preNode.style.paddingRight = "5em"; - - button = this.document.createElement("button"); - button.setAttribute("type","button"); - button.setAttribute("aria-label","Copy code"); - button.setAttribute("title","Copy code"); - button.className = "tc-btn-invisible tc-copy-codeblock-button"; - button.textContent = "Copy"; - button.style.position = "absolute"; - button.style.top = "0.5em"; - button.style.right = "0.5em"; - button.style.zIndex = "1"; - button.style.padding = "0.2em 0.45em"; - button.style.cursor = "pointer"; - - button.addEventListener("click",function(event) { - event.preventDefault(); - event.stopPropagation(); - $tw.utils.copyToClipboard(self.getAttribute("code","")); - }); - - preNode.appendChild(button); -}; - -exports.codeblock = CopyCodeBlockWidget; - -})(); |
