| 1 | /*global $, dotclear, datePicker, commentTb */ |
|---|
| 2 | 'use strict'; |
|---|
| 3 | |
|---|
| 4 | dotclear.viewCommentContent = function(line) { |
|---|
| 5 | var commentId = $(line).attr('id').substr(1); |
|---|
| 6 | var tr = document.getElementById('ce' + commentId); |
|---|
| 7 | |
|---|
| 8 | if (!tr) { |
|---|
| 9 | tr = document.createElement('tr'); |
|---|
| 10 | tr.id = 'ce' + commentId; |
|---|
| 11 | var td = document.createElement('td'); |
|---|
| 12 | td.colSpan = 6; |
|---|
| 13 | td.className = 'expand'; |
|---|
| 14 | tr.appendChild(td); |
|---|
| 15 | |
|---|
| 16 | // Get comment content |
|---|
| 17 | $.get('services.php', { |
|---|
| 18 | f: 'getCommentById', |
|---|
| 19 | id: commentId |
|---|
| 20 | }, function(data) { |
|---|
| 21 | var rsp = $(data).children('rsp')[0]; |
|---|
| 22 | |
|---|
| 23 | if (rsp.attributes[0].value == 'ok') { |
|---|
| 24 | var comment = $(rsp).find('comment_display_content').text(); |
|---|
| 25 | |
|---|
| 26 | if (comment) { |
|---|
| 27 | $(td).append(comment); |
|---|
| 28 | var comment_email = $(rsp).find('comment_email').text(); |
|---|
| 29 | var comment_site = $(rsp).find('comment_site').text(); |
|---|
| 30 | // var comment_ip = $(rsp).find('comment_ip').text(); |
|---|
| 31 | var comment_spam_disp = $(rsp).find('comment_spam_disp').text(); |
|---|
| 32 | |
|---|
| 33 | $(td).append('<p><strong>' + dotclear.msg.website + |
|---|
| 34 | '</strong> ' + comment_site + '<br />' + |
|---|
| 35 | '<strong>' + dotclear.msg.email + '</strong> ' + |
|---|
| 36 | comment_email + '<br />' + comment_spam_disp + '</p>'); |
|---|
| 37 | } |
|---|
| 38 | } else { |
|---|
| 39 | window.alert($(rsp).find('message').text()); |
|---|
| 40 | } |
|---|
| 41 | }); |
|---|
| 42 | |
|---|
| 43 | $(line).toggleClass('expand'); |
|---|
| 44 | line.parentNode.insertBefore(tr, line.nextSibling); |
|---|
| 45 | } else if (tr.style.display == 'none') { |
|---|
| 46 | $(tr).toggle(); |
|---|
| 47 | $(line).toggleClass('expand'); |
|---|
| 48 | } else { |
|---|
| 49 | $(tr).toggle(); |
|---|
| 50 | $(line).toggleClass('expand'); |
|---|
| 51 | } |
|---|
| 52 | }; |
|---|
| 53 | |
|---|
| 54 | $(function() { |
|---|
| 55 | // Post preview |
|---|
| 56 | var $preview_url = $('#post-preview').attr('href'); |
|---|
| 57 | if ($preview_url) { |
|---|
| 58 | |
|---|
| 59 | // Make $preview_url absolute |
|---|
| 60 | var $a = document.createElement('a'); |
|---|
| 61 | $a.href = $('#post-preview').attr('href'); |
|---|
| 62 | $preview_url = $a.href; |
|---|
| 63 | |
|---|
| 64 | // Check if admin and blog have same protocol (ie not mixed-content) |
|---|
| 65 | if (window.location.protocol == $preview_url.substring(0, window.location.protocol.length)) { |
|---|
| 66 | // Open preview in a modal iframe |
|---|
| 67 | $('#post-preview').magnificPopup({ |
|---|
| 68 | type: 'iframe', |
|---|
| 69 | iframe: { |
|---|
| 70 | patterns: { |
|---|
| 71 | dotclear_preview: { |
|---|
| 72 | index: $preview_url, |
|---|
| 73 | src: $preview_url |
|---|
| 74 | } |
|---|
| 75 | } |
|---|
| 76 | } |
|---|
| 77 | }); |
|---|
| 78 | } else { |
|---|
| 79 | // Open preview on antother window |
|---|
| 80 | $('#post-preview').click(function(e) { |
|---|
| 81 | e.preventDefault(); |
|---|
| 82 | window.open($(this).attr('href')); |
|---|
| 83 | }); |
|---|
| 84 | } |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | // Tabs events |
|---|
| 88 | $('#edit-entry').onetabload(function() { |
|---|
| 89 | dotclear.hideLockable(); |
|---|
| 90 | |
|---|
| 91 | // Add date picker |
|---|
| 92 | var post_dtPick = new datePicker($('#post_dt').get(0)); |
|---|
| 93 | post_dtPick.img_top = '1.5em'; |
|---|
| 94 | post_dtPick.draw(); |
|---|
| 95 | |
|---|
| 96 | // Confirm post deletion |
|---|
| 97 | $('input[name="delete"]').click(function() { |
|---|
| 98 | return window.confirm(dotclear.msg.confirm_delete_post); |
|---|
| 99 | }); |
|---|
| 100 | |
|---|
| 101 | // Hide some fields |
|---|
| 102 | $('#notes-area label').toggleWithLegend($('#notes-area').children().not('label'), { |
|---|
| 103 | user_pref: 'dcx_post_notes', |
|---|
| 104 | legend_click: true, |
|---|
| 105 | hide: $('#post_notes').val() == '' |
|---|
| 106 | }); |
|---|
| 107 | $('#post_lang').parent().children('label').toggleWithLegend($('#post_lang'), { |
|---|
| 108 | user_pref: 'dcx_post_lang', |
|---|
| 109 | legend_click: true |
|---|
| 110 | }); |
|---|
| 111 | $('#post_password').parent().children('label').toggleWithLegend($('#post_password'), { |
|---|
| 112 | user_pref: 'dcx_post_password', |
|---|
| 113 | legend_click: true, |
|---|
| 114 | hide: $('#post_password').val() == '' |
|---|
| 115 | }); |
|---|
| 116 | $('#post_status').parent().children('label').toggleWithLegend($('#post_status'), { |
|---|
| 117 | user_pref: 'dcx_post_status', |
|---|
| 118 | legend_click: true |
|---|
| 119 | }); |
|---|
| 120 | $('#post_dt').parent().children('label').toggleWithLegend($('#post_dt').parent().children().not('label'), { |
|---|
| 121 | user_pref: 'dcx_post_dt', |
|---|
| 122 | legend_click: true |
|---|
| 123 | }); |
|---|
| 124 | $('#label_format').toggleWithLegend($('#label_format').parent().children().not('#label_format'), { |
|---|
| 125 | user_pref: 'dcx_post_format', |
|---|
| 126 | legend_click: true |
|---|
| 127 | }); |
|---|
| 128 | $('#label_cat_id').toggleWithLegend($('#label_cat_id').parent().children().not('#label_cat_id'), { |
|---|
| 129 | user_pref: 'dcx_cat_id', |
|---|
| 130 | legend_click: true |
|---|
| 131 | }); |
|---|
| 132 | $('#create_cat').toggleWithLegend($('#create_cat').parent().children().not('#create_cat'), { |
|---|
| 133 | // no cookie on new category as we don't use this every day |
|---|
| 134 | legend_click: true |
|---|
| 135 | }); |
|---|
| 136 | $('#label_comment_tb').toggleWithLegend($('#label_comment_tb').parent().children().not('#label_comment_tb'), { |
|---|
| 137 | user_pref: 'dcx_comment_tb', |
|---|
| 138 | legend_click: true |
|---|
| 139 | }); |
|---|
| 140 | $('#post_url').parent().children('label').toggleWithLegend($('#post_url').parent().children().not('label'), { |
|---|
| 141 | user_pref: 'post_url', |
|---|
| 142 | legend_click: true |
|---|
| 143 | }); |
|---|
| 144 | // We load toolbar on excerpt only when it's ready |
|---|
| 145 | $('#excerpt-area label').toggleWithLegend($('#excerpt-area').children().not('label'), { |
|---|
| 146 | user_pref: 'dcx_post_excerpt', |
|---|
| 147 | legend_click: true, |
|---|
| 148 | hide: $('#post_excerpt').val() == '' |
|---|
| 149 | }); |
|---|
| 150 | |
|---|
| 151 | // Replace attachment remove links by a POST form submit |
|---|
| 152 | $('a.attachment-remove').click(function() { |
|---|
| 153 | this.href = ''; |
|---|
| 154 | var m_name = $(this).parents('ul').find('li:first>a').attr('title'); |
|---|
| 155 | if (window.confirm(dotclear.msg.confirm_remove_attachment.replace('%s', m_name))) { |
|---|
| 156 | var f = $('#attachment-remove-hide').get(0); |
|---|
| 157 | f.elements.media_id.value = this.id.substring(11); |
|---|
| 158 | f.submit(); |
|---|
| 159 | } |
|---|
| 160 | return false; |
|---|
| 161 | }); |
|---|
| 162 | }); |
|---|
| 163 | |
|---|
| 164 | $('#comments').onetabload(function() { |
|---|
| 165 | $.expandContent({ |
|---|
| 166 | lines: $('#form-comments .comments-list tr.line'), |
|---|
| 167 | callback: dotclear.viewCommentContent |
|---|
| 168 | }); |
|---|
| 169 | $('#form-comments .checkboxes-helpers').each(function() { |
|---|
| 170 | dotclear.checkboxesHelpers(this); |
|---|
| 171 | }); |
|---|
| 172 | |
|---|
| 173 | dotclear.commentsActionsHelper(); |
|---|
| 174 | }); |
|---|
| 175 | |
|---|
| 176 | $('#trackbacks').onetabload(function() { |
|---|
| 177 | $.expandContent({ |
|---|
| 178 | lines: $('#form-trackbacks .comments-list tr.line'), |
|---|
| 179 | callback: dotclear.viewCommentContent |
|---|
| 180 | }); |
|---|
| 181 | $('#form-trackbacks .checkboxes-helpers').each(function() { |
|---|
| 182 | dotclear.checkboxesHelpers(this); |
|---|
| 183 | }); |
|---|
| 184 | |
|---|
| 185 | dotclear.commentsActionsHelper(); |
|---|
| 186 | }); |
|---|
| 187 | |
|---|
| 188 | $('#add-comment').onetabload(function() { |
|---|
| 189 | commentTb.draw('xhtml'); |
|---|
| 190 | }); |
|---|
| 191 | }); |
|---|