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