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