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