Skip to content

Commit d1ddfc8

Browse files
redmine 5 support
1 parent c2a3a23 commit d1ddfc8

File tree

5 files changed

+78
-15
lines changed

5 files changed

+78
-15
lines changed

app/views/help/index.html.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@
2525
<tr><th><td style="width:50%;">U</td><td style="width:50%;"><%= l(:shortcuts_help_unwatch_issue) %></td></tr>
2626
<tr><th><td style="width:50%;">W</td><td style="width:50%;"><%= l(:shortcuts_help_watch_issue) %></td></tr>
2727
</table>
28-
<% if @text_formatting == 'textile' || @text_formatting == 'markdown' %>
28+
<% if @text_formatting == 'textile' || @text_formatting == 'markdown' || @text_formatting == 'common_mark' %>
2929
<table style="width:100%">
3030
<tr><th colspan="3"><%= l(:shortcuts_help_editor) %></th></tr>
3131
<tr><th><%= image_tag 'bt_strong.png', :plugin => 'redmine_shortcuts', :alt => 'Strong', :style => 'border: 1px solid #bbb;' %></th><td style="width:50%;">CTRL + B</td><td style="width:50%;"><strong><%= l(:shortcuts_help_strong) %></strong></td></tr>
3232
<tr><th><%= image_tag 'bt_em.png', :plugin => 'redmine_shortcuts', :alt => 'Italic', :style => 'border: 1px solid #bbb;' %></th><td>CTRL + I</td><td><em><%= l(:shortcuts_help_italic) %></em></td></tr>
33+
<% if @text_formatting != 'common_mark' %>
3334
<tr><th><%= image_tag 'bt_ins.png', :plugin => 'redmine_shortcuts', :alt => 'Underline', :style => 'border: 1px solid #bbb;' %></th><td>CTRL + U</td><td><ins><%= l(:shortcuts_help_underline) %></ins></td></tr>
35+
<% end %>
3436
<tr><th><%= image_tag 'bt_del.png', :plugin => 'redmine_shortcuts', :alt => 'Deleted', :style => 'border: 1px solid #bbb;' %></th><td>CTRL + S</td><td><del><%= l(:shortcuts_help_deleted) %></del></td></tr>
3537
<tr><th><%= image_tag 'bt_code.png', :plugin => 'redmine_shortcuts', :alt => 'Inline code', :style => 'border: 1px solid #bbb;' %></th><td>CTRL + L</td><td><code><%= l(:shortcuts_inline_code) %></code></td></tr>
3638
<tr><th><%= image_tag 'bt_pre.png', :plugin => 'redmine_shortcuts', :alt => 'Preformatted text', :style => 'border: 1px solid #bbb;' %></th><td>CTRL + P</td><td><code><%= l(:shortcuts_preformatted_text) %></code></td></tr>

app/views/hooks/_view_layouts_base_body_bottom.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<%= javascript_include_tag 'view_layouts_base_body_bottom_textile', :plugin => 'redmine_shortcuts' %>
44
<% elsif Setting['text_formatting'] == 'markdown' %>
55
<%= javascript_include_tag 'view_layouts_base_body_bottom_markdown', :plugin => 'redmine_shortcuts' %>
6+
<% elsif Setting['text_formatting'] == 'common_mark' %>
7+
<%= javascript_include_tag 'view_layouts_base_body_bottom_common_mark', :plugin => 'redmine_shortcuts' %>
68
<% end %>
79
<% if Setting.plugin_redmine_shortcuts['enable_help_modal'] == '1' && !(Setting.login_required? and User.current.anonymous?) %>
810
<%= javascript_include_tag 'view_layouts_base_body_bottom_questionmark', :plugin => 'redmine_shortcuts' %>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
function styleSelectedText(textarea, prepend, append) {
2+
if (append == undefined) {
3+
append = prepend;
4+
}
5+
6+
$start = textarea.prop('selectionStart');
7+
$end = textarea.prop('selectionEnd');
8+
$content = textarea.val();
9+
if ($content.slice(0, $start).endsWith(prepend) && $content.slice($end, $content.length).replace("\n", '').startsWith(append.replace("\n", ''))) {
10+
$content = $content.slice(0, $start - prepend.length) + $content.slice($start, $end) + $content.slice($end + append.length, $content.length);
11+
textarea.val($content);
12+
textarea.focus();
13+
textarea.prop('selectionStart', $start - prepend.length);
14+
textarea.prop('selectionEnd', $end - prepend.length);
15+
} else {
16+
$content = $content.slice(0, $start) + prepend + $content.slice($start, $end) + append + $content.slice($end, $content.length);
17+
textarea.val($content);
18+
textarea.focus();
19+
textarea.prop('selectionStart', $start + prepend.length);
20+
textarea.prop('selectionEnd', $end + prepend.length);
21+
}
22+
}
23+
24+
$(document).keydown(function (e) {
25+
if ($(document.activeElement).hasClass('wiki-edit')) {
26+
if ((e.ctrlKey || e.metaKey) && !e.shiftKey) {
27+
// CTRL/CMD + B
28+
if (e.keyCode == 66) {
29+
styleSelectedText($(document.activeElement), '**');
30+
e.preventDefault();
31+
// CTRL/CMD + S
32+
} else if (e.keyCode == 83) {
33+
styleSelectedText($(document.activeElement), '~~');
34+
e.preventDefault();
35+
// CTRL/CMD + I
36+
} else if (e.keyCode == 73) {
37+
styleSelectedText($(document.activeElement), '*');
38+
e.preventDefault();
39+
// CTRL/CMD + L
40+
} else if (e.keyCode == 76) {
41+
styleSelectedText($(document.activeElement), '`');
42+
e.preventDefault();
43+
// CTRL/CMD + P
44+
} else if (e.keyCode == 80) {
45+
styleSelectedText($(document.activeElement), "```\n", "\n```");
46+
e.preventDefault();
47+
// CTRL/CMD + ENTER
48+
} else if (e.keyCode == 13) {
49+
$activeElement = $(document.activeElement)
50+
$activeElement.blur();
51+
$('textarea').removeData('changed');
52+
$activeElement.closest('form').submit();
53+
e.preventDefault();
54+
}
55+
}
56+
}
57+
});

init.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'redmine_shortcuts/hooks/hooks'
1+
require File.dirname(__FILE__) + '/lib/redmine_shortcuts/hooks/hooks.rb'
22

33
Redmine::Plugin.register :redmine_shortcuts do
44
name 'Redmine Shortcuts'

lib/redmine_shortcuts/hooks/hooks.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
module RedmineShortcuts
2-
class Hooks < Redmine::Hook::ViewListener
3-
def view_layouts_base_body_bottom(context = {})
4-
context[:controller].send(:render_to_string, { partial: 'hooks/view_layouts_base_body_bottom', locals: context })
5-
end
6-
7-
def view_issues_show_details_bottom(context = {})
8-
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_show_details_bottom', locals: context })
9-
end
2+
module Hooks
3+
class Hooks < Redmine::Hook::ViewListener
4+
def view_layouts_base_body_bottom(context = {})
5+
context[:controller].send(:render_to_string, { partial: 'hooks/view_layouts_base_body_bottom', locals: context })
6+
end
7+
8+
def view_issues_show_details_bottom(context = {})
9+
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_show_details_bottom', locals: context })
10+
end
1011

11-
def view_issues_index_bottom(context = {})
12-
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_index_bottom', locals: context })
13-
end
12+
def view_issues_index_bottom(context = {})
13+
context[:controller].send(:render_to_string, { partial: 'hooks/view_issues_index_bottom', locals: context })
14+
end
1415

15-
def view_layouts_base_html_head(context = {})
16-
context[:controller].send(:render_to_string, { partial: 'hooks/view_layouts_base_html_head', locals: context })
16+
def view_layouts_base_html_head(context = {})
17+
context[:controller].send(:render_to_string, { partial: 'hooks/view_layouts_base_html_head', locals: context })
18+
end
1719
end
1820
end
1921
end

0 commit comments

Comments
 (0)