| 1 | /*global $, dotclear, jsToolBar, getData */ |
|---|
| 2 | 'use strict'; |
|---|
| 3 | |
|---|
| 4 | // Get context |
|---|
| 5 | Object.assign(dotclear, getData('legacy_editor_ctx')); |
|---|
| 6 | |
|---|
| 7 | $(function() { |
|---|
| 8 | if ($('#edit-entry').length == 0) { |
|---|
| 9 | return; |
|---|
| 10 | } |
|---|
| 11 | |
|---|
| 12 | if (dotclear.legacy_editor_context === undefined || |
|---|
| 13 | dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context] === undefined) { |
|---|
| 14 | return; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | // To be reviewed! |
|---|
| 18 | let formatField; |
|---|
| 19 | let excerptTb; |
|---|
| 20 | let contentTb; |
|---|
| 21 | |
|---|
| 22 | if ((dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_content') !== -1) && |
|---|
| 23 | (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_excerpt') !== -1)) { |
|---|
| 24 | // Get document format and prepare toolbars |
|---|
| 25 | formatField = $('#post_format').get(0); |
|---|
| 26 | let last_post_format = $(formatField).val(); |
|---|
| 27 | $(formatField).change(function() { |
|---|
| 28 | if (this.value != 'dcLegacyEditor') { |
|---|
| 29 | return; |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | const post_format = this.value; |
|---|
| 33 | |
|---|
| 34 | // Confirm post format change |
|---|
| 35 | if (window.confirm(dotclear.msg.confirm_change_post_format_noconvert)) { |
|---|
| 36 | excerptTb.switchMode(post_format); |
|---|
| 37 | contentTb.switchMode(post_format); |
|---|
| 38 | last_post_format = $(this).val(); |
|---|
| 39 | } else { |
|---|
| 40 | // Restore last format if change cancelled |
|---|
| 41 | $(this).val(last_post_format); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | $('.format_control > *').addClass('hide'); |
|---|
| 45 | $('.format_control:not(.control_no_' + post_format + ') > *').removeClass('hide'); |
|---|
| 46 | }); |
|---|
| 47 | |
|---|
| 48 | excerptTb = new jsToolBar(document.getElementById('post_excerpt')); |
|---|
| 49 | contentTb = new jsToolBar(document.getElementById('post_content')); |
|---|
| 50 | excerptTb.context = contentTb.context = 'post'; |
|---|
| 51 | |
|---|
| 52 | $('.format_control > *').addClass('hide'); |
|---|
| 53 | $('.format_control:not(.control_no_' + last_post_format + ') > *').removeClass('hide'); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#comment_content') !== -1) { |
|---|
| 57 | if ($('#comment_content').length > 0) { |
|---|
| 58 | let commentTb = new jsToolBar(document.getElementById('comment_content')); |
|---|
| 59 | commentTb.draw('xhtml'); |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | $('#comments').onetabload(function() { |
|---|
| 64 | // Remove required attribut from #comment_content as textarea might be not more focusable |
|---|
| 65 | if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#comment_content') !== -1) { |
|---|
| 66 | $('#comment_content').removeAttr('required'); |
|---|
| 67 | } |
|---|
| 68 | }); |
|---|
| 69 | |
|---|
| 70 | $('#edit-entry').onetabload(function() { |
|---|
| 71 | |
|---|
| 72 | // Remove required attribut from #post_content in XHTML mode as textarea is not more focusable |
|---|
| 73 | if (formatField.value == 'xhtml') { |
|---|
| 74 | if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_content') !== -1) { |
|---|
| 75 | $('#post_content').removeAttr('required'); |
|---|
| 76 | } |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | // Load toolbars |
|---|
| 80 | if (contentTb !== undefined && excerptTb !== undefined) { |
|---|
| 81 | contentTb.switchMode(formatField.value); |
|---|
| 82 | excerptTb.switchMode(formatField.value); |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | // Check unsaved changes before XHTML conversion |
|---|
| 86 | const excerpt = $('#post_excerpt').val(); |
|---|
| 87 | const content = $('#post_content').val(); |
|---|
| 88 | $('#convert-xhtml').click(function() { |
|---|
| 89 | if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) { |
|---|
| 90 | return window.confirm(dotclear.msg.confirm_change_post_format); |
|---|
| 91 | } |
|---|
| 92 | }); |
|---|
| 93 | }); |
|---|
| 94 | }); |
|---|