Subversion Repositories oidplus

Rev

Rev 1422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
597 daniel-mar 1
/**
2
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
3
 * Licensed under the LGPL or a commercial license.
4
 * For LGPL see License.txt in the project root for license information.
5
 * For commercial licenses see https://www.tiny.cloud/
6
 *
1434 daniel-mar 7
 * Version: 5.10.9 (2023-11-15)
597 daniel-mar 8
 */
9
(function () {
10
    'use strict';
11
 
637 daniel-mar 12
    var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
597 daniel-mar 13
 
637 daniel-mar 14
    var global = tinymce.util.Tools.resolve('tinymce.Env');
597 daniel-mar 15
 
16
    var getSeparatorHtml = function (editor) {
17
      return editor.getParam('pagebreak_separator', '<!-- pagebreak -->');
18
    };
19
    var shouldSplitBlock = function (editor) {
20
      return editor.getParam('pagebreak_split_block', false);
21
    };
22
 
23
    var pageBreakClass = 'mce-pagebreak';
24
    var getPlaceholderHtml = function (shouldSplitBlock) {
637 daniel-mar 25
      var html = '<img src="' + global.transparentSrc + '" class="' + pageBreakClass + '" data-mce-resize="false" data-mce-placeholder />';
597 daniel-mar 26
      return shouldSplitBlock ? '<p>' + html + '</p>' : html;
27
    };
637 daniel-mar 28
    var setup$1 = function (editor) {
597 daniel-mar 29
      var separatorHtml = getSeparatorHtml(editor);
30
      var shouldSplitBlock$1 = function () {
31
        return shouldSplitBlock(editor);
32
      };
33
      var pageBreakSeparatorRegExp = new RegExp(separatorHtml.replace(/[\?\.\*\[\]\(\)\{\}\+\^\$\:]/g, function (a) {
34
        return '\\' + a;
35
      }), 'gi');
36
      editor.on('BeforeSetContent', function (e) {
37
        e.content = e.content.replace(pageBreakSeparatorRegExp, getPlaceholderHtml(shouldSplitBlock$1()));
38
      });
39
      editor.on('PreInit', function () {
40
        editor.serializer.addNodeFilter('img', function (nodes) {
41
          var i = nodes.length, node, className;
42
          while (i--) {
43
            node = nodes[i];
44
            className = node.attr('class');
45
            if (className && className.indexOf(pageBreakClass) !== -1) {
46
              var parentNode = node.parent;
47
              if (editor.schema.getBlockElements()[parentNode.name] && shouldSplitBlock$1()) {
48
                parentNode.type = 3;
49
                parentNode.value = separatorHtml;
50
                parentNode.raw = true;
51
                node.remove();
52
                continue;
53
              }
54
              node.type = 3;
55
              node.value = separatorHtml;
56
              node.raw = true;
57
            }
58
          }
59
        });
60
      });
61
    };
62
 
637 daniel-mar 63
    var register$1 = function (editor) {
597 daniel-mar 64
      editor.addCommand('mcePageBreak', function () {
65
        editor.insertContent(getPlaceholderHtml(shouldSplitBlock(editor)));
66
      });
67
    };
68
 
637 daniel-mar 69
    var setup = function (editor) {
597 daniel-mar 70
      editor.on('ResolveName', function (e) {
71
        if (e.target.nodeName === 'IMG' && editor.dom.hasClass(e.target, pageBreakClass)) {
72
          e.name = 'pagebreak';
73
        }
74
      });
75
    };
76
 
637 daniel-mar 77
    var register = function (editor) {
78
      var onAction = function () {
79
        return editor.execCommand('mcePageBreak');
80
      };
597 daniel-mar 81
      editor.ui.registry.addButton('pagebreak', {
82
        icon: 'page-break',
83
        tooltip: 'Page break',
637 daniel-mar 84
        onAction: onAction
597 daniel-mar 85
      });
86
      editor.ui.registry.addMenuItem('pagebreak', {
87
        text: 'Page break',
88
        icon: 'page-break',
637 daniel-mar 89
        onAction: onAction
597 daniel-mar 90
      });
91
    };
92
 
93
    function Plugin () {
637 daniel-mar 94
      global$1.add('pagebreak', function (editor) {
95
        register$1(editor);
597 daniel-mar 96
        register(editor);
637 daniel-mar 97
        setup$1(editor);
597 daniel-mar 98
        setup(editor);
99
      });
100
    }
101
 
102
    Plugin();
103
 
104
}());