Dotclear

source: admin/js/_post.js @ 1812:39cc57b045d6

Revision 1812:39cc57b045d6, 8.4 KB checked in by Lepeltier kévin, 11 years ago (diff)

Ticket #1539: Si wiki est choisi, affichage du bouton "Convertir en xhtml"
Si xhtml est choisi, affichage du bouton "Vérifier la validité xhtml"

Line 
1dotclear.commentExpander = function(line) {
2     var td = line.firstChild;
3
4     var img = document.createElement('img');
5     img.src = dotclear.img_plus_src;
6     img.alt = dotclear.img_plus_alt;
7     img.className = 'expand';
8     $(img).css('cursor','pointer');
9     img.line = line;
10     img.onclick = function() { dotclear.viewCommentContent(this,this.line); };
11
12     td.insertBefore(img,td.firstChild);
13};
14
15dotclear.viewCommentContent = function(img,line) {
16     var commentId = line.id.substr(1);
17
18     var tr = document.getElementById('ce'+commentId);
19
20     if (!tr) {
21          tr = document.createElement('tr');
22          tr.id = 'ce'+commentId;
23          var td = document.createElement('td');
24          td.colSpan = 6;
25          td.className = 'expand';
26          tr.appendChild(td);
27
28          img.src = dotclear.img_minus_src;
29          img.alt = dotclear.img_minus_alt;
30
31          // Get comment content
32          $.get('services.php',{f:'getCommentById',id: commentId},function(data) {
33               var rsp = $(data).children('rsp')[0];
34
35               if (rsp.attributes[0].value == 'ok') {
36                    var comment = $(rsp).find('comment_display_content').text();
37
38                    if (comment) {
39                         $(td).append(comment);
40                         var comment_email = $(rsp).find('comment_email').text();
41                         var comment_site = $(rsp).find('comment_site').text();
42                         var comment_ip = $(rsp).find('comment_ip').text();
43                         var comment_spam_disp = $(rsp).find('comment_spam_disp').text();
44
45                         $(td).append('<p><strong>' + dotclear.msg.website +
46                         '</strong> ' + comment_site + '<br />' +
47                         '<strong>' + dotclear.msg.email + '</strong> ' +
48                         comment_email + '<br />' + comment_spam_disp + '</p>');
49                    }
50               } else {
51                    alert($(rsp).find('message').text());
52               }
53          });
54
55          $(line).toggleClass('expand');
56          line.parentNode.insertBefore(tr,line.nextSibling);
57     }
58     else if (tr.style.display == 'none')
59     {
60          $(tr).toggle();
61          $(line).toggleClass('expand');
62          img.src = dotclear.img_minus_src;
63          img.alt = dotclear.img_minus_alt;
64     }
65     else
66     {
67          $(tr).toggle();
68          $(line).toggleClass('expand');
69          img.src = dotclear.img_plus_src;
70          img.alt = dotclear.img_plus_alt;
71     }
72};
73
74$(function() {
75     if (!document.getElementById) { return; }
76
77     if (document.getElementById('edit-entry'))
78     {
79          // Get document format and prepare toolbars
80          var formatField = $('#post_format').get(0);
81          var last_post_format = $(formatField).val();
82          $(formatField).change(function() {
83               // Confirm post format change
84               if(window.confirm(dotclear.msg.confirm_change_post_format_noconvert)){
85                    excerptTb.switchMode(this.value);
86                    contentTb.switchMode(this.value);
87                    last_post_format = $(this).val();
88               }else{
89                    // Restore last format if change cancelled
90                    $(this).val(last_post_format);
91               }
92               
93               $('.format_control > *').addClass('hide');
94               if( $(this).val() == 'xhtml' ) {
95                    $('.control_xhtml > *').removeClass('hide');
96               } else if ( $(this).val() == 'wiki' ) {
97                    $('.control_wiki > *').removeClass('hide');
98               }
99          });
100
101          var excerptTb = new jsToolBar(document.getElementById('post_excerpt'));
102          var contentTb = new jsToolBar(document.getElementById('post_content'));
103          excerptTb.context = contentTb.context = 'post';
104     }
105
106     if (document.getElementById('comment_content')) {
107          var commentTb = new jsToolBar(document.getElementById('comment_content'));
108     }
109
110     // Post preview
111     $('#post-preview').modalWeb($(window).width()-40,$(window).height()-40);
112
113     // Tabs events
114     $('#edit-entry').onetabload(function() {
115          dotclear.hideLockable();
116
117          // Add date picker
118          var post_dtPick = new datePicker($('#post_dt').get(0));
119          post_dtPick.img_top = '1.5em';
120          post_dtPick.draw();
121
122          // Confirm post deletion
123          $('input[name="delete"]').click(function() {
124               return window.confirm(dotclear.msg.confirm_delete_post);
125          });
126
127          // Markup validator
128          var v = $('<div class="format_control control_xhtml"><p><a id="a-validator"></a></p><div/>').get(0);
129          $('.control_wiki').before(v);
130          var a = $('#a-validator').get(0);
131          a.href = '#';
132          a.className = 'button ';
133          $(a).click(function() {
134               var params = {
135                    xd_check: dotclear.nonce,
136                    f: 'validatePostMarkup',
137                    excerpt: $('#post_excerpt').text(),
138                    content: $('#post_content').text(),
139                    format: $('#post_format').get(0).value,
140                    lang: $('#post_lang').get(0).value
141               };
142
143               $.post('services.php',params,function(data) {
144                    if ($(data).find('rsp').attr('status') != 'ok') {
145                         alert($(data).find('rsp message').text());
146                         return false;
147                    }
148
149                    if ($(data).find('valid').text() == 1) {
150                         var p = document.createElement('p');
151                         p.id = 'markup-validator';
152
153                         if ($('#markup-validator').length > 0) {
154                              $('#markup-validator').remove();
155                         }
156
157                         $(p).addClass('message');
158                         $(p).text(dotclear.msg.xhtml_valid);
159                         $(v).append(p);
160                         $(p).backgroundFade({sColor:'#666666',eColor:'#ffcc00',steps:50},function() {
161                                   $(this).backgroundFade({sColor:'#ffcc00',eColor:'#666666'});
162                         });
163                    } else {
164                         var div = document.createElement('div');
165                         div.id = 'markup-validator';
166
167                         if ($('#markup-validator').length > 0) {
168                              $('#markup-validator').remove();
169                         }
170
171                         $(div).addClass('error');
172                         $(div).html('<p><strong>' + dotclear.msg.xhtml_not_valid + '</strong></p>' + $(data).find('errors').text());
173                         $(v).append(div);
174                         $(div).backgroundFade({sColor:'#ffffff',eColor:'#FFBABA',steps:50},function() {
175                                   $(this).backgroundFade({sColor:'#ffbaba',eColor:'#ffffff'});
176                         });
177                    }
178
179                    return false;
180               });
181
182               return false;
183          });
184
185          a.appendChild(document.createTextNode(dotclear.msg.xhtml_validator));
186         
187          $('.format_control > *').addClass('hide');
188          if ( last_post_format == 'xhtml' ) {
189               $('.control_xhtml > *').removeClass('hide');
190          } else if ( last_post_format == 'wiki' ) {
191               $('.control_wiki > *').removeClass('hide');
192          }
193
194          // Hide some fields
195          $('#notes-area label').toggleWithLegend($('#notes-area').children().not('label'),{
196               cookie: 'dcx_post_notes',
197               legend_click:true,
198               hide: $('#post_notes').val() == ''
199          });
200          $('#create_cat').toggleWithLegend($('#create_cat').parent().children().not('#create_cat'),{
201               // no cookie on new category as we don't use this every day
202               legend_click: true
203          });
204          $('#post_lang').parent().children('label').toggleWithLegend($('#post_lang'),{
205               cookie: 'dcx_post_lang',
206               legend_click: true
207          });
208          $('#post_password').parent().children('label').toggleWithLegend($('#post_password'),{
209               cookie: 'dcx_post_password',
210               legend_click: true,
211               hide: $('#post_password').val() == ''
212          });
213          $('#post_status').parent().children('label').toggleWithLegend($('#post_status'),{
214               cookie: 'dcx_post_status',
215               legend_click: true
216          });
217          $('#post_dt').parent().children('label').toggleWithLegend($('#post_dt').parent().children().not('label'),{
218               cookie: 'dcx_post_dt',
219               legend_click: true
220          });
221          $('#label_format').toggleWithLegend($('#label_format').parent().children().not('#label_format'),{
222               cookie: 'dcx_post_format',
223               legend_click: true
224          });
225          $('#cat_id').parent().children('label').toggleWithLegend($('#cat_id'),{
226               cookie: 'cat_id',
227               legend_click: true
228          });
229          $('#post_url').parent().children('label').toggleWithLegend($('#post_url').parent().children().not('label'),{
230               cookie: 'post_url',
231               legend_click: true
232          });
233          // We load toolbar on excerpt only when it's ready
234          $('#excerpt-area label').toggleWithLegend($('#excerpt-area').children().not('label'),{
235               cookie: 'dcx_post_excerpt',
236               legend_click: true,
237               hide: $('#post_excerpt').val() == ''
238          });
239
240          // Load toolbars
241          contentTb.switchMode(formatField.value);
242          excerptTb.switchMode(formatField.value);
243
244          // Replace attachment remove links by a POST form submit
245          $('a.attachment-remove').click(function() {
246               this.href = '';
247               var m_name = $(this).parents('ul').find('li:first>a').attr('title');
248               if (window.confirm(dotclear.msg.confirm_remove_attachment.replace('%s',m_name))) {
249                    var f = $('#attachment-remove-hide').get(0);
250                    f.elements['media_id'].value = this.id.substring(11);
251                    f.submit();
252               }
253               return false;
254          });
255
256          // Check unsaved changes before XHTML conversion
257          var excerpt = $('#post_excerpt').val();
258          var content = $('#post_content').val();
259          $('#convert-xhtml').click(function() {
260               if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) {
261                    return window.confirm(dotclear.msg.confirm_change_post_format);
262               }
263          });
264     });
265
266     $('#comments').onetabload(function() {
267          $('.comments-list tr.line').each(function() {
268               dotclear.commentExpander(this);
269          });
270          $('.checkboxes-helpers').each(function() {
271               dotclear.checkboxesHelpers(this);
272          });
273
274          dotclear.commentsActionsHelper();
275     });
276
277     $('#add-comment').onetabload(function() {
278          commentTb.draw('xhtml');
279     });
280});
Note: See TracBrowser for help on using the repository browser.

Sites map