Feature #29214 » 0001-Add-copy-button-to-pre-elements.patch
| app/assets/images/icons.svg | ||
|---|---|---|
|
<path d="M13 17v-1a1 1 0 0 1 1 -1h1m3 0h1a1 1 0 0 1 1 1v1m0 3v1a1 1 0 0 1 -1 1h-1m-3 0h-1a1 1 0 0 1 -1 -1v-1"/>
|
||
|
<path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"/>
|
||
|
</symbol>
|
||
|
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--copy-pre-content">
|
||
|
<path d="M9 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2 -2v-12a2 2 0 0 0 -2 -2h-2"/>
|
||
|
<path d="M9 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z"/>
|
||
|
</symbol>
|
||
|
<symbol viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" id="icon--custom-fields">
|
||
|
<path d="M20 13v-4a2 2 0 0 0 -2 -2h-12a2 2 0 0 0 -2 2v5a2 2 0 0 0 2 2h6"/>
|
||
|
<path d="M15 19l2 2l4 -4"/>
|
||
| app/assets/javascripts/application.js | ||
|---|---|---|
|
iconElement.setAttribute('href', iconPath.replace(/#.*$/g, "#icon--" + icon))
|
||
|
}
|
||
|
function createSVGIcon(icon) {
|
||
|
const clonedIcon = document.querySelector('#icon-copy-source svg').cloneNode(true);
|
||
|
updateSVGIcon(clonedIcon, icon);
|
||
|
return clonedIcon
|
||
|
}
|
||
|
function collapseAllRowGroups(el) {
|
||
|
var tbody = $(el).parents('tbody').first();
|
||
|
tbody.children('tr').each(function(index) {
|
||
| ... | ... | |
|
case "list_status":
|
||
|
case "list_subprojects":
|
||
|
const iconType = values.length > 1 ? 'toggle-minus' : 'toggle-plus';
|
||
|
const clonedIcon = document.querySelector('#icon-copy-source svg').cloneNode(true);
|
||
|
updateSVGIcon(clonedIcon, iconType);
|
||
|
const iconSvg = createSVGIcon(iconType)
|
||
|
tr.find('.values').append(
|
||
|
$('<span>', { style: 'display:none;' }).append(
|
||
| ... | ... | |
|
name: `v[${field}][]`,
|
||
|
}),
|
||
|
'\n',
|
||
|
$('<span>', { class: `toggle-multiselect icon-only icon-${iconType}` }).append(clonedIcon)
|
||
|
$('<span>', { class: `toggle-multiselect icon-only icon-${iconType}` }).append(iconSvg)
|
||
|
)
|
||
|
);
|
||
|
select = tr.find('.values select');
|
||
| ... | ... | |
|
return false;
|
||
|
}
|
||
|
function setupCopyButtonsToPreElements() {
|
||
|
document.querySelectorAll('pre:not(.pre-wrapper pre)').forEach((pre) => {
|
||
|
// Wrap the <pre> element with a container and add a copy button
|
||
|
const wrapper = document.createElement("div");
|
||
|
wrapper.classList.add("pre-wrapper");
|
||
|
const copyButton = document.createElement("a");
|
||
|
copyButton.title = rm.I18n.buttonCopy;
|
||
|
copyButton.classList.add("copy-pre-content-link", "icon-only");
|
||
|
copyButton.append(createSVGIcon("copy-pre-content"));
|
||
|
wrapper.appendChild(copyButton);
|
||
|
wrapper.append(pre.cloneNode(true));
|
||
|
pre.replaceWith(wrapper);
|
||
|
// Copy the contents of the pre tag when copyButton is clicked
|
||
|
copyButton.addEventListener("click", (event) => {
|
||
|
event.preventDefault();
|
||
|
let textToCopy = (pre.querySelector("code") || pre).textContent.replace(/\n$/, '');
|
||
|
if (pre.querySelector("code.syntaxhl")) { textToCopy = textToCopy.replace(/ $/, ''); } // Workaround for half-width space issue in Textile's highlighted code
|
||
|
navigator.clipboard.writeText(textToCopy).then(() => {
|
||
|
updateSVGIcon(copyButton, "checked");
|
||
|
setTimeout(() => updateSVGIcon(copyButton, "copy-pre-content"), 2000);
|
||
|
});
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
function updateIssueFrom(url, el) {
|
||
|
$('#all_attributes input, #all_attributes textarea, #all_attributes select').each(function(){
|
||
|
$(this).data('valuebeforeupdate', $(this).val());
|
||
| ... | ... | |
|
});
|
||
|
}
|
||
|
$(function () {
|
||
|
function setupHoverTooltips() {
|
||
|
$("[title]:not(.no-tooltip)").tooltip({
|
||
|
show: {
|
||
|
delay: 400
|
||
| ... | ... | |
|
at: "center top"
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
$(function() { setupHoverTooltips(); });
|
||
|
function inlineAutoComplete(element) {
|
||
|
'use strict';
|
||
| ... | ... | |
|
$(document).on('focus', '[data-auto-complete=true]', function(event) {
|
||
|
inlineAutoComplete(event.target);
|
||
|
});
|
||
|
document.addEventListener("DOMContentLoaded", () => { setupCopyButtonsToPreElements(); });
|
||
| app/assets/stylesheets/application.css | ||
|---|---|---|
|
div.wiki li {line-height: 1.6; margin-bottom: 0.125rem;}
|
||
|
div.wiki li>ul, div.wiki li>ol {margin-bottom: 0;}
|
||
|
div.wiki div.pre-wrapper {
|
||
|
position: relative;
|
||
|
padding-right: 10px;
|
||
|
}
|
||
|
div.wiki pre {
|
||
|
margin: 1em 1em 1em 1.6em;
|
||
|
padding: 8px;
|
||
| ... | ... | |
|
border-radius: 0.1em;
|
||
|
}
|
||
|
div.pre-wrapper a.copy-pre-content-link {
|
||
|
position: absolute;
|
||
|
top: 0px;
|
||
|
right: 8px;
|
||
|
cursor: pointer;
|
||
|
display: none;
|
||
|
}
|
||
|
div.pre-wrapper:hover a.copy-pre-content-link {
|
||
|
display: block;
|
||
|
}
|
||
|
div.wiki ul.toc {
|
||
|
background-color: #ffffdd;
|
||
|
border: 1px solid #e4e4e4;
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def heads_for_i18n
|
||
|
javascript_tag(
|
||
|
"rm = window.rm || {};" \
|
||
|
"rm.I18n = rm.I18n || {};" \
|
||
|
"rm.I18n = Object.freeze({buttonCopy: '#{l(:button_copy)}'});"
|
||
|
)
|
||
|
end
|
||
|
def heads_for_auto_complete(project)
|
||
|
data_sources = autocomplete_data_sources(project)
|
||
|
javascript_tag(
|
||
| app/views/journals/update.js.erb | ||
|---|---|---|
|
journal_header.append('<%= escape_javascript(render_journal_update_info(@journal)) %>');
|
||
|
}
|
||
|
setupWikiTableSortableHeader();
|
||
|
setupCopyButtonsToPreElements();
|
||
|
setupHoverTooltips();
|
||
|
<% end %>
|
||
|
<%= call_hook(:view_journals_update_js_bottom, { :journal => @journal }) %>
|
||
| app/views/layouts/base.html.erb | ||
|---|---|---|
|
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
|
||
|
<%= javascript_heads %>
|
||
|
<%= heads_for_theme %>
|
||
|
<%= heads_for_i18n %>
|
||
|
<%= heads_for_auto_complete(@project) %>
|
||
|
<%= call_hook :view_layouts_base_html_head %>
|
||
|
<!-- page specific tags -->
|
||
| ... | ... | |
|
<div id="ajax-indicator" style="display:none;"><span><%= l(:label_loading) %></span></div>
|
||
|
<div id="ajax-modal" style="display:none;"></div>
|
||
|
<div id="icon-copy-source" style="display: none;"><%= sprite_icon('') %></div>
|
||
|
</div>
|
||
|
<%= call_hook :view_layouts_base_body_bottom %>
|
||
| app/views/queries/_filters.html.erb | ||
|---|---|---|
|
<%= select_tag 'add_filter_select', filters_options_for_select(query), :name => nil %>
|
||
|
</div>
|
||
|
<div id="icon-copy-source" style="display: none;"><%= sprite_icon('') %></div>
|
||
|
<%= hidden_field_tag 'f[]', '' %>
|
||
|
<% include_calendar_headers_tags %>
|
||
| config/icon_source.yml | ||
|---|---|---|
|
svg: square-rounded-plus
|
||
|
- name: toggle-minus
|
||
|
svg: square-rounded-minus
|
||
|
- name: copy-pre-content
|
||
|
svg: clipboard
|
||
| config/locales/en.yml | ||
|---|---|---|
|
button_copy: Copy
|
||
|
button_copy_and_follow: Copy and follow
|
||
|
button_copy_link: Copy link
|
||
|
button_copied: Copied
|
||
|
button_annotate: Annotate
|
||
|
button_fetch_changesets: Fetch commits
|
||
|
button_update: Update
|
||