Jump to content

Layer-09/common.js

From Official NixOS Wiki
Revision as of 08:17, 8 June 2025 by Layer-09 (talk | contribs) (Created page with "// Add copy-to-clipboard functionality for the Command sandbox template $(function () { $(document.body).on('click', '.mw-copy-button', function() { var button = $(this); var block = button.closest('.mw-command-block'); var source = block.find('.mw-copy-source'); if (!source.length) return; navigator.clipboard.writeText(source.val()).then(function() { var originalText = button.text(); button.text('Copi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

// Add copy-to-clipboard functionality for the Command sandbox template $(function () {

   $(document.body).on('click', '.mw-copy-button', function() {
       var button = $(this);
       var block = button.closest('.mw-command-block');
       var source = block.find('.mw-copy-source');
       if (!source.length) return;
       navigator.clipboard.writeText(source.val()).then(function() {
           var originalText = button.text();
           button.text('Copied!');
           button.prop('disabled', true);
           setTimeout(function() {
               button.text(originalText);
               button.prop('disabled', false);
           }, 2000);
       }).catch(function(err) {
           console.error('Failed to copy text: ', err);
           alert('Could not copy text. Please do it manually.');
       });
   });

});