Dotclear

source: admin/js/_post.js @ 1525:c30081595436

Revision 1525:c30081595436, 7.6 KB checked in by Nicolas <nikrou77@…>, 12 years ago (diff)

Fix issue #1541 : improve and simplify categories page.

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

Sites map