Patch #37559 ยป 0001-Use-meta-element-instead-of-javascript-object.patch
app/helpers/application_helper.rb | ||
---|---|---|
1826 | 1826 |
end |
1827 | 1827 |
end |
1828 | 1828 | |
1829 |
def heads_for_auto_complete(project) |
|
1830 |
data_sources = autocomplete_data_sources(project) |
|
1831 |
javascript_tag( |
|
1832 |
"rm = window.rm || {};" \ |
|
1833 |
"rm.AutoComplete = rm.AutoComplete || {};" \ |
|
1834 |
"rm.AutoComplete.dataSources = JSON.parse('#{data_sources.to_json}');" |
|
1835 |
) |
|
1836 |
end |
|
1837 | ||
1838 |
def update_data_sources_for_auto_complete(data_sources) |
|
1839 |
javascript_tag( |
|
1840 |
"rm.AutoComplete.dataSources = Object.assign(rm.AutoComplete.dataSources, JSON.parse('#{data_sources.to_json}'));" |
|
1841 |
) |
|
1842 |
end |
|
1843 | ||
1844 | 1829 |
def copy_object_url_link(url) |
1845 | 1830 |
link_to_function( |
1846 | 1831 |
l(:button_copy_link), 'copyTextToClipboard(this);', |
... | ... | |
1875 | 1860 | |
1876 | 1861 |
def autocomplete_data_sources(project) |
1877 | 1862 |
{ |
1878 |
issues: auto_complete_issues_path(project_id: project, q: ''),
|
|
1879 |
wiki_pages: auto_complete_wiki_pages_path(project_id: project, q: ''), |
|
1863 |
autocomplete_issues: auto_complete_issues_path(project_id: project, q: ''),
|
|
1864 |
autocomplete_wiki_pages: auto_complete_wiki_pages_path(project_id: project, q: ''),
|
|
1880 | 1865 |
} |
1881 | 1866 |
end |
1882 | 1867 |
end |
app/views/issues/_form.html.erb | ||
---|---|---|
53 | 53 |
<% end %> |
54 | 54 | |
55 | 55 |
<% heads_for_wiki_formatter %> |
56 |
<%= heads_for_auto_complete(@issue.project) %> |
|
56 | ||
57 |
<% autocomplete_data_sources(@issue.project).each do |name, content| %> |
|
58 |
<% content_for name, content %> |
|
59 |
<% end %> |
|
57 | 60 | |
58 | 61 |
<% if User.current.allowed_to?(:add_issue_watchers, @issue.project)%> |
59 |
<%= update_data_sources_for_auto_complete({users: watchers_autocomplete_for_mention_path(project_id: @issue.project, q: '', object_type: 'issue',
|
|
60 |
object_id: @issue.id)}) %>
|
|
62 |
<% content = watchers_autocomplete_for_mention_path(project_id: @issue.project, q: '', object_type: 'issue', object_id: @issue.id) %>
|
|
63 |
<%= tag.meta name: :autocomplete_users, content: content %>
|
|
61 | 64 |
<% end %> |
62 | 65 | |
63 | 66 |
<%= javascript_tag do %> |
app/views/layouts/base.html.erb | ||
---|---|---|
13 | 13 |
<%= stylesheet_link_tag 'rtl', :media => 'all' if l(:direction) == 'rtl' %> |
14 | 14 |
<%= javascript_heads %> |
15 | 15 |
<%= heads_for_theme %> |
16 |
<%= heads_for_auto_complete(@project) %> |
|
17 | 16 |
<%= call_hook :view_layouts_base_html_head %> |
18 | 17 |
<!-- page specific tags --> |
19 | 18 |
<%= yield :header_tags -%> |
20 | 19 |
</head> |
21 | 20 |
<body class="<%= body_css_classes %>"> |
22 | 21 |
<%= call_hook :view_layouts_base_body_top %> |
22 | ||
23 |
<% autocomplete_data_sources(@project).each do |name, content| %> |
|
24 |
<%= tag.meta name: name, content: (content_for?(name) ? yield(name) : content) %> |
|
25 |
<% end %> |
|
26 | ||
23 | 27 |
<div id="wrapper"> |
24 | 28 | |
25 | 29 |
<div class="flyout-menu js-flyout-menu"> |
app/views/wiki/edit.html.erb | ||
---|---|---|
66 | 66 |
<%= wikitoolbar_for 'content_text', preview_project_wiki_page_path(:project_id => @project, :id => @page.title) %> |
67 | 67 | |
68 | 68 |
<% if User.current.allowed_to?(:add_wiki_page_watchers, @project)%> |
69 |
<%= update_data_sources_for_auto_complete({users: watchers_autocomplete_for_mention_path(project_id: @project, q: '', object_type: 'wiki_page', object_id: @page.id)}) %> |
|
69 |
<% content = watchers_autocomplete_for_mention_path(project_id: @project, q: '', object_type: 'wiki_page', object_id: @page.id) %> |
|
70 |
<%= tag.meta name: :autocomplete_users, content: content %> |
|
70 | 71 |
<% end %> |
71 | 72 |
<% end %> |
72 | 73 |
public/javascripts/application.js | ||
---|---|---|
1127 | 1127 |
if (element.dataset.tribute === 'true') {return}; |
1128 | 1128 | |
1129 | 1129 |
const getDataSource = function(entity) { |
1130 |
const dataSources = rm.AutoComplete.dataSources; |
|
1131 | ||
1132 |
if (dataSources[entity]) { |
|
1133 |
return dataSources[entity]; |
|
1134 |
} else { |
|
1135 |
return false; |
|
1136 |
} |
|
1130 |
const element = document.body.querySelector(`meta[name="${entity}"]`) |
|
1131 |
return element && element.content |
|
1137 | 1132 |
} |
1138 | 1133 | |
1139 | 1134 |
const remoteSearch = function(url, cb) { |
... | ... | |
1161 | 1156 |
if (event.target.type === 'text' && $(element).attr('autocomplete') != 'off') { |
1162 | 1157 |
$(element).attr('autocomplete', 'off'); |
1163 | 1158 |
} |
1164 |
remoteSearch(getDataSource('issues') + text, function (issues) { |
|
1159 |
remoteSearch(getDataSource('autocomplete_issues') + text, function (issues) {
|
|
1165 | 1160 |
return cb(issues); |
1166 | 1161 |
}); |
1167 | 1162 |
}, |
... | ... | |
1178 | 1173 |
{ |
1179 | 1174 |
trigger: '[[', |
1180 | 1175 |
values: function (text, cb) { |
1181 |
remoteSearch(getDataSource('wiki_pages') + text, function (wikiPages) { |
|
1176 |
remoteSearch(getDataSource('autocomplete_wiki_pages') + text, function (wikiPages) {
|
|
1182 | 1177 |
return cb(wikiPages); |
1183 | 1178 |
}); |
1184 | 1179 |
}, |
... | ... | |
1198 | 1193 |
return user.name + user.firstname + user.lastname + user.login; |
1199 | 1194 |
}, |
1200 | 1195 |
values: function (text, cb) { |
1201 |
const url = getDataSource('users'); |
|
1196 |
const url = getDataSource('autocomplete_users');
|
|
1202 | 1197 |
if (url) { |
1203 | 1198 |
remoteSearch(url + text, function (users) { |
1204 | 1199 |
return cb(users); |