Dotclear

source: admin/js/_post.js @ 1606:6e2d8e9dd7d7

Revision 1606:6e2d8e9dd7d7, 7.9 KB checked in by Nicolas <nikrou77@…>, 11 years ago (diff)

Fix issue #1513 : label can be clicked, like arrow
Update tests

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
94          var excerptTb = new jsToolBar(document.getElementById('post_excerpt'));
95          var contentTb = new jsToolBar(document.getElementById('post_content'));
96          excerptTb.context = contentTb.context = 'post';
97     }
98
99     if (document.getElementById('comment_content')) {
100          var commentTb = new jsToolBar(document.getElementById('comment_content'));
101     }
102
103     // Post preview
104     $('#post-preview').modalWeb($(window).width()-40,$(window).height()-40);
105
106     // Tabs events
107     $('#edit-entry').onetabload(function() {
108          dotclear.hideLockable();
109
110          // Add date picker
111          var post_dtPick = new datePicker($('#post_dt').get(0));
112          post_dtPick.img_top = '1.5em';
113          post_dtPick.draw();
114
115          // Confirm post deletion
116          $('input[name="delete"]').click(function() {
117               return window.confirm(dotclear.msg.confirm_delete_post);
118          });
119
120          // Hide some fields
121          $('#notes-area label').toggleWithLegend($('#notes-area').children().not('label'),{
122               cookie: 'dcx_post_notes',
123               legend_click:true,
124               hide: $('#post_notes').val() == ''
125          });
126          $('#create_cat').toggleWithLegend($('#create_cat').parent().children().not('#create_cat'),{
127               // no cookie on new category as we don't use this every day
128               legend_click: true
129          });
130          $('#post_lang').parent().children('label').toggleWithLegend($('#post_lang'),{
131               cookie: 'dcx_post_lang',
132               legend_click: true
133          });
134          $('#post_password').parent().children('label').toggleWithLegend($('#post_password'),{
135               cookie: 'dcx_post_password',
136               legend_click: true,
137               hide: $('#post_password').val() == ''
138          });
139          $('#post_status').parent().children('label').toggleWithLegend($('#post_status'),{
140               cookie: 'dcx_post_status',
141               legend_click: true
142          });
143          $('#post_dt').parent().children('label').toggleWithLegend($('#post_dt').parent().children().not('label'),{
144               cookie: 'dcx_post_dt',
145               legend_click: true
146          });
147          $('#post_format').parent().children('label').toggleWithLegend($('#post_format'),{
148               cookie: 'dcx_post_format',
149               legend_click: true
150          });
151          $('#cat_id').parent().children('label').toggleWithLegend($('#cat_id'),{
152               cookie: 'cat_id',
153               legend_click: true
154          });
155          $('#post_url').parent().children('label').toggleWithLegend($('#post_url').parent().children().not('label'),{
156               cookie: 'post_url',
157               legend_click: true
158          });
159          // We load toolbar on excerpt only when it's ready
160          $('#excerpt-area label').toggleWithLegend($('#excerpt-area').children().not('label'),{
161               cookie: 'dcx_post_excerpt',
162               hide: $('#post_excerpt').val() == ''
163          });
164
165          // Load toolbars
166          contentTb.switchMode(formatField.value);
167          excerptTb.switchMode(formatField.value);
168
169          // Replace attachment remove links by a POST form submit
170          $('a.attachment-remove').click(function() {
171               this.href = '';
172               var m_name = $(this).parents('ul').find('li:first>a').attr('title');
173               if (window.confirm(dotclear.msg.confirm_remove_attachment.replace('%s',m_name))) {
174                    var f = $('#attachment-remove-hide').get(0);
175                    f.elements['media_id'].value = this.id.substring(11);
176                    f.submit();
177               }
178               return false;
179          });
180
181          // Markup validator
182          var h = document.createElement('h4');
183          var a = document.createElement('a');
184          a.href = '#';
185          a.className = 'button';
186          $(a).click(function() {
187               var params = {
188                    xd_check: dotclear.nonce,
189                    f: 'validatePostMarkup',
190                    excerpt: $('#post_excerpt').text(),
191                    content: $('#post_content').text(),
192                    format: $('#post_format').get(0).value,
193                    lang: $('#post_lang').get(0).value
194               };
195
196               $.post('services.php',params,function(data) {
197                    if ($(data).find('rsp').attr('status') != 'ok') {
198                         alert($(data).find('rsp message').text());
199                         return false;
200                    }
201
202                    if ($(data).find('valid').text() == 1) {
203                         var p = document.createElement('p');
204                         p.id = 'markup-validator';
205
206                         if ($('#markup-validator').length > 0) {
207                              $('#markup-validator').remove();
208                         }
209
210                         $(p).addClass('message');
211                         $(p).text(dotclear.msg.xhtml_valid);
212                         $(p).insertAfter(h);
213                         $(p).backgroundFade({sColor:'#666666',eColor:'#ffcc00',steps:50},function() {
214                                   $(this).backgroundFade({sColor:'#ffcc00',eColor:'#666666'});
215                         });
216                    } else {
217                         var div = document.createElement('div');
218                         div.id = 'markup-validator';
219
220                         if ($('#markup-validator').length > 0) {
221                              $('#markup-validator').remove();
222                         }
223
224                         $(div).addClass('error');
225                         $(div).html('<p><strong>' + dotclear.msg.xhtml_not_valid + '</strong></p>' + $(data).find('errors').text());
226                         $(div).insertAfter(h);
227                         $(div).backgroundFade({sColor:'#ffffff',eColor:'#FFBABA',steps:50},function() {
228                                   $(this).backgroundFade({sColor:'#ffbaba',eColor:'#ffffff'});
229                         });
230                    }
231
232                    return false;
233               });
234
235               return false;
236          });
237
238          a.appendChild(document.createTextNode(dotclear.msg.xhtml_validator));
239          h.appendChild(a);
240          $(h).appendTo('#entry-content');
241
242          // Check unsaved changes before XHTML conversion
243          var excerpt = $('#post_excerpt').val();
244          var content = $('#post_content').val();
245          $('#convert-xhtml').click(function() {
246               if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) {
247                    return window.confirm(dotclear.msg.confirm_change_post_format);
248               }
249          });
250     });
251
252     $('#comments').onetabload(function() {
253          $('.comments-list tr.line').each(function() {
254               dotclear.commentExpander(this);
255          });
256          $('.checkboxes-helpers').each(function() {
257               dotclear.checkboxesHelpers(this);
258          });
259
260          dotclear.commentsActionsHelper();
261     });
262
263     $('#add-comment').onetabload(function() {
264          commentTb.draw('xhtml');
265     });
266});
Note: See TracBrowser for help on using the repository browser.

Sites map