[0] | 1 | dotclear.commentExpander = function(line) { |
---|
| 2 | var td = line.firstChild; |
---|
[1525] | 3 | |
---|
[0] | 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; |
---|
[1140] | 10 | img.onclick = function() { dotclear.viewCommentContent(this,this.line); }; |
---|
[1525] | 11 | |
---|
[0] | 12 | td.insertBefore(img,td.firstChild); |
---|
| 13 | }; |
---|
| 14 | |
---|
| 15 | dotclear.viewCommentContent = function(img,line) { |
---|
| 16 | var commentId = line.id.substr(1); |
---|
[1525] | 17 | |
---|
[0] | 18 | var tr = document.getElementById('ce'+commentId); |
---|
[1525] | 19 | |
---|
[0] | 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); |
---|
[1525] | 27 | |
---|
[0] | 28 | img.src = dotclear.img_minus_src; |
---|
| 29 | img.alt = dotclear.img_minus_alt; |
---|
[1525] | 30 | |
---|
[0] | 31 | // Get comment content |
---|
| 32 | $.get('services.php',{f:'getCommentById',id: commentId},function(data) { |
---|
| 33 | var rsp = $(data).children('rsp')[0]; |
---|
[1525] | 34 | |
---|
[0] | 35 | if (rsp.attributes[0].value == 'ok') { |
---|
| 36 | var comment = $(rsp).find('comment_display_content').text(); |
---|
[1525] | 37 | |
---|
[0] | 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(); |
---|
[1525] | 44 | |
---|
[0] | 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 | }); |
---|
[1525] | 54 | |
---|
[0] | 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; } |
---|
[1525] | 76 | |
---|
[0] | 77 | if (document.getElementById('edit-entry')) |
---|
| 78 | { |
---|
| 79 | // Get document format and prepare toolbars |
---|
| 80 | var formatField = $('#post_format').get(0); |
---|
[1256] | 81 | var last_post_format = $(formatField).val(); |
---|
[0] | 82 | $(formatField).change(function() { |
---|
[1256] | 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 | } |
---|
[1812] | 92 | |
---|
| 93 | $('.format_control > *').addClass('hide'); |
---|
[1830] | 94 | $('.format_control:not(.control_no_'+$(this).val()+') > *').removeClass('hide'); |
---|
[0] | 95 | }); |
---|
[1525] | 96 | |
---|
[0] | 97 | var excerptTb = new jsToolBar(document.getElementById('post_excerpt')); |
---|
| 98 | var contentTb = new jsToolBar(document.getElementById('post_content')); |
---|
| 99 | excerptTb.context = contentTb.context = 'post'; |
---|
| 100 | } |
---|
[1525] | 101 | |
---|
[0] | 102 | if (document.getElementById('comment_content')) { |
---|
| 103 | var commentTb = new jsToolBar(document.getElementById('comment_content')); |
---|
| 104 | } |
---|
[1525] | 105 | |
---|
[0] | 106 | // Post preview |
---|
| 107 | $('#post-preview').modalWeb($(window).width()-40,$(window).height()-40); |
---|
[1525] | 108 | |
---|
[0] | 109 | // Tabs events |
---|
| 110 | $('#edit-entry').onetabload(function() { |
---|
| 111 | dotclear.hideLockable(); |
---|
[1525] | 112 | |
---|
[0] | 113 | // Add date picker |
---|
| 114 | var post_dtPick = new datePicker($('#post_dt').get(0)); |
---|
| 115 | post_dtPick.img_top = '1.5em'; |
---|
| 116 | post_dtPick.draw(); |
---|
[1525] | 117 | |
---|
[0] | 118 | // Confirm post deletion |
---|
| 119 | $('input[name="delete"]').click(function() { |
---|
[1606] | 120 | return window.confirm(dotclear.msg.confirm_delete_post); |
---|
[0] | 121 | }); |
---|
[1525] | 122 | |
---|
[1812] | 123 | // Markup validator |
---|
[1830] | 124 | var v = $('<div class="format_control"><p><a id="a-validator"></a></p><div/>').get(0); |
---|
| 125 | $('.format_control').before(v); |
---|
[1812] | 126 | var a = $('#a-validator').get(0); |
---|
| 127 | a.href = '#'; |
---|
| 128 | a.className = 'button '; |
---|
| 129 | $(a).click(function() { |
---|
[1813] | 130 | |
---|
| 131 | excerpt_content = $('#post_excerpt').css('display') != 'none' ? $('#post_excerpt').val() : $('#excerpt-area iframe').contents().find('body').html(); |
---|
| 132 | post_content = $('#post_content').css('display') != 'none' ? $('#post_content').val() : $('#content-area iframe').contents().find('body').html(); |
---|
| 133 | |
---|
[1812] | 134 | var params = { |
---|
| 135 | xd_check: dotclear.nonce, |
---|
| 136 | f: 'validatePostMarkup', |
---|
[1813] | 137 | excerpt: excerpt_content, |
---|
| 138 | content: post_content, |
---|
[1812] | 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 | } |
---|
[1832] | 148 | |
---|
| 149 | $('.message, .success, .error, .warning-msg').remove(); |
---|
[1812] | 150 | |
---|
| 151 | if ($(data).find('valid').text() == 1) { |
---|
| 152 | var p = document.createElement('p'); |
---|
| 153 | p.id = 'markup-validator'; |
---|
[1830] | 154 | |
---|
| 155 | $(p).addClass('success'); |
---|
[1812] | 156 | $(p).text(dotclear.msg.xhtml_valid); |
---|
[1813] | 157 | $('#entry-content h3').after(p); |
---|
[1830] | 158 | $(p).backgroundFade({sColor:'#9BCA1C',eColor:'#bee74b',steps:20}); |
---|
[1812] | 159 | } else { |
---|
| 160 | var div = document.createElement('div'); |
---|
| 161 | div.id = 'markup-validator'; |
---|
[1830] | 162 | |
---|
[1812] | 163 | $(div).addClass('error'); |
---|
| 164 | $(div).html('<p><strong>' + dotclear.msg.xhtml_not_valid + '</strong></p>' + $(data).find('errors').text()); |
---|
[1813] | 165 | $('#entry-content h3').after(div); |
---|
[1830] | 166 | $(div).backgroundFade({sColor:'#ffdec8',eColor:'#ffbaba',steps:20}); |
---|
[1812] | 167 | } |
---|
[1832] | 168 | |
---|
| 169 | if ( $('#post_excerpt').text() != excerpt_content || $('#post_content').text() != post_content ) { |
---|
| 170 | var pn = document.createElement('p'); |
---|
| 171 | $(pn).addClass('warning-msg'); |
---|
| 172 | $(pn).text(dotclear.msg.warning_validate_no_save_content); |
---|
| 173 | $('#entry-content h3').after(pn); |
---|
| 174 | } |
---|
[1812] | 175 | |
---|
| 176 | return false; |
---|
| 177 | }); |
---|
| 178 | |
---|
| 179 | return false; |
---|
| 180 | }); |
---|
| 181 | |
---|
| 182 | a.appendChild(document.createTextNode(dotclear.msg.xhtml_validator)); |
---|
| 183 | |
---|
| 184 | $('.format_control > *').addClass('hide'); |
---|
[1830] | 185 | $('.format_control:not(.control_no_'+last_post_format+') > *').removeClass('hide'); |
---|
[1812] | 186 | |
---|
[0] | 187 | // Hide some fields |
---|
| 188 | $('#notes-area label').toggleWithLegend($('#notes-area').children().not('label'),{ |
---|
[1699] | 189 | user_pref: 'dcx_post_notes', |
---|
[1606] | 190 | legend_click:true, |
---|
[1562] | 191 | hide: $('#post_notes').val() == '' |
---|
[0] | 192 | }); |
---|
[1606] | 193 | $('#post_lang').parent().children('label').toggleWithLegend($('#post_lang'),{ |
---|
[1699] | 194 | user_pref: 'dcx_post_lang', |
---|
[1606] | 195 | legend_click: true |
---|
| 196 | }); |
---|
| 197 | $('#post_password').parent().children('label').toggleWithLegend($('#post_password'),{ |
---|
[1699] | 198 | user_pref: 'dcx_post_password', |
---|
[1606] | 199 | legend_click: true, |
---|
[1562] | 200 | hide: $('#post_password').val() == '' |
---|
[0] | 201 | }); |
---|
[1606] | 202 | $('#post_status').parent().children('label').toggleWithLegend($('#post_status'),{ |
---|
[1699] | 203 | user_pref: 'dcx_post_status', |
---|
[1606] | 204 | legend_click: true |
---|
[1392] | 205 | }); |
---|
[1606] | 206 | $('#post_dt').parent().children('label').toggleWithLegend($('#post_dt').parent().children().not('label'),{ |
---|
[1699] | 207 | user_pref: 'dcx_post_dt', |
---|
[1606] | 208 | legend_click: true |
---|
[1392] | 209 | }); |
---|
[1619] | 210 | $('#label_format').toggleWithLegend($('#label_format').parent().children().not('#label_format'),{ |
---|
[1699] | 211 | user_pref: 'dcx_post_format', |
---|
[1606] | 212 | legend_click: true |
---|
[1392] | 213 | }); |
---|
[1935] | 214 | $('#label_cat_id').toggleWithLegend($('#label_cat_id').parent().children().not('#label_cat_id'),{ |
---|
| 215 | user_pref: 'dcx_cat_id', |
---|
[1606] | 216 | legend_click: true |
---|
[1392] | 217 | }); |
---|
[1936] | 218 | $('#create_cat').toggleWithLegend($('#create_cat').parent().children().not('#create_cat'),{ |
---|
| 219 | // no cookie on new category as we don't use this every day |
---|
| 220 | legend_click: true |
---|
| 221 | }); |
---|
[1711] | 222 | $('#label_comment_tb').toggleWithLegend($('#label_comment_tb').parent().children().not('#label_comment_tb'),{ |
---|
[1717] | 223 | user_pref: 'dcx_comment_tb', |
---|
[1711] | 224 | legend_click: true |
---|
| 225 | }); |
---|
[1606] | 226 | $('#post_url').parent().children('label').toggleWithLegend($('#post_url').parent().children().not('label'),{ |
---|
[1699] | 227 | user_pref: 'post_url', |
---|
[1606] | 228 | legend_click: true |
---|
[1392] | 229 | }); |
---|
[0] | 230 | // We load toolbar on excerpt only when it's ready |
---|
| 231 | $('#excerpt-area label').toggleWithLegend($('#excerpt-area').children().not('label'),{ |
---|
[1699] | 232 | user_pref: 'dcx_post_excerpt', |
---|
[1638] | 233 | legend_click: true, |
---|
[0] | 234 | hide: $('#post_excerpt').val() == '' |
---|
| 235 | }); |
---|
[1525] | 236 | |
---|
[0] | 237 | // Load toolbars |
---|
| 238 | contentTb.switchMode(formatField.value); |
---|
[1515] | 239 | excerptTb.switchMode(formatField.value); |
---|
[1562] | 240 | |
---|
[0] | 241 | // Replace attachment remove links by a POST form submit |
---|
| 242 | $('a.attachment-remove').click(function() { |
---|
| 243 | this.href = ''; |
---|
| 244 | var m_name = $(this).parents('ul').find('li:first>a').attr('title'); |
---|
| 245 | if (window.confirm(dotclear.msg.confirm_remove_attachment.replace('%s',m_name))) { |
---|
| 246 | var f = $('#attachment-remove-hide').get(0); |
---|
| 247 | f.elements['media_id'].value = this.id.substring(11); |
---|
| 248 | f.submit(); |
---|
| 249 | } |
---|
| 250 | return false; |
---|
| 251 | }); |
---|
[1525] | 252 | |
---|
[0] | 253 | // Check unsaved changes before XHTML conversion |
---|
| 254 | var excerpt = $('#post_excerpt').val(); |
---|
| 255 | var content = $('#post_content').val(); |
---|
| 256 | $('#convert-xhtml').click(function() { |
---|
| 257 | if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) { |
---|
| 258 | return window.confirm(dotclear.msg.confirm_change_post_format); |
---|
[1525] | 259 | } |
---|
[0] | 260 | }); |
---|
| 261 | }); |
---|
[1525] | 262 | |
---|
[0] | 263 | $('#comments').onetabload(function() { |
---|
| 264 | $('.comments-list tr.line').each(function() { |
---|
| 265 | dotclear.commentExpander(this); |
---|
| 266 | }); |
---|
| 267 | $('.checkboxes-helpers').each(function() { |
---|
| 268 | dotclear.checkboxesHelpers(this); |
---|
| 269 | }); |
---|
[1525] | 270 | |
---|
[0] | 271 | dotclear.commentsActionsHelper(); |
---|
| 272 | }); |
---|
[1525] | 273 | |
---|
[0] | 274 | $('#add-comment').onetabload(function() { |
---|
| 275 | commentTb.draw('xhtml'); |
---|
| 276 | }); |
---|
| 277 | }); |
---|