Dotclear

source: plugins/dcLegacyEditor/js/_post_editor.js @ 3744:6abafffe0db8

Revision 3744:6abafffe0db8, 3.1 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Remove required attribute from comment/post content textarea when they are not more focusable (dcLegacyEditor)

RevLine 
[3709]1/*global $, dotclear, jsToolBar */
2'use strict';
3
[2614]4$(function() {
[3709]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  }
[2614]12
[3709]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      }
[2705]22
[3709]23      var post_format = this.value;
[2705]24
[3709]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      }
[2856]34
[3709]35      $('.format_control > *').addClass('hide');
36      $('.format_control:not(.control_no_' + post_format + ') > *').removeClass('hide');
37    });
[2856]38
[3709]39    var excerptTb = new jsToolBar(document.getElementById('post_excerpt'));
40    var contentTb = new jsToolBar(document.getElementById('post_content'));
41    excerptTb.context = contentTb.context = 'post';
[2614]42
[3709]43    $('.format_control > *').addClass('hide');
44    $('.format_control:not(.control_no_' + last_post_format + ') > *').removeClass('hide');
45  }
[2614]46
[3709]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  }
[2614]53
[3744]54  $('#comments').onetabload(function() {
55    // Remove required attribut from #comment_content as textarea might be not more focusable
56    if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#comment_content') !== -1) {
57      $('#comment_content').removeAttr('required');
58    }
59  });
60
[3709]61  $('#edit-entry').onetabload(function() {
[2614]62
[3709]63    // Remove required attribut from #post_content in XHTML mode as textarea is not more focusable
64    if (formatField.value == 'xhtml') {
[3744]65      if (dotclear.legacy_editor_tags_context[dotclear.legacy_editor_context].indexOf('#post_content') !== -1) {
66        $('#post_content').removeAttr('required');
67      }
[3709]68    }
[3665]69
[3709]70    // Load toolbars
71    if (contentTb !== undefined && excerptTb !== undefined) {
72      contentTb.switchMode(formatField.value);
73      excerptTb.switchMode(formatField.value);
74    }
[2614]75
[3709]76    // Check unsaved changes before XHTML conversion
77    var excerpt = $('#post_excerpt').val();
78    var content = $('#post_content').val();
79    $('#convert-xhtml').click(function() {
80      if (excerpt != $('#post_excerpt').val() || content != $('#post_content').val()) {
81        return window.confirm(dotclear.msg.confirm_change_post_format);
82      }
83    });
84  });
[2614]85});
Note: See TracBrowser for help on using the repository browser.

Sites map