| 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 | 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 | $('.format_control:not(.control_no_'+$(this).val()+') > *').removeClass('hide'); |
|---|
| 95 | }); |
|---|
| 96 | |
|---|
| 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 | } |
|---|
| 101 | |
|---|
| 102 | if (document.getElementById('comment_content')) { |
|---|
| 103 | var commentTb = new jsToolBar(document.getElementById('comment_content')); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | // Post preview |
|---|
| 107 | $('#post-preview').modalWeb($(window).width()-40,$(window).height()-40); |
|---|
| 108 | |
|---|
| 109 | // Tabs events |
|---|
| 110 | $('#edit-entry').onetabload(function() { |
|---|
| 111 | dotclear.hideLockable(); |
|---|
| 112 | |
|---|
| 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(); |
|---|
| 117 | |
|---|
| 118 | // Confirm post deletion |
|---|
| 119 | $('input[name="delete"]').click(function() { |
|---|
| 120 | return window.confirm(dotclear.msg.confirm_delete_post); |
|---|
| 121 | }); |
|---|
| 122 | |
|---|
| 123 | // Markup validator |
|---|
| 124 | var v = $('<div class="format_control"><p><a id="a-validator"></a></p><div/>').get(0); |
|---|
| 125 | $('.format_control').before(v); |
|---|
| 126 | var a = $('#a-validator').get(0); |
|---|
| 127 | a.href = '#'; |
|---|
| 128 | a.className = 'button '; |
|---|
| 129 | $(a).click(function() { |
|---|
| 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 | |
|---|
| 134 | var params = { |
|---|
| 135 | xd_check: dotclear.nonce, |
|---|
| 136 | f: 'validatePostMarkup', |
|---|
| 137 | excerpt: excerpt_content, |
|---|
| 138 | content: post_content, |
|---|
| 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 | $('.message, .success, .error, .warning-msg').remove(); |
|---|
| 150 | |
|---|
| 151 | if ($(data).find('valid').text() == 1) { |
|---|
| 152 | var p = document.createElement('p'); |
|---|
| 153 | p.id = 'markup-validator'; |
|---|
| 154 | |
|---|
| 155 | $(p).addClass('success'); |
|---|
| 156 | $(p).text(dotclear.msg.xhtml_valid); |
|---|
| 157 | $('#entry-content h3').after(p); |
|---|
| 158 | $(p).backgroundFade({sColor:'#9BCA1C',eColor:'#bee74b',steps:20}); |
|---|
| 159 | } else { |
|---|
| 160 | var div = document.createElement('div'); |
|---|
| 161 | div.id = 'markup-validator'; |
|---|
| 162 | |
|---|
| 163 | $(div).addClass('error'); |
|---|
| 164 | $(div).html('<p><strong>' + dotclear.msg.xhtml_not_valid + '</strong></p>' + $(data).find('errors').text()); |
|---|
| 165 | $('#entry-content h3').after(div); |
|---|
| 166 | $(div).backgroundFade({sColor:'#ffdec8',eColor:'#ffbaba',steps:20}); |
|---|
| 167 | } |
|---|
| 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 | } |
|---|
| 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'); |
|---|
| 185 | $('.format_control:not(.control_no_'+last_post_format+') > *').removeClass('hide'); |
|---|
| 186 | |
|---|
| 187 | // Hide some fields |
|---|
| 188 | $('#notes-area label').toggleWithLegend($('#notes-area').children().not('label'),{ |
|---|
| 189 | user_pref: 'dcx_post_notes', |
|---|
| 190 | legend_click:true, |
|---|
| 191 | hide: $('#post_notes').val() == '' |
|---|
| 192 | }); |
|---|
| 193 | $('#post_lang').parent().children('label').toggleWithLegend($('#post_lang'),{ |
|---|
| 194 | user_pref: 'dcx_post_lang', |
|---|
| 195 | legend_click: true |
|---|
| 196 | }); |
|---|
| 197 | $('#post_password').parent().children('label').toggleWithLegend($('#post_password'),{ |
|---|
| 198 | user_pref: 'dcx_post_password', |
|---|
| 199 | legend_click: true, |
|---|
| 200 | hide: $('#post_password').val() == '' |
|---|
| 201 | }); |
|---|
| 202 | $('#post_status').parent().children('label').toggleWithLegend($('#post_status'),{ |
|---|
| 203 | user_pref: 'dcx_post_status', |
|---|
| 204 | legend_click: true |
|---|
| 205 | }); |
|---|
| 206 | $('#post_dt').parent().children('label').toggleWithLegend($('#post_dt').parent().children().not('label'),{ |
|---|
| 207 | user_pref: 'dcx_post_dt', |
|---|
| 208 | legend_click: true |
|---|
| 209 | }); |
|---|
| 210 | $('#label_format').toggleWithLegend($('#label_format').parent().children().not('#label_format'),{ |
|---|
| 211 | user_pref: 'dcx_post_format', |
|---|
| 212 | legend_click: true |
|---|
| 213 | }); |
|---|
| 214 | $('#label_cat_id').toggleWithLegend($('#label_cat_id').parent().children().not('#label_cat_id'),{ |
|---|
| 215 | user_pref: 'dcx_cat_id', |
|---|
| 216 | legend_click: true |
|---|
| 217 | }); |
|---|
| 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 | }); |
|---|
| 222 | $('#label_comment_tb').toggleWithLegend($('#label_comment_tb').parent().children().not('#label_comment_tb'),{ |
|---|
| 223 | user_pref: 'dcx_comment_tb', |
|---|
| 224 | legend_click: true |
|---|
| 225 | }); |
|---|
| 226 | $('#post_url').parent().children('label').toggleWithLegend($('#post_url').parent().children().not('label'),{ |
|---|
| 227 | user_pref: 'post_url', |
|---|
| 228 | legend_click: true |
|---|
| 229 | }); |
|---|
| 230 | // We load toolbar on excerpt only when it's ready |
|---|
| 231 | $('#excerpt-area label').toggleWithLegend($('#excerpt-area').children().not('label'),{ |
|---|
| 232 | user_pref: 'dcx_post_excerpt', |
|---|
| 233 | legend_click: true, |
|---|
| 234 | hide: $('#post_excerpt').val() == '' |
|---|
| 235 | }); |
|---|
| 236 | |
|---|
| 237 | // Load toolbars |
|---|
| 238 | contentTb.switchMode(formatField.value); |
|---|
| 239 | excerptTb.switchMode(formatField.value); |
|---|
| 240 | |
|---|
| 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 | }); |
|---|
| 252 | |
|---|
| 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); |
|---|
| 259 | } |
|---|
| 260 | }); |
|---|
| 261 | }); |
|---|
| 262 | |
|---|
| 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 | }); |
|---|
| 270 | |
|---|
| 271 | dotclear.commentsActionsHelper(); |
|---|
| 272 | }); |
|---|
| 273 | |
|---|
| 274 | $('#add-comment').onetabload(function() { |
|---|
| 275 | commentTb.draw('xhtml'); |
|---|
| 276 | }); |
|---|
| 277 | }); |
|---|