├── README.md
├── app
└── views
│ ├── journals
│ └── edit.js.erb
│ └── redmine_editor_preview_tab
│ ├── _redmine_editor_preview_tab_partial.html.erb
│ └── _settings.html.erb
├── assets
├── javascripts
│ └── redmine_editor_preview_tab.js
└── stylesheets
│ ├── redmine_editor_preview_tab.css
│ └── redmine_editor_preview_tab_hide.css
├── config
└── locales
│ ├── de.yml
│ ├── en.yml
│ ├── fr.yml
│ ├── ja.yml
│ ├── pt-BR.yml
│ └── ru.yml
├── docs
├── screenshot_preview.png
├── screenshot_settings.png
└── screenshot_write.png
├── init.rb
└── lib
└── redmine_editor_preview_tab.rb
/README.md:
--------------------------------------------------------------------------------
1 | [](https://shields.io/)
2 | # THIS PROJECT IS NO LONGER BEING MAINTAINED
3 | The author no longer uses Redmine and cannot effectively update and maintain this repo.
4 |
5 | # Redmine Editor Preview Tab
6 |
7 | ## Summary
8 |
9 | The Redmine Editor Preview Tab Extension adds a preview tab to the [Redmine](http://www.redmine.org/) text editor, similar to the editor on Github.
10 |
11 | 
12 |
13 | 
14 |
15 | ## Installation
16 | ```
17 | $ cd redmine/plugins
18 | $ git clone https://github.com/tleish/redmine_editor_preview_tab
19 | ```
20 |
21 | restart Redmine
22 |
23 | ## Settings
24 | By default, both tab and the default Redmine preview functionality is still enabled. You can disable/hide the default Redmine preview in the plugin settings.
25 |
26 | Go to Adminstration > Plugins > Redmine Editor Preview Tab Extension
27 |
28 | 
29 |
--------------------------------------------------------------------------------
/app/views/journals/edit.js.erb:
--------------------------------------------------------------------------------
1 | $("#journal-<%= @journal.id %>-notes").hide();
2 |
3 | if ($("form#journal-<%= @journal.id %>-form").length > 0) {
4 | // journal edit form already loaded
5 | $("#journal-<%= @journal.id %>-form").show();
6 | } else {
7 | $("#journal-<%= @journal.id %>-notes").after('<%= escape_javascript(render :partial => 'notes_form') %>');
8 | }
9 |
10 | $("#journal_<%= @journal.id %>_notes").focus();
--------------------------------------------------------------------------------
/app/views/redmine_editor_preview_tab/_redmine_editor_preview_tab_partial.html.erb:
--------------------------------------------------------------------------------
1 | <%
2 | if content_for(:header_tags).present? && content_for(:header_tags).include?('/jstoolbar/')
3 | content_for :header_tags do %>
4 |
17 | <%= javascript_include_tag('redmine_editor_preview_tab.js', plugin: 'redmine_editor_preview_tab') %>
18 | <%= stylesheet_link_tag('redmine_editor_preview_tab.css', plugin: 'redmine_editor_preview_tab') %>
19 | <% end
20 |
21 | if Setting.plugin_redmine_editor_preview_tab[:hide_default_preview]
22 | content_for :header_tags do
23 | stylesheet_link_tag('redmine_editor_preview_tab_hide.css', plugin: 'redmine_editor_preview_tab')
24 | end
25 | end
26 |
27 | end
28 | %>
--------------------------------------------------------------------------------
/app/views/redmine_editor_preview_tab/_settings.html.erb:
--------------------------------------------------------------------------------
1 | <% settings = {} unless settings.is_a? Hash %>
2 |
3 |
4 | <%= hidden_field_tag 'settings[enabled]', true %>
5 | <%= check_box_tag 'settings[hide_default_preview]', true, !!settings[:hide_default_preview] %>
6 | Disable/Hide Redmine default preview
7 |
--------------------------------------------------------------------------------
/assets/javascripts/redmine_editor_preview_tab.js:
--------------------------------------------------------------------------------
1 |
2 | // Namespace
3 | var RedmineWikiTabPreview = RedmineWikiTabPreview || {};
4 |
5 | /* ***********************************************
6 | CONFIG BEGIN
7 | ************************************************/
8 |
9 | /**
10 | * @class Text
11 | * @desc Text labels
12 | */
13 |
14 | RedmineWikiTabPreview.Text = RedmineWikiTabPreview.Text || {
15 | NO_PREVIEW: 'Nothing to preview',
16 | PREVIEW_DIVS: {
17 | description: 'Description',
18 | notes: 'Notes',
19 | preview: 'Preview',
20 | text: 'Preview',
21 | write: 'Write'
22 | }
23 | };
24 |
25 | /**
26 | * @class Elements
27 | * @desc Renders Elements
28 | * @methods draw()
29 | */
30 | RedmineWikiTabPreview.Elements = (function(Text) {
31 | var $textArea;
32 | var $editor;
33 | var $buttonsHtml = '' +
36 | '';
37 |
38 | var init = function(editor) {
39 | $editor = editor;
40 | $textArea = $editor.find('textarea');
41 | return this;
42 | };
43 |
44 | var draw = function() {
45 | $editor.addClass('write');
46 | $editor.prepend($buttonsHtml)
47 | .append(drawWikiPreview());
48 | return this;
49 | };
50 |
51 | var drawWikiPreview = function() {
52 | // issue[notes] regex
53 | var regex = /\[([^\]]+)\]/;
54 | var name = $textArea.prop('name');
55 | var type = (name.match(regex)) ? name.match(/\[([^\]]+)\]/)[1] : name;
56 | return $('', {
57 | 'id': 'wiki-preview-' + type,
58 | 'class': 'wiki-preview wiki',
59 | 'data-type': type
60 | });
61 | };
62 |
63 | return {
64 | init: init,
65 | draw: draw
66 | };
67 | })(RedmineWikiTabPreview.Text);
68 |
69 | /**
70 | * @class View
71 | * @desc Updates preview html
72 | * @methods draw()
73 | */
74 | RedmineWikiTabPreview.View = (function(Text) {
75 | var $preview;
76 |
77 | var init = function(preview, original_preview) {
78 | $preview = preview;
79 | $original_preview = original_preview;
80 | return this;
81 | };
82 |
83 | var update = function() {
84 | var html = original_preview_html();
85 | if (html.length === 0) {
86 | html = Text.NO_PREVIEW;
87 | }
88 | $preview.html(html);
89 | return this;
90 | };
91 |
92 | var original_preview_html = function(){
93 | return $original_preview
94 | .find('.preview')
95 | .html()
96 | .replace(/