Dotclear

source: plugins/dcLegacyEditor/js/_post_editor.js @ 3709:c88e69474c34

Revision 3709:c88e69474c34, 2.7 KB checked in by franck <carnet.franck.paul@…>, 8 years ago (diff)

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

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

Sites map