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