Dotclear

source: admin/js/_post.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 5.8 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

RevLine 
[3706]1/*global $, dotclear, datePicker, commentTb */
2'use strict';
[1525]3
[3878]4dotclear.viewCommentContent = function(line, action, e) {
5  action = action || 'toggle';
6  if ($(line).attr('id') == undefined) {
7    return;
8  }
9
[3880]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'));
[1525]16
[3706]17  if (!tr) {
18    // Get comment content
[3878]19    dotclear.getCommentContent(commentId, function(content) {
20      if (content) {
21        // Content found
22        tr = document.createElement('tr');
[3880]23        tr.id = lineId;
24        const td = document.createElement('td');
[3878]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);
[3706]31      } else {
[3878]32        // No content, content not found or server error
33        $(line).removeClass('expand');
[3706]34      }
[3878]35    }, {
36      ip: false,
[3880]37      clean: clean
[3706]38    });
39  } else {
40    $(tr).toggle();
41    $(line).toggleClass('expand');
42  }
[0]43};
44
45$(function() {
[3706]46  // Post preview
[3880]47  let $preview_url = $('#post-preview').attr('href');
[3706]48  if ($preview_url) {
[3241]49
[3706]50    // Make $preview_url absolute
[3880]51    let $a = document.createElement('a');
[3706]52    $a.href = $('#post-preview').attr('href');
53    $preview_url = $a.href;
[3241]54
[3706]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  }
[1525]77
[3706]78  // Tabs events
79  $('#edit-entry').onetabload(function() {
80    dotclear.hideLockable();
[1525]81
[3706]82    // Add date picker
[3880]83    const post_dtPick = new datePicker($('#post_dt').get(0));
[3706]84    post_dtPick.img_top = '1.5em';
85    post_dtPick.draw();
[1525]86
[3706]87    // Confirm post deletion
88    $('input[name="delete"]').click(function() {
89      return window.confirm(dotclear.msg.confirm_delete_post);
90    });
[1525]91
[3706]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    });
[1525]141
[3706]142    // Replace attachment remove links by a POST form submit
143    $('a.attachment-remove').click(function() {
144      this.href = '';
[3880]145      const m_name = $(this).parents('ul').find('li:first>a').attr('title');
[3706]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  });
[1525]154
[3706]155  $('#comments').onetabload(function() {
156    $.expandContent({
[3878]157      line: $('#form-comments .comments-list tr:not(.line)'),
[3706]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    });
[2089]164
[3706]165    dotclear.commentsActionsHelper();
166  });
[2089]167
[3706]168  $('#trackbacks').onetabload(function() {
169    $.expandContent({
[3878]170      line: $('#form-trackbacks .comments-list tr:not(.line)'),
[3706]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    });
[1525]177
[3706]178    dotclear.commentsActionsHelper();
179  });
[1525]180
[3706]181  $('#add-comment').onetabload(function() {
182    commentTb.draw('xhtml');
183  });
[0]184});
Note: See TracBrowser for help on using the repository browser.

Sites map