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