Patch #37559 ยป 0001-Use-meta-element-instead-of-javascript-object.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
|
end
|
||
|
end
|
||
|
def heads_for_auto_complete(project)
|
||
|
data_sources = autocomplete_data_sources(project)
|
||
|
javascript_tag(
|
||
|
"rm = window.rm || {};" \
|
||
|
"rm.AutoComplete = rm.AutoComplete || {};" \
|
||
|
"rm.AutoComplete.dataSources = JSON.parse('#{data_sources.to_json}');"
|
||
|
)
|
||
|
end
|
||
|
def update_data_sources_for_auto_complete(data_sources)
|
||
|
javascript_tag(
|
||
|
"rm.AutoComplete.dataSources = Object.assign(rm.AutoComplete.dataSources, JSON.parse('#{data_sources.to_json}'));"
|
||
|
)
|
||
|
end
|
||
|
def copy_object_url_link(url)
|
||
|
link_to_function(
|
||
|
l(:button_copy_link), 'copyTextToClipboard(this);',
|
||
| ... | ... | |
|
def autocomplete_data_sources(project)
|
||
|
{
|
||
|
issues: auto_complete_issues_path(project_id: project, q: ''),
|
||
|
wiki_pages: auto_complete_wiki_pages_path(project_id: project, q: ''),
|
||
|
autocomplete_issues: auto_complete_issues_path(project_id: project, q: ''),
|
||
|
autocomplete_wiki_pages: auto_complete_wiki_pages_path(project_id: project, q: ''),
|
||
|
}
|
||
|
end
|
||
|
end
|
||
| app/views/issues/_form.html.erb | ||
|---|---|---|
|
<% end %>
|
||
|
<% heads_for_wiki_formatter %>
|
||
|
<%= heads_for_auto_complete(@issue.project) %>
|
||
|
<% autocomplete_data_sources(@issue.project).each do |name, content| %>
|
||
|
<% content_for name, content %>
|
||
|
<% end %>
|
||
|
<% if User.current.allowed_to?(:add_issue_watchers, @issue.project)%>
|
||
|
<%= update_data_sources_for_auto_complete({users: watchers_autocomplete_for_mention_path(project_id: @issue.project, q: '', object_type: 'issue',
|
||
|
object_id: @issue.id)}) %>
|
||
|
<% content = watchers_autocomplete_for_mention_path(project_id: @issue.project, q: '', object_type: 'issue', object_id: @issue.id) %>
|
||
|
<%= tag.meta name: :autocomplete_users, content: content %>
|
||
|
<% end %>
|
||
|
<%= javascript_tag do %>
|
||
| app/views/layouts/base.html.erb | ||
|---|---|---|
|
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %>
|
||
|
<%= javascript_heads %>
|
||
|
<%= heads_for_theme %>
|
||
|
<%= heads_for_auto_complete(@project) %>
|
||
|
<%= call_hook :view_layouts_base_html_head %>
|
||
|
<!-- page specific tags -->
|
||
|
<%= yield :header_tags -%>
|
||
|
</head>
|
||
|
<body class="<%= body_css_classes %>">
|
||
|
<%= call_hook :view_layouts_base_body_top %>
|
||
|
<% autocomplete_data_sources(@project).each do |name, content| %>
|
||
|
<%= tag.meta name: name, content: (content_for?(name) ? yield(name) : content) %>
|
||
|
<% end %>
|
||
|
<div id="wrapper">
|
||
|
<div class="flyout-menu js-flyout-menu">
|
||
| app/views/wiki/edit.html.erb | ||
|---|---|---|
|
<%= wikitoolbar_for 'content_text', preview_project_wiki_page_path(:project_id => @project, :id => @page.title) %>
|
||
|
<% if User.current.allowed_to?(:add_wiki_page_watchers, @project)%>
|
||
|
<%= update_data_sources_for_auto_complete({users: watchers_autocomplete_for_mention_path(project_id: @project, q: '', object_type: 'wiki_page', object_id: @page.id)}) %>
|
||
|
<% content = watchers_autocomplete_for_mention_path(project_id: @project, q: '', object_type: 'wiki_page', object_id: @page.id) %>
|
||
|
<%= tag.meta name: :autocomplete_users, content: content %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
| public/javascripts/application.js | ||
|---|---|---|
|
if (element.dataset.tribute === 'true') {return};
|
||
|
const getDataSource = function(entity) {
|
||
|
const dataSources = rm.AutoComplete.dataSources;
|
||
|
if (dataSources[entity]) {
|
||
|
return dataSources[entity];
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
const element = document.body.querySelector(`meta[name="${entity}"]`)
|
||
|
return element && element.content
|
||
|
}
|
||
|
const remoteSearch = function(url, cb) {
|
||
| ... | ... | |
|
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') {
|
||
|
$(element).attr('autocomplete', 'off');
|
||
|
}
|
||
|
remoteSearch(getDataSource('issues') + text, function (issues) {
|
||
|
remoteSearch(getDataSource('autocomplete_issues') + text, function (issues) {
|
||
|
return cb(issues);
|
||
|
});
|
||
|
},
|
||
| ... | ... | |
|
{
|
||
|
trigger: '[[',
|
||
|
values: function (text, cb) {
|
||
|
remoteSearch(getDataSource('wiki_pages') + text, function (wikiPages) {
|
||
|
remoteSearch(getDataSource('autocomplete_wiki_pages') + text, function (wikiPages) {
|
||
|
return cb(wikiPages);
|
||
|
});
|
||
|
},
|
||
| ... | ... | |
|
return user.name + user.firstname + user.lastname + user.login;
|
||
|
},
|
||
|
values: function (text, cb) {
|
||
|
const url = getDataSource('users');
|
||
|
const url = getDataSource('autocomplete_users');
|
||
|
if (url) {
|
||
|
remoteSearch(url + text, function (users) {
|
||
|
return cb(users);
|
||