MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
$(function() { | $(function() { | ||
$('pre, .mw-code | // Procura apenas por blocos de código técnicos e ignora a área de produtos | ||
$('.mw-highlight pre, .syntaxhighlight pre, pre.mw-code-example').each(function() { | |||
var $this = $(this); | var $this = $(this); | ||
// Verifica se o elemento já tem um botão para não duplicar | |||
if ($this.parent().find('.copy-code-button').length > 0) return; | |||
var $button = $('<button>') | var $button = $('<button>') | ||
.text('Copy') | .text('Copy') | ||
.addClass('copy-code-button') | .addClass('copy-code-button') | ||
.click(function() { | .click(function() { | ||
var text = $this.text( | var text = $this.text(); | ||
navigator.clipboard.writeText(text).then(function() { | navigator.clipboard.writeText(text).then(function() { | ||
$button.text('Copied!'); | $button.text('Copied!'); | ||
| Line 22: | Line 20: | ||
}); | }); | ||
}); | }); | ||
$this. | |||
// Insere o botão antes do bloco de código | |||
$this.before($button); | |||
}); | }); | ||
}); | }); | ||