Subversion Repositories oidplus

Rev

Rev 1042 | Go to most recent revision | 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
 *
1422 daniel-mar 7
 * Version: 5.10.8 (2023-10-19)
597 daniel-mar 8
 */
9
(function () {
10
    'use strict';
11
 
12
    var Cell = function (initial) {
13
      var value = initial;
14
      var get = function () {
15
        return value;
16
      };
17
      var set = function (v) {
18
        value = v;
19
      };
20
      return {
21
        get: get,
22
        set: set
23
      };
24
    };
25
 
637 daniel-mar 26
    var hasOwnProperty = Object.hasOwnProperty;
27
    var has = function (obj, key) {
28
      return hasOwnProperty.call(obj, key);
29
    };
597 daniel-mar 30
 
637 daniel-mar 31
    var global$2 = tinymce.util.Tools.resolve('tinymce.PluginManager');
32
 
597 daniel-mar 33
    var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
34
 
637 daniel-mar 35
    var global = tinymce.util.Tools.resolve('tinymce.util.Delay');
597 daniel-mar 36
 
37
    var fireResizeEditor = function (editor) {
38
      return editor.fire('ResizeEditor');
39
    };
40
 
41
    var getAutoResizeMinHeight = function (editor) {
42
      return editor.getParam('min_height', editor.getElement().offsetHeight, 'number');
43
    };
44
    var getAutoResizeMaxHeight = function (editor) {
45
      return editor.getParam('max_height', 0, 'number');
46
    };
47
    var getAutoResizeOverflowPadding = function (editor) {
48
      return editor.getParam('autoresize_overflow_padding', 1, 'number');
49
    };
50
    var getAutoResizeBottomMargin = function (editor) {
51
      return editor.getParam('autoresize_bottom_margin', 50, 'number');
52
    };
53
    var shouldAutoResizeOnInit = function (editor) {
54
      return editor.getParam('autoresize_on_init', true, 'boolean');
55
    };
56
 
57
    var isFullscreen = function (editor) {
58
      return editor.plugins.fullscreen && editor.plugins.fullscreen.isFullscreen();
59
    };
60
    var wait = function (editor, oldSize, times, interval, callback) {
637 daniel-mar 61
      global.setEditorTimeout(editor, function () {
597 daniel-mar 62
        resize(editor, oldSize);
63
        if (times--) {
64
          wait(editor, oldSize, times, interval, callback);
65
        } else if (callback) {
66
          callback();
67
        }
68
      }, interval);
69
    };
70
    var toggleScrolling = function (editor, state) {
71
      var body = editor.getBody();
72
      if (body) {
73
        body.style.overflowY = state ? '' : 'hidden';
74
        if (!state) {
75
          body.scrollTop = 0;
76
        }
77
      }
78
    };
79
    var parseCssValueToInt = function (dom, elm, name, computed) {
80
      var value = parseInt(dom.getStyle(elm, name, computed), 10);
81
      return isNaN(value) ? 0 : value;
82
    };
679 daniel-mar 83
    var shouldScrollIntoView = function (trigger) {
84
      if ((trigger === null || trigger === void 0 ? void 0 : trigger.type.toLowerCase()) === 'setcontent') {
85
        var setContentEvent = trigger;
86
        return setContentEvent.selection === true || setContentEvent.paste === true;
87
      } else {
88
        return false;
89
      }
90
    };
91
    var resize = function (editor, oldSize, trigger) {
597 daniel-mar 92
      var dom = editor.dom;
93
      var doc = editor.getDoc();
94
      if (!doc) {
95
        return;
96
      }
97
      if (isFullscreen(editor)) {
98
        toggleScrolling(editor, true);
99
        return;
100
      }
101
      var docEle = doc.documentElement;
102
      var resizeBottomMargin = getAutoResizeBottomMargin(editor);
103
      var resizeHeight = getAutoResizeMinHeight(editor);
104
      var marginTop = parseCssValueToInt(dom, docEle, 'margin-top', true);
105
      var marginBottom = parseCssValueToInt(dom, docEle, 'margin-bottom', true);
106
      var contentHeight = docEle.offsetHeight + marginTop + marginBottom + resizeBottomMargin;
107
      if (contentHeight < 0) {
108
        contentHeight = 0;
109
      }
110
      var containerHeight = editor.getContainer().offsetHeight;
111
      var contentAreaHeight = editor.getContentAreaContainer().offsetHeight;
112
      var chromeHeight = containerHeight - contentAreaHeight;
113
      if (contentHeight + chromeHeight > getAutoResizeMinHeight(editor)) {
114
        resizeHeight = contentHeight + chromeHeight;
115
      }
116
      var maxHeight = getAutoResizeMaxHeight(editor);
117
      if (maxHeight && resizeHeight > maxHeight) {
118
        resizeHeight = maxHeight;
119
        toggleScrolling(editor, true);
120
      } else {
121
        toggleScrolling(editor, false);
122
      }
123
      if (resizeHeight !== oldSize.get()) {
124
        var deltaSize = resizeHeight - oldSize.get();
125
        dom.setStyle(editor.getContainer(), 'height', resizeHeight + 'px');
126
        oldSize.set(resizeHeight);
127
        fireResizeEditor(editor);
128
        if (global$1.browser.isSafari() && global$1.mac) {
129
          var win = editor.getWin();
130
          win.scrollTo(win.pageXOffset, win.pageYOffset);
131
        }
679 daniel-mar 132
        if (editor.hasFocus() && shouldScrollIntoView(trigger)) {
133
          editor.selection.scrollIntoView();
597 daniel-mar 134
        }
135
        if (global$1.webkit && deltaSize < 0) {
679 daniel-mar 136
          resize(editor, oldSize, trigger);
597 daniel-mar 137
        }
138
      }
139
    };
140
    var setup = function (editor, oldSize) {
141
      editor.on('init', function () {
142
        var overflowPadding = getAutoResizeOverflowPadding(editor);
143
        var dom = editor.dom;
144
        dom.setStyles(editor.getDoc().documentElement, { height: 'auto' });
145
        dom.setStyles(editor.getBody(), {
146
          'paddingLeft': overflowPadding,
147
          'paddingRight': overflowPadding,
148
          'min-height': 0
149
        });
150
      });
679 daniel-mar 151
      editor.on('NodeChange SetContent keyup FullscreenStateChanged ResizeContent', function (e) {
152
        resize(editor, oldSize, e);
597 daniel-mar 153
      });
154
      if (shouldAutoResizeOnInit(editor)) {
155
        editor.on('init', function () {
156
          wait(editor, oldSize, 20, 100, function () {
157
            wait(editor, oldSize, 5, 1000);
158
          });
159
        });
160
      }
161
    };
162
 
163
    var register = function (editor, oldSize) {
164
      editor.addCommand('mceAutoResize', function () {
165
        resize(editor, oldSize);
166
      });
167
    };
168
 
169
    function Plugin () {
637 daniel-mar 170
      global$2.add('autoresize', function (editor) {
171
        if (!has(editor.settings, 'resize')) {
597 daniel-mar 172
          editor.settings.resize = false;
173
        }
174
        if (!editor.inline) {
175
          var oldSize = Cell(0);
176
          register(editor, oldSize);
177
          setup(editor, oldSize);
178
        }
179
      });
180
    }
181
 
182
    Plugin();
183
 
184
}());