Dotclear

source: plugins/dcLegacyEditor/js/_post_editor.js @ 2856:b9ae6bf9bd6e

Revision 2856:b9ae6bf9bd6e, 4.7 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Load wanted editor for each context
Closes #2011, Closes #2014

Line 
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          // Markup validator
49          var v = $('<div class="format_control"><p><a id="a-validator"></a></p><div/>').get(0);
50          $('.format_control').before(v);
51          var a = $('#a-validator').get(0);
52          a.href = '#';
53          a.className = 'button ';
54          $(a).click(function() {
55
56               excerpt_content = $('#post_excerpt').css('display') != 'none' ? $('#post_excerpt').val() : $('#excerpt-area iframe').contents().find('body').html();
57               post_content   = $('#post_content').css('display') != 'none' ? $('#post_content').val() : $('#content-area iframe').contents().find('body').html();
58
59               var params = {
60                    xd_check: dotclear.nonce,
61                    f: 'validatePostMarkup',
62                    excerpt: excerpt_content,
63                    content: post_content,
64                    format: $('#post_format').get(0).value,
65                    lang: $('#post_lang').get(0).value
66               };
67
68               $.post('services.php',params,function(data) {
69                    if ($(data).find('rsp').attr('status') != 'ok') {
70                         alert($(data).find('rsp message').text());
71                         return false;
72                    }
73
74                    $('.message, .success, .error, .warning-msg').remove();
75
76                    if ($(data).find('valid').text() == 1) {
77                         var p = document.createElement('p');
78                         p.id = 'markup-validator';
79
80                         $(p).addClass('success');
81                         $(p).text(dotclear.msg.xhtml_valid);
82                         $('#entry-content h3').after(p);
83                         $(p).backgroundFade({sColor: dotclear.fadeColor.beginValidatorMsg, eColor: dotclear.fadeColor.endValidatorMsg, steps: 50},function() {
84                              $(this).backgroundFade({sColor: dotclear.fadeColor.endValidatorMsg, eColor: dotclear.fadeColor.beginValidatorMsg});
85                         });
86                    } else {
87                         var div = document.createElement('div');
88                         div.id = 'markup-validator';
89
90                         $(div).addClass('error');
91                         $(div).html('<p><strong>' + dotclear.msg.xhtml_not_valid + '</strong></p>' + $(data).find('errors').text());
92                         $('#entry-content h3').after(div);
93                         $(div).backgroundFade({sColor: dotclear.fadeColor.beginValidatorErr,eColor: dotclear.fadeColor.endValidatorErr, steps: 50},function() {
94                              $(this).backgroundFade({sColor: dotclear.fadeColor.endValidatorErr, eColor: dotclear.fadeColor.beginValidatorErr});
95                         });
96                    }
97
98                    if ( $('#post_excerpt').text() != excerpt_content || $('#post_content').text() != post_content ) {
99                         var pn = document.createElement('p');
100                         $(pn).addClass('warning-msg');
101                         $(pn).text(dotclear.msg.warning_validate_no_save_content);
102                         $('#entry-content h3').after(pn);
103                    }
104
105                    return false;
106               });
107
108               return false;
109          });
110
111          a.appendChild(document.createTextNode(dotclear.msg.xhtml_validator));
112
113          // Load toolbars
114          if (contentTb!==undefined && excerptTb!==undefined) {
115               contentTb.switchMode(formatField.value);
116               excerptTb.switchMode(formatField.value);
117          }
118
119          // Check unsaved changes before XHTML conversion
120          var excerpt = $('#post_excerpt').val();
121          var content = $('#post_content').val();
122          $('#convert-xhtml').click(function() {
123               if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) {
124                    return window.confirm(dotclear.msg.confirm_change_post_format);
125               }
126          });
127     });
128});
Note: See TracBrowser for help on using the repository browser.

Sites map