Skip to content

Commit

Permalink
arkhitech#64 Easy Redmine 2018 compatibility
Browse files Browse the repository at this point in the history
We have to load textcomplete a bit later, ensuring easy_ckeditor is already loaded
  • Loading branch information
amenk committed Sep 17, 2018
1 parent 4dbf686 commit 967334d
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions app/views/hooks/redmine_mentions/_edit_mentionable.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,44 @@
<% users_regex = users.collect{|u| "#{Setting.plugin_redmine_mentions['trigger']}#{u.login}"}.join('|')%>
<% regex_highlight = '/\B('+users_regex+')\b/g' %>
<script>
$('#issue_notes,#issue_description').textcomplete([
{
mentions: <%= users.collect{|u| "#{u.firstname} #{u.lastname} - <small>#{u.login}</small>"}.to_json.html_safe %>,
match: <%=regex_find%>,
search: function(term, callback) {
callback($.map(this.mentions, function(mention) {
return mention.toLowerCase().indexOf(term.toLowerCase()) !== -1 ? mention : null;
}));
},
index: 1,
replace: function(mention) {
var parts = mention.split(' - ');
var name = parts[1].substring(parts[1].lastIndexOf("<small>")+7,parts[1].lastIndexOf("</small>"));
return '<%=Setting.plugin_redmine_mentions['trigger']%>' + name + ' ';
}
}
]);
var redmineMentionsLoader = function() {
$('#issue_notes,#issue_description').textcomplete([
{
mentions: <%= users.collect{|u| "#{u.firstname} #{u.lastname} - <small>#{u.login}</small>"}.to_json.html_safe %>,
match: <%=regex_find%>,
search: function(term, callback) {
console.log(term);
callback($.map(this.mentions, function(mention) {
return mention.toLowerCase().indexOf(term.toLowerCase()) !== -1 ? mention : null;
}));
},
index: 1,
replace: function(mention) {
var parts = mention.split(' - ');
var name = parts[1].substring(parts[1].lastIndexOf("<small>")+7,parts[1].lastIndexOf("</small>"));
return '<%=Setting.plugin_redmine_mentions['trigger']%>' + name + ' ';
}
}
]);


if (typeof CKEDITOR == 'undefined') { // compat problems with CKEditor, we can live without that...
$('#issue_notes,#issue_description').overlay([
{
match: new RegExp(<%=regex_highlight%>),
css: {
'background-color': '#C6D5F3',
if (typeof CKEDITOR === 'undefined') { // compat problems with CKEditor, we can live without that...
$('#issue_notes,#issue_description').overlay([
{
match: new RegExp(<%=regex_highlight%>),
css: {
'background-color': '#C6D5F3',
}
}
]);
}
}
]);
}
};

if (typeof EasyGem !== 'undefined') {
// some special compatbility code for EasyRedmine 2018
// easy_ckeditor is loaded via module, so we have to load the easy_ckeditor first
EasyGem.loadModules(['easy_ckeditor'], redmineMentionsLoader);
} else {
redmineMentionsLoader();
}
</script>

0 comments on commit 967334d

Please sign in to comment.