Dotclear

source: plugins/dcLegacyEditor/js/_post_editor.js @ 3880:e6d1f6d9d7df

Revision 3880:e6d1f6d9d7df, 3.1 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

Line 
1/*global $, dotclear, jsToolBar */
2'use strict';
3
4$(function() {
5  if ($('#edit-entry').length == 0) {
6    return;
7  }
8  if (dotclear.legacy_editor_context === undefined ||
9    dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context] === undefined) {
10    return;
11  }
12
13  // To be reviewed!
14  let formatField;
15  let excerptTb;
16  let contentTb;
17
18  if ((dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_content') !== -1) &&
19    (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_excerpt') !== -1)) {
20    // Get document format and prepare toolbars
21    formatField = $('#post_format').get(0);
22    let last_post_format = $(formatField).val();
23    $(formatField).change(function() {
24      if (this.value != 'dcLegacyEditor') {
25        return;
26      }
27
28      const post_format = this.value;
29
30      // Confirm post format change
31      if (window.confirm(dotclear.msg.confirm_change_post_format_noconvert)) {
32        excerptTb.switchMode(post_format);
33        contentTb.switchMode(post_format);
34        last_post_format = $(this).val();
35      } else {
36        // Restore last format if change cancelled
37        $(this).val(last_post_format);
38      }
39
40      $('.format_control > *').addClass('hide');
41      $('.format_control:not(.control_no_' + post_format + ') > *').removeClass('hide');
42    });
43
44    excerptTb = new jsToolBar(document.getElementById('post_excerpt'));
45    contentTb = new jsToolBar(document.getElementById('post_content'));
46    excerptTb.context = contentTb.context = 'post';
47
48    $('.format_control > *').addClass('hide');
49    $('.format_control:not(.control_no_' + last_post_format + ') > *').removeClass('hide');
50  }
51
52  if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#comment_content') !== -1) {
53    if ($('#comment_content').length > 0) {
54      let commentTb = new jsToolBar(document.getElementById('comment_content'));
55      commentTb.draw('xhtml');
56    }
57  }
58
59  $('#comments').onetabload(function() {
60    // Remove required attribut from #comment_content as textarea might be not more focusable
61    if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#comment_content') !== -1) {
62      $('#comment_content').removeAttr('required');
63    }
64  });
65
66  $('#edit-entry').onetabload(function() {
67
68    // Remove required attribut from #post_content in XHTML mode as textarea is not more focusable
69    if (formatField.value == 'xhtml') {
70      if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_content') !== -1) {
71        $('#post_content').removeAttr('required');
72      }
73    }
74
75    // Load toolbars
76    if (contentTb !== undefined && excerptTb !== undefined) {
77      contentTb.switchMode(formatField.value);
78      excerptTb.switchMode(formatField.value);
79    }
80
81    // Check unsaved changes before XHTML conversion
82    const excerpt = $('#post_excerpt').val();
83    const content = $('#post_content').val();
84    $('#convert-xhtml').click(function() {
85      if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) {
86        return window.confirm(dotclear.msg.confirm_change_post_format);
87      }
88    });
89  });
90});
Note: See TracBrowser for help on using the repository browser.

Sites map