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
 
14
    var applyListFormat = function (editor, listName, styleValue) {
15
      var cmd = listName === 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList';
16
      editor.execCommand(cmd, false, styleValue === false ? null : { 'list-style-type': styleValue });
17
    };
18
 
637 daniel-mar 19
    var register$1 = function (editor) {
597 daniel-mar 20
      editor.addCommand('ApplyUnorderedListStyle', function (ui, value) {
21
        applyListFormat(editor, 'UL', value['list-style-type']);
22
      });
23
      editor.addCommand('ApplyOrderedListStyle', function (ui, value) {
24
        applyListFormat(editor, 'OL', value['list-style-type']);
25
      });
26
    };
27
 
637 daniel-mar 28
    var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
597 daniel-mar 29
 
30
    var getNumberStyles = function (editor) {
31
      var styles = editor.getParam('advlist_number_styles', 'default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman');
32
      return styles ? styles.split(/[ ,]/) : [];
33
    };
34
    var getBulletStyles = function (editor) {
35
      var styles = editor.getParam('advlist_bullet_styles', 'default,circle,square');
36
      return styles ? styles.split(/[ ,]/) : [];
37
    };
38
 
39
    var noop = function () {
40
    };
41
    var constant = function (value) {
42
      return function () {
43
        return value;
44
      };
45
    };
637 daniel-mar 46
    var identity = function (x) {
47
      return x;
48
    };
597 daniel-mar 49
    var never = constant(false);
50
    var always = constant(true);
51
 
52
    var none = function () {
53
      return NONE;
54
    };
55
    var NONE = function () {
56
      var call = function (thunk) {
57
        return thunk();
58
      };
637 daniel-mar 59
      var id = identity;
597 daniel-mar 60
      var me = {
61
        fold: function (n, _s) {
62
          return n();
63
        },
64
        isSome: never,
65
        isNone: always,
66
        getOr: id,
67
        getOrThunk: call,
68
        getOrDie: function (msg) {
69
          throw new Error(msg || 'error: getOrDie called on none.');
70
        },
71
        getOrNull: constant(null),
72
        getOrUndefined: constant(undefined),
73
        or: id,
74
        orThunk: call,
75
        map: none,
76
        each: noop,
77
        bind: none,
78
        exists: never,
79
        forall: always,
637 daniel-mar 80
        filter: function () {
81
          return none();
82
        },
597 daniel-mar 83
        toArray: function () {
84
          return [];
85
        },
86
        toString: constant('none()')
87
      };
88
      return me;
89
    }();
90
    var some = function (a) {
91
      var constant_a = constant(a);
92
      var self = function () {
93
        return me;
94
      };
95
      var bind = function (f) {
96
        return f(a);
97
      };
98
      var me = {
99
        fold: function (n, s) {
100
          return s(a);
101
        },
102
        isSome: always,
103
        isNone: never,
104
        getOr: constant_a,
105
        getOrThunk: constant_a,
106
        getOrDie: constant_a,
107
        getOrNull: constant_a,
108
        getOrUndefined: constant_a,
109
        or: self,
110
        orThunk: self,
111
        map: function (f) {
112
          return some(f(a));
113
        },
114
        each: function (f) {
115
          f(a);
116
        },
117
        bind: bind,
118
        exists: bind,
119
        forall: bind,
120
        filter: function (f) {
121
          return f(a) ? me : NONE;
122
        },
123
        toArray: function () {
124
          return [a];
125
        },
126
        toString: function () {
127
          return 'some(' + a + ')';
128
        }
129
      };
130
      return me;
131
    };
132
    var from = function (value) {
133
      return value === null || value === undefined ? NONE : some(value);
134
    };
135
    var Optional = {
136
      some: some,
137
      none: none,
138
      from: from
139
    };
140
 
141
    var isChildOfBody = function (editor, elm) {
142
      return editor.$.contains(editor.getBody(), elm);
143
    };
144
    var isTableCellNode = function (node) {
145
      return node && /^(TH|TD)$/.test(node.nodeName);
146
    };
147
    var isListNode = function (editor) {
148
      return function (node) {
149
        return node && /^(OL|UL|DL)$/.test(node.nodeName) && isChildOfBody(editor, node);
150
      };
151
    };
152
    var getSelectedStyleType = function (editor) {
153
      var listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
154
      var style = editor.dom.getStyle(listElm, 'listStyleType');
155
      return Optional.from(style);
156
    };
157
 
158
    var findIndex = function (list, predicate) {
159
      for (var index = 0; index < list.length; index++) {
160
        var element = list[index];
161
        if (predicate(element)) {
162
          return index;
163
        }
164
      }
165
      return -1;
166
    };
167
    var styleValueToText = function (styleValue) {
168
      return styleValue.replace(/\-/g, ' ').replace(/\b\w/g, function (chr) {
169
        return chr.toUpperCase();
170
      });
171
    };
172
    var isWithinList = function (editor, e, nodeName) {
173
      var tableCellIndex = findIndex(e.parents, isTableCellNode);
174
      var parents = tableCellIndex !== -1 ? e.parents.slice(0, tableCellIndex) : e.parents;
637 daniel-mar 175
      var lists = global.grep(parents, isListNode(editor));
597 daniel-mar 176
      return lists.length > 0 && lists[0].nodeName === nodeName;
177
    };
637 daniel-mar 178
    var makeSetupHandler = function (editor, nodeName) {
179
      return function (api) {
180
        var nodeChangeHandler = function (e) {
181
          api.setActive(isWithinList(editor, e, nodeName));
182
        };
183
        editor.on('NodeChange', nodeChangeHandler);
184
        return function () {
185
          return editor.off('NodeChange', nodeChangeHandler);
186
        };
187
      };
188
    };
597 daniel-mar 189
    var addSplitButton = function (editor, id, tooltip, cmd, nodeName, styles) {
190
      editor.ui.registry.addSplitButton(id, {
191
        tooltip: tooltip,
192
        icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
193
        presets: 'listpreview',
194
        columns: 3,
195
        fetch: function (callback) {
637 daniel-mar 196
          var items = global.map(styles, function (styleValue) {
597 daniel-mar 197
            var iconStyle = nodeName === 'OL' ? 'num' : 'bull';
198
            var iconName = styleValue === 'disc' || styleValue === 'decimal' ? 'default' : styleValue;
199
            var itemValue = styleValue === 'default' ? '' : styleValue;
200
            var displayText = styleValueToText(styleValue);
201
            return {
202
              type: 'choiceitem',
203
              value: itemValue,
204
              icon: 'list-' + iconStyle + '-' + iconName,
205
              text: displayText
206
            };
207
          });
208
          callback(items);
209
        },
210
        onAction: function () {
211
          return editor.execCommand(cmd);
212
        },
213
        onItemAction: function (_splitButtonApi, value) {
214
          applyListFormat(editor, nodeName, value);
215
        },
216
        select: function (value) {
217
          var listStyleType = getSelectedStyleType(editor);
218
          return listStyleType.map(function (listStyle) {
219
            return value === listStyle;
220
          }).getOr(false);
221
        },
637 daniel-mar 222
        onSetup: makeSetupHandler(editor, nodeName)
597 daniel-mar 223
      });
224
    };
225
    var addButton = function (editor, id, tooltip, cmd, nodeName, _styles) {
226
      editor.ui.registry.addToggleButton(id, {
227
        active: false,
228
        tooltip: tooltip,
229
        icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
637 daniel-mar 230
        onSetup: makeSetupHandler(editor, nodeName),
597 daniel-mar 231
        onAction: function () {
232
          return editor.execCommand(cmd);
233
        }
234
      });
235
    };
236
    var addControl = function (editor, id, tooltip, cmd, nodeName, styles) {
237
      if (styles.length > 1) {
238
        addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
239
      } else {
240
        addButton(editor, id, tooltip, cmd, nodeName);
241
      }
242
    };
637 daniel-mar 243
    var register = function (editor) {
597 daniel-mar 244
      addControl(editor, 'numlist', 'Numbered list', 'InsertOrderedList', 'OL', getNumberStyles(editor));
245
      addControl(editor, 'bullist', 'Bullet list', 'InsertUnorderedList', 'UL', getBulletStyles(editor));
246
    };
247
 
248
    function Plugin () {
637 daniel-mar 249
      global$1.add('advlist', function (editor) {
597 daniel-mar 250
        if (editor.hasPlugin('lists')) {
637 daniel-mar 251
          register(editor);
597 daniel-mar 252
          register$1(editor);
253
        } else {
254
          console.error('Please use the Lists plugin together with the Advanced List plugin.');
255
        }
256
      });
257
    }
258
 
259
    Plugin();
260
 
261
}());