Passed
Push — master ( 7e07d9...30706c )
by Ron
02:08 queued 12s
created

proto$1.layoutRect   F

Complexity

Conditions 28
Paths > 20000

Size

Total Lines 73
Code Lines 57

Duplication

Lines 73
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 57
nc 320002
nop 1
dl 73
loc 73
c 0
b 0
f 0
cc 28
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Complexity

Complex classes like proto$1.layoutRect often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
(function () {
2
var modern = (function () {
0 ignored issues
show
Unused Code introduced by
The variable modern seems to be never used. Consider removing it.
Loading history...
3
    'use strict';
4
5
    var global = tinymce.util.Tools.resolve('tinymce.ThemeManager');
0 ignored issues
show
Bug introduced by
The variable tinymce seems to be never declared. If this is a global, consider adding a /** global: tinymce */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
7
    var global$1 = tinymce.util.Tools.resolve('tinymce.EditorManager');
8
9
    var global$2 = tinymce.util.Tools.resolve('tinymce.util.Tools');
10
11
    var isBrandingEnabled = function (editor) {
12
      return editor.getParam('branding', true, 'boolean');
13
    };
14
    var hasMenubar = function (editor) {
15
      return getMenubar(editor) !== false;
16
    };
17
    var getMenubar = function (editor) {
18
      return editor.getParam('menubar');
19
    };
20
    var hasStatusbar = function (editor) {
21
      return editor.getParam('statusbar', true, 'boolean');
22
    };
23
    var getToolbarSize = function (editor) {
24
      return editor.getParam('toolbar_items_size');
25
    };
26
    var isReadOnly = function (editor) {
27
      return editor.getParam('readonly', false, 'boolean');
28
    };
29
    var getFixedToolbarContainer = function (editor) {
30
      return editor.getParam('fixed_toolbar_container');
31
    };
32
    var getInlineToolbarPositionHandler = function (editor) {
33
      return editor.getParam('inline_toolbar_position_handler');
34
    };
35
    var getMenu = function (editor) {
36
      return editor.getParam('menu');
37
    };
38
    var getRemovedMenuItems = function (editor) {
39
      return editor.getParam('removed_menuitems', '');
40
    };
41
    var getMinWidth = function (editor) {
42
      return editor.getParam('min_width', 100, 'number');
43
    };
44
    var getMinHeight = function (editor) {
45
      return editor.getParam('min_height', 100, 'number');
46
    };
47
    var getMaxWidth = function (editor) {
48
      return editor.getParam('max_width', 65535, 'number');
49
    };
50
    var getMaxHeight = function (editor) {
51
      return editor.getParam('max_height', 65535, 'number');
52
    };
53
    var isSkinDisabled = function (editor) {
54
      return editor.settings.skin === false;
55
    };
56
    var isInline = function (editor) {
57
      return editor.getParam('inline', false, 'boolean');
58
    };
59
    var getResize = function (editor) {
60
      var resize = editor.getParam('resize', 'vertical');
61
      if (resize === false) {
62
        return 'none';
63
      } else if (resize === 'both') {
64
        return 'both';
65
      } else {
66
        return 'vertical';
67
      }
68
    };
69
    var getSkinUrl = function (editor) {
70
      var settings = editor.settings;
71
      var skin = settings.skin;
72
      var skinUrl = settings.skin_url;
73
      if (skin !== false) {
74
        var skinName = skin ? skin : 'lightgray';
75
        if (skinUrl) {
76
          skinUrl = editor.documentBaseURI.toAbsolute(skinUrl);
77
        } else {
78
          skinUrl = global$1.baseURL + '/skins/' + skinName;
79
        }
80
      }
81
      return skinUrl;
82
    };
83
    var getIndexedToolbars = function (settings, defaultToolbar) {
84
      var toolbars = [];
85
      for (var i = 1; i < 10; i++) {
86
        var toolbar = settings['toolbar' + i];
87
        if (!toolbar) {
88
          break;
89
        }
90
        toolbars.push(toolbar);
91
      }
92
      var mainToolbar = settings.toolbar ? [settings.toolbar] : [defaultToolbar];
93
      return toolbars.length > 0 ? toolbars : mainToolbar;
94
    };
95
    var getToolbars = function (editor) {
96
      var toolbar = editor.getParam('toolbar');
97
      var defaultToolbar = 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image';
98
      if (toolbar === false) {
99
        return [];
100
      } else if (global$2.isArray(toolbar)) {
101
        return global$2.grep(toolbar, function (toolbar) {
102
          return toolbar.length > 0;
103
        });
104
      } else {
105
        return getIndexedToolbars(editor.settings, defaultToolbar);
106
      }
107
    };
108
109
    var global$3 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
110
111
    var global$4 = tinymce.util.Tools.resolve('tinymce.ui.Factory');
112
113
    var global$5 = tinymce.util.Tools.resolve('tinymce.util.I18n');
114
115
    var fireSkinLoaded = function (editor) {
116
      return editor.fire('SkinLoaded');
117
    };
118
    var fireResizeEditor = function (editor) {
119
      return editor.fire('ResizeEditor');
120
    };
121
    var fireBeforeRenderUI = function (editor) {
122
      return editor.fire('BeforeRenderUI');
123
    };
124
    var Events = {
125
      fireSkinLoaded: fireSkinLoaded,
126
      fireResizeEditor: fireResizeEditor,
127
      fireBeforeRenderUI: fireBeforeRenderUI
128
    };
129
130
    var focus = function (panel, type) {
131
      return function () {
132
        var item = panel.find(type)[0];
133
        if (item) {
134
          item.focus(true);
135
        }
136
      };
137
    };
138
    var addKeys = function (editor, panel) {
139
      editor.shortcuts.add('Alt+F9', '', focus(panel, 'menubar'));
140
      editor.shortcuts.add('Alt+F10,F10', '', focus(panel, 'toolbar'));
141
      editor.shortcuts.add('Alt+F11', '', focus(panel, 'elementpath'));
142
      panel.on('cancel', function () {
143
        editor.focus();
144
      });
145
    };
146
    var A11y = { addKeys: addKeys };
147
148
    var global$6 = tinymce.util.Tools.resolve('tinymce.geom.Rect');
149
150
    var global$7 = tinymce.util.Tools.resolve('tinymce.util.Delay');
151
152
    var noop = function () {
153
      var args = [];
154
      for (var _i = 0; _i < arguments.length; _i++) {
155
        args[_i] = arguments[_i];
156
      }
157
    };
158
    var constant = function (value) {
159
      return function () {
160
        return value;
161
      };
162
    };
163
    var never = constant(false);
164
    var always = constant(true);
165
166
    var never$1 = never;
167
    var always$1 = always;
168
    var none = function () {
169
      return NONE;
170
    };
171 View Code Duplication
    var NONE = function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
172
      var eq = function (o) {
173
        return o.isNone();
174
      };
175
      var call$$1 = function (thunk) {
176
        return thunk();
177
      };
178
      var id = function (n) {
179
        return n;
180
      };
181
      var noop$$1 = function () {
182
      };
183
      var nul = function () {
184
        return null;
185
      };
186
      var undef = function () {
187
        return undefined;
188
      };
189
      var me = {
190
        fold: function (n, s) {
0 ignored issues
show
Unused Code introduced by
The parameter s is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
191
          return n();
192
        },
193
        is: never$1,
194
        isSome: never$1,
195
        isNone: always$1,
196
        getOr: id,
197
        getOrThunk: call$$1,
198
        getOrDie: function (msg) {
199
          throw new Error(msg || 'error: getOrDie called on none.');
200
        },
201
        getOrNull: nul,
202
        getOrUndefined: undef,
203
        or: id,
204
        orThunk: call$$1,
205
        map: none,
206
        ap: none,
207
        each: noop$$1,
208
        bind: none,
209
        flatten: none,
210
        exists: never$1,
211
        forall: always$1,
212
        filter: none,
213
        equals: eq,
214
        equals_: eq,
215
        toArray: function () {
216
          return [];
217
        },
218
        toString: constant('none()')
219
      };
220
      if (Object.freeze)
221
        Object.freeze(me);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
222
      return me;
223
    }();
224 View Code Duplication
    var some = function (a) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
225
      var constant_a = function () {
226
        return a;
227
      };
228
      var self = function () {
229
        return me;
230
      };
231
      var map = function (f) {
232
        return some(f(a));
233
      };
234
      var bind = function (f) {
235
        return f(a);
236
      };
237
      var me = {
238
        fold: function (n, s) {
239
          return s(a);
240
        },
241
        is: function (v) {
242
          return a === v;
243
        },
244
        isSome: always$1,
245
        isNone: never$1,
246
        getOr: constant_a,
247
        getOrThunk: constant_a,
248
        getOrDie: constant_a,
249
        getOrNull: constant_a,
250
        getOrUndefined: constant_a,
251
        or: self,
252
        orThunk: self,
253
        map: map,
254
        ap: function (optfab) {
255
          return optfab.fold(none, function (fab) {
256
            return some(fab(a));
257
          });
258
        },
259
        each: function (f) {
260
          f(a);
261
        },
262
        bind: bind,
263
        flatten: constant_a,
264
        exists: bind,
265
        forall: bind,
266
        filter: function (f) {
267
          return f(a) ? me : NONE;
268
        },
269
        equals: function (o) {
270
          return o.is(a);
271
        },
272
        equals_: function (o, elementEq) {
273
          return o.fold(never$1, function (b) {
274
            return elementEq(a, b);
275
          });
276
        },
277
        toArray: function () {
278
          return [a];
279
        },
280
        toString: function () {
281
          return 'some(' + a + ')';
282
        }
283
      };
284
      return me;
285
    };
286
    var from = function (value) {
287
      return value === null || value === undefined ? NONE : some(value);
288
    };
289
    var Option = {
290
      some: some,
291
      none: none,
292
      from: from
293
    };
294
295
    var getUiContainerDelta = function (ctrl) {
296
      var uiContainer = getUiContainer(ctrl);
297
      if (uiContainer && global$3.DOM.getStyle(uiContainer, 'position', true) !== 'static') {
298
        var containerPos = global$3.DOM.getPos(uiContainer);
299
        var dx = uiContainer.scrollLeft - containerPos.x;
300
        var dy = uiContainer.scrollTop - containerPos.y;
301
        return Option.some({
302
          x: dx,
303
          y: dy
304
        });
305
      } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
306
        return Option.none();
307
      }
308
    };
309
    var setUiContainer = function (editor, ctrl) {
310
      var uiContainer = global$3.DOM.select(editor.settings.ui_container)[0];
311
      ctrl.getRoot().uiContainer = uiContainer;
312
    };
313
    var getUiContainer = function (ctrl) {
314
      return ctrl ? ctrl.getRoot().uiContainer : null;
315
    };
316
    var inheritUiContainer = function (fromCtrl, toCtrl) {
317
      return toCtrl.uiContainer = getUiContainer(fromCtrl);
318
    };
319
    var UiContainer = {
320
      getUiContainerDelta: getUiContainerDelta,
321
      setUiContainer: setUiContainer,
322
      getUiContainer: getUiContainer,
323
      inheritUiContainer: inheritUiContainer
324
    };
325
326
    var createToolbar = function (editor, items, size) {
327
      var toolbarItems = [];
328
      var buttonGroup;
329
      if (!items) {
330
        return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
331
      }
332
      global$2.each(items.split(/[ ,]/), function (item) {
333
        var itemName;
334
        var bindSelectorChanged = function () {
335
          var selection = editor.selection;
336
          if (item.settings.stateSelector) {
337
            selection.selectorChanged(item.settings.stateSelector, function (state) {
338
              item.active(state);
339
            }, true);
340
          }
341
          if (item.settings.disabledStateSelector) {
342
            selection.selectorChanged(item.settings.disabledStateSelector, function (state) {
343
              item.disabled(state);
344
            });
345
          }
346
        };
347
        if (item === '|') {
348
          buttonGroup = null;
349
        } else {
350
          if (!buttonGroup) {
351
            buttonGroup = {
352
              type: 'buttongroup',
353
              items: []
354
            };
355
            toolbarItems.push(buttonGroup);
356
          }
357
          if (editor.buttons[item]) {
358
            itemName = item;
359
            item = editor.buttons[itemName];
360
            if (typeof item === 'function') {
361
              item = item();
362
            }
363
            item.type = item.type || 'button';
364
            item.size = size;
365
            item = global$4.create(item);
366
            buttonGroup.items.push(item);
367
            if (editor.initialized) {
368
              bindSelectorChanged();
369
            } else {
370
              editor.on('init', bindSelectorChanged);
371
            }
372
          }
373
        }
374
      });
375
      return {
376
        type: 'toolbar',
377
        layout: 'flow',
378
        items: toolbarItems
379
      };
380
    };
381
    var createToolbars = function (editor, size) {
382
      var toolbars = [];
383
      var addToolbar = function (items) {
384
        if (items) {
385
          toolbars.push(createToolbar(editor, items, size));
386
        }
387
      };
388
      global$2.each(getToolbars(editor), function (toolbar) {
389
        addToolbar(toolbar);
390
      });
391
      if (toolbars.length) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if toolbars.length is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
392
        return {
393
          type: 'panel',
394
          layout: 'stack',
395
          classes: 'toolbar-grp',
396
          ariaRoot: true,
397
          ariaRemember: true,
398
          items: toolbars
399
        };
400
      }
401
    };
402
    var Toolbar = {
403
      createToolbar: createToolbar,
404
      createToolbars: createToolbars
405
    };
406
407
    var DOM = global$3.DOM;
408
    var toClientRect = function (geomRect) {
409
      return {
410
        left: geomRect.x,
411
        top: geomRect.y,
412
        width: geomRect.w,
413
        height: geomRect.h,
414
        right: geomRect.x + geomRect.w,
415
        bottom: geomRect.y + geomRect.h
416
      };
417
    };
418
    var hideAllFloatingPanels = function (editor) {
419
      global$2.each(editor.contextToolbars, function (toolbar) {
420
        if (toolbar.panel) {
421
          toolbar.panel.hide();
422
        }
423
      });
424
    };
425
    var movePanelTo = function (panel, pos) {
426
      panel.moveTo(pos.left, pos.top);
427
    };
428
    var togglePositionClass = function (panel, relPos, predicate) {
429
      relPos = relPos ? relPos.substr(0, 2) : '';
430
      global$2.each({
431
        t: 'down',
432
        b: 'up'
433
      }, function (cls, pos) {
434
        panel.classes.toggle('arrow-' + cls, predicate(pos, relPos.substr(0, 1)));
435
      });
436
      global$2.each({
437
        l: 'left',
438
        r: 'right'
439
      }, function (cls, pos) {
440
        panel.classes.toggle('arrow-' + cls, predicate(pos, relPos.substr(1, 1)));
441
      });
442
    };
443
    var userConstrain = function (handler, x, y, elementRect, contentAreaRect, panelRect) {
444
      panelRect = toClientRect({
445
        x: x,
446
        y: y,
447
        w: panelRect.w,
448
        h: panelRect.h
449
      });
450
      if (handler) {
451
        panelRect = handler({
452
          elementRect: toClientRect(elementRect),
453
          contentAreaRect: toClientRect(contentAreaRect),
454
          panelRect: panelRect
455
        });
456
      }
457
      return panelRect;
458
    };
459
    var addContextualToolbars = function (editor) {
460
      var scrollContainer;
461
      var getContextToolbars = function () {
462
        return editor.contextToolbars || [];
463
      };
464
      var getElementRect = function (elm) {
465
        var pos, targetRect, root;
466
        pos = DOM.getPos(editor.getContentAreaContainer());
467
        targetRect = editor.dom.getRect(elm);
468
        root = editor.dom.getRoot();
469
        if (root.nodeName === 'BODY') {
470
          targetRect.x -= root.ownerDocument.documentElement.scrollLeft || root.scrollLeft;
471
          targetRect.y -= root.ownerDocument.documentElement.scrollTop || root.scrollTop;
472
        }
473
        targetRect.x += pos.x;
474
        targetRect.y += pos.y;
475
        return targetRect;
476
      };
477
      var reposition = function (match, shouldShow) {
478
        var relPos, panelRect, elementRect, contentAreaRect, panel, relRect, testPositions, smallElementWidthThreshold;
479
        var handler = getInlineToolbarPositionHandler(editor);
480
        if (editor.removed) {
481
          return;
482
        }
483
        if (!match || !match.toolbar.panel) {
484
          hideAllFloatingPanels(editor);
485
          return;
486
        }
487
        testPositions = [
488
          'bc-tc',
489
          'tc-bc',
490
          'tl-bl',
491
          'bl-tl',
492
          'tr-br',
493
          'br-tr'
494
        ];
495
        panel = match.toolbar.panel;
496
        if (shouldShow) {
497
          panel.show();
498
        }
499
        elementRect = getElementRect(match.element);
500
        panelRect = DOM.getRect(panel.getEl());
501
        contentAreaRect = DOM.getRect(editor.getContentAreaContainer() || editor.getBody());
502
        var delta = UiContainer.getUiContainerDelta(panel).getOr({
503
          x: 0,
504
          y: 0
505
        });
506
        elementRect.x += delta.x;
507
        elementRect.y += delta.y;
508
        panelRect.x += delta.x;
509
        panelRect.y += delta.y;
510
        contentAreaRect.x += delta.x;
511
        contentAreaRect.y += delta.y;
512
        smallElementWidthThreshold = 25;
513
        if (DOM.getStyle(match.element, 'display', true) !== 'inline') {
514
          var clientRect = match.element.getBoundingClientRect();
515
          elementRect.w = clientRect.width;
516
          elementRect.h = clientRect.height;
517
        }
518
        if (!editor.inline) {
519
          contentAreaRect.w = editor.getDoc().documentElement.offsetWidth;
520
        }
521
        if (editor.selection.controlSelection.isResizable(match.element) && elementRect.w < smallElementWidthThreshold) {
522
          elementRect = global$6.inflate(elementRect, 0, 8);
523
        }
524
        relPos = global$6.findBestRelativePosition(panelRect, elementRect, contentAreaRect, testPositions);
525
        elementRect = global$6.clamp(elementRect, contentAreaRect);
526
        if (relPos) {
527
          relRect = global$6.relativePosition(panelRect, elementRect, relPos);
528
          movePanelTo(panel, userConstrain(handler, relRect.x, relRect.y, elementRect, contentAreaRect, panelRect));
529
        } else {
530
          contentAreaRect.h += panelRect.h;
531
          elementRect = global$6.intersect(contentAreaRect, elementRect);
532
          if (elementRect) {
533
            relPos = global$6.findBestRelativePosition(panelRect, elementRect, contentAreaRect, [
534
              'bc-tc',
535
              'bl-tl',
536
              'br-tr'
537
            ]);
538
            if (relPos) {
539
              relRect = global$6.relativePosition(panelRect, elementRect, relPos);
540
              movePanelTo(panel, userConstrain(handler, relRect.x, relRect.y, elementRect, contentAreaRect, panelRect));
541
            } else {
542
              movePanelTo(panel, userConstrain(handler, elementRect.x, elementRect.y, elementRect, contentAreaRect, panelRect));
543
            }
544
          } else {
545
            panel.hide();
546
          }
547
        }
548
        togglePositionClass(panel, relPos, function (pos1, pos2) {
549
          return pos1 === pos2;
550
        });
551
      };
552
      var repositionHandler = function (show) {
553
        return function () {
554
          var execute = function () {
555
            if (editor.selection) {
556
              reposition(findFrontMostMatch(editor.selection.getNode()), show);
557
            }
558
          };
559
          global$7.requestAnimationFrame(execute);
560
        };
561
      };
562
      var bindScrollEvent = function (panel) {
563
        if (!scrollContainer) {
564
          var reposition_1 = repositionHandler(true);
565
          var uiContainer_1 = UiContainer.getUiContainer(panel);
566
          scrollContainer = editor.selection.getScrollContainer() || editor.getWin();
567
          DOM.bind(scrollContainer, 'scroll', reposition_1);
568
          DOM.bind(uiContainer_1, 'scroll', reposition_1);
569
          editor.on('remove', function () {
570
            DOM.unbind(scrollContainer, 'scroll', reposition_1);
571
            DOM.unbind(uiContainer_1, 'scroll', reposition_1);
572
          });
573
        }
574
      };
575
      var showContextToolbar = function (match) {
576
        var panel;
577
        if (match.toolbar.panel) {
578
          match.toolbar.panel.show();
579
          reposition(match);
580
          return;
581
        }
582
        panel = global$4.create({
583
          type: 'floatpanel',
584
          role: 'dialog',
585
          classes: 'tinymce tinymce-inline arrow',
586
          ariaLabel: 'Inline toolbar',
587
          layout: 'flex',
588
          direction: 'column',
589
          align: 'stretch',
590
          autohide: false,
591
          autofix: true,
592
          fixed: true,
593
          border: 1,
594
          items: Toolbar.createToolbar(editor, match.toolbar.items),
595
          oncancel: function () {
596
            editor.focus();
597
          }
598
        });
599
        UiContainer.setUiContainer(editor, panel);
600
        bindScrollEvent(panel);
601
        match.toolbar.panel = panel;
602
        panel.renderTo().reflow();
603
        reposition(match);
604
      };
605
      var hideAllContextToolbars = function () {
606
        global$2.each(getContextToolbars(), function (toolbar) {
607
          if (toolbar.panel) {
608
            toolbar.panel.hide();
609
          }
610
        });
611
      };
612
      var findFrontMostMatch = function (targetElm) {
613
        var i, y, parentsAndSelf;
614
        var toolbars = getContextToolbars();
615
        parentsAndSelf = editor.$(targetElm).parents().add(targetElm);
616
        for (i = parentsAndSelf.length - 1; i >= 0; i--) {
617
          for (y = toolbars.length - 1; y >= 0; y--) {
618
            if (toolbars[y].predicate(parentsAndSelf[i])) {
619
              return {
620
                toolbar: toolbars[y],
621
                element: parentsAndSelf[i]
622
              };
623
            }
624
          }
625
        }
626
        return null;
627
      };
628
      editor.on('click keyup setContent ObjectResized', function (e) {
629
        if (e.type === 'setcontent' && !e.selection) {
630
          return;
631
        }
632
        global$7.setEditorTimeout(editor, function () {
633
          var match;
634
          match = findFrontMostMatch(editor.selection.getNode());
635
          if (match) {
636
            hideAllContextToolbars();
637
            showContextToolbar(match);
638
          } else {
639
            hideAllContextToolbars();
640
          }
641
        });
642
      });
643
      editor.on('blur hide contextmenu', hideAllContextToolbars);
644
      editor.on('ObjectResizeStart', function () {
645
        var match = findFrontMostMatch(editor.selection.getNode());
646
        if (match && match.toolbar.panel) {
647
          match.toolbar.panel.hide();
648
        }
649
      });
650
      editor.on('ResizeEditor ResizeWindow', repositionHandler(true));
651
      editor.on('nodeChange', repositionHandler(false));
652
      editor.on('remove', function () {
653
        global$2.each(getContextToolbars(), function (toolbar) {
654
          if (toolbar.panel) {
655
            toolbar.panel.remove();
656
          }
657
        });
658
        editor.contextToolbars = {};
659
      });
660
      editor.shortcuts.add('ctrl+F9', '', function () {
661
        var match = findFrontMostMatch(editor.selection.getNode());
662
        if (match && match.toolbar.panel) {
663
          match.toolbar.panel.items()[0].focus();
664
        }
665
      });
666
    };
667
    var ContextToolbars = { addContextualToolbars: addContextualToolbars };
668
669
    var typeOf = function (x) {
670
      if (x === null)
671
        return 'null';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
672
      var t = typeof x;
673
      if (t === 'object' && Array.prototype.isPrototypeOf(x))
674
        return 'array';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
675
      if (t === 'object' && String.prototype.isPrototypeOf(x))
676
        return 'string';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
677
      return t;
678
    };
679
    var isType = function (type) {
680
      return function (value) {
681
        return typeOf(value) === type;
682
      };
683
    };
684
    var isFunction = isType('function');
685
    var isNumber = isType('number');
686
687
    var rawIndexOf = function () {
688
      var pIndexOf = Array.prototype.indexOf;
689
      var fastIndex = function (xs, x) {
690
        return pIndexOf.call(xs, x);
691
      };
692
      var slowIndex = function (xs, x) {
693
        return slowIndexOf(xs, x);
694
      };
695
      return pIndexOf === undefined ? slowIndex : fastIndex;
696
    }();
697
    var indexOf = function (xs, x) {
698
      var r = rawIndexOf(xs, x);
699
      return r === -1 ? Option.none() : Option.some(r);
700
    };
701
    var exists = function (xs, pred) {
702
      return findIndex(xs, pred).isSome();
703
    };
704
    var map = function (xs, f) {
705
      var len = xs.length;
706
      var r = new Array(len);
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
707
      for (var i = 0; i < len; i++) {
708
        var x = xs[i];
709
        r[i] = f(x, i, xs);
710
      }
711
      return r;
712
    };
713
    var each = function (xs, f) {
714
      for (var i = 0, len = xs.length; i < len; i++) {
715
        var x = xs[i];
716
        f(x, i, xs);
717
      }
718
    };
719
    var filter = function (xs, pred) {
720
      var r = [];
721
      for (var i = 0, len = xs.length; i < len; i++) {
722
        var x = xs[i];
723
        if (pred(x, i, xs)) {
724
          r.push(x);
725
        }
726
      }
727
      return r;
728
    };
729
    var foldl = function (xs, f, acc) {
730
      each(xs, function (x) {
731
        acc = f(acc, x);
732
      });
733
      return acc;
734
    };
735
    var find = function (xs, pred) {
736
      for (var i = 0, len = xs.length; i < len; i++) {
737
        var x = xs[i];
738
        if (pred(x, i, xs)) {
739
          return Option.some(x);
740
        }
741
      }
742
      return Option.none();
743
    };
744
    var findIndex = function (xs, pred) {
745
      for (var i = 0, len = xs.length; i < len; i++) {
746
        var x = xs[i];
747
        if (pred(x, i, xs)) {
748
          return Option.some(i);
749
        }
750
      }
751
      return Option.none();
752
    };
753
    var slowIndexOf = function (xs, x) {
754
      for (var i = 0, len = xs.length; i < len; ++i) {
755
        if (xs[i] === x) {
756
          return i;
757
        }
758
      }
759
      return -1;
760
    };
761
    var push = Array.prototype.push;
762
    var flatten = function (xs) {
763
      var r = [];
764
      for (var i = 0, len = xs.length; i < len; ++i) {
765
        if (!Array.prototype.isPrototypeOf(xs[i]))
766
          throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
767
        push.apply(r, xs[i]);
768
      }
769
      return r;
770
    };
771
    var slice = Array.prototype.slice;
772
    var from$1 = isFunction(Array.from) ? Array.from : function (x) {
0 ignored issues
show
Unused Code introduced by
The variable from$1 seems to be never used. Consider removing it.
Loading history...
773
      return slice.call(x);
774
    };
775
776
    var defaultMenus = {
777
      file: {
778
        title: 'File',
779
        items: 'newdocument restoredraft | preview | print'
780
      },
781
      edit: {
782
        title: 'Edit',
783
        items: 'undo redo | cut copy paste pastetext | selectall'
784
      },
785
      view: {
786
        title: 'View',
787
        items: 'code | visualaid visualchars visualblocks | spellchecker | preview fullscreen'
788
      },
789
      insert: {
790
        title: 'Insert',
791
        items: 'image link media template codesample inserttable | charmap hr | pagebreak nonbreaking anchor toc | insertdatetime'
792
      },
793
      format: {
794
        title: 'Format',
795
        items: 'bold italic underline strikethrough superscript subscript codeformat | blockformats align | removeformat'
796
      },
797
      tools: {
798
        title: 'Tools',
799
        items: 'spellchecker spellcheckerlanguage | a11ycheck code'
800
      },
801
      table: { title: 'Table' },
802
      help: { title: 'Help' }
803
    };
804
    var delimiterMenuNamePair = function () {
805
      return {
806
        name: '|',
807
        item: { text: '|' }
808
      };
809
    };
810
    var createMenuNameItemPair = function (name, item) {
811
      var menuItem = item ? {
812
        name: name,
813
        item: item
814
      } : null;
815
      return name === '|' ? delimiterMenuNamePair() : menuItem;
816
    };
817
    var hasItemName = function (namedMenuItems, name) {
818
      return findIndex(namedMenuItems, function (namedMenuItem) {
819
        return namedMenuItem.name === name;
820
      }).isSome();
821
    };
822
    var isSeparator = function (namedMenuItem) {
823
      return namedMenuItem && namedMenuItem.item.text === '|';
824
    };
825
    var cleanupMenu = function (namedMenuItems, removedMenuItems) {
826
      var menuItemsPass1 = filter(namedMenuItems, function (namedMenuItem) {
827
        return removedMenuItems.hasOwnProperty(namedMenuItem.name) === false;
828
      });
829
      var menuItemsPass2 = filter(menuItemsPass1, function (namedMenuItem, i, namedMenuItems) {
830
        return !isSeparator(namedMenuItem) || !isSeparator(namedMenuItems[i - 1]);
831
      });
832
      return filter(menuItemsPass2, function (namedMenuItem, i, namedMenuItems) {
833
        return !isSeparator(namedMenuItem) || i > 0 && i < namedMenuItems.length - 1;
834
      });
835
    };
836
    var createMenu = function (editorMenuItems, menus, removedMenuItems, context) {
837
      var menuButton, menu, namedMenuItems, isUserDefined;
838
      if (menus) {
839
        menu = menus[context];
840
        isUserDefined = true;
841
      } else {
842
        menu = defaultMenus[context];
843
      }
844
      if (menu) {
845
        menuButton = { text: menu.title };
846
        namedMenuItems = [];
847
        global$2.each((menu.items || '').split(/[ ,]/), function (name) {
848
          var namedMenuItem = createMenuNameItemPair(name, editorMenuItems[name]);
849
          if (namedMenuItem) {
850
            namedMenuItems.push(namedMenuItem);
851
          }
852
        });
853
        if (!isUserDefined) {
854
          global$2.each(editorMenuItems, function (item, name) {
855
            if (item.context === context && !hasItemName(namedMenuItems, name)) {
856
              if (item.separator === 'before') {
857
                namedMenuItems.push(delimiterMenuNamePair());
858
              }
859
              if (item.prependToContext) {
860
                namedMenuItems.unshift(createMenuNameItemPair(name, item));
861
              } else {
862
                namedMenuItems.push(createMenuNameItemPair(name, item));
863
              }
864
              if (item.separator === 'after') {
865
                namedMenuItems.push(delimiterMenuNamePair());
866
              }
867
            }
868
          });
869
        }
870
        menuButton.menu = map(cleanupMenu(namedMenuItems, removedMenuItems), function (menuItem) {
871
          return menuItem.item;
872
        });
873
        if (!menuButton.menu.length) {
874
          return null;
875
        }
876
      }
877
      return menuButton;
0 ignored issues
show
Bug introduced by
The variable menuButton does not seem to be initialized in case menu on line 844 is false. Are you sure this can never be the case?
Loading history...
878
    };
879
    var getDefaultMenubar = function (editor) {
880
      var name;
881
      var defaultMenuBar = [];
882
      var menu = getMenu(editor);
883
      if (menu) {
884
        for (name in menu) {
885
          defaultMenuBar.push(name);
886
        }
887
      } else {
888
        for (name in defaultMenus) {
889
          defaultMenuBar.push(name);
890
        }
891
      }
892
      return defaultMenuBar;
893
    };
894
    var createMenuButtons = function (editor) {
895
      var menuButtons = [];
896
      var defaultMenuBar = getDefaultMenubar(editor);
897
      var removedMenuItems = global$2.makeMap(getRemovedMenuItems(editor).split(/[ ,]/));
898
      var menubar = getMenubar(editor);
899
      var enabledMenuNames = typeof menubar === 'string' ? menubar.split(/[ ,]/) : defaultMenuBar;
900
      for (var i = 0; i < enabledMenuNames.length; i++) {
901
        var menuItems = enabledMenuNames[i];
902
        var menu = createMenu(editor.menuItems, getMenu(editor), removedMenuItems, menuItems);
903
        if (menu) {
904
          menuButtons.push(menu);
905
        }
906
      }
907
      return menuButtons;
908
    };
909
    var Menubar = { createMenuButtons: createMenuButtons };
910
911
    var DOM$1 = global$3.DOM;
912
    var getSize = function (elm) {
913
      return {
914
        width: elm.clientWidth,
915
        height: elm.clientHeight
916
      };
917
    };
918
    var resizeTo = function (editor, width, height) {
919
      var containerElm, iframeElm, containerSize, iframeSize;
920
      containerElm = editor.getContainer();
921
      iframeElm = editor.getContentAreaContainer().firstChild;
922
      containerSize = getSize(containerElm);
923
      iframeSize = getSize(iframeElm);
924
      if (width !== null) {
925
        width = Math.max(getMinWidth(editor), width);
926
        width = Math.min(getMaxWidth(editor), width);
927
        DOM$1.setStyle(containerElm, 'width', width + (containerSize.width - iframeSize.width));
928
        DOM$1.setStyle(iframeElm, 'width', width);
929
      }
930
      height = Math.max(getMinHeight(editor), height);
931
      height = Math.min(getMaxHeight(editor), height);
932
      DOM$1.setStyle(iframeElm, 'height', height);
933
      Events.fireResizeEditor(editor);
934
    };
935
    var resizeBy = function (editor, dw, dh) {
936
      var elm = editor.getContentAreaContainer();
937
      resizeTo(editor, elm.clientWidth + dw, elm.clientHeight + dh);
938
    };
939
    var Resize = {
940
      resizeTo: resizeTo,
941
      resizeBy: resizeBy
942
    };
943
944
    var global$8 = tinymce.util.Tools.resolve('tinymce.Env');
945
946
    var api = function (elm) {
947
      return {
948
        element: function () {
949
          return elm;
950
        }
951
      };
952
    };
953
    var trigger = function (sidebar, panel, callbackName) {
954
      var callback = sidebar.settings[callbackName];
955
      if (callback) {
956
        callback(api(panel.getEl('body')));
957
      }
958
    };
959
    var hidePanels = function (name, container, sidebars) {
960
      global$2.each(sidebars, function (sidebar) {
961
        var panel = container.items().filter('#' + sidebar.name)[0];
962
        if (panel && panel.visible() && sidebar.name !== name) {
963
          trigger(sidebar, panel, 'onhide');
964
          panel.visible(false);
965
        }
966
      });
967
    };
968
    var deactivateButtons = function (toolbar) {
969
      toolbar.items().each(function (ctrl) {
970
        ctrl.active(false);
971
      });
972
    };
973
    var findSidebar = function (sidebars, name) {
974
      return global$2.grep(sidebars, function (sidebar) {
975
        return sidebar.name === name;
976
      })[0];
977
    };
978
    var showPanel = function (editor, name, sidebars) {
979
      return function (e) {
980
        var btnCtrl = e.control;
981
        var container = btnCtrl.parents().filter('panel')[0];
982
        var panel = container.find('#' + name)[0];
983
        var sidebar = findSidebar(sidebars, name);
984
        hidePanels(name, container, sidebars);
985
        deactivateButtons(btnCtrl.parent());
986
        if (panel && panel.visible()) {
987
          trigger(sidebar, panel, 'onhide');
988
          panel.hide();
989
          btnCtrl.active(false);
990
        } else {
991
          if (panel) {
992
            panel.show();
993
            trigger(sidebar, panel, 'onshow');
994
          } else {
995
            panel = global$4.create({
996
              type: 'container',
997
              name: name,
998
              layout: 'stack',
999
              classes: 'sidebar-panel',
1000
              html: ''
1001
            });
1002
            container.prepend(panel);
1003
            trigger(sidebar, panel, 'onrender');
1004
            trigger(sidebar, panel, 'onshow');
1005
          }
1006
          btnCtrl.active(true);
1007
        }
1008
        Events.fireResizeEditor(editor);
1009
      };
1010
    };
1011
    var isModernBrowser = function () {
1012
      return !global$8.ie || global$8.ie >= 11;
1013
    };
1014
    var hasSidebar = function (editor) {
1015
      return isModernBrowser() && editor.sidebars ? editor.sidebars.length > 0 : false;
1016
    };
1017
    var createSidebar = function (editor) {
1018
      var buttons = global$2.map(editor.sidebars, function (sidebar) {
1019
        var settings = sidebar.settings;
1020
        return {
1021
          type: 'button',
1022
          icon: settings.icon,
1023
          image: settings.image,
1024
          tooltip: settings.tooltip,
1025
          onclick: showPanel(editor, sidebar.name, editor.sidebars)
1026
        };
1027
      });
1028
      return {
1029
        type: 'panel',
1030
        name: 'sidebar',
1031
        layout: 'stack',
1032
        classes: 'sidebar',
1033
        items: [{
1034
            type: 'toolbar',
1035
            layout: 'stack',
1036
            classes: 'sidebar-toolbar',
1037
            items: buttons
1038
          }]
1039
      };
1040
    };
1041
    var Sidebar = {
1042
      hasSidebar: hasSidebar,
1043
      createSidebar: createSidebar
1044
    };
1045
1046
    var fireSkinLoaded$1 = function (editor) {
1047
      var done = function () {
1048
        editor._skinLoaded = true;
1049
        Events.fireSkinLoaded(editor);
1050
      };
1051
      return function () {
1052
        if (editor.initialized) {
1053
          done();
1054
        } else {
1055
          editor.on('init', done);
1056
        }
1057
      };
1058
    };
1059
    var SkinLoaded = { fireSkinLoaded: fireSkinLoaded$1 };
1060
1061
    var DOM$2 = global$3.DOM;
1062
    var switchMode = function (panel) {
1063
      return function (e) {
1064
        panel.find('*').disabled(e.mode === 'readonly');
1065
      };
1066
    };
1067
    var editArea = function (border) {
1068
      return {
1069
        type: 'panel',
1070
        name: 'iframe',
1071
        layout: 'stack',
1072
        classes: 'edit-area',
1073
        border: border,
1074
        html: ''
1075
      };
1076
    };
1077
    var editAreaContainer = function (editor) {
1078
      return {
1079
        type: 'panel',
1080
        layout: 'stack',
1081
        classes: 'edit-aria-container',
1082
        border: '1 0 0 0',
1083
        items: [
1084
          editArea('0'),
1085
          Sidebar.createSidebar(editor)
1086
        ]
1087
      };
1088
    };
1089
    var render = function (editor, theme, args) {
1090
      var panel, resizeHandleCtrl, startSize;
1091
      if (isSkinDisabled(editor) === false && args.skinUiCss) {
1092
        DOM$2.styleSheetLoader.load(args.skinUiCss, SkinLoaded.fireSkinLoaded(editor));
1093
      } else {
1094
        SkinLoaded.fireSkinLoaded(editor)();
1095
      }
1096
      panel = theme.panel = global$4.create({
1097
        type: 'panel',
1098
        role: 'application',
1099
        classes: 'tinymce',
1100
        style: 'visibility: hidden',
1101
        layout: 'stack',
1102
        border: 1,
1103
        items: [
1104
          {
1105
            type: 'container',
1106
            classes: 'top-part',
1107
            items: [
1108
              hasMenubar(editor) === false ? null : {
1109
                type: 'menubar',
1110
                border: '0 0 1 0',
1111
                items: Menubar.createMenuButtons(editor)
1112
              },
1113
              Toolbar.createToolbars(editor, getToolbarSize(editor))
1114
            ]
1115
          },
1116
          Sidebar.hasSidebar(editor) ? editAreaContainer(editor) : editArea('1 0 0 0')
1117
        ]
1118
      });
1119
      UiContainer.setUiContainer(editor, panel);
1120
      if (getResize(editor) !== 'none') {
1121
        resizeHandleCtrl = {
1122
          type: 'resizehandle',
1123
          direction: getResize(editor),
1124
          onResizeStart: function () {
1125
            var elm = editor.getContentAreaContainer().firstChild;
1126
            startSize = {
1127
              width: elm.clientWidth,
1128
              height: elm.clientHeight
1129
            };
1130
          },
1131
          onResize: function (e) {
1132
            if (getResize(editor) === 'both') {
1133
              Resize.resizeTo(editor, startSize.width + e.deltaX, startSize.height + e.deltaY);
1134
            } else {
1135
              Resize.resizeTo(editor, null, startSize.height + e.deltaY);
1136
            }
1137
          }
1138
        };
1139
      }
1140
      if (hasStatusbar(editor)) {
1141
        var linkHtml = '<a href="https://www.tinymce.com/?utm_campaign=editor_referral&amp;utm_medium=poweredby&amp;utm_source=tinymce" rel="noopener" target="_blank" role="presentation" tabindex="-1">tinymce</a>';
1142
        var html = global$5.translate([
1143
          'Powered by {0}',
1144
          linkHtml
1145
        ]);
1146
        var brandingLabel = isBrandingEnabled(editor) ? {
1147
          type: 'label',
1148
          classes: 'branding',
1149
          html: ' ' + html
1150
        } : null;
1151
        panel.add({
1152
          type: 'panel',
1153
          name: 'statusbar',
1154
          classes: 'statusbar',
1155
          layout: 'flow',
1156
          border: '1 0 0 0',
1157
          ariaRoot: true,
1158
          items: [
1159
            {
1160
              type: 'elementpath',
1161
              editor: editor
1162
            },
1163
            resizeHandleCtrl,
0 ignored issues
show
Bug introduced by
The variable resizeHandleCtrl does not seem to be initialized in case getResize(editor) !== "none" on line 1120 is false. Are you sure this can never be the case?
Loading history...
1164
            brandingLabel
1165
          ]
1166
        });
1167
      }
1168
      Events.fireBeforeRenderUI(editor);
1169
      editor.on('SwitchMode', switchMode(panel));
1170
      panel.renderBefore(args.targetNode).reflow();
1171
      if (isReadOnly(editor)) {
1172
        editor.setMode('readonly');
1173
      }
1174
      if (args.width) {
1175
        DOM$2.setStyle(panel.getEl(), 'width', args.width);
1176
      }
1177
      editor.on('remove', function () {
1178
        panel.remove();
1179
        panel = null;
1180
      });
1181
      A11y.addKeys(editor, panel);
1182
      ContextToolbars.addContextualToolbars(editor);
1183
      return {
1184
        iframeContainer: panel.find('#iframe')[0].getEl(),
1185
        editorContainer: panel.getEl()
1186
      };
1187
    };
1188
    var Iframe = { render: render };
1189
1190
    var global$9 = tinymce.util.Tools.resolve('tinymce.dom.DomQuery');
1191
1192
    var count = 0;
1193
    var funcs = {
1194
      id: function () {
1195
        return 'mceu_' + count++;
1196
      },
1197
      create: function (name$$1, attrs, children) {
1198
        var elm = document.createElement(name$$1);
1199
        global$3.DOM.setAttribs(elm, attrs);
1200
        if (typeof children === 'string') {
1201
          elm.innerHTML = children;
1202
        } else {
1203
          global$2.each(children, function (child) {
1204
            if (child.nodeType) {
1205
              elm.appendChild(child);
1206
            }
1207
          });
1208
        }
1209
        return elm;
1210
      },
1211
      createFragment: function (html) {
1212
        return global$3.DOM.createFragment(html);
1213
      },
1214
      getWindowSize: function () {
1215
        return global$3.DOM.getViewPort();
1216
      },
1217
      getSize: function (elm) {
1218
        var width, height;
1219
        if (elm.getBoundingClientRect) {
1220
          var rect = elm.getBoundingClientRect();
1221
          width = Math.max(rect.width || rect.right - rect.left, elm.offsetWidth);
1222
          height = Math.max(rect.height || rect.bottom - rect.bottom, elm.offsetHeight);
1223
        } else {
1224
          width = elm.offsetWidth;
1225
          height = elm.offsetHeight;
1226
        }
1227
        return {
1228
          width: width,
1229
          height: height
1230
        };
1231
      },
1232
      getPos: function (elm, root) {
1233
        return global$3.DOM.getPos(elm, root || funcs.getContainer());
1234
      },
1235
      getContainer: function () {
1236
        return global$8.container ? global$8.container : document.body;
1237
      },
1238
      getViewPort: function (win) {
1239
        return global$3.DOM.getViewPort(win);
1240
      },
1241
      get: function (id) {
1242
        return document.getElementById(id);
1243
      },
1244
      addClass: function (elm, cls) {
1245
        return global$3.DOM.addClass(elm, cls);
1246
      },
1247
      removeClass: function (elm, cls) {
1248
        return global$3.DOM.removeClass(elm, cls);
1249
      },
1250
      hasClass: function (elm, cls) {
1251
        return global$3.DOM.hasClass(elm, cls);
1252
      },
1253
      toggleClass: function (elm, cls, state) {
1254
        return global$3.DOM.toggleClass(elm, cls, state);
1255
      },
1256
      css: function (elm, name$$1, value) {
1257
        return global$3.DOM.setStyle(elm, name$$1, value);
1258
      },
1259
      getRuntimeStyle: function (elm, name$$1) {
1260
        return global$3.DOM.getStyle(elm, name$$1, true);
1261
      },
1262
      on: function (target, name$$1, callback, scope) {
1263
        return global$3.DOM.bind(target, name$$1, callback, scope);
1264
      },
1265
      off: function (target, name$$1, callback) {
1266
        return global$3.DOM.unbind(target, name$$1, callback);
1267
      },
1268
      fire: function (target, name$$1, args) {
1269
        return global$3.DOM.fire(target, name$$1, args);
1270
      },
1271
      innerHtml: function (elm, html) {
1272
        global$3.DOM.setHTML(elm, html);
1273
      }
1274
    };
1275
1276
    var isStatic = function (elm) {
1277
      return funcs.getRuntimeStyle(elm, 'position') === 'static';
1278
    };
1279
    var isFixed = function (ctrl) {
1280
      return ctrl.state.get('fixed');
1281
    };
1282 View Code Duplication
    function calculateRelativePosition(ctrl, targetElm, rel) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1283
      var ctrlElm, pos, x, y, selfW, selfH, targetW, targetH, viewport, size;
1284
      viewport = getWindowViewPort();
1285
      pos = funcs.getPos(targetElm, UiContainer.getUiContainer(ctrl));
1286
      x = pos.x;
1287
      y = pos.y;
1288
      if (isFixed(ctrl) && isStatic(document.body)) {
1289
        x -= viewport.x;
1290
        y -= viewport.y;
1291
      }
1292
      ctrlElm = ctrl.getEl();
1293
      size = funcs.getSize(ctrlElm);
1294
      selfW = size.width;
1295
      selfH = size.height;
1296
      size = funcs.getSize(targetElm);
1297
      targetW = size.width;
1298
      targetH = size.height;
1299
      rel = (rel || '').split('');
1300
      if (rel[0] === 'b') {
1301
        y += targetH;
1302
      }
1303
      if (rel[1] === 'r') {
1304
        x += targetW;
1305
      }
1306
      if (rel[0] === 'c') {
1307
        y += Math.round(targetH / 2);
1308
      }
1309
      if (rel[1] === 'c') {
1310
        x += Math.round(targetW / 2);
1311
      }
1312
      if (rel[3] === 'b') {
1313
        y -= selfH;
1314
      }
1315
      if (rel[4] === 'r') {
1316
        x -= selfW;
1317
      }
1318
      if (rel[3] === 'c') {
1319
        y -= Math.round(selfH / 2);
1320
      }
1321
      if (rel[4] === 'c') {
1322
        x -= Math.round(selfW / 2);
1323
      }
1324
      return {
1325
        x: x,
1326
        y: y,
1327
        w: selfW,
1328
        h: selfH
1329
      };
1330
    }
1331
    var getUiContainerViewPort = function (customUiContainer) {
1332
      return {
1333
        x: 0,
1334
        y: 0,
1335
        w: customUiContainer.scrollWidth - 1,
1336
        h: customUiContainer.scrollHeight - 1
1337
      };
1338
    };
1339
    var getWindowViewPort = function () {
1340
      var win = window;
1341
      var x = Math.max(win.pageXOffset, document.body.scrollLeft, document.documentElement.scrollLeft);
1342
      var y = Math.max(win.pageYOffset, document.body.scrollTop, document.documentElement.scrollTop);
1343
      var w = win.innerWidth || document.documentElement.clientWidth;
1344
      var h = win.innerHeight || document.documentElement.clientHeight;
1345
      return {
1346
        x: x,
1347
        y: y,
1348
        w: w,
1349
        h: h
1350
      };
1351
    };
1352
    var getViewPortRect = function (ctrl) {
1353
      var customUiContainer = UiContainer.getUiContainer(ctrl);
1354
      return customUiContainer && !isFixed(ctrl) ? getUiContainerViewPort(customUiContainer) : getWindowViewPort();
1355
    };
1356
    var Movable = {
1357 View Code Duplication
      testMoveRel: function (elm, rels) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1358
        var viewPortRect = getViewPortRect(this);
1359
        for (var i = 0; i < rels.length; i++) {
1360
          var pos = calculateRelativePosition(this, elm, rels[i]);
1361
          if (isFixed(this)) {
1362
            if (pos.x > 0 && pos.x + pos.w < viewPortRect.w && pos.y > 0 && pos.y + pos.h < viewPortRect.h) {
1363
              return rels[i];
1364
            }
1365
          } else {
1366
            if (pos.x > viewPortRect.x && pos.x + pos.w < viewPortRect.w + viewPortRect.x && pos.y > viewPortRect.y && pos.y + pos.h < viewPortRect.h + viewPortRect.y) {
1367
              return rels[i];
1368
            }
1369
          }
1370
        }
1371
        return rels[0];
1372
      },
1373
      moveRel: function (elm, rel) {
1374
        if (typeof rel !== 'string') {
1375
          rel = this.testMoveRel(elm, rel);
1376
        }
1377
        var pos = calculateRelativePosition(this, elm, rel);
1378
        return this.moveTo(pos.x, pos.y);
1379
      },
1380
      moveBy: function (dx, dy) {
1381
        var self$$1 = this, rect = self$$1.layoutRect();
1382
        self$$1.moveTo(rect.x + dx, rect.y + dy);
1383
        return self$$1;
1384
      },
1385 View Code Duplication
      moveTo: function (x, y) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1386
        var self$$1 = this;
1387
        function constrain(value, max, size) {
1388
          if (value < 0) {
1389
            return 0;
1390
          }
1391
          if (value + size > max) {
1392
            value = max - size;
1393
            return value < 0 ? 0 : value;
1394
          }
1395
          return value;
1396
        }
1397
        if (self$$1.settings.constrainToViewport) {
1398
          var viewPortRect = getViewPortRect(this);
1399
          var layoutRect = self$$1.layoutRect();
1400
          x = constrain(x, viewPortRect.w + viewPortRect.x, layoutRect.w);
1401
          y = constrain(y, viewPortRect.h + viewPortRect.y, layoutRect.h);
1402
        }
1403
        var uiContainer = UiContainer.getUiContainer(self$$1);
1404
        if (uiContainer && isStatic(uiContainer) && !isFixed(self$$1)) {
1405
          x -= uiContainer.scrollLeft;
1406
          y -= uiContainer.scrollTop;
1407
        }
1408
        if (uiContainer) {
1409
          x += 1;
1410
          y += 1;
1411
        }
1412
        if (self$$1.state.get('rendered')) {
1413
          self$$1.layoutRect({
1414
            x: x,
1415
            y: y
1416
          }).repaint();
1417
        } else {
1418
          self$$1.settings.x = x;
1419
          self$$1.settings.y = y;
1420
        }
1421
        self$$1.fire('move', {
1422
          x: x,
1423
          y: y
1424
        });
1425
        return self$$1;
1426
      }
1427
    };
1428
1429
    var global$a = tinymce.util.Tools.resolve('tinymce.util.Class');
1430
1431
    var global$b = tinymce.util.Tools.resolve('tinymce.util.EventDispatcher');
1432
1433
    var BoxUtils = {
1434 View Code Duplication
      parseBox: function (value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1435
        var len;
1436
        var radix = 10;
1437
        if (!value) {
1438
          return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
1439
        }
1440
        if (typeof value === 'number') {
1441
          value = value || 0;
1442
          return {
1443
            top: value,
1444
            left: value,
1445
            bottom: value,
1446
            right: value
1447
          };
1448
        }
1449
        value = value.split(' ');
1450
        len = value.length;
1451
        if (len === 1) {
1452
          value[1] = value[2] = value[3] = value[0];
1453
        } else if (len === 2) {
1454
          value[2] = value[0];
1455
          value[3] = value[1];
1456
        } else if (len === 3) {
1457
          value[3] = value[1];
1458
        }
1459
        return {
1460
          top: parseInt(value[0], radix) || 0,
1461
          right: parseInt(value[1], radix) || 0,
1462
          bottom: parseInt(value[2], radix) || 0,
1463
          left: parseInt(value[3], radix) || 0
1464
        };
1465
      },
1466 View Code Duplication
      measureBox: function (elm, prefix) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1467
        function getStyle(name) {
1468
          var defaultView = elm.ownerDocument.defaultView;
1469
          if (defaultView) {
1470
            var computedStyle = defaultView.getComputedStyle(elm, null);
1471
            if (computedStyle) {
1472
              name = name.replace(/[A-Z]/g, function (a) {
1473
                return '-' + a;
1474
              });
1475
              return computedStyle.getPropertyValue(name);
1476
            } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
1477
              return null;
1478
            }
1479
          }
1480
          return elm.currentStyle[name];
1481
        }
1482
        function getSide(name) {
1483
          var val = parseFloat(getStyle(name));
1484
          return isNaN(val) ? 0 : val;
1485
        }
1486
        return {
1487
          top: getSide(prefix + 'TopWidth'),
1488
          right: getSide(prefix + 'RightWidth'),
1489
          bottom: getSide(prefix + 'BottomWidth'),
1490
          left: getSide(prefix + 'LeftWidth')
1491
        };
1492
      }
1493
    };
1494
1495
    function noop$1() {
1496
    }
1497
    function ClassList(onchange) {
1498
      this.cls = [];
1499
      this.cls._map = {};
1500
      this.onchange = onchange || noop$1;
1501
      this.prefix = '';
1502
    }
1503
    global$2.extend(ClassList.prototype, {
1504
      add: function (cls) {
1505
        if (cls && !this.contains(cls)) {
1506
          this.cls._map[cls] = true;
1507
          this.cls.push(cls);
1508
          this._change();
1509
        }
1510
        return this;
1511
      },
1512
      remove: function (cls) {
1513
        if (this.contains(cls)) {
1514
          var i = void 0;
0 ignored issues
show
Unused Code introduced by
The assignment to variable i seems to be never used. Consider removing it.
Loading history...
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
1515
          for (i = 0; i < this.cls.length; i++) {
1516
            if (this.cls[i] === cls) {
1517
              break;
1518
            }
1519
          }
1520
          this.cls.splice(i, 1);
1521
          delete this.cls._map[cls];
1522
          this._change();
1523
        }
1524
        return this;
1525
      },
1526
      toggle: function (cls, state) {
1527
        var curState = this.contains(cls);
1528
        if (curState !== state) {
1529
          if (curState) {
1530
            this.remove(cls);
1531
          } else {
1532
            this.add(cls);
1533
          }
1534
          this._change();
1535
        }
1536
        return this;
1537
      },
1538
      contains: function (cls) {
1539
        return !!this.cls._map[cls];
1540
      },
1541
      _change: function () {
1542
        delete this.clsValue;
1543
        this.onchange.call(this);
1544
      }
1545
    });
1546
    ClassList.prototype.toString = function () {
1547
      var value;
1548
      if (this.clsValue) {
1549
        return this.clsValue;
1550
      }
1551
      value = '';
1552
      for (var i = 0; i < this.cls.length; i++) {
1553
        if (i > 0) {
1554
          value += ' ';
1555
        }
1556
        value += this.prefix + this.cls[i];
1557
      }
1558
      return value;
1559
    };
1560
1561
    function unique(array) {
1562
      var uniqueItems = [];
1563
      var i = array.length, item;
1564
      while (i--) {
1565
        item = array[i];
1566
        if (!item.__checked) {
1567
          uniqueItems.push(item);
1568
          item.__checked = 1;
1569
        }
1570
      }
1571
      i = uniqueItems.length;
1572
      while (i--) {
1573
        delete uniqueItems[i].__checked;
1574
      }
1575
      return uniqueItems;
1576
    }
1577
    var expression = /^([\w\\*]+)?(?:#([\w\-\\]+))?(?:\.([\w\\\.]+))?(?:\[\@?([\w\\]+)([\^\$\*!~]?=)([\w\\]+)\])?(?:\:(.+))?/i;
1578
    var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g;
1579
    var whiteSpace = /^\s*|\s*$/g;
1580
    var Collection;
1581
    var Selector = global$a.extend({
1582 View Code Duplication
      init: function (selector) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1583
        var match = this.match;
1584
        function compileNameFilter(name) {
1585
          if (name) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if name is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1586
            name = name.toLowerCase();
1587
            return function (item) {
1588
              return name === '*' || item.type === name;
1589
            };
1590
          }
1591
        }
1592
        function compileIdFilter(id) {
1593
          if (id) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if id is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1594
            return function (item) {
1595
              return item._name === id;
1596
            };
1597
          }
1598
        }
1599
        function compileClassesFilter(classes) {
1600
          if (classes) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if classes is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1601
            classes = classes.split('.');
1602
            return function (item) {
1603
              var i = classes.length;
1604
              while (i--) {
1605
                if (!item.classes.contains(classes[i])) {
1606
                  return false;
1607
                }
1608
              }
1609
              return true;
1610
            };
1611
          }
1612
        }
1613
        function compileAttrFilter(name, cmp, check) {
1614
          if (name) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if name is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1615
            return function (item) {
1616
              var value = item[name] ? item[name]() : '';
1617
              return !cmp ? !!check : cmp === '=' ? value === check : cmp === '*=' ? value.indexOf(check) >= 0 : cmp === '~=' ? (' ' + value + ' ').indexOf(' ' + check + ' ') >= 0 : cmp === '!=' ? value !== check : cmp === '^=' ? value.indexOf(check) === 0 : cmp === '$=' ? value.substr(value.length - check.length) === check : false;
1618
            };
1619
          }
1620
        }
1621
        function compilePsuedoFilter(name) {
1622
          var notSelectors;
1623
          if (name) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if name is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1624
            name = /(?:not\((.+)\))|(.+)/i.exec(name);
1625
            if (!name[1]) {
1626
              name = name[2];
1627
              return function (item, index, length) {
1628
                return name === 'first' ? index === 0 : name === 'last' ? index === length - 1 : name === 'even' ? index % 2 === 0 : name === 'odd' ? index % 2 === 1 : item[name] ? item[name]() : false;
1629
              };
1630
            }
1631
            notSelectors = parseChunks(name[1], []);
1632
            return function (item) {
1633
              return !match(item, notSelectors);
1634
            };
1635
          }
1636
        }
1637
        function compile(selector, filters, direct) {
1638
          var parts;
1639
          function add(filter) {
1640
            if (filter) {
1641
              filters.push(filter);
1642
            }
1643
          }
1644
          parts = expression.exec(selector.replace(whiteSpace, ''));
1645
          add(compileNameFilter(parts[1]));
1646
          add(compileIdFilter(parts[2]));
1647
          add(compileClassesFilter(parts[3]));
1648
          add(compileAttrFilter(parts[4], parts[5], parts[6]));
1649
          add(compilePsuedoFilter(parts[7]));
1650
          filters.pseudo = !!parts[7];
1651
          filters.direct = direct;
1652
          return filters;
1653
        }
1654
        function parseChunks(selector, selectors) {
1655
          var parts = [];
1656
          var extra, matches, i;
1657
          do {
1658
            chunker.exec('');
1659
            matches = chunker.exec(selector);
1660
            if (matches) {
1661
              selector = matches[3];
1662
              parts.push(matches[1]);
1663
              if (matches[2]) {
1664
                extra = matches[3];
1665
                break;
1666
              }
1667
            }
1668
          } while (matches);
1669
          if (extra) {
1670
            parseChunks(extra, selectors);
1671
          }
1672
          selector = [];
1673
          for (i = 0; i < parts.length; i++) {
1674
            if (parts[i] !== '>') {
1675
              selector.push(compile(parts[i], [], parts[i - 1] === '>'));
1676
            }
1677
          }
1678
          selectors.push(selector);
1679
          return selectors;
1680
        }
1681
        this._selectors = parseChunks(selector, []);
1682
      },
1683 View Code Duplication
      match: function (control, selectors) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1684
        var i, l, si, sl, selector, fi, fl, filters, index, length, siblings, count, item;
1685
        selectors = selectors || this._selectors;
1686
        for (i = 0, l = selectors.length; i < l; i++) {
1687
          selector = selectors[i];
1688
          sl = selector.length;
1689
          item = control;
1690
          count = 0;
1691
          for (si = sl - 1; si >= 0; si--) {
1692
            filters = selector[si];
1693
            while (item) {
1694
              if (filters.pseudo) {
1695
                siblings = item.parent().items();
1696
                index = length = siblings.length;
1697
                while (index--) {
1698
                  if (siblings[index] === item) {
1699
                    break;
1700
                  }
1701
                }
1702
              }
1703
              for (fi = 0, fl = filters.length; fi < fl; fi++) {
1704
                if (!filters[fi](item, index, length)) {
0 ignored issues
show
Bug introduced by
The variable index seems to not be initialized for all possible execution paths. Are you sure fi handles undefined variables?
Loading history...
Bug introduced by
The variable length seems to not be initialized for all possible execution paths. Are you sure fi handles undefined variables?
Loading history...
1705
                  fi = fl + 1;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable fi here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
1706
                  break;
1707
                }
1708
              }
1709
              if (fi === fl) {
1710
                count++;
1711
                break;
1712
              } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
1713
                if (si === sl - 1) {
1714
                  break;
1715
                }
1716
              }
1717
              item = item.parent();
1718
            }
1719
          }
1720
          if (count === sl) {
1721
            return true;
1722
          }
1723
        }
1724
        return false;
1725
      },
1726 View Code Duplication
      find: function (container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1727
        var matches = [], i, l;
1728
        var selectors = this._selectors;
1729
        function collect(items, selector, index) {
1730
          var i, l, fi, fl, item;
1731
          var filters = selector[index];
1732
          for (i = 0, l = items.length; i < l; i++) {
1733
            item = items[i];
1734
            for (fi = 0, fl = filters.length; fi < fl; fi++) {
1735
              if (!filters[fi](item, i, l)) {
1736
                fi = fl + 1;
0 ignored issues
show
Complexity Coding Style introduced by
You seem to be assigning a new value to the loop variable fi here. Please check if this was indeed your intention. Even if it was, consider using another kind of loop instead.
Loading history...
1737
                break;
1738
              }
1739
            }
1740
            if (fi === fl) {
1741
              if (index === selector.length - 1) {
1742
                matches.push(item);
1743
              } else {
1744
                if (item.items) {
1745
                  collect(item.items(), selector, index + 1);
1746
                }
1747
              }
1748
            } else if (filters.direct) {
1749
              return;
1750
            }
1751
            if (item.items) {
1752
              collect(item.items(), selector, index);
1753
            }
1754
          }
1755
        }
1756
        if (container.items) {
1757
          for (i = 0, l = selectors.length; i < l; i++) {
1758
            collect(container.items(), selectors[i], 0);
1759
          }
1760
          if (l > 1) {
1761
            matches = unique(matches);
1762
          }
1763
        }
1764
        if (!Collection) {
1765
          Collection = Selector.Collection;
1766
        }
1767
        return new Collection(matches);
1768
      }
1769
    });
1770
1771
    var Collection$1, proto;
1772
    var push$1 = Array.prototype.push, slice$1 = Array.prototype.slice;
1773
    proto = {
1774
      length: 0,
1775
      init: function (items) {
1776
        if (items) {
1777
          this.add(items);
1778
        }
1779
      },
1780
      add: function (items) {
1781
        var self = this;
1782
        if (!global$2.isArray(items)) {
1783
          if (items instanceof Collection$1) {
1784
            self.add(items.toArray());
1785
          } else {
1786
            push$1.call(self, items);
1787
          }
1788
        } else {
1789
          push$1.apply(self, items);
1790
        }
1791
        return self;
1792
      },
1793
      set: function (items) {
1794
        var self = this;
1795
        var len = self.length;
1796
        var i;
1797
        self.length = 0;
1798
        self.add(items);
1799
        for (i = self.length; i < len; i++) {
1800
          delete self[i];
1801
        }
1802
        return self;
1803
      },
1804 View Code Duplication
      filter: function (selector) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1805
        var self = this;
1806
        var i, l;
1807
        var matches = [];
1808
        var item, match;
1809
        if (typeof selector === 'string') {
1810
          selector = new Selector(selector);
1811
          match = function (item) {
1812
            return selector.match(item);
1813
          };
1814
        } else {
1815
          match = selector;
1816
        }
1817
        for (i = 0, l = self.length; i < l; i++) {
1818
          item = self[i];
1819
          if (match(item)) {
1820
            matches.push(item);
1821
          }
1822
        }
1823
        return new Collection$1(matches);
1824
      },
1825
      slice: function () {
1826
        return new Collection$1(slice$1.apply(this, arguments));
1827
      },
1828
      eq: function (index) {
1829
        return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
1830
      },
1831
      each: function (callback) {
1832
        global$2.each(this, callback);
1833
        return this;
1834
      },
1835
      toArray: function () {
1836
        return global$2.toArray(this);
1837
      },
1838
      indexOf: function (ctrl) {
1839
        var self = this;
1840
        var i = self.length;
1841
        while (i--) {
1842
          if (self[i] === ctrl) {
1843
            break;
1844
          }
1845
        }
1846
        return i;
1847
      },
1848
      reverse: function () {
1849
        return new Collection$1(global$2.toArray(this).reverse());
1850
      },
1851
      hasClass: function (cls) {
1852
        return this[0] ? this[0].classes.contains(cls) : false;
1853
      },
1854
      prop: function (name, value) {
1855
        var self = this;
1856
        var item;
1857
        if (value !== undefined) {
1858
          self.each(function (item) {
1859
            if (item[name]) {
1860
              item[name](value);
1861
            }
1862
          });
1863
          return self;
1864
        }
1865
        item = self[0];
1866
        if (item && item[name]) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if item && item.name is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1867
          return item[name]();
1868
        }
1869
      },
1870
      exec: function (name) {
1871
        var self = this, args = global$2.toArray(arguments).slice(1);
1872
        self.each(function (item) {
1873
          if (item[name]) {
1874
            item[name].apply(item, args);
1875
          }
1876
        });
1877
        return self;
1878
      },
1879
      remove: function () {
1880
        var i = this.length;
1881
        while (i--) {
1882
          this[i].remove();
1883
        }
1884
        return this;
1885
      },
1886
      addClass: function (cls) {
1887
        return this.each(function (item) {
1888
          item.classes.add(cls);
1889
        });
1890
      },
1891
      removeClass: function (cls) {
1892
        return this.each(function (item) {
1893
          item.classes.remove(cls);
1894
        });
1895
      }
1896
    };
1897
    global$2.each('fire on off show hide append prepend before after reflow'.split(' '), function (name) {
1898
      proto[name] = function () {
1899
        var args = global$2.toArray(arguments);
1900
        this.each(function (ctrl) {
1901
          if (name in ctrl) {
1902
            ctrl[name].apply(ctrl, args);
1903
          }
1904
        });
1905
        return this;
1906
      };
1907
    });
1908
    global$2.each('text name disabled active selected checked visible parent value data'.split(' '), function (name) {
1909
      proto[name] = function (value) {
1910
        return this.prop(name, value);
1911
      };
1912
    });
1913
    Collection$1 = global$a.extend(proto);
1914
    Selector.Collection = Collection$1;
1915
    var Collection$2 = Collection$1;
1916
1917
    var Binding = function (settings) {
1918
      this.create = settings.create;
1919
    };
1920 View Code Duplication
    Binding.create = function (model, name) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
1921
      return new Binding({
1922
        create: function (otherModel, otherName) {
1923
          var bindings;
1924
          var fromSelfToOther = function (e) {
1925
            otherModel.set(otherName, e.value);
1926
          };
1927
          var fromOtherToSelf = function (e) {
1928
            model.set(name, e.value);
1929
          };
1930
          otherModel.on('change:' + otherName, fromOtherToSelf);
1931
          model.on('change:' + name, fromSelfToOther);
1932
          bindings = otherModel._bindings;
1933
          if (!bindings) {
1934
            bindings = otherModel._bindings = [];
1935
            otherModel.on('destroy', function () {
1936
              var i = bindings.length;
1937
              while (i--) {
1938
                bindings[i]();
1939
              }
1940
            });
1941
          }
1942
          bindings.push(function () {
1943
            model.off('change:' + name, fromSelfToOther);
1944
          });
1945
          return model.get(name);
1946
        }
1947
      });
1948
    };
1949
1950
    var global$c = tinymce.util.Tools.resolve('tinymce.util.Observable');
1951
1952
    function isNode(node) {
1953
      return node.nodeType > 0;
1954
    }
1955
    function isEqual(a, b) {
1956
      var k, checked;
1957
      if (a === b) {
1958
        return true;
1959
      }
1960
      if (a === null || b === null) {
1961
        return a === b;
1962
      }
1963
      if (typeof a !== 'object' || typeof b !== 'object') {
1964
        return a === b;
1965
      }
1966
      if (global$2.isArray(b)) {
1967
        if (a.length !== b.length) {
1968
          return false;
1969
        }
1970
        k = a.length;
1971
        while (k--) {
1972
          if (!isEqual(a[k], b[k])) {
1973
            return false;
1974
          }
1975
        }
1976
      }
1977
      if (isNode(a) || isNode(b)) {
1978
        return a === b;
1979
      }
1980
      checked = {};
1981
      for (k in b) {
1982
        if (!isEqual(a[k], b[k])) {
1983
          return false;
1984
        }
1985
        checked[k] = true;
1986
      }
1987
      for (k in a) {
1988
        if (!checked[k] && !isEqual(a[k], b[k])) {
1989
          return false;
1990
        }
1991
      }
1992
      return true;
1993
    }
1994
    var ObservableObject = global$a.extend({
1995
      Mixins: [global$c],
1996
      init: function (data) {
1997
        var name, value;
1998
        data = data || {};
1999
        for (name in data) {
2000
          value = data[name];
2001
          if (value instanceof Binding) {
2002
            data[name] = value.create(this, name);
2003
          }
2004
        }
2005
        this.data = data;
2006
      },
2007 View Code Duplication
      set: function (name, value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2008
        var key, args;
2009
        var oldValue = this.data[name];
2010
        if (value instanceof Binding) {
2011
          value = value.create(this, name);
2012
        }
2013
        if (typeof name === 'object') {
2014
          for (key in name) {
2015
            this.set(key, name[key]);
2016
          }
2017
          return this;
2018
        }
2019
        if (!isEqual(oldValue, value)) {
2020
          this.data[name] = value;
2021
          args = {
2022
            target: this,
2023
            name: name,
2024
            value: value,
2025
            oldValue: oldValue
2026
          };
2027
          this.fire('change:' + name, args);
2028
          this.fire('change', args);
2029
        }
2030
        return this;
2031
      },
2032
      get: function (name) {
2033
        return this.data[name];
2034
      },
2035
      has: function (name) {
2036
        return name in this.data;
2037
      },
2038
      bind: function (name) {
2039
        return Binding.create(this, name);
2040
      },
2041
      destroy: function () {
2042
        this.fire('destroy');
2043
      }
2044
    });
2045
2046
    var dirtyCtrls = {}, animationFrameRequested;
2047
    var ReflowQueue = {
2048
      add: function (ctrl) {
2049
        var parent$$1 = ctrl.parent();
2050
        if (parent$$1) {
2051
          if (!parent$$1._layout || parent$$1._layout.isNative()) {
2052
            return;
2053
          }
2054
          if (!dirtyCtrls[parent$$1._id]) {
2055
            dirtyCtrls[parent$$1._id] = parent$$1;
2056
          }
2057
          if (!animationFrameRequested) {
2058
            animationFrameRequested = true;
2059
            global$7.requestAnimationFrame(function () {
2060
              var id, ctrl;
2061
              animationFrameRequested = false;
2062
              for (id in dirtyCtrls) {
2063
                ctrl = dirtyCtrls[id];
2064
                if (ctrl.state.get('rendered')) {
2065
                  ctrl.reflow();
2066
                }
2067
              }
2068
              dirtyCtrls = {};
2069
            }, document.body);
2070
          }
2071
        }
2072
      },
2073
      remove: function (ctrl) {
2074
        if (dirtyCtrls[ctrl._id]) {
2075
          delete dirtyCtrls[ctrl._id];
2076
        }
2077
      }
2078
    };
2079
2080
    var hasMouseWheelEventSupport = 'onmousewheel' in document;
2081
    var hasWheelEventSupport = false;
2082
    var classPrefix = 'mce-';
2083
    var Control, idCounter = 0;
2084
    var proto$1 = {
2085
      Statics: { classPrefix: classPrefix },
2086
      isRtl: function () {
2087
        return Control.rtl;
2088
      },
2089
      classPrefix: classPrefix,
2090 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2091
        var self$$1 = this;
2092
        var classes, defaultClasses;
2093
        function applyClasses(classes) {
2094
          var i;
2095
          classes = classes.split(' ');
2096
          for (i = 0; i < classes.length; i++) {
2097
            self$$1.classes.add(classes[i]);
2098
          }
2099
        }
2100
        self$$1.settings = settings = global$2.extend({}, self$$1.Defaults, settings);
2101
        self$$1._id = settings.id || 'mceu_' + idCounter++;
2102
        self$$1._aria = { role: settings.role };
2103
        self$$1._elmCache = {};
2104
        self$$1.$ = global$9;
2105
        self$$1.state = new ObservableObject({
2106
          visible: true,
2107
          active: false,
2108
          disabled: false,
2109
          value: ''
2110
        });
2111
        self$$1.data = new ObservableObject(settings.data);
2112
        self$$1.classes = new ClassList(function () {
2113
          if (self$$1.state.get('rendered')) {
2114
            self$$1.getEl().className = this.toString();
2115
          }
2116
        });
2117
        self$$1.classes.prefix = self$$1.classPrefix;
2118
        classes = settings.classes;
2119
        if (classes) {
2120
          if (self$$1.Defaults) {
2121
            defaultClasses = self$$1.Defaults.classes;
2122
            if (defaultClasses && classes !== defaultClasses) {
2123
              applyClasses(defaultClasses);
2124
            }
2125
          }
2126
          applyClasses(classes);
2127
        }
2128
        global$2.each('title text name visible disabled active value'.split(' '), function (name$$1) {
2129
          if (name$$1 in settings) {
2130
            self$$1[name$$1](settings[name$$1]);
2131
          }
2132
        });
2133
        self$$1.on('click', function () {
2134
          if (self$$1.disabled()) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if self$$1.disabled() is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
2135
            return false;
2136
          }
2137
        });
2138
        self$$1.settings = settings;
2139
        self$$1.borderBox = BoxUtils.parseBox(settings.border);
2140
        self$$1.paddingBox = BoxUtils.parseBox(settings.padding);
2141
        self$$1.marginBox = BoxUtils.parseBox(settings.margin);
2142
        if (settings.hidden) {
2143
          self$$1.hide();
2144
        }
2145
      },
2146
      Properties: 'parent,name',
2147
      getContainerElm: function () {
2148
        var uiContainer = UiContainer.getUiContainer(this);
2149
        return uiContainer ? uiContainer : funcs.getContainer();
2150
      },
2151
      getParentCtrl: function (elm) {
2152
        var ctrl;
2153
        var lookup = this.getRoot().controlIdLookup;
2154
        while (elm && lookup) {
2155
          ctrl = lookup[elm.id];
2156
          if (ctrl) {
2157
            break;
2158
          }
2159
          elm = elm.parentNode;
2160
        }
2161
        return ctrl;
0 ignored issues
show
Comprehensibility Bug introduced by
The variable ctrl does not seem to be initialized in case the while loop on line 2154 is not entered. Are you sure this can never be the case?
Loading history...
2162
      },
2163 View Code Duplication
      initLayoutRect: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2164
        var self$$1 = this;
2165
        var settings = self$$1.settings;
2166
        var borderBox, layoutRect;
2167
        var elm = self$$1.getEl();
2168
        var width, height, minWidth, minHeight, autoResize;
2169
        var startMinWidth, startMinHeight, initialSize;
2170
        borderBox = self$$1.borderBox = self$$1.borderBox || BoxUtils.measureBox(elm, 'border');
2171
        self$$1.paddingBox = self$$1.paddingBox || BoxUtils.measureBox(elm, 'padding');
2172
        self$$1.marginBox = self$$1.marginBox || BoxUtils.measureBox(elm, 'margin');
2173
        initialSize = funcs.getSize(elm);
2174
        startMinWidth = settings.minWidth;
2175
        startMinHeight = settings.minHeight;
2176
        minWidth = startMinWidth || initialSize.width;
2177
        minHeight = startMinHeight || initialSize.height;
2178
        width = settings.width;
2179
        height = settings.height;
2180
        autoResize = settings.autoResize;
2181
        autoResize = typeof autoResize !== 'undefined' ? autoResize : !width && !height;
2182
        width = width || minWidth;
2183
        height = height || minHeight;
2184
        var deltaW = borderBox.left + borderBox.right;
2185
        var deltaH = borderBox.top + borderBox.bottom;
2186
        var maxW = settings.maxWidth || 65535;
2187
        var maxH = settings.maxHeight || 65535;
2188
        self$$1._layoutRect = layoutRect = {
2189
          x: settings.x || 0,
2190
          y: settings.y || 0,
2191
          w: width,
2192
          h: height,
2193
          deltaW: deltaW,
2194
          deltaH: deltaH,
2195
          contentW: width - deltaW,
2196
          contentH: height - deltaH,
2197
          innerW: width - deltaW,
2198
          innerH: height - deltaH,
2199
          startMinWidth: startMinWidth || 0,
2200
          startMinHeight: startMinHeight || 0,
2201
          minW: Math.min(minWidth, maxW),
2202
          minH: Math.min(minHeight, maxH),
2203
          maxW: maxW,
2204
          maxH: maxH,
2205
          autoResize: autoResize,
2206
          scrollW: 0
2207
        };
2208
        self$$1._lastLayoutRect = {};
2209
        return layoutRect;
2210
      },
2211 View Code Duplication
      layoutRect: function (newRect) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2212
        var self$$1 = this;
2213
        var curRect = self$$1._layoutRect, lastLayoutRect, size, deltaWidth, deltaHeight, repaintControls;
2214
        if (!curRect) {
2215
          curRect = self$$1.initLayoutRect();
2216
        }
2217
        if (newRect) {
2218
          deltaWidth = curRect.deltaW;
2219
          deltaHeight = curRect.deltaH;
2220
          if (newRect.x !== undefined) {
2221
            curRect.x = newRect.x;
2222
          }
2223
          if (newRect.y !== undefined) {
2224
            curRect.y = newRect.y;
2225
          }
2226
          if (newRect.minW !== undefined) {
2227
            curRect.minW = newRect.minW;
2228
          }
2229
          if (newRect.minH !== undefined) {
2230
            curRect.minH = newRect.minH;
2231
          }
2232
          size = newRect.w;
2233
          if (size !== undefined) {
2234
            size = size < curRect.minW ? curRect.minW : size;
2235
            size = size > curRect.maxW ? curRect.maxW : size;
2236
            curRect.w = size;
2237
            curRect.innerW = size - deltaWidth;
2238
          }
2239
          size = newRect.h;
2240
          if (size !== undefined) {
2241
            size = size < curRect.minH ? curRect.minH : size;
2242
            size = size > curRect.maxH ? curRect.maxH : size;
2243
            curRect.h = size;
2244
            curRect.innerH = size - deltaHeight;
2245
          }
2246
          size = newRect.innerW;
2247
          if (size !== undefined) {
2248
            size = size < curRect.minW - deltaWidth ? curRect.minW - deltaWidth : size;
2249
            size = size > curRect.maxW - deltaWidth ? curRect.maxW - deltaWidth : size;
2250
            curRect.innerW = size;
2251
            curRect.w = size + deltaWidth;
2252
          }
2253
          size = newRect.innerH;
2254
          if (size !== undefined) {
2255
            size = size < curRect.minH - deltaHeight ? curRect.minH - deltaHeight : size;
2256
            size = size > curRect.maxH - deltaHeight ? curRect.maxH - deltaHeight : size;
2257
            curRect.innerH = size;
2258
            curRect.h = size + deltaHeight;
2259
          }
2260
          if (newRect.contentW !== undefined) {
2261
            curRect.contentW = newRect.contentW;
2262
          }
2263
          if (newRect.contentH !== undefined) {
2264
            curRect.contentH = newRect.contentH;
2265
          }
2266
          lastLayoutRect = self$$1._lastLayoutRect;
2267
          if (lastLayoutRect.x !== curRect.x || lastLayoutRect.y !== curRect.y || lastLayoutRect.w !== curRect.w || lastLayoutRect.h !== curRect.h) {
2268
            repaintControls = Control.repaintControls;
2269
            if (repaintControls) {
2270
              if (repaintControls.map && !repaintControls.map[self$$1._id]) {
2271
                repaintControls.push(self$$1);
2272
                repaintControls.map[self$$1._id] = true;
2273
              }
2274
            }
2275
            lastLayoutRect.x = curRect.x;
2276
            lastLayoutRect.y = curRect.y;
2277
            lastLayoutRect.w = curRect.w;
2278
            lastLayoutRect.h = curRect.h;
2279
          }
2280
          return self$$1;
2281
        }
2282
        return curRect;
2283
      },
2284 View Code Duplication
      repaint: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2285
        var self$$1 = this;
2286
        var style, bodyStyle, bodyElm, rect, borderBox;
2287
        var borderW, borderH, lastRepaintRect, round, value;
2288
        round = !document.createRange ? Math.round : function (value) {
2289
          return value;
2290
        };
2291
        style = self$$1.getEl().style;
2292
        rect = self$$1._layoutRect;
2293
        lastRepaintRect = self$$1._lastRepaintRect || {};
2294
        borderBox = self$$1.borderBox;
2295
        borderW = borderBox.left + borderBox.right;
2296
        borderH = borderBox.top + borderBox.bottom;
2297
        if (rect.x !== lastRepaintRect.x) {
2298
          style.left = round(rect.x) + 'px';
2299
          lastRepaintRect.x = rect.x;
2300
        }
2301
        if (rect.y !== lastRepaintRect.y) {
2302
          style.top = round(rect.y) + 'px';
2303
          lastRepaintRect.y = rect.y;
2304
        }
2305
        if (rect.w !== lastRepaintRect.w) {
2306
          value = round(rect.w - borderW);
2307
          style.width = (value >= 0 ? value : 0) + 'px';
2308
          lastRepaintRect.w = rect.w;
2309
        }
2310
        if (rect.h !== lastRepaintRect.h) {
2311
          value = round(rect.h - borderH);
2312
          style.height = (value >= 0 ? value : 0) + 'px';
2313
          lastRepaintRect.h = rect.h;
2314
        }
2315
        if (self$$1._hasBody && rect.innerW !== lastRepaintRect.innerW) {
2316
          value = round(rect.innerW);
2317
          bodyElm = self$$1.getEl('body');
2318
          if (bodyElm) {
2319
            bodyStyle = bodyElm.style;
2320
            bodyStyle.width = (value >= 0 ? value : 0) + 'px';
2321
          }
2322
          lastRepaintRect.innerW = rect.innerW;
2323
        }
2324
        if (self$$1._hasBody && rect.innerH !== lastRepaintRect.innerH) {
2325
          value = round(rect.innerH);
2326
          bodyElm = bodyElm || self$$1.getEl('body');
2327
          if (bodyElm) {
2328
            bodyStyle = bodyStyle || bodyElm.style;
2329
            bodyStyle.height = (value >= 0 ? value : 0) + 'px';
2330
          }
2331
          lastRepaintRect.innerH = rect.innerH;
2332
        }
2333
        self$$1._lastRepaintRect = lastRepaintRect;
2334
        self$$1.fire('repaint', {}, false);
2335
      },
2336
      updateLayoutRect: function () {
2337
        var self$$1 = this;
2338
        self$$1.parent()._lastRect = null;
2339
        funcs.css(self$$1.getEl(), {
2340
          width: '',
2341
          height: ''
2342
        });
2343
        self$$1._layoutRect = self$$1._lastRepaintRect = self$$1._lastLayoutRect = null;
2344
        self$$1.initLayoutRect();
2345
      },
2346 View Code Duplication
      on: function (name$$1, callback) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2347
        var self$$1 = this;
2348
        function resolveCallbackName(name$$1) {
2349
          var callback, scope;
2350
          if (typeof name$$1 !== 'string') {
2351
            return name$$1;
2352
          }
2353
          return function (e) {
2354
            if (!callback) {
2355
              self$$1.parentsAndSelf().each(function (ctrl) {
2356
                var callbacks = ctrl.settings.callbacks;
2357
                if (callbacks && (callback = callbacks[name$$1])) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if callbacks && callback = callbacks.name$$1 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
2358
                  scope = ctrl;
2359
                  return false;
2360
                }
2361
              });
2362
            }
2363
            if (!callback) {
2364
              e.action = name$$1;
2365
              this.fire('execute', e);
2366
              return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
2367
            }
2368
            return callback.call(scope, e);
2369
          };
2370
        }
2371
        getEventDispatcher(self$$1).on(name$$1, resolveCallbackName(callback));
2372
        return self$$1;
2373
      },
2374
      off: function (name$$1, callback) {
2375
        getEventDispatcher(this).off(name$$1, callback);
2376
        return this;
2377
      },
2378 View Code Duplication
      fire: function (name$$1, args, bubble) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2379
        var self$$1 = this;
2380
        args = args || {};
2381
        if (!args.control) {
2382
          args.control = self$$1;
2383
        }
2384
        args = getEventDispatcher(self$$1).fire(name$$1, args);
2385
        if (bubble !== false && self$$1.parent) {
2386
          var parent$$1 = self$$1.parent();
2387
          while (parent$$1 && !args.isPropagationStopped()) {
2388
            parent$$1.fire(name$$1, args, false);
2389
            parent$$1 = parent$$1.parent();
2390
          }
2391
        }
2392
        return args;
2393
      },
2394
      hasEventListeners: function (name$$1) {
2395
        return getEventDispatcher(this).has(name$$1);
2396
      },
2397
      parents: function (selector) {
2398
        var self$$1 = this;
2399
        var ctrl, parents = new Collection$2();
2400
        for (ctrl = self$$1.parent(); ctrl; ctrl = ctrl.parent()) {
2401
          parents.add(ctrl);
2402
        }
2403
        if (selector) {
2404
          parents = parents.filter(selector);
2405
        }
2406
        return parents;
2407
      },
2408
      parentsAndSelf: function (selector) {
2409
        return new Collection$2(this).add(this.parents(selector));
2410
      },
2411
      next: function () {
2412
        var parentControls = this.parent().items();
2413
        return parentControls[parentControls.indexOf(this) + 1];
2414
      },
2415
      prev: function () {
2416
        var parentControls = this.parent().items();
2417
        return parentControls[parentControls.indexOf(this) - 1];
2418
      },
2419
      innerHtml: function (html) {
2420
        this.$el.html(html);
2421
        return this;
2422
      },
2423
      getEl: function (suffix) {
2424
        var id = suffix ? this._id + '-' + suffix : this._id;
2425
        if (!this._elmCache[id]) {
2426
          this._elmCache[id] = global$9('#' + id)[0];
2427
        }
2428
        return this._elmCache[id];
2429
      },
2430
      show: function () {
2431
        return this.visible(true);
2432
      },
2433
      hide: function () {
2434
        return this.visible(false);
2435
      },
2436
      focus: function () {
2437
        try {
2438
          this.getEl().focus();
2439
        } catch (ex) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
2440
        }
2441
        return this;
2442
      },
2443
      blur: function () {
2444
        this.getEl().blur();
2445
        return this;
2446
      },
2447
      aria: function (name$$1, value) {
2448
        var self$$1 = this, elm = self$$1.getEl(self$$1.ariaTarget);
2449
        if (typeof value === 'undefined') {
2450
          return self$$1._aria[name$$1];
2451
        }
2452
        self$$1._aria[name$$1] = value;
2453
        if (self$$1.state.get('rendered')) {
2454
          elm.setAttribute(name$$1 === 'role' ? name$$1 : 'aria-' + name$$1, value);
2455
        }
2456
        return self$$1;
2457
      },
2458
      encode: function (text, translate) {
2459
        if (translate !== false) {
2460
          text = this.translate(text);
2461
        }
2462
        return (text || '').replace(/[&<>"]/g, function (match) {
2463
          return '&#' + match.charCodeAt(0) + ';';
2464
        });
2465
      },
2466
      translate: function (text) {
2467
        return Control.translate ? Control.translate(text) : text;
2468
      },
2469
      before: function (items) {
2470
        var self$$1 = this, parent$$1 = self$$1.parent();
2471
        if (parent$$1) {
2472
          parent$$1.insert(items, parent$$1.items().indexOf(self$$1), true);
2473
        }
2474
        return self$$1;
2475
      },
2476
      after: function (items) {
2477
        var self$$1 = this, parent$$1 = self$$1.parent();
2478
        if (parent$$1) {
2479
          parent$$1.insert(items, parent$$1.items().indexOf(self$$1));
2480
        }
2481
        return self$$1;
2482
      },
2483 View Code Duplication
      remove: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2484
        var self$$1 = this;
2485
        var elm = self$$1.getEl();
2486
        var parent$$1 = self$$1.parent();
2487
        var newItems, i;
2488
        if (self$$1.items) {
2489
          var controls = self$$1.items().toArray();
2490
          i = controls.length;
2491
          while (i--) {
2492
            controls[i].remove();
2493
          }
2494
        }
2495
        if (parent$$1 && parent$$1.items) {
2496
          newItems = [];
2497
          parent$$1.items().each(function (item) {
2498
            if (item !== self$$1) {
2499
              newItems.push(item);
2500
            }
2501
          });
2502
          parent$$1.items().set(newItems);
2503
          parent$$1._lastRect = null;
2504
        }
2505
        if (self$$1._eventsRoot && self$$1._eventsRoot === self$$1) {
2506
          global$9(elm).off();
2507
        }
2508
        var lookup = self$$1.getRoot().controlIdLookup;
2509
        if (lookup) {
2510
          delete lookup[self$$1._id];
2511
        }
2512
        if (elm && elm.parentNode) {
2513
          elm.parentNode.removeChild(elm);
2514
        }
2515
        self$$1.state.set('rendered', false);
2516
        self$$1.state.destroy();
2517
        self$$1.fire('remove');
2518
        return self$$1;
2519
      },
2520
      renderBefore: function (elm) {
2521
        global$9(elm).before(this.renderHtml());
2522
        this.postRender();
2523
        return this;
2524
      },
2525
      renderTo: function (elm) {
2526
        global$9(elm || this.getContainerElm()).append(this.renderHtml());
2527
        this.postRender();
2528
        return this;
2529
      },
2530
      preRender: function () {
2531
      },
2532
      render: function () {
2533
      },
2534
      renderHtml: function () {
2535
        return '<div id="' + this._id + '" class="' + this.classes + '"></div>';
2536
      },
2537 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2538
        var self$$1 = this;
2539
        var settings = self$$1.settings;
2540
        var elm, box, parent$$1, name$$1, parentEventsRoot;
2541
        self$$1.$el = global$9(self$$1.getEl());
2542
        self$$1.state.set('rendered', true);
2543
        for (name$$1 in settings) {
2544
          if (name$$1.indexOf('on') === 0) {
2545
            self$$1.on(name$$1.substr(2), settings[name$$1]);
2546
          }
2547
        }
2548
        if (self$$1._eventsRoot) {
2549
          for (parent$$1 = self$$1.parent(); !parentEventsRoot && parent$$1; parent$$1 = parent$$1.parent()) {
2550
            parentEventsRoot = parent$$1._eventsRoot;
2551
          }
2552
          if (parentEventsRoot) {
2553
            for (name$$1 in parentEventsRoot._nativeEvents) {
2554
              self$$1._nativeEvents[name$$1] = true;
2555
            }
2556
          }
2557
        }
2558
        bindPendingEvents(self$$1);
2559
        if (settings.style) {
2560
          elm = self$$1.getEl();
2561
          if (elm) {
2562
            elm.setAttribute('style', settings.style);
2563
            elm.style.cssText = settings.style;
2564
          }
2565
        }
2566
        if (self$$1.settings.border) {
2567
          box = self$$1.borderBox;
2568
          self$$1.$el.css({
2569
            'border-top-width': box.top,
2570
            'border-right-width': box.right,
2571
            'border-bottom-width': box.bottom,
2572
            'border-left-width': box.left
2573
          });
2574
        }
2575
        var root = self$$1.getRoot();
2576
        if (!root.controlIdLookup) {
2577
          root.controlIdLookup = {};
2578
        }
2579
        root.controlIdLookup[self$$1._id] = self$$1;
2580
        for (var key in self$$1._aria) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
2581
          self$$1.aria(key, self$$1._aria[key]);
2582
        }
2583
        if (self$$1.state.get('visible') === false) {
2584
          self$$1.getEl().style.display = 'none';
2585
        }
2586
        self$$1.bindStates();
2587
        self$$1.state.on('change:visible', function (e) {
2588
          var state = e.value;
2589
          var parentCtrl;
2590
          if (self$$1.state.get('rendered')) {
2591
            self$$1.getEl().style.display = state === false ? 'none' : '';
2592
            self$$1.getEl().getBoundingClientRect();
2593
          }
2594
          parentCtrl = self$$1.parent();
2595
          if (parentCtrl) {
2596
            parentCtrl._lastRect = null;
2597
          }
2598
          self$$1.fire(state ? 'show' : 'hide');
2599
          ReflowQueue.add(self$$1);
2600
        });
2601
        self$$1.fire('postrender', {}, false);
2602
      },
2603
      bindStates: function () {
2604
      },
2605 View Code Duplication
      scrollIntoView: function (align) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2606
        function getOffset(elm, rootElm) {
2607
          var x, y, parent$$1 = elm;
2608
          x = y = 0;
2609
          while (parent$$1 && parent$$1 !== rootElm && parent$$1.nodeType) {
2610
            x += parent$$1.offsetLeft || 0;
2611
            y += parent$$1.offsetTop || 0;
2612
            parent$$1 = parent$$1.offsetParent;
2613
          }
2614
          return {
2615
            x: x,
2616
            y: y
2617
          };
2618
        }
2619
        var elm = this.getEl(), parentElm = elm.parentNode;
2620
        var x, y, width, height, parentWidth, parentHeight;
2621
        var pos = getOffset(elm, parentElm);
2622
        x = pos.x;
2623
        y = pos.y;
2624
        width = elm.offsetWidth;
2625
        height = elm.offsetHeight;
2626
        parentWidth = parentElm.clientWidth;
2627
        parentHeight = parentElm.clientHeight;
2628
        if (align === 'end') {
2629
          x -= parentWidth - width;
2630
          y -= parentHeight - height;
2631
        } else if (align === 'center') {
2632
          x -= parentWidth / 2 - width / 2;
2633
          y -= parentHeight / 2 - height / 2;
2634
        }
2635
        parentElm.scrollLeft = x;
2636
        parentElm.scrollTop = y;
2637
        return this;
2638
      },
2639 View Code Duplication
      getRoot: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2640
        var ctrl = this, rootControl;
2641
        var parents = [];
2642
        while (ctrl) {
2643
          if (ctrl.rootControl) {
2644
            rootControl = ctrl.rootControl;
2645
            break;
2646
          }
2647
          parents.push(ctrl);
2648
          rootControl = ctrl;
2649
          ctrl = ctrl.parent();
2650
        }
2651
        if (!rootControl) {
2652
          rootControl = this;
2653
        }
2654
        var i = parents.length;
2655
        while (i--) {
2656
          parents[i].rootControl = rootControl;
2657
        }
2658
        return rootControl;
2659
      },
2660
      reflow: function () {
2661
        ReflowQueue.remove(this);
2662
        var parent$$1 = this.parent();
2663
        if (parent$$1 && parent$$1._layout && !parent$$1._layout.isNative()) {
2664
          parent$$1.reflow();
2665
        }
2666
        return this;
2667
      }
2668
    };
2669
    global$2.each('text title visible disabled active value'.split(' '), function (name$$1) {
2670
      proto$1[name$$1] = function (value) {
2671
        if (arguments.length === 0) {
2672
          return this.state.get(name$$1);
2673
        }
2674
        if (typeof value !== 'undefined') {
2675
          this.state.set(name$$1, value);
2676
        }
2677
        return this;
2678
      };
2679
    });
2680
    Control = global$a.extend(proto$1);
2681
    function getEventDispatcher(obj) {
2682
      if (!obj._eventDispatcher) {
2683
        obj._eventDispatcher = new global$b({
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like global$b should be capitalized.
Loading history...
2684
          scope: obj,
2685
          toggleEvent: function (name$$1, state) {
2686
            if (state && global$b.isNative(name$$1)) {
2687
              if (!obj._nativeEvents) {
2688
                obj._nativeEvents = {};
2689
              }
2690
              obj._nativeEvents[name$$1] = true;
2691
              if (obj.state.get('rendered')) {
2692
                bindPendingEvents(obj);
2693
              }
2694
            }
2695
          }
2696
        });
2697
      }
2698
      return obj._eventDispatcher;
2699
    }
2700 View Code Duplication
    function bindPendingEvents(eventCtrl) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2701
      var i, l, parents, eventRootCtrl, nativeEvents, name$$1;
2702
      function delegate(e) {
2703
        var control = eventCtrl.getParentCtrl(e.target);
2704
        if (control) {
2705
          control.fire(e.type, e);
2706
        }
2707
      }
2708
      function mouseLeaveHandler() {
2709
        var ctrl = eventRootCtrl._lastHoverCtrl;
2710
        if (ctrl) {
2711
          ctrl.fire('mouseleave', { target: ctrl.getEl() });
2712
          ctrl.parents().each(function (ctrl) {
2713
            ctrl.fire('mouseleave', { target: ctrl.getEl() });
2714
          });
2715
          eventRootCtrl._lastHoverCtrl = null;
2716
        }
2717
      }
2718
      function mouseEnterHandler(e) {
2719
        var ctrl = eventCtrl.getParentCtrl(e.target), lastCtrl = eventRootCtrl._lastHoverCtrl, idx = 0, i, parents, lastParents;
2720
        if (ctrl !== lastCtrl) {
2721
          eventRootCtrl._lastHoverCtrl = ctrl;
2722
          parents = ctrl.parents().toArray().reverse();
2723
          parents.push(ctrl);
2724
          if (lastCtrl) {
2725
            lastParents = lastCtrl.parents().toArray().reverse();
2726
            lastParents.push(lastCtrl);
2727
            for (idx = 0; idx < lastParents.length; idx++) {
2728
              if (parents[idx] !== lastParents[idx]) {
2729
                break;
2730
              }
2731
            }
2732
            for (i = lastParents.length - 1; i >= idx; i--) {
2733
              lastCtrl = lastParents[i];
2734
              lastCtrl.fire('mouseleave', { target: lastCtrl.getEl() });
2735
            }
2736
          }
2737
          for (i = idx; i < parents.length; i++) {
2738
            ctrl = parents[i];
2739
            ctrl.fire('mouseenter', { target: ctrl.getEl() });
2740
          }
2741
        }
2742
      }
2743
      function fixWheelEvent(e) {
2744
        e.preventDefault();
2745
        if (e.type === 'mousewheel') {
2746
          e.deltaY = -1 / 40 * e.wheelDelta;
2747
          if (e.wheelDeltaX) {
2748
            e.deltaX = -1 / 40 * e.wheelDeltaX;
2749
          }
2750
        } else {
2751
          e.deltaX = 0;
2752
          e.deltaY = e.detail;
2753
        }
2754
        e = eventCtrl.fire('wheel', e);
0 ignored issues
show
Unused Code introduced by
The assignment to variable e seems to be never used. Consider removing it.
Loading history...
2755
      }
2756
      nativeEvents = eventCtrl._nativeEvents;
2757
      if (nativeEvents) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if nativeEvents is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
2758
        parents = eventCtrl.parents().toArray();
2759
        parents.unshift(eventCtrl);
2760
        for (i = 0, l = parents.length; !eventRootCtrl && i < l; i++) {
2761
          eventRootCtrl = parents[i]._eventsRoot;
2762
        }
2763
        if (!eventRootCtrl) {
2764
          eventRootCtrl = parents[parents.length - 1] || eventCtrl;
2765
        }
2766
        eventCtrl._eventsRoot = eventRootCtrl;
2767
        for (l = i, i = 0; i < l; i++) {
2768
          parents[i]._eventsRoot = eventRootCtrl;
2769
        }
2770
        var eventRootDelegates = eventRootCtrl._delegates;
2771
        if (!eventRootDelegates) {
2772
          eventRootDelegates = eventRootCtrl._delegates = {};
2773
        }
2774
        for (name$$1 in nativeEvents) {
2775
          if (!nativeEvents) {
2776
            return false;
2777
          }
2778
          if (name$$1 === 'wheel' && !hasWheelEventSupport) {
2779
            if (hasMouseWheelEventSupport) {
2780
              global$9(eventCtrl.getEl()).on('mousewheel', fixWheelEvent);
2781
            } else {
2782
              global$9(eventCtrl.getEl()).on('DOMMouseScroll', fixWheelEvent);
2783
            }
2784
            continue;
2785
          }
2786
          if (name$$1 === 'mouseenter' || name$$1 === 'mouseleave') {
2787
            if (!eventRootCtrl._hasMouseEnter) {
2788
              global$9(eventRootCtrl.getEl()).on('mouseleave', mouseLeaveHandler).on('mouseover', mouseEnterHandler);
2789
              eventRootCtrl._hasMouseEnter = 1;
2790
            }
2791
          } else if (!eventRootDelegates[name$$1]) {
2792
            global$9(eventRootCtrl.getEl()).on(name$$1, delegate);
2793
            eventRootDelegates[name$$1] = true;
2794
          }
2795
          nativeEvents[name$$1] = false;
2796
        }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2797
      }
2798
    }
2799
    var Control$1 = Control;
2800
2801
    var hasTabstopData = function (elm) {
2802
      return elm.getAttribute('data-mce-tabstop') ? true : false;
2803
    };
2804 View Code Duplication
    function KeyboardNavigation (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2805
      var root = settings.root;
2806
      var focusedElement, focusedControl;
2807
      function isElement(node) {
2808
        return node && node.nodeType === 1;
2809
      }
2810
      try {
2811
        focusedElement = document.activeElement;
2812
      } catch (ex) {
2813
        focusedElement = document.body;
2814
      }
2815
      focusedControl = root.getParentCtrl(focusedElement);
2816
      function getRole(elm) {
2817
        elm = elm || focusedElement;
2818
        if (isElement(elm)) {
2819
          return elm.getAttribute('role');
2820
        }
2821
        return null;
2822
      }
2823
      function getParentRole(elm) {
2824
        var role, parent$$1 = elm || focusedElement;
2825
        while (parent$$1 = parent$$1.parentNode) {
2826
          if (role = getRole(parent$$1)) {
2827
            return role;
2828
          }
2829
        }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
2830
      }
2831
      function getAriaProp(name$$1) {
2832
        var elm = focusedElement;
2833
        if (isElement(elm)) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if isElement(elm) is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
2834
          return elm.getAttribute('aria-' + name$$1);
2835
        }
2836
      }
2837
      function isTextInputElement(elm) {
2838
        var tagName = elm.tagName.toUpperCase();
2839
        return tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT';
2840
      }
2841
      function canFocus(elm) {
2842
        if (isTextInputElement(elm) && !elm.hidden) {
2843
          return true;
2844
        }
2845
        if (hasTabstopData(elm)) {
2846
          return true;
2847
        }
2848
        if (/^(button|menuitem|checkbox|tab|menuitemcheckbox|option|gridcell|slider)$/.test(getRole(elm))) {
2849
          return true;
2850
        }
2851
        return false;
2852
      }
2853
      function getFocusElements(elm) {
2854
        var elements = [];
2855
        function collect(elm) {
2856
          if (elm.nodeType !== 1 || elm.style.display === 'none' || elm.disabled) {
2857
            return;
2858
          }
2859
          if (canFocus(elm)) {
2860
            elements.push(elm);
2861
          }
2862
          for (var i = 0; i < elm.childNodes.length; i++) {
2863
            collect(elm.childNodes[i]);
2864
          }
2865
        }
2866
        collect(elm || root.getEl());
2867
        return elements;
2868
      }
2869
      function getNavigationRoot(targetControl) {
2870
        var navigationRoot, controls;
2871
        targetControl = targetControl || focusedControl;
2872
        controls = targetControl.parents().toArray();
2873
        controls.unshift(targetControl);
2874
        for (var i = 0; i < controls.length; i++) {
2875
          navigationRoot = controls[i];
2876
          if (navigationRoot.settings.ariaRoot) {
2877
            break;
2878
          }
2879
        }
2880
        return navigationRoot;
0 ignored issues
show
Bug introduced by
The variable navigationRoot seems to not be initialized for all possible execution paths.
Loading history...
2881
      }
2882
      function focusFirst(targetControl) {
2883
        var navigationRoot = getNavigationRoot(targetControl);
2884
        var focusElements = getFocusElements(navigationRoot.getEl());
2885
        if (navigationRoot.settings.ariaRemember && 'lastAriaIndex' in navigationRoot) {
2886
          moveFocusToIndex(navigationRoot.lastAriaIndex, focusElements);
2887
        } else {
2888
          moveFocusToIndex(0, focusElements);
2889
        }
2890
      }
2891
      function moveFocusToIndex(idx, elements) {
2892
        if (idx < 0) {
2893
          idx = elements.length - 1;
2894
        } else if (idx >= elements.length) {
2895
          idx = 0;
2896
        }
2897
        if (elements[idx]) {
2898
          elements[idx].focus();
2899
        }
2900
        return idx;
2901
      }
2902
      function moveFocus(dir, elements) {
2903
        var idx = -1;
2904
        var navigationRoot = getNavigationRoot();
2905
        elements = elements || getFocusElements(navigationRoot.getEl());
2906
        for (var i = 0; i < elements.length; i++) {
2907
          if (elements[i] === focusedElement) {
2908
            idx = i;
2909
          }
2910
        }
2911
        idx += dir;
2912
        navigationRoot.lastAriaIndex = moveFocusToIndex(idx, elements);
2913
      }
2914
      function left() {
2915
        var parentRole = getParentRole();
2916
        if (parentRole === 'tablist') {
2917
          moveFocus(-1, getFocusElements(focusedElement.parentNode));
2918
        } else if (focusedControl.parent().submenu) {
2919
          cancel();
2920
        } else {
2921
          moveFocus(-1);
2922
        }
2923
      }
2924
      function right() {
2925
        var role = getRole(), parentRole = getParentRole();
2926
        if (parentRole === 'tablist') {
2927
          moveFocus(1, getFocusElements(focusedElement.parentNode));
2928
        } else if (role === 'menuitem' && parentRole === 'menu' && getAriaProp('haspopup')) {
2929
          enter();
2930
        } else {
2931
          moveFocus(1);
2932
        }
2933
      }
2934
      function up() {
2935
        moveFocus(-1);
2936
      }
2937
      function down() {
2938
        var role = getRole(), parentRole = getParentRole();
2939
        if (role === 'menuitem' && parentRole === 'menubar') {
2940
          enter();
2941
        } else if (role === 'button' && getAriaProp('haspopup')) {
2942
          enter({ key: 'down' });
2943
        } else {
2944
          moveFocus(1);
2945
        }
2946
      }
2947
      function tab(e) {
2948
        var parentRole = getParentRole();
2949
        if (parentRole === 'tablist') {
2950
          var elm = getFocusElements(focusedControl.getEl('body'))[0];
2951
          if (elm) {
2952
            elm.focus();
2953
          }
2954
        } else {
2955
          moveFocus(e.shiftKey ? -1 : 1);
2956
        }
2957
      }
2958
      function cancel() {
2959
        focusedControl.fire('cancel');
2960
      }
2961
      function enter(aria) {
2962
        aria = aria || {};
2963
        focusedControl.fire('click', {
2964
          target: focusedElement,
2965
          aria: aria
2966
        });
2967
      }
2968
      root.on('keydown', function (e) {
2969
        function handleNonTabOrEscEvent(e, handler) {
2970
          if (isTextInputElement(focusedElement) || hasTabstopData(focusedElement)) {
2971
            return;
2972
          }
2973
          if (getRole(focusedElement) === 'slider') {
2974
            return;
2975
          }
2976
          if (handler(e) !== false) {
2977
            e.preventDefault();
2978
          }
2979
        }
2980
        if (e.isDefaultPrevented()) {
2981
          return;
2982
        }
2983
        switch (e.keyCode) {
2984
        case 37:
2985
          handleNonTabOrEscEvent(e, left);
2986
          break;
2987
        case 39:
2988
          handleNonTabOrEscEvent(e, right);
2989
          break;
2990
        case 38:
2991
          handleNonTabOrEscEvent(e, up);
2992
          break;
2993
        case 40:
2994
          handleNonTabOrEscEvent(e, down);
2995
          break;
2996
        case 27:
2997
          cancel();
2998
          break;
2999
        case 14:
3000
        case 13:
3001
        case 32:
3002
          handleNonTabOrEscEvent(e, enter);
3003
          break;
3004
        case 9:
3005
          tab(e);
3006
          e.preventDefault();
3007
          break;
3008
        }
3009
      });
3010
      root.on('focusin', function (e) {
3011
        focusedElement = e.target;
3012
        focusedControl = e.control;
3013
      });
3014
      return { focusFirst: focusFirst };
3015
    }
3016
3017
    var selectorCache = {};
3018
    var Container = Control$1.extend({
3019 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3020
        var self = this;
3021
        self._super(settings);
3022
        settings = self.settings;
3023
        if (settings.fixed) {
3024
          self.state.set('fixed', true);
3025
        }
3026
        self._items = new Collection$2();
3027
        if (self.isRtl()) {
3028
          self.classes.add('rtl');
3029
        }
3030
        self.bodyClasses = new ClassList(function () {
3031
          if (self.state.get('rendered')) {
3032
            self.getEl('body').className = this.toString();
3033
          }
3034
        });
3035
        self.bodyClasses.prefix = self.classPrefix;
3036
        self.classes.add('container');
3037
        self.bodyClasses.add('container-body');
3038
        if (settings.containerCls) {
3039
          self.classes.add(settings.containerCls);
3040
        }
3041
        self._layout = global$4.create((settings.layout || '') + 'layout');
3042
        if (self.settings.items) {
3043
          self.add(self.settings.items);
3044
        } else {
3045
          self.add(self.render());
3046
        }
3047
        self._hasBody = true;
3048
      },
3049
      items: function () {
3050
        return this._items;
3051
      },
3052
      find: function (selector) {
3053
        selector = selectorCache[selector] = selectorCache[selector] || new Selector(selector);
3054
        return selector.find(this);
3055
      },
3056
      add: function (items) {
3057
        var self = this;
3058
        self.items().add(self.create(items)).parent(self);
3059
        return self;
3060
      },
3061 View Code Duplication
      focus: function (keyboard) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3062
        var self = this;
3063
        var focusCtrl, keyboardNav, items;
3064
        if (keyboard) {
3065
          keyboardNav = self.keyboardNav || self.parents().eq(-1)[0].keyboardNav;
3066
          if (keyboardNav) {
3067
            keyboardNav.focusFirst(self);
3068
            return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
3069
          }
3070
        }
3071
        items = self.find('*');
3072
        if (self.statusbar) {
3073
          items.add(self.statusbar.items());
3074
        }
3075
        items.each(function (ctrl) {
3076
          if (ctrl.settings.autofocus) {
3077
            focusCtrl = null;
3078
            return false;
3079
          }
3080
          if (ctrl.canFocus) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if ctrl.canFocus is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
3081
            focusCtrl = focusCtrl || ctrl;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
3082
          }
3083
        });
3084
        if (focusCtrl) {
3085
          focusCtrl.focus();
3086
        }
3087
        return self;
3088
      },
3089 View Code Duplication
      replace: function (oldItem, newItem) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3090
        var ctrlElm;
3091
        var items = this.items();
3092
        var i = items.length;
3093
        while (i--) {
3094
          if (items[i] === oldItem) {
3095
            items[i] = newItem;
3096
            break;
3097
          }
3098
        }
3099
        if (i >= 0) {
3100
          ctrlElm = newItem.getEl();
3101
          if (ctrlElm) {
3102
            ctrlElm.parentNode.removeChild(ctrlElm);
3103
          }
3104
          ctrlElm = oldItem.getEl();
3105
          if (ctrlElm) {
3106
            ctrlElm.parentNode.removeChild(ctrlElm);
3107
          }
3108
        }
3109
        newItem.parent(this);
3110
      },
3111
      create: function (items) {
3112
        var self = this;
3113
        var settings;
3114
        var ctrlItems = [];
3115
        if (!global$2.isArray(items)) {
3116
          items = [items];
3117
        }
3118
        global$2.each(items, function (item) {
3119
          if (item) {
3120
            if (!(item instanceof Control$1)) {
3121
              if (typeof item === 'string') {
3122
                item = { type: item };
3123
              }
3124
              settings = global$2.extend({}, self.settings.defaults, item);
3125
              item.type = settings.type = settings.type || item.type || self.settings.defaultType || (settings.defaults ? settings.defaults.type : null);
3126
              item = global$4.create(settings);
3127
            }
3128
            ctrlItems.push(item);
3129
          }
3130
        });
3131
        return ctrlItems;
3132
      },
3133
      renderNew: function () {
3134
        var self = this;
3135
        self.items().each(function (ctrl, index) {
3136
          var containerElm;
3137
          ctrl.parent(self);
3138
          if (!ctrl.state.get('rendered')) {
3139
            containerElm = self.getEl('body');
3140
            if (containerElm.hasChildNodes() && index <= containerElm.childNodes.length - 1) {
3141
              global$9(containerElm.childNodes[index]).before(ctrl.renderHtml());
3142
            } else {
3143
              global$9(containerElm).append(ctrl.renderHtml());
3144
            }
3145
            ctrl.postRender();
3146
            ReflowQueue.add(ctrl);
3147
          }
3148
        });
3149
        self._layout.applyClasses(self.items().filter(':visible'));
3150
        self._lastRect = null;
3151
        return self;
3152
      },
3153
      append: function (items) {
3154
        return this.add(items).renderNew();
3155
      },
3156
      prepend: function (items) {
3157
        var self = this;
3158
        self.items().set(self.create(items).concat(self.items().toArray()));
3159
        return self.renderNew();
3160
      },
3161 View Code Duplication
      insert: function (items, index, before) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3162
        var self = this;
3163
        var curItems, beforeItems, afterItems;
3164
        items = self.create(items);
3165
        curItems = self.items();
3166
        if (!before && index < curItems.length - 1) {
3167
          index += 1;
3168
        }
3169
        if (index >= 0 && index < curItems.length) {
3170
          beforeItems = curItems.slice(0, index).toArray();
3171
          afterItems = curItems.slice(index).toArray();
3172
          curItems.set(beforeItems.concat(items, afterItems));
3173
        }
3174
        return self.renderNew();
3175
      },
3176
      fromJSON: function (data) {
3177
        var self = this;
3178
        for (var name in data) {
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
3179
          self.find('#' + name).value(data[name]);
3180
        }
3181
        return self;
3182
      },
3183
      toJSON: function () {
3184
        var self = this, data = {};
3185
        self.find('*').each(function (ctrl) {
3186
          var name = ctrl.name(), value = ctrl.value();
3187
          if (name && typeof value !== 'undefined') {
3188
            data[name] = value;
3189
          }
3190
        });
3191
        return data;
3192
      },
3193 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3194
        var self = this, layout = self._layout, role = this.settings.role;
3195
        self.preRender();
3196
        layout.preRender(self);
3197
        return '<div id="' + self._id + '" class="' + self.classes + '"' + (role ? ' role="' + this.settings.role + '"' : '') + '>' + '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + (self.settings.html || '') + layout.renderHtml(self) + '</div>' + '</div>';
3198
      },
3199
      postRender: function () {
3200
        var self = this;
3201
        var box;
3202
        self.items().exec('postRender');
3203
        self._super();
3204
        self._layout.postRender(self);
3205
        self.state.set('rendered', true);
3206
        if (self.settings.style) {
3207
          self.$el.css(self.settings.style);
3208
        }
3209
        if (self.settings.border) {
3210
          box = self.borderBox;
3211
          self.$el.css({
3212
            'border-top-width': box.top,
3213
            'border-right-width': box.right,
3214
            'border-bottom-width': box.bottom,
3215
            'border-left-width': box.left
3216
          });
3217
        }
3218
        if (!self.parent()) {
3219
          self.keyboardNav = KeyboardNavigation({ root: self });
3220
        }
3221
        return self;
3222
      },
3223
      initLayoutRect: function () {
3224
        var self = this, layoutRect = self._super();
3225
        self._layout.recalc(self);
3226
        return layoutRect;
3227
      },
3228 View Code Duplication
      recalc: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3229
        var self = this;
3230
        var rect = self._layoutRect;
3231
        var lastRect = self._lastRect;
3232
        if (!lastRect || lastRect.w !== rect.w || lastRect.h !== rect.h) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if !lastRect || lastRect.w ...| lastRect.h !== rect.h is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
3233
          self._layout.recalc(self);
3234
          rect = self.layoutRect();
3235
          self._lastRect = {
3236
            x: rect.x,
3237
            y: rect.y,
3238
            w: rect.w,
3239
            h: rect.h
3240
          };
3241
          return true;
3242
        }
3243
      },
3244 View Code Duplication
      reflow: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3245
        var i;
3246
        ReflowQueue.remove(this);
3247
        if (this.visible()) {
3248
          Control$1.repaintControls = [];
3249
          Control$1.repaintControls.map = {};
3250
          this.recalc();
3251
          i = Control$1.repaintControls.length;
3252
          while (i--) {
3253
            Control$1.repaintControls[i].repaint();
3254
          }
3255
          if (this.settings.layout !== 'flow' && this.settings.layout !== 'stack') {
3256
            this.repaint();
3257
          }
3258
          Control$1.repaintControls = [];
3259
        }
3260
        return this;
3261
      }
3262
    });
3263
3264 View Code Duplication
    function getDocumentSize(doc) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3265
      var documentElement, body, scrollWidth, clientWidth;
3266
      var offsetWidth, scrollHeight, clientHeight, offsetHeight;
3267
      var max = Math.max;
3268
      documentElement = doc.documentElement;
3269
      body = doc.body;
3270
      scrollWidth = max(documentElement.scrollWidth, body.scrollWidth);
3271
      clientWidth = max(documentElement.clientWidth, body.clientWidth);
3272
      offsetWidth = max(documentElement.offsetWidth, body.offsetWidth);
3273
      scrollHeight = max(documentElement.scrollHeight, body.scrollHeight);
3274
      clientHeight = max(documentElement.clientHeight, body.clientHeight);
3275
      offsetHeight = max(documentElement.offsetHeight, body.offsetHeight);
3276
      return {
3277
        width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
3278
        height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
3279
      };
3280
    }
3281
    function updateWithTouchData(e) {
3282
      var keys, i;
3283
      if (e.changedTouches) {
3284
        keys = 'screenX screenY pageX pageY clientX clientY'.split(' ');
3285
        for (i = 0; i < keys.length; i++) {
3286
          e[keys[i]] = e.changedTouches[0][keys[i]];
3287
        }
3288
      }
3289
    }
3290 View Code Duplication
    function DragHelper (id, settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3291
      var $eventOverlay;
3292
      var doc = settings.document || document;
3293
      var downButton;
3294
      var start, stop$$1, drag, startX, startY;
3295
      settings = settings || {};
3296
      var handleElement = doc.getElementById(settings.handle || id);
3297
      start = function (e) {
3298
        var docSize = getDocumentSize(doc);
3299
        var handleElm, cursor;
3300
        updateWithTouchData(e);
3301
        e.preventDefault();
3302
        downButton = e.button;
3303
        handleElm = handleElement;
3304
        startX = e.screenX;
3305
        startY = e.screenY;
3306
        if (window.getComputedStyle) {
3307
          cursor = window.getComputedStyle(handleElm, null).getPropertyValue('cursor');
3308
        } else {
3309
          cursor = handleElm.runtimeStyle.cursor;
3310
        }
3311
        $eventOverlay = global$9('<div></div>').css({
3312
          position: 'absolute',
3313
          top: 0,
3314
          left: 0,
3315
          width: docSize.width,
3316
          height: docSize.height,
3317
          zIndex: 2147483647,
3318
          opacity: 0.0001,
3319
          cursor: cursor
3320
        }).appendTo(doc.body);
3321
        global$9(doc).on('mousemove touchmove', drag).on('mouseup touchend', stop$$1);
3322
        settings.start(e);
3323
      };
3324
      drag = function (e) {
3325
        updateWithTouchData(e);
3326
        if (e.button !== downButton) {
3327
          return stop$$1(e);
3328
        }
3329
        e.deltaX = e.screenX - startX;
3330
        e.deltaY = e.screenY - startY;
3331
        e.preventDefault();
3332
        settings.drag(e);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
3333
      };
3334
      stop$$1 = function (e) {
3335
        updateWithTouchData(e);
3336
        global$9(doc).off('mousemove touchmove', drag).off('mouseup touchend', stop$$1);
3337
        $eventOverlay.remove();
3338
        if (settings.stop) {
3339
          settings.stop(e);
3340
        }
3341
      };
3342
      this.destroy = function () {
3343
        global$9(handleElement).off();
3344
      };
3345
      global$9(handleElement).on('mousedown touchstart', start);
3346
    }
3347
3348
    var Scrollable = {
3349
      init: function () {
3350
        var self = this;
3351
        self.on('repaint', self.renderScroll);
3352
      },
3353 View Code Duplication
      renderScroll: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3354
        var self = this, margin = 2;
3355
        function repaintScroll() {
3356
          var hasScrollH, hasScrollV, bodyElm;
3357
          function repaintAxis(axisName, posName, sizeName, contentSizeName, hasScroll, ax) {
3358
            var containerElm, scrollBarElm, scrollThumbElm;
3359
            var containerSize, scrollSize, ratio, rect;
3360
            var posNameLower, sizeNameLower;
3361
            scrollBarElm = self.getEl('scroll' + axisName);
3362
            if (scrollBarElm) {
3363
              posNameLower = posName.toLowerCase();
3364
              sizeNameLower = sizeName.toLowerCase();
3365
              global$9(self.getEl('absend')).css(posNameLower, self.layoutRect()[contentSizeName] - 1);
3366
              if (!hasScroll) {
3367
                global$9(scrollBarElm).css('display', 'none');
3368
                return;
3369
              }
3370
              global$9(scrollBarElm).css('display', 'block');
3371
              containerElm = self.getEl('body');
3372
              scrollThumbElm = self.getEl('scroll' + axisName + 't');
3373
              containerSize = containerElm['client' + sizeName] - margin * 2;
3374
              containerSize -= hasScrollH && hasScrollV ? scrollBarElm['client' + ax] : 0;
3375
              scrollSize = containerElm['scroll' + sizeName];
3376
              ratio = containerSize / scrollSize;
3377
              rect = {};
3378
              rect[posNameLower] = containerElm['offset' + posName] + margin;
3379
              rect[sizeNameLower] = containerSize;
3380
              global$9(scrollBarElm).css(rect);
3381
              rect = {};
3382
              rect[posNameLower] = containerElm['scroll' + posName] * ratio;
3383
              rect[sizeNameLower] = containerSize * ratio;
3384
              global$9(scrollThumbElm).css(rect);
3385
            }
3386
          }
3387
          bodyElm = self.getEl('body');
3388
          hasScrollH = bodyElm.scrollWidth > bodyElm.clientWidth;
3389
          hasScrollV = bodyElm.scrollHeight > bodyElm.clientHeight;
3390
          repaintAxis('h', 'Left', 'Width', 'contentW', hasScrollH, 'Height');
3391
          repaintAxis('v', 'Top', 'Height', 'contentH', hasScrollV, 'Width');
3392
        }
3393
        function addScroll() {
3394
          function addScrollAxis(axisName, posName, sizeName, deltaPosName, ax) {
3395
            var scrollStart;
3396
            var axisId = self._id + '-scroll' + axisName, prefix = self.classPrefix;
3397
            global$9(self.getEl()).append('<div id="' + axisId + '" class="' + prefix + 'scrollbar ' + prefix + 'scrollbar-' + axisName + '">' + '<div id="' + axisId + 't" class="' + prefix + 'scrollbar-thumb"></div>' + '</div>');
3398
            self.draghelper = new DragHelper(axisId + 't', {
3399
              start: function () {
3400
                scrollStart = self.getEl('body')['scroll' + posName];
3401
                global$9('#' + axisId).addClass(prefix + 'active');
3402
              },
3403
              drag: function (e) {
3404
                var ratio, hasScrollH, hasScrollV, containerSize;
3405
                var layoutRect = self.layoutRect();
3406
                hasScrollH = layoutRect.contentW > layoutRect.innerW;
3407
                hasScrollV = layoutRect.contentH > layoutRect.innerH;
3408
                containerSize = self.getEl('body')['client' + sizeName] - margin * 2;
3409
                containerSize -= hasScrollH && hasScrollV ? self.getEl('scroll' + axisName)['client' + ax] : 0;
3410
                ratio = containerSize / self.getEl('body')['scroll' + sizeName];
3411
                self.getEl('body')['scroll' + posName] = scrollStart + e['delta' + deltaPosName] / ratio;
3412
              },
3413
              stop: function () {
3414
                global$9('#' + axisId).removeClass(prefix + 'active');
3415
              }
3416
            });
3417
          }
3418
          self.classes.add('scroll');
3419
          addScrollAxis('v', 'Top', 'Height', 'Y', 'Width');
3420
          addScrollAxis('h', 'Left', 'Width', 'X', 'Height');
3421
        }
3422
        if (self.settings.autoScroll) {
3423
          if (!self._hasScroll) {
3424
            self._hasScroll = true;
3425
            addScroll();
3426
            self.on('wheel', function (e) {
3427
              var bodyEl = self.getEl('body');
3428
              bodyEl.scrollLeft += (e.deltaX || 0) * 10;
3429
              bodyEl.scrollTop += e.deltaY * 10;
3430
              repaintScroll();
3431
            });
3432
            global$9(self.getEl('body')).on('scroll', repaintScroll);
3433
          }
3434
          repaintScroll();
3435
        }
3436
      }
3437
    };
3438
3439
    var Panel = Container.extend({
3440
      Defaults: {
3441
        layout: 'fit',
3442
        containerCls: 'panel'
3443
      },
3444
      Mixins: [Scrollable],
3445 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3446
        var self = this;
3447
        var layout = self._layout;
3448
        var innerHtml = self.settings.html;
3449
        self.preRender();
3450
        layout.preRender(self);
3451
        if (typeof innerHtml === 'undefined') {
3452
          innerHtml = '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + layout.renderHtml(self) + '</div>';
3453
        } else {
3454
          if (typeof innerHtml === 'function') {
3455
            innerHtml = innerHtml.call(self);
3456
          }
3457
          self._hasBody = false;
3458
        }
3459
        return '<div id="' + self._id + '" class="' + self.classes + '" hidefocus="1" tabindex="-1" role="group">' + (self._preBodyHtml || '') + innerHtml + '</div>';
3460
      }
3461
    });
3462
3463
    var Resizable = {
3464
      resizeToContent: function () {
3465
        this._layoutRect.autoResize = true;
3466
        this._lastRect = null;
3467
        this.reflow();
3468
      },
3469 View Code Duplication
      resizeTo: function (w, h) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3470
        if (w <= 1 || h <= 1) {
3471
          var rect = funcs.getWindowSize();
3472
          w = w <= 1 ? w * rect.w : w;
3473
          h = h <= 1 ? h * rect.h : h;
3474
        }
3475
        this._layoutRect.autoResize = false;
3476
        return this.layoutRect({
3477
          minW: w,
3478
          minH: h,
3479
          w: w,
3480
          h: h
3481
        }).reflow();
3482
      },
3483
      resizeBy: function (dw, dh) {
3484
        var self = this, rect = self.layoutRect();
3485
        return self.resizeTo(rect.w + dw, rect.h + dh);
3486
      }
3487
    };
3488
3489
    var documentClickHandler, documentScrollHandler, windowResizeHandler;
3490
    var visiblePanels = [];
3491
    var zOrder = [];
3492
    var hasModal;
3493
    function isChildOf(ctrl, parent$$1) {
3494
      while (ctrl) {
3495
        if (ctrl === parent$$1) {
3496
          return true;
3497
        }
3498
        ctrl = ctrl.parent();
3499
      }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
3500
    }
3501
    function skipOrHidePanels(e) {
3502
      var i = visiblePanels.length;
3503
      while (i--) {
3504
        var panel = visiblePanels[i], clickCtrl = panel.getParentCtrl(e.target);
3505
        if (panel.settings.autohide) {
3506
          if (clickCtrl) {
3507
            if (isChildOf(clickCtrl, panel) || panel.parent() === clickCtrl) {
3508
              continue;
3509
            }
3510
          }
3511
          e = panel.fire('autohide', { target: e.target });
3512
          if (!e.isDefaultPrevented()) {
3513
            panel.hide();
3514
          }
3515
        }
3516
      }
3517
    }
3518
    function bindDocumentClickHandler() {
3519
      if (!documentClickHandler) {
3520
        documentClickHandler = function (e) {
3521
          if (e.button === 2) {
3522
            return;
3523
          }
3524
          skipOrHidePanels(e);
3525
        };
3526
        global$9(document).on('click touchstart', documentClickHandler);
3527
      }
3528
    }
3529
    function bindDocumentScrollHandler() {
3530
      if (!documentScrollHandler) {
3531
        documentScrollHandler = function () {
3532
          var i;
3533
          i = visiblePanels.length;
3534
          while (i--) {
3535
            repositionPanel(visiblePanels[i]);
3536
          }
3537
        };
3538
        global$9(window).on('scroll', documentScrollHandler);
3539
      }
3540
    }
3541
    function bindWindowResizeHandler() {
3542
      if (!windowResizeHandler) {
3543
        var docElm_1 = document.documentElement;
3544
        var clientWidth_1 = docElm_1.clientWidth, clientHeight_1 = docElm_1.clientHeight;
3545
        windowResizeHandler = function () {
3546
          if (!document.all || clientWidth_1 !== docElm_1.clientWidth || clientHeight_1 !== docElm_1.clientHeight) {
3547
            clientWidth_1 = docElm_1.clientWidth;
3548
            clientHeight_1 = docElm_1.clientHeight;
3549
            FloatPanel.hideAll();
3550
          }
3551
        };
3552
        global$9(window).on('resize', windowResizeHandler);
3553
      }
3554
    }
3555 View Code Duplication
    function repositionPanel(panel) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3556
      var scrollY$$1 = funcs.getViewPort().y;
3557
      function toggleFixedChildPanels(fixed, deltaY) {
3558
        var parent$$1;
3559
        for (var i = 0; i < visiblePanels.length; i++) {
3560
          if (visiblePanels[i] !== panel) {
3561
            parent$$1 = visiblePanels[i].parent();
3562
            while (parent$$1 && (parent$$1 = parent$$1.parent())) {
3563
              if (parent$$1 === panel) {
3564
                visiblePanels[i].fixed(fixed).moveBy(0, deltaY).repaint();
3565
              }
3566
            }
3567
          }
3568
        }
3569
      }
3570
      if (panel.settings.autofix) {
3571
        if (!panel.state.get('fixed')) {
3572
          panel._autoFixY = panel.layoutRect().y;
3573
          if (panel._autoFixY < scrollY$$1) {
3574
            panel.fixed(true).layoutRect({ y: 0 }).repaint();
3575
            toggleFixedChildPanels(true, scrollY$$1 - panel._autoFixY);
3576
          }
3577
        } else {
3578
          if (panel._autoFixY > scrollY$$1) {
3579
            panel.fixed(false).layoutRect({ y: panel._autoFixY }).repaint();
3580
            toggleFixedChildPanels(false, panel._autoFixY - scrollY$$1);
3581
          }
3582
        }
3583
      }
3584
    }
3585
    function addRemove(add, ctrl) {
3586
      var i, zIndex = FloatPanel.zIndex || 65535, topModal;
3587
      if (add) {
3588
        zOrder.push(ctrl);
3589
      } else {
3590
        i = zOrder.length;
3591
        while (i--) {
3592
          if (zOrder[i] === ctrl) {
3593
            zOrder.splice(i, 1);
3594
          }
3595
        }
3596
      }
3597
      if (zOrder.length) {
3598
        for (i = 0; i < zOrder.length; i++) {
3599
          if (zOrder[i].modal) {
3600
            zIndex++;
3601
            topModal = zOrder[i];
3602
          }
3603
          zOrder[i].getEl().style.zIndex = zIndex;
3604
          zOrder[i].zIndex = zIndex;
3605
          zIndex++;
3606
        }
3607
      }
3608
      var modalBlockEl = global$9('#' + ctrl.classPrefix + 'modal-block', ctrl.getContainerElm())[0];
3609
      if (topModal) {
3610
        global$9(modalBlockEl).css('z-index', topModal.zIndex - 1);
3611
      } else if (modalBlockEl) {
3612
        modalBlockEl.parentNode.removeChild(modalBlockEl);
3613
        hasModal = false;
3614
      }
3615
      FloatPanel.currentZIndex = zIndex;
3616
    }
3617
    var FloatPanel = Panel.extend({
3618
      Mixins: [
3619
        Movable,
3620
        Resizable
3621
      ],
3622
      init: function (settings) {
3623
        var self$$1 = this;
3624
        self$$1._super(settings);
3625
        self$$1._eventsRoot = self$$1;
3626
        self$$1.classes.add('floatpanel');
3627
        if (settings.autohide) {
3628
          bindDocumentClickHandler();
3629
          bindWindowResizeHandler();
3630
          visiblePanels.push(self$$1);
3631
        }
3632
        if (settings.autofix) {
3633
          bindDocumentScrollHandler();
3634
          self$$1.on('move', function () {
3635
            repositionPanel(this);
3636
          });
3637
        }
3638
        self$$1.on('postrender show', function (e) {
3639
          if (e.control === self$$1) {
3640
            var $modalBlockEl_1;
3641
            var prefix_1 = self$$1.classPrefix;
3642
            if (self$$1.modal && !hasModal) {
3643
              $modalBlockEl_1 = global$9('#' + prefix_1 + 'modal-block', self$$1.getContainerElm());
3644
              if (!$modalBlockEl_1[0]) {
3645
                $modalBlockEl_1 = global$9('<div id="' + prefix_1 + 'modal-block" class="' + prefix_1 + 'reset ' + prefix_1 + 'fade"></div>').appendTo(self$$1.getContainerElm());
3646
              }
3647
              global$7.setTimeout(function () {
3648
                $modalBlockEl_1.addClass(prefix_1 + 'in');
3649
                global$9(self$$1.getEl()).addClass(prefix_1 + 'in');
3650
              });
3651
              hasModal = true;
3652
            }
3653
            addRemove(true, self$$1);
3654
          }
3655
        });
3656
        self$$1.on('show', function () {
3657
          self$$1.parents().each(function (ctrl) {
3658
            if (ctrl.state.get('fixed')) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if ctrl.state.get("fixed") is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
3659
              self$$1.fixed(true);
3660
              return false;
3661
            }
3662
          });
3663
        });
3664
        if (settings.popover) {
3665
          self$$1._preBodyHtml = '<div class="' + self$$1.classPrefix + 'arrow"></div>';
3666
          self$$1.classes.add('popover').add('bottom').add(self$$1.isRtl() ? 'end' : 'start');
3667
        }
3668
        self$$1.aria('label', settings.ariaLabel);
3669
        self$$1.aria('labelledby', self$$1._id);
3670
        self$$1.aria('describedby', self$$1.describedBy || self$$1._id + '-none');
3671
      },
3672
      fixed: function (state) {
3673
        var self$$1 = this;
3674
        if (self$$1.state.get('fixed') !== state) {
3675
          if (self$$1.state.get('rendered')) {
3676
            var viewport = funcs.getViewPort();
3677
            if (state) {
3678
              self$$1.layoutRect().y -= viewport.y;
3679
            } else {
3680
              self$$1.layoutRect().y += viewport.y;
3681
            }
3682
          }
3683
          self$$1.classes.toggle('fixed', state);
3684
          self$$1.state.set('fixed', state);
3685
        }
3686
        return self$$1;
3687
      },
3688
      show: function () {
3689
        var self$$1 = this;
3690
        var i;
3691
        var state = self$$1._super();
3692
        i = visiblePanels.length;
3693
        while (i--) {
3694
          if (visiblePanels[i] === self$$1) {
3695
            break;
3696
          }
3697
        }
3698
        if (i === -1) {
3699
          visiblePanels.push(self$$1);
3700
        }
3701
        return state;
3702
      },
3703
      hide: function () {
3704
        removeVisiblePanel(this);
3705
        addRemove(false, this);
3706
        return this._super();
3707
      },
3708
      hideAll: function () {
3709
        FloatPanel.hideAll();
3710
      },
3711
      close: function () {
3712
        var self$$1 = this;
3713
        if (!self$$1.fire('close').isDefaultPrevented()) {
3714
          self$$1.remove();
3715
          addRemove(false, self$$1);
3716
        }
3717
        return self$$1;
3718
      },
3719
      remove: function () {
3720
        removeVisiblePanel(this);
3721
        this._super();
3722
      },
3723
      postRender: function () {
3724
        var self$$1 = this;
3725
        if (self$$1.settings.bodyRole) {
3726
          this.getEl('body').setAttribute('role', self$$1.settings.bodyRole);
3727
        }
3728
        return self$$1._super();
3729
      }
3730
    });
3731
    FloatPanel.hideAll = function () {
3732
      var i = visiblePanels.length;
3733
      while (i--) {
3734
        var panel = visiblePanels[i];
3735
        if (panel && panel.settings.autohide) {
3736
          panel.hide();
3737
          visiblePanels.splice(i, 1);
3738
        }
3739
      }
3740
    };
3741
    function removeVisiblePanel(panel) {
3742
      var i;
3743
      i = visiblePanels.length;
3744
      while (i--) {
3745
        if (visiblePanels[i] === panel) {
3746
          visiblePanels.splice(i, 1);
3747
        }
3748
      }
3749
      i = zOrder.length;
3750
      while (i--) {
3751
        if (zOrder[i] === panel) {
3752
          zOrder.splice(i, 1);
3753
        }
3754
      }
3755
    }
3756
3757
    var isFixed$1 = function (inlineToolbarContainer, editor) {
3758
      return !!(inlineToolbarContainer && !editor.settings.ui_container);
3759
    };
3760
    var render$1 = function (editor, theme, args) {
3761
      var panel, inlineToolbarContainer;
3762
      var DOM = global$3.DOM;
3763
      var fixedToolbarContainer = getFixedToolbarContainer(editor);
3764
      if (fixedToolbarContainer) {
3765
        inlineToolbarContainer = DOM.select(fixedToolbarContainer)[0];
3766
      }
3767
      var reposition = function () {
3768
        if (panel && panel.moveRel && panel.visible() && !panel._fixed) {
3769
          var scrollContainer = editor.selection.getScrollContainer(), body = editor.getBody();
3770
          var deltaX = 0, deltaY = 0;
3771
          if (scrollContainer) {
3772
            var bodyPos = DOM.getPos(body), scrollContainerPos = DOM.getPos(scrollContainer);
3773
            deltaX = Math.max(0, scrollContainerPos.x - bodyPos.x);
3774
            deltaY = Math.max(0, scrollContainerPos.y - bodyPos.y);
3775
          }
3776
          panel.fixed(false).moveRel(body, editor.rtl ? [
3777
            'tr-br',
3778
            'br-tr'
3779
          ] : [
3780
            'tl-bl',
3781
            'bl-tl',
3782
            'tr-br'
3783
          ]).moveBy(deltaX, deltaY);
3784
        }
3785
      };
3786
      var show = function () {
3787
        if (panel) {
3788
          panel.show();
3789
          reposition();
3790
          DOM.addClass(editor.getBody(), 'mce-edit-focus');
3791
        }
3792
      };
3793
      var hide = function () {
3794
        if (panel) {
3795
          panel.hide();
3796
          FloatPanel.hideAll();
3797
          DOM.removeClass(editor.getBody(), 'mce-edit-focus');
3798
        }
3799
      };
3800
      var render = function () {
3801
        if (panel) {
3802
          if (!panel.visible()) {
3803
            show();
3804
          }
3805
          return;
3806
        }
3807
        panel = theme.panel = global$4.create({
3808
          type: inlineToolbarContainer ? 'panel' : 'floatpanel',
3809
          role: 'application',
3810
          classes: 'tinymce tinymce-inline',
3811
          layout: 'flex',
3812
          direction: 'column',
3813
          align: 'stretch',
3814
          autohide: false,
3815
          autofix: true,
3816
          fixed: isFixed$1(inlineToolbarContainer, editor),
3817
          border: 1,
3818
          items: [
3819
            hasMenubar(editor) === false ? null : {
3820
              type: 'menubar',
3821
              border: '0 0 1 0',
3822
              items: Menubar.createMenuButtons(editor)
3823
            },
3824
            Toolbar.createToolbars(editor, getToolbarSize(editor))
3825
          ]
3826
        });
3827
        UiContainer.setUiContainer(editor, panel);
3828
        Events.fireBeforeRenderUI(editor);
3829
        if (inlineToolbarContainer) {
3830
          panel.renderTo(inlineToolbarContainer).reflow();
3831
        } else {
3832
          panel.renderTo().reflow();
3833
        }
3834
        A11y.addKeys(editor, panel);
3835
        show();
3836
        ContextToolbars.addContextualToolbars(editor);
3837
        editor.on('nodeChange', reposition);
3838
        editor.on('ResizeWindow', reposition);
3839
        editor.on('activate', show);
3840
        editor.on('deactivate', hide);
3841
        editor.nodeChanged();
3842
      };
3843
      editor.settings.content_editable = true;
3844
      editor.on('focus', function () {
3845
        if (isSkinDisabled(editor) === false && args.skinUiCss) {
3846
          DOM.styleSheetLoader.load(args.skinUiCss, render, render);
3847
        } else {
3848
          render();
3849
        }
3850
      });
3851
      editor.on('blur hide', hide);
3852
      editor.on('remove', function () {
3853
        if (panel) {
3854
          panel.remove();
3855
          panel = null;
3856
        }
3857
      });
3858
      if (isSkinDisabled(editor) === false && args.skinUiCss) {
3859
        DOM.styleSheetLoader.load(args.skinUiCss, SkinLoaded.fireSkinLoaded(editor));
3860
      } else {
3861
        SkinLoaded.fireSkinLoaded(editor)();
3862
      }
3863
      return {};
3864
    };
3865
    var Inline = { render: render$1 };
3866
3867
    function Throbber (elm, inline) {
3868
      var self = this;
3869
      var state;
3870
      var classPrefix = Control$1.classPrefix;
3871
      var timer;
3872
      self.show = function (time, callback) {
3873
        function render() {
3874
          if (state) {
3875
            global$9(elm).append('<div class="' + classPrefix + 'throbber' + (inline ? ' ' + classPrefix + 'throbber-inline' : '') + '"></div>');
3876
            if (callback) {
3877
              callback();
3878
            }
3879
          }
3880
        }
3881
        self.hide();
3882
        state = true;
3883
        if (time) {
3884
          timer = global$7.setTimeout(render, time);
3885
        } else {
3886
          render();
3887
        }
3888
        return self;
3889
      };
3890
      self.hide = function () {
3891
        var child = elm.lastChild;
3892
        global$7.clearTimeout(timer);
3893
        if (child && child.className.indexOf('throbber') !== -1) {
3894
          child.parentNode.removeChild(child);
3895
        }
3896
        state = false;
3897
        return self;
3898
      };
3899
    }
3900
3901
    var setup = function (editor, theme) {
3902
      var throbber;
3903
      editor.on('ProgressState', function (e) {
3904
        throbber = throbber || new Throbber(theme.panel.getEl('body'));
3905
        if (e.state) {
3906
          throbber.show(e.time);
3907
        } else {
3908
          throbber.hide();
3909
        }
3910
      });
3911
    };
3912
    var ProgressState = { setup: setup };
3913
3914
    var renderUI = function (editor, theme, args) {
3915
      var skinUrl = getSkinUrl(editor);
3916
      if (skinUrl) {
3917
        args.skinUiCss = skinUrl + '/skin.min.css';
3918
        editor.contentCSS.push(skinUrl + '/content' + (editor.inline ? '.inline' : '') + '.min.css');
3919
      }
3920
      ProgressState.setup(editor, theme);
3921
      return isInline(editor) ? Inline.render(editor, theme, args) : Iframe.render(editor, theme, args);
3922
    };
3923
    var Render = { renderUI: renderUI };
3924
3925
    var Tooltip = Control$1.extend({
3926
      Mixins: [Movable],
3927
      Defaults: { classes: 'widget tooltip tooltip-n' },
3928
      renderHtml: function () {
3929
        var self = this, prefix = self.classPrefix;
3930
        return '<div id="' + self._id + '" class="' + self.classes + '" role="presentation">' + '<div class="' + prefix + 'tooltip-arrow"></div>' + '<div class="' + prefix + 'tooltip-inner">' + self.encode(self.state.get('text')) + '</div>' + '</div>';
3931
      },
3932
      bindStates: function () {
3933
        var self = this;
3934
        self.state.on('change:text', function (e) {
3935
          self.getEl().lastChild.innerHTML = self.encode(e.value);
3936
        });
3937
        return self._super();
3938
      },
3939
      repaint: function () {
3940
        var self = this;
3941
        var style, rect;
3942
        style = self.getEl().style;
3943
        rect = self._layoutRect;
3944
        style.left = rect.x + 'px';
3945
        style.top = rect.y + 'px';
3946
        style.zIndex = 65535 + 65535;
3947
      }
3948
    });
3949
3950
    var Widget = Control$1.extend({
3951 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
3952
        var self = this;
3953
        self._super(settings);
3954
        settings = self.settings;
3955
        self.canFocus = true;
3956
        if (settings.tooltip && Widget.tooltips !== false) {
3957
          self.on('mouseenter', function (e) {
3958
            var tooltip = self.tooltip().moveTo(-65535);
3959
            if (e.control === self) {
3960
              var rel = tooltip.text(settings.tooltip).show().testMoveRel(self.getEl(), [
3961
                'bc-tc',
3962
                'bc-tl',
3963
                'bc-tr'
3964
              ]);
3965
              tooltip.classes.toggle('tooltip-n', rel === 'bc-tc');
3966
              tooltip.classes.toggle('tooltip-nw', rel === 'bc-tl');
3967
              tooltip.classes.toggle('tooltip-ne', rel === 'bc-tr');
3968
              tooltip.moveRel(self.getEl(), rel);
3969
            } else {
3970
              tooltip.hide();
3971
            }
3972
          });
3973
          self.on('mouseleave mousedown click', function () {
3974
            self.tooltip().remove();
3975
            self._tooltip = null;
3976
          });
3977
        }
3978
        self.aria('label', settings.ariaLabel || settings.tooltip);
3979
      },
3980
      tooltip: function () {
3981
        if (!this._tooltip) {
3982
          this._tooltip = new Tooltip({ type: 'tooltip' });
3983
          UiContainer.inheritUiContainer(this, this._tooltip);
3984
          this._tooltip.renderTo();
3985
        }
3986
        return this._tooltip;
3987
      },
3988
      postRender: function () {
3989
        var self = this, settings = self.settings;
3990
        self._super();
3991
        if (!self.parent() && (settings.width || settings.height)) {
3992
          self.initLayoutRect();
3993
          self.repaint();
3994
        }
3995
        if (settings.autofocus) {
3996
          self.focus();
3997
        }
3998
      },
3999
      bindStates: function () {
4000
        var self = this;
4001
        function disable(state) {
4002
          self.aria('disabled', state);
4003
          self.classes.toggle('disabled', state);
4004
        }
4005
        function active(state) {
4006
          self.aria('pressed', state);
4007
          self.classes.toggle('active', state);
4008
        }
4009
        self.state.on('change:disabled', function (e) {
4010
          disable(e.value);
4011
        });
4012
        self.state.on('change:active', function (e) {
4013
          active(e.value);
4014
        });
4015
        if (self.state.get('disabled')) {
4016
          disable(true);
4017
        }
4018
        if (self.state.get('active')) {
4019
          active(true);
4020
        }
4021
        return self._super();
4022
      },
4023
      remove: function () {
4024
        this._super();
4025
        if (this._tooltip) {
4026
          this._tooltip.remove();
4027
          this._tooltip = null;
4028
        }
4029
      }
4030
    });
4031
4032
    var Progress = Widget.extend({
4033
      Defaults: { value: 0 },
4034
      init: function (settings) {
4035
        var self = this;
4036
        self._super(settings);
4037
        self.classes.add('progress');
4038
        if (!self.settings.filter) {
4039
          self.settings.filter = function (value) {
4040
            return Math.round(value);
4041
          };
4042
        }
4043
      },
4044 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4045
        var self = this, id = self._id, prefix = this.classPrefix;
4046
        return '<div id="' + id + '" class="' + self.classes + '">' + '<div class="' + prefix + 'bar-container">' + '<div class="' + prefix + 'bar"></div>' + '</div>' + '<div class="' + prefix + 'text">0%</div>' + '</div>';
4047
      },
4048
      postRender: function () {
4049
        var self = this;
4050
        self._super();
4051
        self.value(self.settings.value);
4052
        return self;
4053
      },
4054
      bindStates: function () {
4055
        var self = this;
4056
        function setValue(value) {
4057
          value = self.settings.filter(value);
4058
          self.getEl().lastChild.innerHTML = value + '%';
4059
          self.getEl().firstChild.firstChild.style.width = value + '%';
4060
        }
4061
        self.state.on('change:value', function (e) {
4062
          setValue(e.value);
4063
        });
4064
        setValue(self.state.get('value'));
4065
        return self._super();
4066
      }
4067
    });
4068
4069
    var updateLiveRegion = function (ctx, text) {
4070
      ctx.getEl().lastChild.textContent = text + (ctx.progressBar ? ' ' + ctx.progressBar.value() + '%' : '');
4071
    };
4072
    var Notification = Control$1.extend({
4073
      Mixins: [Movable],
4074
      Defaults: { classes: 'widget notification' },
4075 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4076
        var self = this;
4077
        self._super(settings);
4078
        self.maxWidth = settings.maxWidth;
4079
        if (settings.text) {
4080
          self.text(settings.text);
4081
        }
4082
        if (settings.icon) {
4083
          self.icon = settings.icon;
4084
        }
4085
        if (settings.color) {
4086
          self.color = settings.color;
4087
        }
4088
        if (settings.type) {
4089
          self.classes.add('notification-' + settings.type);
4090
        }
4091
        if (settings.timeout && (settings.timeout < 0 || settings.timeout > 0) && !settings.closeButton) {
4092
          self.closeButton = false;
4093
        } else {
4094
          self.classes.add('has-close');
4095
          self.closeButton = true;
4096
        }
4097
        if (settings.progressBar) {
4098
          self.progressBar = new Progress();
4099
        }
4100
        self.on('click', function (e) {
4101
          if (e.target.className.indexOf(self.classPrefix + 'close') !== -1) {
4102
            self.close();
4103
          }
4104
        });
4105
      },
4106 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4107
        var self = this;
4108
        var prefix = self.classPrefix;
4109
        var icon = '', closeButton = '', progressBar = '', notificationStyle = '';
4110
        if (self.icon) {
4111
          icon = '<i class="' + prefix + 'ico' + ' ' + prefix + 'i-' + self.icon + '"></i>';
4112
        }
4113
        notificationStyle = ' style="max-width: ' + self.maxWidth + 'px;' + (self.color ? 'background-color: ' + self.color + ';"' : '"');
4114
        if (self.closeButton) {
4115
          closeButton = '<button type="button" class="' + prefix + 'close" aria-hidden="true">\xD7</button>';
4116
        }
4117
        if (self.progressBar) {
4118
          progressBar = self.progressBar.renderHtml();
4119
        }
4120
        return '<div id="' + self._id + '" class="' + self.classes + '"' + notificationStyle + ' role="presentation">' + icon + '<div class="' + prefix + 'notification-inner">' + self.state.get('text') + '</div>' + progressBar + closeButton + '<div style="clip: rect(1px, 1px, 1px, 1px);height: 1px;overflow: hidden;position: absolute;width: 1px;"' + ' aria-live="assertive" aria-relevant="additions" aria-atomic="true"></div>' + '</div>';
4121
      },
4122
      postRender: function () {
4123
        var self = this;
4124
        global$7.setTimeout(function () {
4125
          self.$el.addClass(self.classPrefix + 'in');
4126
          updateLiveRegion(self, self.state.get('text'));
4127
        }, 100);
4128
        return self._super();
4129
      },
4130
      bindStates: function () {
4131
        var self = this;
4132
        self.state.on('change:text', function (e) {
4133
          self.getEl().firstChild.innerHTML = e.value;
4134
          updateLiveRegion(self, e.value);
4135
        });
4136
        if (self.progressBar) {
4137
          self.progressBar.bindStates();
4138
          self.progressBar.state.on('change:value', function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
4139
            updateLiveRegion(self, self.state.get('text'));
4140
          });
4141
        }
4142
        return self._super();
4143
      },
4144
      close: function () {
4145
        var self = this;
4146
        if (!self.fire('close').isDefaultPrevented()) {
4147
          self.remove();
4148
        }
4149
        return self;
4150
      },
4151
      repaint: function () {
4152
        var self = this;
4153
        var style, rect;
4154
        style = self.getEl().style;
4155
        rect = self._layoutRect;
4156
        style.left = rect.x + 'px';
4157
        style.top = rect.y + 'px';
4158
        style.zIndex = 65535 - 1;
4159
      }
4160
    });
4161
4162 View Code Duplication
    function NotificationManagerImpl (editor) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4163
      var getEditorContainer = function (editor) {
4164
        return editor.inline ? editor.getElement() : editor.getContentAreaContainer();
4165
      };
4166
      var getContainerWidth = function () {
4167
        var container = getEditorContainer(editor);
4168
        return funcs.getSize(container).width;
4169
      };
4170
      var prePositionNotifications = function (notifications) {
4171
        each(notifications, function (notification) {
4172
          notification.moveTo(0, 0);
4173
        });
4174
      };
4175
      var positionNotifications = function (notifications) {
4176
        if (notifications.length > 0) {
4177
          var firstItem = notifications.slice(0, 1)[0];
4178
          var container = getEditorContainer(editor);
4179
          firstItem.moveRel(container, 'tc-tc');
4180
          each(notifications, function (notification, index) {
4181
            if (index > 0) {
4182
              notification.moveRel(notifications[index - 1].getEl(), 'bc-tc');
4183
            }
4184
          });
4185
        }
4186
      };
4187
      var reposition = function (notifications) {
4188
        prePositionNotifications(notifications);
4189
        positionNotifications(notifications);
4190
      };
4191
      var open = function (args, closeCallback) {
4192
        var extendedArgs = global$2.extend(args, { maxWidth: getContainerWidth() });
4193
        var notif = new Notification(extendedArgs);
4194
        notif.args = extendedArgs;
4195
        if (extendedArgs.timeout > 0) {
4196
          notif.timer = setTimeout(function () {
4197
            notif.close();
4198
            closeCallback();
4199
          }, extendedArgs.timeout);
4200
        }
4201
        notif.on('close', function () {
4202
          closeCallback();
4203
        });
4204
        notif.renderTo();
4205
        return notif;
4206
      };
4207
      var close = function (notification) {
4208
        notification.close();
4209
      };
4210
      var getArgs = function (notification) {
4211
        return notification.args;
4212
      };
4213
      return {
4214
        open: open,
4215
        close: close,
4216
        reposition: reposition,
4217
        getArgs: getArgs
4218
      };
4219
    }
4220
4221
    var windows = [];
4222
    var oldMetaValue = '';
4223
    function toggleFullScreenState(state) {
4224
      var noScaleMetaValue = 'width=device-width,initial-scale=1.0,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0';
4225
      var viewport = global$9('meta[name=viewport]')[0], contentValue;
4226
      if (global$8.overrideViewPort === false) {
4227
        return;
4228
      }
4229
      if (!viewport) {
4230
        viewport = document.createElement('meta');
4231
        viewport.setAttribute('name', 'viewport');
4232
        document.getElementsByTagName('head')[0].appendChild(viewport);
4233
      }
4234
      contentValue = viewport.getAttribute('content');
4235
      if (contentValue && typeof oldMetaValue !== 'undefined') {
4236
        oldMetaValue = contentValue;
4237
      }
4238
      viewport.setAttribute('content', state ? noScaleMetaValue : oldMetaValue);
4239
    }
4240
    function toggleBodyFullScreenClasses(classPrefix, state) {
4241
      if (checkFullscreenWindows() && state === false) {
4242
        global$9([
4243
          document.documentElement,
4244
          document.body
4245
        ]).removeClass(classPrefix + 'fullscreen');
4246
      }
4247
    }
4248
    function checkFullscreenWindows() {
4249
      for (var i = 0; i < windows.length; i++) {
4250
        if (windows[i]._fullscreen) {
4251
          return true;
4252
        }
4253
      }
4254
      return false;
4255
    }
4256
    function handleWindowResize() {
4257
      if (!global$8.desktop) {
4258
        var lastSize_1 = {
4259
          w: window.innerWidth,
4260
          h: window.innerHeight
4261
        };
4262
        global$7.setInterval(function () {
4263
          var w = window.innerWidth, h = window.innerHeight;
4264
          if (lastSize_1.w !== w || lastSize_1.h !== h) {
4265
            lastSize_1 = {
4266
              w: w,
4267
              h: h
4268
            };
4269
            global$9(window).trigger('resize');
4270
          }
4271
        }, 100);
4272
      }
4273 View Code Duplication
      function reposition() {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4274
        var i;
4275
        var rect = funcs.getWindowSize();
4276
        var layoutRect;
4277
        for (i = 0; i < windows.length; i++) {
4278
          layoutRect = windows[i].layoutRect();
4279
          windows[i].moveTo(windows[i].settings.x || Math.max(0, rect.w / 2 - layoutRect.w / 2), windows[i].settings.y || Math.max(0, rect.h / 2 - layoutRect.h / 2));
4280
        }
4281
      }
4282
      global$9(window).on('resize', reposition);
4283
    }
4284
    var Window$$1 = FloatPanel.extend({
4285
      modal: true,
4286
      Defaults: {
4287
        border: 1,
4288
        layout: 'flex',
4289
        containerCls: 'panel',
4290
        role: 'dialog',
4291
        callbacks: {
4292
          submit: function () {
4293
            this.fire('submit', { data: this.toJSON() });
4294
          },
4295
          close: function () {
4296
            this.close();
4297
          }
4298
        }
4299
      },
4300 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4301
        var self$$1 = this;
4302
        self$$1._super(settings);
4303
        if (self$$1.isRtl()) {
4304
          self$$1.classes.add('rtl');
4305
        }
4306
        self$$1.classes.add('window');
4307
        self$$1.bodyClasses.add('window-body');
4308
        self$$1.state.set('fixed', true);
4309
        if (settings.buttons) {
4310
          self$$1.statusbar = new Panel({
4311
            layout: 'flex',
4312
            border: '1 0 0 0',
4313
            spacing: 3,
4314
            padding: 10,
4315
            align: 'center',
4316
            pack: self$$1.isRtl() ? 'start' : 'end',
4317
            defaults: { type: 'button' },
4318
            items: settings.buttons
4319
          });
4320
          self$$1.statusbar.classes.add('foot');
4321
          self$$1.statusbar.parent(self$$1);
4322
        }
4323
        self$$1.on('click', function (e) {
4324
          var closeClass = self$$1.classPrefix + 'close';
4325
          if (funcs.hasClass(e.target, closeClass) || funcs.hasClass(e.target.parentNode, closeClass)) {
4326
            self$$1.close();
4327
          }
4328
        });
4329
        self$$1.on('cancel', function () {
4330
          self$$1.close();
4331
        });
4332
        self$$1.on('move', function (e) {
4333
          if (e.control === self$$1) {
4334
            FloatPanel.hideAll();
4335
          }
4336
        });
4337
        self$$1.aria('describedby', self$$1.describedBy || self$$1._id + '-none');
4338
        self$$1.aria('label', settings.title);
4339
        self$$1._fullscreen = false;
4340
      },
4341 View Code Duplication
      recalc: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4342
        var self$$1 = this;
4343
        var statusbar$$1 = self$$1.statusbar;
4344
        var layoutRect, width, x, needsRecalc;
4345
        if (self$$1._fullscreen) {
4346
          self$$1.layoutRect(funcs.getWindowSize());
4347
          self$$1.layoutRect().contentH = self$$1.layoutRect().innerH;
4348
        }
4349
        self$$1._super();
4350
        layoutRect = self$$1.layoutRect();
4351
        if (self$$1.settings.title && !self$$1._fullscreen) {
4352
          width = layoutRect.headerW;
4353
          if (width > layoutRect.w) {
4354
            x = layoutRect.x - Math.max(0, width / 2);
4355
            self$$1.layoutRect({
4356
              w: width,
4357
              x: x
4358
            });
4359
            needsRecalc = true;
4360
          }
4361
        }
4362
        if (statusbar$$1) {
4363
          statusbar$$1.layoutRect({ w: self$$1.layoutRect().innerW }).recalc();
4364
          width = statusbar$$1.layoutRect().minW + layoutRect.deltaW;
4365
          if (width > layoutRect.w) {
4366
            x = layoutRect.x - Math.max(0, width - layoutRect.w);
4367
            self$$1.layoutRect({
4368
              w: width,
4369
              x: x
4370
            });
4371
            needsRecalc = true;
4372
          }
4373
        }
4374
        if (needsRecalc) {
4375
          self$$1.recalc();
4376
        }
4377
      },
4378 View Code Duplication
      initLayoutRect: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4379
        var self$$1 = this;
4380
        var layoutRect = self$$1._super();
4381
        var deltaH = 0, headEl;
4382
        if (self$$1.settings.title && !self$$1._fullscreen) {
4383
          headEl = self$$1.getEl('head');
4384
          var size = funcs.getSize(headEl);
4385
          layoutRect.headerW = size.width;
4386
          layoutRect.headerH = size.height;
4387
          deltaH += layoutRect.headerH;
4388
        }
4389
        if (self$$1.statusbar) {
4390
          deltaH += self$$1.statusbar.layoutRect().h;
4391
        }
4392
        layoutRect.deltaH += deltaH;
4393
        layoutRect.minH += deltaH;
4394
        layoutRect.h += deltaH;
4395
        var rect = funcs.getWindowSize();
4396
        layoutRect.x = self$$1.settings.x || Math.max(0, rect.w / 2 - layoutRect.w / 2);
4397
        layoutRect.y = self$$1.settings.y || Math.max(0, rect.h / 2 - layoutRect.h / 2);
4398
        return layoutRect;
4399
      },
4400 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4401
        var self$$1 = this, layout = self$$1._layout, id = self$$1._id, prefix = self$$1.classPrefix;
4402
        var settings = self$$1.settings;
4403
        var headerHtml = '', footerHtml = '', html = settings.html;
4404
        self$$1.preRender();
4405
        layout.preRender(self$$1);
4406
        if (settings.title) {
4407
          headerHtml = '<div id="' + id + '-head" class="' + prefix + 'window-head">' + '<div id="' + id + '-title" class="' + prefix + 'title">' + self$$1.encode(settings.title) + '</div>' + '<div id="' + id + '-dragh" class="' + prefix + 'dragh"></div>' + '<button type="button" class="' + prefix + 'close" aria-hidden="true">' + '<i class="mce-ico mce-i-remove"></i>' + '</button>' + '</div>';
4408
        }
4409
        if (settings.url) {
4410
          html = '<iframe src="' + settings.url + '" tabindex="-1"></iframe>';
4411
        }
4412
        if (typeof html === 'undefined') {
4413
          html = layout.renderHtml(self$$1);
4414
        }
4415
        if (self$$1.statusbar) {
4416
          footerHtml = self$$1.statusbar.renderHtml();
4417
        }
4418
        return '<div id="' + id + '" class="' + self$$1.classes + '" hidefocus="1">' + '<div class="' + self$$1.classPrefix + 'reset" role="application">' + headerHtml + '<div id="' + id + '-body" class="' + self$$1.bodyClasses + '">' + html + '</div>' + footerHtml + '</div>' + '</div>';
4419
      },
4420 View Code Duplication
      fullscreen: function (state) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4421
        var self$$1 = this;
4422
        var documentElement = document.documentElement;
4423
        var slowRendering;
4424
        var prefix = self$$1.classPrefix;
4425
        var layoutRect;
4426
        if (state !== self$$1._fullscreen) {
4427
          global$9(window).on('resize', function () {
4428
            var time;
4429
            if (self$$1._fullscreen) {
4430
              if (!slowRendering) {
4431
                time = new Date().getTime();
4432
                var rect = funcs.getWindowSize();
4433
                self$$1.moveTo(0, 0).resizeTo(rect.w, rect.h);
4434
                if (new Date().getTime() - time > 50) {
4435
                  slowRendering = true;
4436
                }
4437
              } else {
4438
                if (!self$$1._timer) {
4439
                  self$$1._timer = global$7.setTimeout(function () {
4440
                    var rect = funcs.getWindowSize();
4441
                    self$$1.moveTo(0, 0).resizeTo(rect.w, rect.h);
4442
                    self$$1._timer = 0;
4443
                  }, 50);
4444
                }
4445
              }
4446
            }
4447
          });
4448
          layoutRect = self$$1.layoutRect();
4449
          self$$1._fullscreen = state;
4450
          if (!state) {
4451
            self$$1.borderBox = BoxUtils.parseBox(self$$1.settings.border);
4452
            self$$1.getEl('head').style.display = '';
4453
            layoutRect.deltaH += layoutRect.headerH;
4454
            global$9([
4455
              documentElement,
4456
              document.body
4457
            ]).removeClass(prefix + 'fullscreen');
4458
            self$$1.classes.remove('fullscreen');
4459
            self$$1.moveTo(self$$1._initial.x, self$$1._initial.y).resizeTo(self$$1._initial.w, self$$1._initial.h);
4460
          } else {
4461
            self$$1._initial = {
4462
              x: layoutRect.x,
4463
              y: layoutRect.y,
4464
              w: layoutRect.w,
4465
              h: layoutRect.h
4466
            };
4467
            self$$1.borderBox = BoxUtils.parseBox('0');
4468
            self$$1.getEl('head').style.display = 'none';
4469
            layoutRect.deltaH -= layoutRect.headerH + 2;
4470
            global$9([
4471
              documentElement,
4472
              document.body
4473
            ]).addClass(prefix + 'fullscreen');
4474
            self$$1.classes.add('fullscreen');
4475
            var rect = funcs.getWindowSize();
4476
            self$$1.moveTo(0, 0).resizeTo(rect.w, rect.h);
4477
          }
4478
        }
4479
        return self$$1.reflow();
4480
      },
4481 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4482
        var self$$1 = this;
4483
        var startPos;
4484
        setTimeout(function () {
4485
          self$$1.classes.add('in');
4486
          self$$1.fire('open');
4487
        }, 0);
4488
        self$$1._super();
4489
        if (self$$1.statusbar) {
4490
          self$$1.statusbar.postRender();
4491
        }
4492
        self$$1.focus();
4493
        this.dragHelper = new DragHelper(self$$1._id + '-dragh', {
4494
          start: function () {
4495
            startPos = {
4496
              x: self$$1.layoutRect().x,
4497
              y: self$$1.layoutRect().y
4498
            };
4499
          },
4500
          drag: function (e) {
4501
            self$$1.moveTo(startPos.x + e.deltaX, startPos.y + e.deltaY);
4502
          }
4503
        });
4504
        self$$1.on('submit', function (e) {
4505
          if (!e.isDefaultPrevented()) {
4506
            self$$1.close();
4507
          }
4508
        });
4509
        windows.push(self$$1);
4510
        toggleFullScreenState(true);
4511
      },
4512
      submit: function () {
4513
        return this.fire('submit', { data: this.toJSON() });
4514
      },
4515
      remove: function () {
4516
        var self$$1 = this;
4517
        var i;
4518
        self$$1.dragHelper.destroy();
4519
        self$$1._super();
4520
        if (self$$1.statusbar) {
4521
          this.statusbar.remove();
4522
        }
4523
        toggleBodyFullScreenClasses(self$$1.classPrefix, false);
4524
        i = windows.length;
4525
        while (i--) {
4526
          if (windows[i] === self$$1) {
4527
            windows.splice(i, 1);
4528
          }
4529
        }
4530
        toggleFullScreenState(windows.length > 0);
4531
      },
4532
      getContentWindow: function () {
4533
        var ifr = this.getEl().getElementsByTagName('iframe')[0];
4534
        return ifr ? ifr.contentWindow : null;
4535
      }
4536
    });
4537
    handleWindowResize();
4538
4539
    var MessageBox = Window$$1.extend({
4540
      init: function (settings) {
4541
        settings = {
4542
          border: 1,
4543
          padding: 20,
4544
          layout: 'flex',
4545
          pack: 'center',
4546
          align: 'center',
4547
          containerCls: 'panel',
4548
          autoScroll: true,
4549
          buttons: {
4550
            type: 'button',
4551
            text: 'Ok',
4552
            action: 'ok'
4553
          },
4554
          items: {
4555
            type: 'label',
4556
            multiline: true,
4557
            maxWidth: 500,
4558
            maxHeight: 200
4559
          }
4560
        };
4561
        this._super(settings);
4562
      },
4563
      Statics: {
4564
        OK: 1,
4565
        OK_CANCEL: 2,
4566
        YES_NO: 3,
4567
        YES_NO_CANCEL: 4,
4568 View Code Duplication
        msgBox: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4569
          var buttons;
4570
          var callback = settings.callback || function () {
4571
          };
4572
          function createButton(text, status$$1, primary) {
4573
            return {
4574
              type: 'button',
4575
              text: text,
4576
              subtype: primary ? 'primary' : '',
4577
              onClick: function (e) {
4578
                e.control.parents()[1].close();
4579
                callback(status$$1);
4580
              }
4581
            };
4582
          }
4583
          switch (settings.buttons) {
4584
          case MessageBox.OK_CANCEL:
4585
            buttons = [
4586
              createButton('Ok', true, true),
4587
              createButton('Cancel', false)
4588
            ];
4589
            break;
4590
          case MessageBox.YES_NO:
4591
          case MessageBox.YES_NO_CANCEL:
4592
            buttons = [
4593
              createButton('Yes', 1, true),
4594
              createButton('No', 0)
4595
            ];
4596
            if (settings.buttons === MessageBox.YES_NO_CANCEL) {
4597
              buttons.push(createButton('Cancel', -1));
4598
            }
4599
            break;
4600
          default:
4601
            buttons = [createButton('Ok', true, true)];
4602
            break;
4603
          }
4604
          return new Window$$1({
4605
            padding: 20,
4606
            x: settings.x,
4607
            y: settings.y,
4608
            minWidth: 300,
4609
            minHeight: 100,
4610
            layout: 'flex',
4611
            pack: 'center',
4612
            align: 'center',
4613
            buttons: buttons,
4614
            title: settings.title,
4615
            role: 'alertdialog',
4616
            items: {
4617
              type: 'label',
4618
              multiline: true,
4619
              maxWidth: 500,
4620
              maxHeight: 200,
4621
              text: settings.text
4622
            },
4623
            onPostRender: function () {
4624
              this.aria('describedby', this.items()[0]._id);
4625
            },
4626
            onClose: settings.onClose,
4627
            onCancel: function () {
4628
              callback(false);
4629
            }
4630
          }).renderTo(document.body).reflow();
4631
        },
4632
        alert: function (settings, callback) {
4633
          if (typeof settings === 'string') {
4634
            settings = { text: settings };
4635
          }
4636
          settings.callback = callback;
4637
          return MessageBox.msgBox(settings);
4638
        },
4639
        confirm: function (settings, callback) {
4640
          if (typeof settings === 'string') {
4641
            settings = { text: settings };
4642
          }
4643
          settings.callback = callback;
4644
          settings.buttons = MessageBox.OK_CANCEL;
4645
          return MessageBox.msgBox(settings);
4646
        }
4647
      }
4648
    });
4649
4650 View Code Duplication
    function WindowManagerImpl (editor) {
0 ignored issues
show
Unused Code introduced by
The parameter editor is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4651
      var open$$1 = function (args, params, closeCallback) {
4652
        var win;
4653
        args.title = args.title || ' ';
4654
        args.url = args.url || args.file;
4655
        if (args.url) {
4656
          args.width = parseInt(args.width || 320, 10);
4657
          args.height = parseInt(args.height || 240, 10);
4658
        }
4659
        if (args.body) {
4660
          args.items = {
4661
            defaults: args.defaults,
4662
            type: args.bodyType || 'form',
4663
            items: args.body,
4664
            data: args.data,
4665
            callbacks: args.commands
4666
          };
4667
        }
4668
        if (!args.url && !args.buttons) {
4669
          args.buttons = [
4670
            {
4671
              text: 'Ok',
4672
              subtype: 'primary',
4673
              onclick: function () {
4674
                win.find('form')[0].submit();
4675
              }
4676
            },
4677
            {
4678
              text: 'Cancel',
4679
              onclick: function () {
4680
                win.close();
4681
              }
4682
            }
4683
          ];
4684
        }
4685
        win = new Window$$1(args);
4686
        win.on('close', function () {
4687
          closeCallback(win);
4688
        });
4689
        if (args.data) {
4690
          win.on('postRender', function () {
4691
            this.find('*').each(function (ctrl) {
4692
              var name$$1 = ctrl.name();
4693
              if (name$$1 in args.data) {
4694
                ctrl.value(args.data[name$$1]);
4695
              }
4696
            });
4697
          });
4698
        }
4699
        win.features = args || {};
4700
        win.params = params || {};
4701
        win = win.renderTo(document.body).reflow();
4702
        return win;
4703
      };
4704
      var alert$$1 = function (message, choiceCallback, closeCallback) {
4705
        var win;
4706
        win = MessageBox.alert(message, function () {
4707
          choiceCallback();
4708
        });
4709
        win.on('close', function () {
4710
          closeCallback(win);
4711
        });
4712
        return win;
4713
      };
4714
      var confirm$$1 = function (message, choiceCallback, closeCallback) {
4715
        var win;
4716
        win = MessageBox.confirm(message, function (state) {
4717
          choiceCallback(state);
4718
        });
4719
        win.on('close', function () {
4720
          closeCallback(win);
4721
        });
4722
        return win;
4723
      };
4724
      var close$$1 = function (window$$1) {
4725
        window$$1.close();
4726
      };
4727
      var getParams = function (window$$1) {
4728
        return window$$1.params;
4729
      };
4730
      var setParams = function (window$$1, params) {
4731
        window$$1.params = params;
4732
      };
4733
      return {
4734
        open: open$$1,
4735
        alert: alert$$1,
4736
        confirm: confirm$$1,
4737
        close: close$$1,
4738
        getParams: getParams,
4739
        setParams: setParams
4740
      };
4741
    }
4742
4743
    var get = function (editor) {
4744
      var renderUI = function (args) {
4745
        return Render.renderUI(editor, this, args);
4746
      };
4747
      var resizeTo = function (w, h) {
4748
        return Resize.resizeTo(editor, w, h);
4749
      };
4750
      var resizeBy = function (dw, dh) {
4751
        return Resize.resizeBy(editor, dw, dh);
4752
      };
4753
      var getNotificationManagerImpl = function () {
4754
        return NotificationManagerImpl(editor);
4755
      };
4756
      var getWindowManagerImpl = function () {
4757
        return WindowManagerImpl(editor);
4758
      };
4759
      return {
4760
        renderUI: renderUI,
4761
        resizeTo: resizeTo,
4762
        resizeBy: resizeBy,
4763
        getNotificationManagerImpl: getNotificationManagerImpl,
4764
        getWindowManagerImpl: getWindowManagerImpl
4765
      };
4766
    };
4767
    var ThemeApi = { get: get };
4768
4769
    var Layout = global$a.extend({
4770
      Defaults: {
4771
        firstControlClass: 'first',
4772
        lastControlClass: 'last'
4773
      },
4774
      init: function (settings) {
4775
        this.settings = global$2.extend({}, this.Defaults, settings);
4776
      },
4777
      preRender: function (container) {
4778
        container.bodyClasses.add(this.settings.containerClass);
4779
      },
4780
      applyClasses: function (items) {
4781
        var self = this;
4782
        var settings = self.settings;
4783
        var firstClass, lastClass, firstItem, lastItem;
4784
        firstClass = settings.firstControlClass;
4785
        lastClass = settings.lastControlClass;
4786
        items.each(function (item) {
4787
          item.classes.remove(firstClass).remove(lastClass).add(settings.controlClass);
4788
          if (item.visible()) {
4789
            if (!firstItem) {
4790
              firstItem = item;
4791
            }
4792
            lastItem = item;
4793
          }
4794
        });
4795
        if (firstItem) {
4796
          firstItem.classes.add(firstClass);
4797
        }
4798
        if (lastItem) {
4799
          lastItem.classes.add(lastClass);
4800
        }
4801
      },
4802
      renderHtml: function (container) {
4803
        var self = this;
4804
        var html = '';
4805
        self.applyClasses(container.items());
4806
        container.items().each(function (item) {
4807
          html += item.renderHtml();
4808
        });
4809
        return html;
4810
      },
4811
      recalc: function () {
4812
      },
4813
      postRender: function () {
4814
      },
4815
      isNative: function () {
4816
        return false;
4817
      }
4818
    });
4819
4820
    var AbsoluteLayout = Layout.extend({
4821
      Defaults: {
4822
        containerClass: 'abs-layout',
4823
        controlClass: 'abs-layout-item'
4824
      },
4825
      recalc: function (container) {
4826
        container.items().filter(':visible').each(function (ctrl) {
4827
          var settings = ctrl.settings;
4828
          ctrl.layoutRect({
4829
            x: settings.x,
4830
            y: settings.y,
4831
            w: settings.w,
4832
            h: settings.h
4833
          });
4834
          if (ctrl.recalc) {
4835
            ctrl.recalc();
4836
          }
4837
        });
4838
      },
4839
      renderHtml: function (container) {
4840
        return '<div id="' + container._id + '-absend" class="' + container.classPrefix + 'abs-end"></div>' + this._super(container);
4841
      }
4842
    });
4843
4844
    var Button = Widget.extend({
4845
      Defaults: {
4846
        classes: 'widget btn',
4847
        role: 'button'
4848
      },
4849
      init: function (settings) {
4850
        var self$$1 = this;
4851
        var size;
4852
        self$$1._super(settings);
4853
        settings = self$$1.settings;
4854
        size = self$$1.settings.size;
4855
        self$$1.on('click mousedown', function (e) {
4856
          e.preventDefault();
4857
        });
4858
        self$$1.on('touchstart', function (e) {
4859
          self$$1.fire('click', e);
4860
          e.preventDefault();
4861
        });
4862
        if (settings.subtype) {
4863
          self$$1.classes.add(settings.subtype);
4864
        }
4865
        if (size) {
4866
          self$$1.classes.add('btn-' + size);
4867
        }
4868
        if (settings.icon) {
4869
          self$$1.icon(settings.icon);
4870
        }
4871
      },
4872
      icon: function (icon) {
4873
        if (!arguments.length) {
4874
          return this.state.get('icon');
4875
        }
4876
        this.state.set('icon', icon);
4877
        return this;
4878
      },
4879
      repaint: function () {
4880
        var btnElm = this.getEl().firstChild;
4881
        var btnStyle;
4882
        if (btnElm) {
4883
          btnStyle = btnElm.style;
4884
          btnStyle.width = btnStyle.height = '100%';
4885
        }
4886
        this._super();
4887
      },
4888 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4889
        var self$$1 = this, id = self$$1._id, prefix = self$$1.classPrefix;
4890
        var icon = self$$1.state.get('icon'), image;
4891
        var text = self$$1.state.get('text');
4892
        var textHtml = '';
4893
        var ariaPressed;
4894
        var settings = self$$1.settings;
4895
        image = settings.image;
4896
        if (image) {
4897
          icon = 'none';
4898
          if (typeof image !== 'string') {
4899
            image = window.getSelection ? image[0] : image[1];
4900
          }
4901
          image = ' style="background-image: url(\'' + image + '\')"';
4902
        } else {
4903
          image = '';
4904
        }
4905
        if (text) {
4906
          self$$1.classes.add('btn-has-text');
4907
          textHtml = '<span class="' + prefix + 'txt">' + self$$1.encode(text) + '</span>';
4908
        }
4909
        icon = icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
4910
        ariaPressed = typeof settings.active === 'boolean' ? ' aria-pressed="' + settings.active + '"' : '';
4911
        return '<div id="' + id + '" class="' + self$$1.classes + '" tabindex="-1"' + ariaPressed + '>' + '<button id="' + id + '-button" role="presentation" type="button" tabindex="-1">' + (icon ? '<i class="' + icon + '"' + image + '></i>' : '') + textHtml + '</button>' + '</div>';
4912
      },
4913 View Code Duplication
      bindStates: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
4914
        var self$$1 = this, $ = self$$1.$, textCls = self$$1.classPrefix + 'txt';
4915
        function setButtonText(text) {
4916
          var $span = $('span.' + textCls, self$$1.getEl());
4917
          if (text) {
4918
            if (!$span[0]) {
4919
              $('button:first', self$$1.getEl()).append('<span class="' + textCls + '"></span>');
4920
              $span = $('span.' + textCls, self$$1.getEl());
4921
            }
4922
            $span.html(self$$1.encode(text));
4923
          } else {
4924
            $span.remove();
4925
          }
4926
          self$$1.classes.toggle('btn-has-text', !!text);
4927
        }
4928
        self$$1.state.on('change:text', function (e) {
4929
          setButtonText(e.value);
4930
        });
4931
        self$$1.state.on('change:icon', function (e) {
4932
          var icon = e.value;
4933
          var prefix = self$$1.classPrefix;
4934
          self$$1.settings.icon = icon;
4935
          icon = icon ? prefix + 'ico ' + prefix + 'i-' + self$$1.settings.icon : '';
4936
          var btnElm = self$$1.getEl().firstChild;
4937
          var iconElm = btnElm.getElementsByTagName('i')[0];
4938
          if (icon) {
4939
            if (!iconElm || iconElm !== btnElm.firstChild) {
4940
              iconElm = document.createElement('i');
4941
              btnElm.insertBefore(iconElm, btnElm.firstChild);
4942
            }
4943
            iconElm.className = icon;
4944
          } else if (iconElm) {
4945
            btnElm.removeChild(iconElm);
4946
          }
4947
          setButtonText(self$$1.state.get('text'));
4948
        });
4949
        return self$$1._super();
4950
      }
4951
    });
4952
4953
    var BrowseButton = Button.extend({
4954
      init: function (settings) {
4955
        var self = this;
4956
        settings = global$2.extend({
4957
          text: 'Browse...',
4958
          multiple: false,
4959
          accept: null
4960
        }, settings);
4961
        self._super(settings);
4962
        self.classes.add('browsebutton');
4963
        if (settings.multiple) {
4964
          self.classes.add('multiple');
4965
        }
4966
      },
4967
      postRender: function () {
4968
        var self = this;
4969
        var input = funcs.create('input', {
4970
          type: 'file',
4971
          id: self._id + '-browse',
4972
          accept: self.settings.accept
4973
        });
4974
        self._super();
4975
        global$9(input).on('change', function (e) {
4976
          var files = e.target.files;
4977
          self.value = function () {
4978
            if (!files.length) {
4979
              return null;
4980
            } else if (self.settings.multiple) {
4981
              return files;
4982
            } else {
4983
              return files[0];
4984
            }
4985
          };
4986
          e.preventDefault();
4987
          if (files.length) {
4988
            self.fire('change', e);
4989
          }
4990
        });
4991
        global$9(input).on('click', function (e) {
4992
          e.stopPropagation();
4993
        });
4994
        global$9(self.getEl('button')).on('click', function (e) {
4995
          e.stopPropagation();
4996
          input.click();
4997
        });
4998
        self.getEl().appendChild(input);
4999
      },
5000
      remove: function () {
5001
        global$9(this.getEl('button')).off();
5002
        global$9(this.getEl('input')).off();
5003
        this._super();
5004
      }
5005
    });
5006
5007
    var ButtonGroup = Container.extend({
5008
      Defaults: {
5009
        defaultType: 'button',
5010
        role: 'group'
5011
      },
5012
      renderHtml: function () {
5013
        var self = this, layout = self._layout;
5014
        self.classes.add('btn-group');
5015
        self.preRender();
5016
        layout.preRender(self);
5017
        return '<div id="' + self._id + '" class="' + self.classes + '">' + '<div id="' + self._id + '-body">' + (self.settings.html || '') + layout.renderHtml(self) + '</div>' + '</div>';
5018
      }
5019
    });
5020
5021
    var Checkbox = Widget.extend({
5022
      Defaults: {
5023
        classes: 'checkbox',
5024
        role: 'checkbox',
5025
        checked: false
5026
      },
5027
      init: function (settings) {
5028
        var self$$1 = this;
5029
        self$$1._super(settings);
5030
        self$$1.on('click mousedown', function (e) {
5031
          e.preventDefault();
5032
        });
5033
        self$$1.on('click', function (e) {
5034
          e.preventDefault();
5035
          if (!self$$1.disabled()) {
5036
            self$$1.checked(!self$$1.checked());
5037
          }
5038
        });
5039
        self$$1.checked(self$$1.settings.checked);
5040
      },
5041
      checked: function (state) {
5042
        if (!arguments.length) {
5043
          return this.state.get('checked');
5044
        }
5045
        this.state.set('checked', state);
5046
        return this;
5047
      },
5048
      value: function (state) {
5049
        if (!arguments.length) {
5050
          return this.checked();
5051
        }
5052
        return this.checked(state);
5053
      },
5054 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5055
        var self$$1 = this, id = self$$1._id, prefix = self$$1.classPrefix;
5056
        return '<div id="' + id + '" class="' + self$$1.classes + '" unselectable="on" aria-labelledby="' + id + '-al" tabindex="-1">' + '<i class="' + prefix + 'ico ' + prefix + 'i-checkbox"></i>' + '<span id="' + id + '-al" class="' + prefix + 'label">' + self$$1.encode(self$$1.state.get('text')) + '</span>' + '</div>';
5057
      },
5058 View Code Duplication
      bindStates: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5059
        var self$$1 = this;
5060
        function checked(state) {
5061
          self$$1.classes.toggle('checked', state);
5062
          self$$1.aria('checked', state);
5063
        }
5064
        self$$1.state.on('change:text', function (e) {
5065
          self$$1.getEl('al').firstChild.data = self$$1.translate(e.value);
5066
        });
5067
        self$$1.state.on('change:checked change:value', function (e) {
5068
          self$$1.fire('change');
5069
          checked(e.value);
5070
        });
5071
        self$$1.state.on('change:icon', function (e) {
5072
          var icon = e.value;
5073
          var prefix = self$$1.classPrefix;
5074
          if (typeof icon === 'undefined') {
5075
            return self$$1.settings.icon;
5076
          }
5077
          self$$1.settings.icon = icon;
5078
          icon = icon ? prefix + 'ico ' + prefix + 'i-' + self$$1.settings.icon : '';
5079
          var btnElm = self$$1.getEl().firstChild;
5080
          var iconElm = btnElm.getElementsByTagName('i')[0];
5081
          if (icon) {
5082
            if (!iconElm || iconElm !== btnElm.firstChild) {
5083
              iconElm = document.createElement('i');
5084
              btnElm.insertBefore(iconElm, btnElm.firstChild);
5085
            }
5086
            iconElm.className = icon;
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
5087
          } else if (iconElm) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if iconElm is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
5088
            btnElm.removeChild(iconElm);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
5089
          }
5090
        });
5091
        if (self$$1.state.get('checked')) {
5092
          checked(true);
5093
        }
5094
        return self$$1._super();
5095
      }
5096
    });
5097
5098
    var global$d = tinymce.util.Tools.resolve('tinymce.util.VK');
5099
5100
    var ComboBox = Widget.extend({
5101 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5102
        var self$$1 = this;
5103
        self$$1._super(settings);
5104
        settings = self$$1.settings;
5105
        self$$1.classes.add('combobox');
5106
        self$$1.subinput = true;
5107
        self$$1.ariaTarget = 'inp';
5108
        settings.menu = settings.menu || settings.values;
5109
        if (settings.menu) {
5110
          settings.icon = 'caret';
5111
        }
5112
        self$$1.on('click', function (e) {
5113
          var elm = e.target;
5114
          var root = self$$1.getEl();
5115
          if (!global$9.contains(root, elm) && elm !== root) {
5116
            return;
5117
          }
5118
          while (elm && elm !== root) {
5119
            if (elm.id && elm.id.indexOf('-open') !== -1) {
5120
              self$$1.fire('action');
5121
              if (settings.menu) {
5122
                self$$1.showMenu();
5123
                if (e.aria) {
5124
                  self$$1.menu.items()[0].focus();
5125
                }
5126
              }
5127
            }
5128
            elm = elm.parentNode;
5129
          }
5130
        });
5131
        self$$1.on('keydown', function (e) {
5132
          var rootControl;
5133
          if (e.keyCode === 13 && e.target.nodeName === 'INPUT') {
5134
            e.preventDefault();
5135
            self$$1.parents().reverse().each(function (ctrl) {
5136
              if (ctrl.toJSON) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if ctrl.toJSON is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
5137
                rootControl = ctrl;
5138
                return false;
5139
              }
5140
            });
5141
            self$$1.fire('submit', { data: rootControl.toJSON() });
5142
          }
5143
        });
5144
        self$$1.on('keyup', function (e) {
5145
          if (e.target.nodeName === 'INPUT') {
5146
            var oldValue = self$$1.state.get('value');
5147
            var newValue = e.target.value;
5148
            if (newValue !== oldValue) {
5149
              self$$1.state.set('value', newValue);
5150
              self$$1.fire('autocomplete', e);
5151
            }
5152
          }
5153
        });
5154
        self$$1.on('mouseover', function (e) {
5155
          var tooltip = self$$1.tooltip().moveTo(-65535);
5156
          if (self$$1.statusLevel() && e.target.className.indexOf(self$$1.classPrefix + 'status') !== -1) {
5157
            var statusMessage = self$$1.statusMessage() || 'Ok';
5158
            var rel = tooltip.text(statusMessage).show().testMoveRel(e.target, [
5159
              'bc-tc',
5160
              'bc-tl',
5161
              'bc-tr'
5162
            ]);
5163
            tooltip.classes.toggle('tooltip-n', rel === 'bc-tc');
5164
            tooltip.classes.toggle('tooltip-nw', rel === 'bc-tl');
5165
            tooltip.classes.toggle('tooltip-ne', rel === 'bc-tr');
5166
            tooltip.moveRel(e.target, rel);
5167
          }
5168
        });
5169
      },
5170
      statusLevel: function (value) {
5171
        if (arguments.length > 0) {
5172
          this.state.set('statusLevel', value);
5173
        }
5174
        return this.state.get('statusLevel');
5175
      },
5176
      statusMessage: function (value) {
5177
        if (arguments.length > 0) {
5178
          this.state.set('statusMessage', value);
5179
        }
5180
        return this.state.get('statusMessage');
5181
      },
5182 View Code Duplication
      showMenu: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5183
        var self$$1 = this;
5184
        var settings = self$$1.settings;
5185
        var menu;
5186
        if (!self$$1.menu) {
5187
          menu = settings.menu || [];
5188
          if (menu.length) {
5189
            menu = {
5190
              type: 'menu',
5191
              items: menu
5192
            };
5193
          } else {
5194
            menu.type = menu.type || 'menu';
5195
          }
5196
          self$$1.menu = global$4.create(menu).parent(self$$1).renderTo(self$$1.getContainerElm());
5197
          self$$1.fire('createmenu');
5198
          self$$1.menu.reflow();
5199
          self$$1.menu.on('cancel', function (e) {
5200
            if (e.control === self$$1.menu) {
5201
              self$$1.focus();
5202
            }
5203
          });
5204
          self$$1.menu.on('show hide', function (e) {
5205
            e.control.items().each(function (ctrl) {
5206
              ctrl.active(ctrl.value() === self$$1.value());
5207
            });
5208
          }).fire('show');
5209
          self$$1.menu.on('select', function (e) {
5210
            self$$1.value(e.control.value());
5211
          });
5212
          self$$1.on('focusin', function (e) {
5213
            if (e.target.tagName.toUpperCase() === 'INPUT') {
5214
              self$$1.menu.hide();
5215
            }
5216
          });
5217
          self$$1.aria('expanded', true);
5218
        }
5219
        self$$1.menu.show();
5220
        self$$1.menu.layoutRect({ w: self$$1.layoutRect().w });
5221
        self$$1.menu.moveRel(self$$1.getEl(), self$$1.isRtl() ? [
5222
          'br-tr',
5223
          'tr-br'
5224
        ] : [
5225
          'bl-tl',
5226
          'tl-bl'
5227
        ]);
5228
      },
5229
      focus: function () {
5230
        this.getEl('inp').focus();
5231
      },
5232
      repaint: function () {
5233
        var self$$1 = this, elm = self$$1.getEl(), openElm = self$$1.getEl('open'), rect = self$$1.layoutRect();
5234
        var width, lineHeight, innerPadding = 0;
5235
        var inputElm = elm.firstChild;
5236
        if (self$$1.statusLevel() && self$$1.statusLevel() !== 'none') {
5237
          innerPadding = parseInt(funcs.getRuntimeStyle(inputElm, 'padding-right'), 10) - parseInt(funcs.getRuntimeStyle(inputElm, 'padding-left'), 10);
5238
        }
5239
        if (openElm) {
5240
          width = rect.w - funcs.getSize(openElm).width - 10;
5241
        } else {
5242
          width = rect.w - 10;
5243
        }
5244
        var doc = document;
5245
        if (doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
5246
          lineHeight = self$$1.layoutRect().h - 2 + 'px';
5247
        }
5248
        global$9(inputElm).css({
5249
          width: width - innerPadding,
5250
          lineHeight: lineHeight
0 ignored issues
show
Bug introduced by
The variable lineHeight does not seem to be initialized in case doc.all && !doc.document...| doc.documentMode <= 8 on line 5245 is false. Are you sure this can never be the case?
Loading history...
5251
        });
5252
        self$$1._super();
5253
        return self$$1;
5254
      },
5255
      postRender: function () {
5256
        var self$$1 = this;
5257
        global$9(this.getEl('inp')).on('change', function (e) {
5258
          self$$1.state.set('value', e.target.value);
5259
          self$$1.fire('change', e);
5260
        });
5261
        return self$$1._super();
5262
      },
5263 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5264
        var self$$1 = this, id = self$$1._id, settings = self$$1.settings, prefix = self$$1.classPrefix;
5265
        var value = self$$1.state.get('value') || '';
5266
        var icon, text, openBtnHtml = '', extraAttrs = '', statusHtml = '';
5267
        if ('spellcheck' in settings) {
5268
          extraAttrs += ' spellcheck="' + settings.spellcheck + '"';
5269
        }
5270
        if (settings.maxLength) {
5271
          extraAttrs += ' maxlength="' + settings.maxLength + '"';
5272
        }
5273
        if (settings.size) {
5274
          extraAttrs += ' size="' + settings.size + '"';
5275
        }
5276
        if (settings.subtype) {
5277
          extraAttrs += ' type="' + settings.subtype + '"';
5278
        }
5279
        statusHtml = '<i id="' + id + '-status" class="mce-status mce-ico" style="display: none"></i>';
5280
        if (self$$1.disabled()) {
5281
          extraAttrs += ' disabled="disabled"';
5282
        }
5283
        icon = settings.icon;
5284
        if (icon && icon !== 'caret') {
5285
          icon = prefix + 'ico ' + prefix + 'i-' + settings.icon;
5286
        }
5287
        text = self$$1.state.get('text');
5288
        if (icon || text) {
5289
          openBtnHtml = '<div id="' + id + '-open" class="' + prefix + 'btn ' + prefix + 'open" tabIndex="-1" role="button">' + '<button id="' + id + '-action" type="button" hidefocus="1" tabindex="-1">' + (icon !== 'caret' ? '<i class="' + icon + '"></i>' : '<i class="' + prefix + 'caret"></i>') + (text ? (icon ? ' ' : '') + text : '') + '</button>' + '</div>';
5290
          self$$1.classes.add('has-open');
5291
        }
5292
        return '<div id="' + id + '" class="' + self$$1.classes + '">' + '<input id="' + id + '-inp" class="' + prefix + 'textbox" value="' + self$$1.encode(value, false) + '" hidefocus="1"' + extraAttrs + ' placeholder="' + self$$1.encode(settings.placeholder) + '" />' + statusHtml + openBtnHtml + '</div>';
5293
      },
5294
      value: function (value) {
5295
        if (arguments.length) {
5296
          this.state.set('value', value);
5297
          return this;
5298
        }
5299
        if (this.state.get('rendered')) {
5300
          this.state.set('value', this.getEl('inp').value);
5301
        }
5302
        return this.state.get('value');
5303
      },
5304 View Code Duplication
      showAutoComplete: function (items, term) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5305
        var self$$1 = this;
5306
        if (items.length === 0) {
5307
          self$$1.hideMenu();
5308
          return;
5309
        }
5310
        var insert = function (value, title) {
5311
          return function () {
5312
            self$$1.fire('selectitem', {
5313
              title: title,
5314
              value: value
5315
            });
5316
          };
5317
        };
5318
        if (self$$1.menu) {
5319
          self$$1.menu.items().remove();
5320
        } else {
5321
          self$$1.menu = global$4.create({
5322
            type: 'menu',
5323
            classes: 'combobox-menu',
5324
            layout: 'flow'
5325
          }).parent(self$$1).renderTo();
5326
        }
5327
        global$2.each(items, function (item) {
5328
          self$$1.menu.add({
5329
            text: item.title,
5330
            url: item.previewUrl,
5331
            match: term,
5332
            classes: 'menu-item-ellipsis',
5333
            onclick: insert(item.value, item.title)
5334
          });
5335
        });
5336
        self$$1.menu.renderNew();
5337
        self$$1.hideMenu();
5338
        self$$1.menu.on('cancel', function (e) {
5339
          if (e.control.parent() === self$$1.menu) {
5340
            e.stopPropagation();
5341
            self$$1.focus();
5342
            self$$1.hideMenu();
5343
          }
5344
        });
5345
        self$$1.menu.on('select', function () {
5346
          self$$1.focus();
5347
        });
5348
        var maxW = self$$1.layoutRect().w;
5349
        self$$1.menu.layoutRect({
5350
          w: maxW,
5351
          minW: 0,
5352
          maxW: maxW
5353
        });
5354
        self$$1.menu.repaint();
5355
        self$$1.menu.reflow();
5356
        self$$1.menu.show();
5357
        self$$1.menu.moveRel(self$$1.getEl(), self$$1.isRtl() ? [
5358
          'br-tr',
5359
          'tr-br'
5360
        ] : [
5361
          'bl-tl',
5362
          'tl-bl'
5363
        ]);
5364
      },
5365
      hideMenu: function () {
5366
        if (this.menu) {
5367
          this.menu.hide();
5368
        }
5369
      },
5370 View Code Duplication
      bindStates: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5371
        var self$$1 = this;
5372
        self$$1.state.on('change:value', function (e) {
5373
          if (self$$1.getEl('inp').value !== e.value) {
5374
            self$$1.getEl('inp').value = e.value;
5375
          }
5376
        });
5377
        self$$1.state.on('change:disabled', function (e) {
5378
          self$$1.getEl('inp').disabled = e.value;
5379
        });
5380
        self$$1.state.on('change:statusLevel', function (e) {
5381
          var statusIconElm = self$$1.getEl('status');
5382
          var prefix = self$$1.classPrefix, value = e.value;
5383
          funcs.css(statusIconElm, 'display', value === 'none' ? 'none' : '');
5384
          funcs.toggleClass(statusIconElm, prefix + 'i-checkmark', value === 'ok');
5385
          funcs.toggleClass(statusIconElm, prefix + 'i-warning', value === 'warn');
5386
          funcs.toggleClass(statusIconElm, prefix + 'i-error', value === 'error');
5387
          self$$1.classes.toggle('has-status', value !== 'none');
5388
          self$$1.repaint();
5389
        });
5390
        funcs.on(self$$1.getEl('status'), 'mouseleave', function () {
5391
          self$$1.tooltip().hide();
5392
        });
5393
        self$$1.on('cancel', function (e) {
5394
          if (self$$1.menu && self$$1.menu.visible()) {
5395
            e.stopPropagation();
5396
            self$$1.hideMenu();
5397
          }
5398
        });
5399
        var focusIdx = function (idx, menu) {
5400
          if (menu && menu.items().length > 0) {
5401
            menu.items().eq(idx)[0].focus();
5402
          }
5403
        };
5404
        self$$1.on('keydown', function (e) {
5405
          var keyCode = e.keyCode;
5406
          if (e.target.nodeName === 'INPUT') {
5407
            if (keyCode === global$d.DOWN) {
5408
              e.preventDefault();
5409
              self$$1.fire('autocomplete');
5410
              focusIdx(0, self$$1.menu);
5411
            } else if (keyCode === global$d.UP) {
5412
              e.preventDefault();
5413
              focusIdx(-1, self$$1.menu);
5414
            }
5415
          }
5416
        });
5417
        return self$$1._super();
5418
      },
5419
      remove: function () {
5420
        global$9(this.getEl('inp')).off();
5421
        if (this.menu) {
5422
          this.menu.remove();
5423
        }
5424
        this._super();
5425
      }
5426
    });
5427
5428
    var ColorBox = ComboBox.extend({
5429
      init: function (settings) {
5430
        var self = this;
5431
        settings.spellcheck = false;
5432
        if (settings.onaction) {
5433
          settings.icon = 'none';
5434
        }
5435
        self._super(settings);
5436
        self.classes.add('colorbox');
5437
        self.on('change keyup postrender', function () {
5438
          self.repaintColor(self.value());
5439
        });
5440
      },
5441
      repaintColor: function (value) {
5442
        var openElm = this.getEl('open');
5443
        var elm = openElm ? openElm.getElementsByTagName('i')[0] : null;
5444
        if (elm) {
5445
          try {
5446
            elm.style.background = value;
5447
          } catch (ex) {
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
5448
          }
5449
        }
5450
      },
5451
      bindStates: function () {
5452
        var self = this;
5453
        self.state.on('change:value', function (e) {
5454
          if (self.state.get('rendered')) {
5455
            self.repaintColor(e.value);
5456
          }
5457
        });
5458
        return self._super();
5459
      }
5460
    });
5461
5462
    var PanelButton = Button.extend({
5463 View Code Duplication
      showPanel: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5464
        var self = this, settings = self.settings;
5465
        self.classes.add('opened');
5466
        if (!self.panel) {
5467
          var panelSettings = settings.panel;
5468
          if (panelSettings.type) {
5469
            panelSettings = {
5470
              layout: 'grid',
5471
              items: panelSettings
5472
            };
5473
          }
5474
          panelSettings.role = panelSettings.role || 'dialog';
5475
          panelSettings.popover = true;
5476
          panelSettings.autohide = true;
5477
          panelSettings.ariaRoot = true;
5478
          self.panel = new FloatPanel(panelSettings).on('hide', function () {
5479
            self.classes.remove('opened');
5480
          }).on('cancel', function (e) {
5481
            e.stopPropagation();
5482
            self.focus();
5483
            self.hidePanel();
5484
          }).parent(self).renderTo(self.getContainerElm());
5485
          self.panel.fire('show');
5486
          self.panel.reflow();
5487
        } else {
5488
          self.panel.show();
5489
        }
5490
        var rtlRels = [
5491
          'bc-tc',
5492
          'bc-tl',
5493
          'bc-tr'
5494
        ];
5495
        var ltrRels = [
5496
          'bc-tc',
5497
          'bc-tr',
5498
          'bc-tl',
5499
          'tc-bc',
5500
          'tc-br',
5501
          'tc-bl'
5502
        ];
5503
        var rel = self.panel.testMoveRel(self.getEl(), settings.popoverAlign || (self.isRtl() ? rtlRels : ltrRels));
5504
        self.panel.classes.toggle('start', rel.substr(-1) === 'l');
5505
        self.panel.classes.toggle('end', rel.substr(-1) === 'r');
5506
        var isTop = rel.substr(0, 1) === 't';
5507
        self.panel.classes.toggle('bottom', !isTop);
5508
        self.panel.classes.toggle('top', isTop);
5509
        self.panel.moveRel(self.getEl(), rel);
5510
      },
5511
      hidePanel: function () {
5512
        var self = this;
5513
        if (self.panel) {
5514
          self.panel.hide();
5515
        }
5516
      },
5517
      postRender: function () {
5518
        var self = this;
5519
        self.aria('haspopup', true);
5520
        self.on('click', function (e) {
5521
          if (e.control === self) {
5522
            if (self.panel && self.panel.visible()) {
5523
              self.hidePanel();
5524
            } else {
5525
              self.showPanel();
5526
              self.panel.focus(!!e.aria);
5527
            }
5528
          }
5529
        });
5530
        return self._super();
5531
      },
5532
      remove: function () {
5533
        if (this.panel) {
5534
          this.panel.remove();
5535
          this.panel = null;
5536
        }
5537
        return this._super();
5538
      }
5539
    });
5540
5541
    var DOM$3 = global$3.DOM;
5542
    var ColorButton = PanelButton.extend({
5543
      init: function (settings) {
5544
        this._super(settings);
5545
        this.classes.add('splitbtn');
5546
        this.classes.add('colorbutton');
5547
      },
5548
      color: function (color) {
5549
        if (color) {
5550
          this._color = color;
5551
          this.getEl('preview').style.backgroundColor = color;
5552
          return this;
5553
        }
5554
        return this._color;
5555
      },
5556
      resetColor: function () {
5557
        this._color = null;
5558
        this.getEl('preview').style.backgroundColor = null;
5559
        return this;
5560
      },
5561 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5562
        var self = this, id = self._id, prefix = self.classPrefix, text = self.state.get('text');
5563
        var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
5564
        var image = self.settings.image ? ' style="background-image: url(\'' + self.settings.image + '\')"' : '';
5565
        var textHtml = '';
5566
        if (text) {
5567
          self.classes.add('btn-has-text');
5568
          textHtml = '<span class="' + prefix + 'txt">' + self.encode(text) + '</span>';
5569
        }
5570
        return '<div id="' + id + '" class="' + self.classes + '" role="button" tabindex="-1" aria-haspopup="true">' + '<button role="presentation" hidefocus="1" type="button" tabindex="-1">' + (icon ? '<i class="' + icon + '"' + image + '></i>' : '') + '<span id="' + id + '-preview" class="' + prefix + 'preview"></span>' + textHtml + '</button>' + '<button type="button" class="' + prefix + 'open" hidefocus="1" tabindex="-1">' + ' <i class="' + prefix + 'caret"></i>' + '</button>' + '</div>';
5571
      },
5572
      postRender: function () {
5573
        var self = this, onClickHandler = self.settings.onclick;
5574
        self.on('click', function (e) {
5575
          if (e.aria && e.aria.key === 'down') {
5576
            return;
5577
          }
5578
          if (e.control === self && !DOM$3.getParent(e.target, '.' + self.classPrefix + 'open')) {
5579
            e.stopImmediatePropagation();
5580
            onClickHandler.call(self, e);
5581
          }
5582
        });
5583
        delete self.settings.onclick;
5584
        return self._super();
5585
      }
5586
    });
5587
5588
    var global$e = tinymce.util.Tools.resolve('tinymce.util.Color');
5589
5590
    var ColorPicker = Widget.extend({
5591
      Defaults: { classes: 'widget colorpicker' },
5592
      init: function (settings) {
5593
        this._super(settings);
5594
      },
5595 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5596
        var self = this;
5597
        var color = self.color();
5598
        var hsv, hueRootElm, huePointElm, svRootElm, svPointElm;
5599
        hueRootElm = self.getEl('h');
5600
        huePointElm = self.getEl('hp');
5601
        svRootElm = self.getEl('sv');
5602
        svPointElm = self.getEl('svp');
5603
        function getPos(elm, event) {
5604
          var pos = funcs.getPos(elm);
5605
          var x, y;
5606
          x = event.pageX - pos.x;
5607
          y = event.pageY - pos.y;
5608
          x = Math.max(0, Math.min(x / elm.clientWidth, 1));
5609
          y = Math.max(0, Math.min(y / elm.clientHeight, 1));
5610
          return {
5611
            x: x,
5612
            y: y
5613
          };
5614
        }
5615
        function updateColor(hsv, hueUpdate) {
5616
          var hue = (360 - hsv.h) / 360;
5617
          funcs.css(huePointElm, { top: hue * 100 + '%' });
5618
          if (!hueUpdate) {
5619
            funcs.css(svPointElm, {
5620
              left: hsv.s + '%',
5621
              top: 100 - hsv.v + '%'
5622
            });
5623
          }
5624
          svRootElm.style.background = global$e({
5625
            s: 100,
5626
            v: 100,
5627
            h: hsv.h
5628
          }).toHex();
5629
          self.color().parse({
5630
            s: hsv.s,
5631
            v: hsv.v,
5632
            h: hsv.h
5633
          });
5634
        }
5635
        function updateSaturationAndValue(e) {
5636
          var pos;
5637
          pos = getPos(svRootElm, e);
5638
          hsv.s = pos.x * 100;
5639
          hsv.v = (1 - pos.y) * 100;
5640
          updateColor(hsv);
5641
          self.fire('change');
5642
        }
5643
        function updateHue(e) {
5644
          var pos;
5645
          pos = getPos(hueRootElm, e);
5646
          hsv = color.toHsv();
5647
          hsv.h = (1 - pos.y) * 360;
5648
          updateColor(hsv, true);
5649
          self.fire('change');
5650
        }
5651
        self._repaint = function () {
5652
          hsv = color.toHsv();
5653
          updateColor(hsv);
5654
        };
5655
        self._super();
5656
        self._svdraghelper = new DragHelper(self._id + '-sv', {
5657
          start: updateSaturationAndValue,
5658
          drag: updateSaturationAndValue
5659
        });
5660
        self._hdraghelper = new DragHelper(self._id + '-h', {
5661
          start: updateHue,
5662
          drag: updateHue
5663
        });
5664
        self._repaint();
5665
      },
5666
      rgb: function () {
5667
        return this.color().toRgb();
5668
      },
5669
      value: function (value) {
5670
        var self = this;
5671
        if (arguments.length) {
5672
          self.color().parse(value);
5673
          if (self._rendered) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if self._rendered is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
5674
            self._repaint();
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
5675
          }
5676
        } else {
5677
          return self.color().toHex();
5678
        }
5679
      },
5680
      color: function () {
5681
        if (!this._color) {
5682
          this._color = global$e();
5683
        }
5684
        return this._color;
5685
      },
5686 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5687
        var self = this;
5688
        var id = self._id;
5689
        var prefix = self.classPrefix;
5690
        var hueHtml;
5691
        var stops = '#ff0000,#ff0080,#ff00ff,#8000ff,#0000ff,#0080ff,#00ffff,#00ff80,#00ff00,#80ff00,#ffff00,#ff8000,#ff0000';
5692
        function getOldIeFallbackHtml() {
5693
          var i, l, html = '', gradientPrefix, stopsList;
5694
          gradientPrefix = 'filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=';
5695
          stopsList = stops.split(',');
5696
          for (i = 0, l = stopsList.length - 1; i < l; i++) {
5697
            html += '<div class="' + prefix + 'colorpicker-h-chunk" style="' + 'height:' + 100 / l + '%;' + gradientPrefix + stopsList[i] + ',endColorstr=' + stopsList[i + 1] + ');' + '-ms-' + gradientPrefix + stopsList[i] + ',endColorstr=' + stopsList[i + 1] + ')' + '"></div>';
5698
          }
5699
          return html;
5700
        }
5701
        var gradientCssText = 'background: -ms-linear-gradient(top,' + stops + ');' + 'background: linear-gradient(to bottom,' + stops + ');';
5702
        hueHtml = '<div id="' + id + '-h" class="' + prefix + 'colorpicker-h" style="' + gradientCssText + '">' + getOldIeFallbackHtml() + '<div id="' + id + '-hp" class="' + prefix + 'colorpicker-h-marker"></div>' + '</div>';
5703
        return '<div id="' + id + '" class="' + self.classes + '">' + '<div id="' + id + '-sv" class="' + prefix + 'colorpicker-sv">' + '<div class="' + prefix + 'colorpicker-overlay1">' + '<div class="' + prefix + 'colorpicker-overlay2">' + '<div id="' + id + '-svp" class="' + prefix + 'colorpicker-selector1">' + '<div class="' + prefix + 'colorpicker-selector2"></div>' + '</div>' + '</div>' + '</div>' + '</div>' + hueHtml + '</div>';
5704
      }
5705
    });
5706
5707
    var DropZone = Widget.extend({
5708
      init: function (settings) {
5709
        var self = this;
5710
        settings = global$2.extend({
5711
          height: 100,
5712
          text: 'Drop an image here',
5713
          multiple: false,
5714
          accept: null
5715
        }, settings);
5716
        self._super(settings);
5717
        self.classes.add('dropzone');
5718
        if (settings.multiple) {
5719
          self.classes.add('multiple');
5720
        }
5721
      },
5722 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5723
        var self = this;
5724
        var attrs, elm;
5725
        var cfg = self.settings;
5726
        attrs = {
5727
          id: self._id,
5728
          hidefocus: '1'
5729
        };
5730
        elm = funcs.create('div', attrs, '<span>' + this.translate(cfg.text) + '</span>');
5731
        if (cfg.height) {
5732
          funcs.css(elm, 'height', cfg.height + 'px');
5733
        }
5734
        if (cfg.width) {
5735
          funcs.css(elm, 'width', cfg.width + 'px');
5736
        }
5737
        elm.className = self.classes;
5738
        return elm.outerHTML;
5739
      },
5740 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5741
        var self = this;
5742
        var toggleDragClass = function (e) {
5743
          e.preventDefault();
5744
          self.classes.toggle('dragenter');
5745
          self.getEl().className = self.classes;
5746
        };
5747
        var filter = function (files) {
5748
          var accept = self.settings.accept;
5749
          if (typeof accept !== 'string') {
5750
            return files;
5751
          }
5752
          var re = new RegExp('(' + accept.split(/\s*,\s*/).join('|') + ')$', 'i');
5753
          return global$2.grep(files, function (file) {
5754
            return re.test(file.name);
5755
          });
5756
        };
5757
        self._super();
5758
        self.$el.on('dragover', function (e) {
5759
          e.preventDefault();
5760
        });
5761
        self.$el.on('dragenter', toggleDragClass);
5762
        self.$el.on('dragleave', toggleDragClass);
5763
        self.$el.on('drop', function (e) {
5764
          e.preventDefault();
5765
          if (self.state.get('disabled')) {
5766
            return;
5767
          }
5768
          var files = filter(e.dataTransfer.files);
5769
          self.value = function () {
5770
            if (!files.length) {
5771
              return null;
5772
            } else if (self.settings.multiple) {
5773
              return files;
5774
            } else {
5775
              return files[0];
5776
            }
5777
          };
5778
          if (files.length) {
5779
            self.fire('change', e);
5780
          }
5781
        });
5782
      },
5783
      remove: function () {
5784
        this.$el.off();
5785
        this._super();
5786
      }
5787
    });
5788
5789
    var Path = Widget.extend({
5790
      init: function (settings) {
5791
        var self = this;
5792
        if (!settings.delimiter) {
5793
          settings.delimiter = '\xBB';
5794
        }
5795
        self._super(settings);
5796
        self.classes.add('path');
5797
        self.canFocus = true;
5798
        self.on('click', function (e) {
5799
          var index;
5800
          var target = e.target;
5801
          if (index = target.getAttribute('data-index')) {
5802
            self.fire('select', {
5803
              value: self.row()[index],
5804
              index: index
5805
            });
5806
          }
5807
        });
5808
        self.row(self.settings.row);
5809
      },
5810
      focus: function () {
5811
        var self = this;
5812
        self.getEl().firstChild.focus();
5813
        return self;
5814
      },
5815
      row: function (row) {
5816
        if (!arguments.length) {
5817
          return this.state.get('row');
5818
        }
5819
        this.state.set('row', row);
5820
        return this;
5821
      },
5822
      renderHtml: function () {
5823
        var self = this;
5824
        return '<div id="' + self._id + '" class="' + self.classes + '">' + self._getDataPathHtml(self.state.get('row')) + '</div>';
5825
      },
5826
      bindStates: function () {
5827
        var self = this;
5828
        self.state.on('change:row', function (e) {
5829
          self.innerHtml(self._getDataPathHtml(e.value));
5830
        });
5831
        return self._super();
5832
      },
5833 View Code Duplication
      _getDataPathHtml: function (data) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5834
        var self = this;
5835
        var parts = data || [];
5836
        var i, l, html = '';
5837
        var prefix = self.classPrefix;
5838
        for (i = 0, l = parts.length; i < l; i++) {
5839
          html += (i > 0 ? '<div class="' + prefix + 'divider" aria-hidden="true"> ' + self.settings.delimiter + ' </div>' : '') + '<div role="button" class="' + prefix + 'path-item' + (i === l - 1 ? ' ' + prefix + 'last' : '') + '" data-index="' + i + '" tabindex="-1" id="' + self._id + '-' + i + '" aria-level="' + (i + 1) + '">' + parts[i].name + '</div>';
5840
        }
5841
        if (!html) {
5842
          html = '<div class="' + prefix + 'path-item">\xA0</div>';
5843
        }
5844
        return html;
5845
      }
5846
    });
5847
5848
    var ElementPath = Path.extend({
5849 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5850
        var self = this, editor = self.settings.editor;
5851
        function isHidden(elm) {
5852
          if (elm.nodeType === 1) {
5853
            if (elm.nodeName === 'BR' || !!elm.getAttribute('data-mce-bogus')) {
5854
              return true;
5855
            }
5856
            if (elm.getAttribute('data-mce-type') === 'bookmark') {
5857
              return true;
5858
            }
5859
          }
5860
          return false;
5861
        }
5862
        if (editor.settings.elementpath !== false) {
5863
          self.on('select', function (e) {
5864
            editor.focus();
5865
            editor.selection.select(this.row()[e.index].element);
5866
            editor.nodeChanged();
5867
          });
5868
          editor.on('nodeChange', function (e) {
5869
            var outParents = [];
5870
            var parents = e.parents;
5871
            var i = parents.length;
5872
            while (i--) {
5873
              if (parents[i].nodeType === 1 && !isHidden(parents[i])) {
5874
                var args = editor.fire('ResolveName', {
5875
                  name: parents[i].nodeName.toLowerCase(),
5876
                  target: parents[i]
5877
                });
5878
                if (!args.isDefaultPrevented()) {
5879
                  outParents.push({
5880
                    name: args.name,
5881
                    element: parents[i]
5882
                  });
5883
                }
5884
                if (args.isPropagationStopped()) {
5885
                  break;
5886
                }
5887
              }
5888
            }
5889
            self.row(outParents);
5890
          });
5891
        }
5892
        return self._super();
5893
      }
5894
    });
5895
5896
    var FormItem = Container.extend({
5897
      Defaults: {
5898
        layout: 'flex',
5899
        align: 'center',
5900
        defaults: { flex: 1 }
5901
      },
5902 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5903
        var self = this, layout = self._layout, prefix = self.classPrefix;
5904
        self.classes.add('formitem');
5905
        layout.preRender(self);
5906
        return '<div id="' + self._id + '" class="' + self.classes + '" hidefocus="1" tabindex="-1">' + (self.settings.title ? '<div id="' + self._id + '-title" class="' + prefix + 'title">' + self.settings.title + '</div>' : '') + '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + (self.settings.html || '') + layout.renderHtml(self) + '</div>' + '</div>';
5907
      }
5908
    });
5909
5910
    var Form = Container.extend({
5911
      Defaults: {
5912
        containerCls: 'form',
5913
        layout: 'flex',
5914
        direction: 'column',
5915
        align: 'stretch',
5916
        flex: 1,
5917
        padding: 15,
5918
        labelGap: 30,
5919
        spacing: 10,
5920
        callbacks: {
5921
          submit: function () {
5922
            this.submit();
5923
          }
5924
        }
5925
      },
5926
      preRender: function () {
5927
        var self = this, items = self.items();
5928
        if (!self.settings.formItemDefaults) {
5929
          self.settings.formItemDefaults = {
5930
            layout: 'flex',
5931
            autoResize: 'overflow',
5932
            defaults: { flex: 1 }
5933
          };
5934
        }
5935
        items.each(function (ctrl) {
5936
          var formItem;
5937
          var label = ctrl.settings.label;
5938
          if (label) {
5939
            formItem = new FormItem(global$2.extend({
5940
              items: {
5941
                type: 'label',
5942
                id: ctrl._id + '-l',
5943
                text: label,
5944
                flex: 0,
5945
                forId: ctrl._id,
5946
                disabled: ctrl.disabled()
5947
              }
5948
            }, self.settings.formItemDefaults));
5949
            formItem.type = 'formitem';
5950
            ctrl.aria('labelledby', ctrl._id + '-l');
5951
            if (typeof ctrl.settings.flex === 'undefined') {
5952
              ctrl.settings.flex = 1;
5953
            }
5954
            self.replace(ctrl, formItem);
5955
            formItem.add(ctrl);
5956
          }
5957
        });
5958
      },
5959
      submit: function () {
5960
        return this.fire('submit', { data: this.toJSON() });
5961
      },
5962
      postRender: function () {
5963
        var self = this;
5964
        self._super();
5965
        self.fromJSON(self.settings.data);
5966
      },
5967 View Code Duplication
      bindStates: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
5968
        var self = this;
5969
        self._super();
5970
        function recalcLabels() {
5971
          var maxLabelWidth = 0;
5972
          var labels = [];
5973
          var i, labelGap, items;
5974
          if (self.settings.labelGapCalc === false) {
5975
            return;
5976
          }
5977
          if (self.settings.labelGapCalc === 'children') {
5978
            items = self.find('formitem');
5979
          } else {
5980
            items = self.items();
5981
          }
5982
          items.filter('formitem').each(function (item) {
5983
            var labelCtrl = item.items()[0], labelWidth = labelCtrl.getEl().clientWidth;
5984
            maxLabelWidth = labelWidth > maxLabelWidth ? labelWidth : maxLabelWidth;
5985
            labels.push(labelCtrl);
5986
          });
5987
          labelGap = self.settings.labelGap || 0;
5988
          i = labels.length;
5989
          while (i--) {
5990
            labels[i].settings.minWidth = maxLabelWidth + labelGap;
5991
          }
5992
        }
5993
        self.on('show', recalcLabels);
5994
        recalcLabels();
5995
      }
5996
    });
5997
5998
    var FieldSet = Form.extend({
5999
      Defaults: {
6000
        containerCls: 'fieldset',
6001
        layout: 'flex',
6002
        direction: 'column',
6003
        align: 'stretch',
6004
        flex: 1,
6005
        padding: '25 15 5 15',
6006
        labelGap: 30,
6007
        spacing: 10,
6008
        border: 1
6009
      },
6010 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6011
        var self = this, layout = self._layout, prefix = self.classPrefix;
6012
        self.preRender();
6013
        layout.preRender(self);
6014
        return '<fieldset id="' + self._id + '" class="' + self.classes + '" hidefocus="1" tabindex="-1">' + (self.settings.title ? '<legend id="' + self._id + '-title" class="' + prefix + 'fieldset-title">' + self.settings.title + '</legend>' : '') + '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + (self.settings.html || '') + layout.renderHtml(self) + '</div>' + '</fieldset>';
6015
      }
6016
    });
6017
6018
    var unique$1 = 0;
6019
    var generate = function (prefix) {
6020
      var date = new Date();
6021
      var time = date.getTime();
6022
      var random = Math.floor(Math.random() * 1000000000);
6023
      unique$1++;
6024
      return prefix + '_' + random + unique$1 + String(time);
6025
    };
6026
6027
    var fromHtml = function (html, scope) {
6028
      var doc = scope || document;
6029
      var div = doc.createElement('div');
6030
      div.innerHTML = html;
6031
      if (!div.hasChildNodes() || div.childNodes.length > 1) {
6032
        console.error('HTML does not have a single root node', html);
6033
        throw 'HTML must have a single root node';
6034
      }
6035
      return fromDom(div.childNodes[0]);
6036
    };
6037
    var fromTag = function (tag, scope) {
6038
      var doc = scope || document;
6039
      var node = doc.createElement(tag);
6040
      return fromDom(node);
6041
    };
6042
    var fromText = function (text, scope) {
6043
      var doc = scope || document;
6044
      var node = doc.createTextNode(text);
6045
      return fromDom(node);
6046
    };
6047
    var fromDom = function (node) {
6048
      if (node === null || node === undefined)
6049
        throw new Error('Node cannot be null or undefined');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6050
      return { dom: constant(node) };
6051
    };
6052
    var fromPoint = function (docElm, x, y) {
6053
      var doc = docElm.dom();
6054
      return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
6055
    };
6056
    var Element$$1 = {
6057
      fromHtml: fromHtml,
6058
      fromTag: fromTag,
6059
      fromText: fromText,
6060
      fromDom: fromDom,
6061
      fromPoint: fromPoint
6062
    };
6063
6064 View Code Duplication
    var cached = function (f) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6065
      var called = false;
6066
      var r;
6067
      return function () {
6068
        var args = [];
6069
        for (var _i = 0; _i < arguments.length; _i++) {
6070
          args[_i] = arguments[_i];
6071
        }
6072
        if (!called) {
6073
          called = true;
6074
          r = f.apply(null, args);
6075
        }
6076
        return r;
0 ignored issues
show
Bug introduced by
The variable r does not seem to be initialized in case !called on line 6072 is false. Are you sure this can never be the case?
Loading history...
6077
      };
6078
    };
6079
6080
    var ATTRIBUTE = Node.ATTRIBUTE_NODE;
0 ignored issues
show
Bug introduced by
The variable Node seems to be never declared. If this is a global, consider adding a /** global: Node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Unused Code introduced by
The variable ATTRIBUTE seems to be never used. Consider removing it.
Loading history...
6081
    var CDATA_SECTION = Node.CDATA_SECTION_NODE;
0 ignored issues
show
Unused Code introduced by
The variable CDATA_SECTION seems to be never used. Consider removing it.
Loading history...
6082
    var COMMENT = Node.COMMENT_NODE;
0 ignored issues
show
Unused Code introduced by
The variable COMMENT seems to be never used. Consider removing it.
Loading history...
6083
    var DOCUMENT = Node.DOCUMENT_NODE;
6084
    var DOCUMENT_TYPE = Node.DOCUMENT_TYPE_NODE;
0 ignored issues
show
Unused Code introduced by
The variable DOCUMENT_TYPE seems to be never used. Consider removing it.
Loading history...
6085
    var DOCUMENT_FRAGMENT = Node.DOCUMENT_FRAGMENT_NODE;
0 ignored issues
show
Unused Code introduced by
The variable DOCUMENT_FRAGMENT seems to be never used. Consider removing it.
Loading history...
6086
    var ELEMENT = Node.ELEMENT_NODE;
6087
    var TEXT = Node.TEXT_NODE;
0 ignored issues
show
Unused Code introduced by
The variable TEXT seems to be never used. Consider removing it.
Loading history...
6088
    var PROCESSING_INSTRUCTION = Node.PROCESSING_INSTRUCTION_NODE;
0 ignored issues
show
Unused Code introduced by
The variable PROCESSING_INSTRUCTION seems to be never used. Consider removing it.
Loading history...
6089
    var ENTITY_REFERENCE = Node.ENTITY_REFERENCE_NODE;
0 ignored issues
show
Unused Code introduced by
The variable ENTITY_REFERENCE seems to be never used. Consider removing it.
Loading history...
6090
    var ENTITY = Node.ENTITY_NODE;
0 ignored issues
show
Unused Code introduced by
The variable ENTITY seems to be never used. Consider removing it.
Loading history...
6091
    var NOTATION = Node.NOTATION_NODE;
0 ignored issues
show
Unused Code introduced by
The variable NOTATION seems to be never used. Consider removing it.
Loading history...
6092
6093 View Code Duplication
    var Immutable = function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6094
      var fields = [];
6095
      for (var _i = 0; _i < arguments.length; _i++) {
6096
        fields[_i] = arguments[_i];
6097
      }
6098
      return function () {
6099
        var values = [];
6100
        for (var _i = 0; _i < arguments.length; _i++) {
6101
          values[_i] = arguments[_i];
6102
        }
6103
        if (fields.length !== values.length) {
6104
          throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
6105
        }
6106
        var struct = {};
6107
        each(fields, function (name, i) {
6108
          struct[name] = constant(values[i]);
6109
        });
6110
        return struct;
6111
      };
6112
    };
6113
6114
    var Global = typeof window !== 'undefined' ? window : Function('return this;')();
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
6115
6116 View Code Duplication
    var path = function (parts, scope) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6117
      var o = scope !== undefined && scope !== null ? scope : Global;
6118
      for (var i = 0; i < parts.length && o !== undefined && o !== null; ++i)
6119
        o = o[parts[i]];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6120
      return o;
6121
    };
6122
    var resolve = function (p, scope) {
6123
      var parts = p.split('.');
6124
      return path(parts, scope);
6125
    };
6126
6127
    var unsafe = function (name, scope) {
6128
      return resolve(name, scope);
6129
    };
6130
    var getOrDie = function (name, scope) {
6131
      var actual = unsafe(name, scope);
6132
      if (actual === undefined || actual === null)
6133
        throw name + ' not available on this browser';
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6134
      return actual;
6135
    };
6136
    var Global$1 = { getOrDie: getOrDie };
6137
6138
    var node = function () {
6139
      var f = Global$1.getOrDie('Node');
6140
      return f;
6141
    };
6142
    var compareDocumentPosition = function (a, b, match) {
6143
      return (a.compareDocumentPosition(b) & match) !== 0;
6144
    };
6145
    var documentPositionPreceding = function (a, b) {
6146
      return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_PRECEDING);
6147
    };
6148
    var documentPositionContainedBy = function (a, b) {
6149
      return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_CONTAINED_BY);
6150
    };
6151
    var Node$1 = {
6152
      documentPositionPreceding: documentPositionPreceding,
6153
      documentPositionContainedBy: documentPositionContainedBy
6154
    };
6155
6156
    var firstMatch = function (regexes, s) {
6157
      for (var i = 0; i < regexes.length; i++) {
6158
        var x = regexes[i];
6159
        if (x.test(s))
6160
          return x;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6161
      }
6162
      return undefined;
6163
    };
6164
    var find$2 = function (regexes, agent) {
6165
      var r = firstMatch(regexes, agent);
6166
      if (!r)
6167
        return {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6168
          major: 0,
6169
          minor: 0
6170
        };
6171
      var group = function (i) {
6172
        return Number(agent.replace(r, '$' + i));
6173
      };
6174
      return nu(group(1), group(2));
6175
    };
6176
    var detect = function (versionRegexes, agent) {
6177
      var cleanedAgent = String(agent).toLowerCase();
6178
      if (versionRegexes.length === 0)
6179
        return unknown();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
6180
      return find$2(versionRegexes, cleanedAgent);
6181
    };
6182
    var unknown = function () {
6183
      return nu(0, 0);
6184
    };
6185
    var nu = function (major, minor) {
6186
      return {
6187
        major: major,
6188
        minor: minor
6189
      };
6190
    };
6191
    var Version = {
6192
      nu: nu,
6193
      detect: detect,
6194
      unknown: unknown
6195
    };
6196
6197
    var edge = 'Edge';
6198
    var chrome = 'Chrome';
6199
    var ie = 'IE';
6200
    var opera = 'Opera';
6201
    var firefox = 'Firefox';
6202
    var safari = 'Safari';
6203
    var isBrowser = function (name, current) {
6204
      return function () {
6205
        return current === name;
6206
      };
6207
    };
6208
    var unknown$1 = function () {
6209
      return nu$1({
6210
        current: undefined,
6211
        version: Version.unknown()
6212
      });
6213
    };
6214
    var nu$1 = function (info) {
6215
      var current = info.current;
6216
      var version = info.version;
6217
      return {
6218
        current: current,
6219
        version: version,
6220
        isEdge: isBrowser(edge, current),
6221
        isChrome: isBrowser(chrome, current),
6222
        isIE: isBrowser(ie, current),
6223
        isOpera: isBrowser(opera, current),
6224
        isFirefox: isBrowser(firefox, current),
6225
        isSafari: isBrowser(safari, current)
6226
      };
6227
    };
6228
    var Browser = {
6229
      unknown: unknown$1,
6230
      nu: nu$1,
6231
      edge: constant(edge),
6232
      chrome: constant(chrome),
6233
      ie: constant(ie),
6234
      opera: constant(opera),
6235
      firefox: constant(firefox),
6236
      safari: constant(safari)
6237
    };
6238
6239
    var windows$1 = 'Windows';
6240
    var ios = 'iOS';
6241
    var android = 'Android';
6242
    var linux = 'Linux';
6243
    var osx = 'OSX';
6244
    var solaris = 'Solaris';
6245
    var freebsd = 'FreeBSD';
6246
    var isOS = function (name, current) {
6247
      return function () {
6248
        return current === name;
6249
      };
6250
    };
6251
    var unknown$2 = function () {
6252
      return nu$2({
6253
        current: undefined,
6254
        version: Version.unknown()
6255
      });
6256
    };
6257
    var nu$2 = function (info) {
6258
      var current = info.current;
6259
      var version = info.version;
6260
      return {
6261
        current: current,
6262
        version: version,
6263
        isWindows: isOS(windows$1, current),
6264
        isiOS: isOS(ios, current),
6265
        isAndroid: isOS(android, current),
6266
        isOSX: isOS(osx, current),
6267
        isLinux: isOS(linux, current),
6268
        isSolaris: isOS(solaris, current),
6269
        isFreeBSD: isOS(freebsd, current)
6270
      };
6271
    };
6272
    var OperatingSystem = {
6273
      unknown: unknown$2,
6274
      nu: nu$2,
6275
      windows: constant(windows$1),
6276
      ios: constant(ios),
6277
      android: constant(android),
6278
      linux: constant(linux),
6279
      osx: constant(osx),
6280
      solaris: constant(solaris),
6281
      freebsd: constant(freebsd)
6282
    };
6283
6284 View Code Duplication
    var DeviceType = function (os, browser, userAgent) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6285
      var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
6286
      var isiPhone = os.isiOS() && !isiPad;
6287
      var isAndroid3 = os.isAndroid() && os.version.major === 3;
6288
      var isAndroid4 = os.isAndroid() && os.version.major === 4;
6289
      var isTablet = isiPad || isAndroid3 || isAndroid4 && /mobile/i.test(userAgent) === true;
6290
      var isTouch = os.isiOS() || os.isAndroid();
6291
      var isPhone = isTouch && !isTablet;
6292
      var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
6293
      return {
6294
        isiPad: constant(isiPad),
6295
        isiPhone: constant(isiPhone),
6296
        isTablet: constant(isTablet),
6297
        isPhone: constant(isPhone),
6298
        isTouch: constant(isTouch),
6299
        isAndroid: os.isAndroid,
6300
        isiOS: os.isiOS,
6301
        isWebView: constant(iOSwebview)
6302
      };
6303
    };
6304
6305
    var detect$1 = function (candidates, userAgent) {
6306
      var agent = String(userAgent).toLowerCase();
6307
      return find(candidates, function (candidate) {
6308
        return candidate.search(agent);
6309
      });
6310
    };
6311
    var detectBrowser = function (browsers, userAgent) {
6312
      return detect$1(browsers, userAgent).map(function (browser) {
6313
        var version = Version.detect(browser.versionRegexes, userAgent);
6314
        return {
6315
          current: browser.name,
6316
          version: version
6317
        };
6318
      });
6319
    };
6320
    var detectOs = function (oses, userAgent) {
6321
      return detect$1(oses, userAgent).map(function (os) {
6322
        var version = Version.detect(os.versionRegexes, userAgent);
6323
        return {
6324
          current: os.name,
6325
          version: version
6326
        };
6327
      });
6328
    };
6329
    var UaString = {
6330
      detectBrowser: detectBrowser,
6331
      detectOs: detectOs
6332
    };
6333
6334
    var contains$1 = function (str, substr) {
6335
      return str.indexOf(substr) !== -1;
6336
    };
6337
6338
    var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
6339
    var checkContains = function (target) {
6340
      return function (uastring) {
6341
        return contains$1(uastring, target);
6342
      };
6343
    };
6344
    var browsers = [
6345
      {
6346
        name: 'Edge',
6347
        versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
6348
        search: function (uastring) {
6349
          var monstrosity = contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
6350
          return monstrosity;
6351
        }
6352
      },
6353
      {
6354
        name: 'Chrome',
6355
        versionRegexes: [
6356
          /.*?chrome\/([0-9]+)\.([0-9]+).*/,
6357
          normalVersionRegex
6358
        ],
6359
        search: function (uastring) {
6360
          return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
6361
        }
6362
      },
6363
      {
6364
        name: 'IE',
6365
        versionRegexes: [
6366
          /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
6367
          /.*?rv:([0-9]+)\.([0-9]+).*/
6368
        ],
6369
        search: function (uastring) {
6370
          return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
6371
        }
6372
      },
6373
      {
6374
        name: 'Opera',
6375
        versionRegexes: [
6376
          normalVersionRegex,
6377
          /.*?opera\/([0-9]+)\.([0-9]+).*/
6378
        ],
6379
        search: checkContains('opera')
6380
      },
6381
      {
6382
        name: 'Firefox',
6383
        versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
6384
        search: checkContains('firefox')
6385
      },
6386
      {
6387
        name: 'Safari',
6388
        versionRegexes: [
6389
          normalVersionRegex,
6390
          /.*?cpu os ([0-9]+)_([0-9]+).*/
6391
        ],
6392
        search: function (uastring) {
6393
          return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
6394
        }
6395
      }
6396
    ];
6397
    var oses = [
6398
      {
6399
        name: 'Windows',
6400
        search: checkContains('win'),
6401
        versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
6402
      },
6403
      {
6404
        name: 'iOS',
6405
        search: function (uastring) {
6406
          return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
6407
        },
6408
        versionRegexes: [
6409
          /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
6410
          /.*cpu os ([0-9]+)_([0-9]+).*/,
6411
          /.*cpu iphone os ([0-9]+)_([0-9]+).*/
6412
        ]
6413
      },
6414
      {
6415
        name: 'Android',
6416
        search: checkContains('android'),
6417
        versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
6418
      },
6419
      {
6420
        name: 'OSX',
6421
        search: checkContains('os x'),
6422
        versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
6423
      },
6424
      {
6425
        name: 'Linux',
6426
        search: checkContains('linux'),
6427
        versionRegexes: []
6428
      },
6429
      {
6430
        name: 'Solaris',
6431
        search: checkContains('sunos'),
6432
        versionRegexes: []
6433
      },
6434
      {
6435
        name: 'FreeBSD',
6436
        search: checkContains('freebsd'),
6437
        versionRegexes: []
6438
      }
6439
    ];
6440
    var PlatformInfo = {
6441
      browsers: constant(browsers),
6442
      oses: constant(oses)
6443
    };
6444
6445
    var detect$2 = function (userAgent) {
6446
      var browsers = PlatformInfo.browsers();
6447
      var oses = PlatformInfo.oses();
6448
      var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
6449
      var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
6450
      var deviceType = DeviceType(os, browser, userAgent);
6451
      return {
6452
        browser: browser,
6453
        os: os,
6454
        deviceType: deviceType
6455
      };
6456
    };
6457
    var PlatformDetection = { detect: detect$2 };
6458
6459
    var detect$3 = cached(function () {
6460
      var userAgent = navigator.userAgent;
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6461
      return PlatformDetection.detect(userAgent);
6462
    });
6463
    var PlatformDetection$1 = { detect: detect$3 };
6464
6465
    var ELEMENT$1 = ELEMENT;
6466
    var DOCUMENT$1 = DOCUMENT;
6467
    var bypassSelector = function (dom) {
6468
      return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
6469
    };
6470
    var all = function (selector, scope) {
6471
      var base = scope === undefined ? document : scope.dom();
6472
      return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element$$1.fromDom);
6473
    };
6474
    var one = function (selector, scope) {
6475
      var base = scope === undefined ? document : scope.dom();
6476
      return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element$$1.fromDom);
6477
    };
6478
6479
    var regularContains = function (e1, e2) {
6480
      var d1 = e1.dom(), d2 = e2.dom();
6481
      return d1 === d2 ? false : d1.contains(d2);
6482
    };
6483
    var ieContains = function (e1, e2) {
6484
      return Node$1.documentPositionContainedBy(e1.dom(), e2.dom());
6485
    };
6486
    var browser = PlatformDetection$1.detect().browser;
6487
    var contains$2 = browser.isIE() ? ieContains : regularContains;
0 ignored issues
show
Unused Code introduced by
The variable contains$2 seems to be never used. Consider removing it.
Loading history...
6488
6489
    var spot = Immutable('element', 'offset');
0 ignored issues
show
Unused Code introduced by
The variable spot seems to be never used. Consider removing it.
Loading history...
6490
6491
    var descendants$1 = function (scope, selector) {
6492
      return all(selector, scope);
6493
    };
6494
6495
    var trim$1 = global$2.trim;
6496
    var hasContentEditableState = function (value) {
6497
      return function (node) {
6498
        if (node && node.nodeType === 1) {
6499
          if (node.contentEditable === value) {
6500
            return true;
6501
          }
6502
          if (node.getAttribute('data-mce-contenteditable') === value) {
6503
            return true;
6504
          }
6505
        }
6506
        return false;
6507
      };
6508
    };
6509
    var isContentEditableTrue = hasContentEditableState('true');
6510
    var isContentEditableFalse = hasContentEditableState('false');
6511
    var create = function (type, title, url, level, attach) {
6512
      return {
6513
        type: type,
6514
        title: title,
6515
        url: url,
6516
        level: level,
6517
        attach: attach
6518
      };
6519
    };
6520
    var isChildOfContentEditableTrue = function (node) {
6521
      while (node = node.parentNode) {
6522
        var value = node.contentEditable;
6523
        if (value && value !== 'inherit') {
6524
          return isContentEditableTrue(node);
6525
        }
6526
      }
6527
      return false;
6528
    };
6529
    var select = function (selector, root) {
6530
      return map(descendants$1(Element$$1.fromDom(root), selector), function (element) {
6531
        return element.dom();
6532
      });
6533
    };
6534
    var getElementText = function (elm) {
6535
      return elm.innerText || elm.textContent;
6536
    };
6537
    var getOrGenerateId = function (elm) {
6538
      return elm.id ? elm.id : generate('h');
6539
    };
6540
    var isAnchor = function (elm) {
6541
      return elm && elm.nodeName === 'A' && (elm.id || elm.name);
6542
    };
6543
    var isValidAnchor = function (elm) {
6544
      return isAnchor(elm) && isEditable(elm);
6545
    };
6546
    var isHeader = function (elm) {
6547
      return elm && /^(H[1-6])$/.test(elm.nodeName);
6548
    };
6549
    var isEditable = function (elm) {
6550
      return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
6551
    };
6552
    var isValidHeader = function (elm) {
6553
      return isHeader(elm) && isEditable(elm);
6554
    };
6555
    var getLevel = function (elm) {
6556
      return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
6557
    };
6558
    var headerTarget = function (elm) {
6559
      var headerId = getOrGenerateId(elm);
6560
      var attach = function () {
6561
        elm.id = headerId;
6562
      };
6563
      return create('header', getElementText(elm), '#' + headerId, getLevel(elm), attach);
6564
    };
6565
    var anchorTarget = function (elm) {
6566
      var anchorId = elm.id || elm.name;
6567
      var anchorText = getElementText(elm);
6568
      return create('anchor', anchorText ? anchorText : '#' + anchorId, '#' + anchorId, 0, noop);
6569
    };
6570
    var getHeaderTargets = function (elms) {
6571
      return map(filter(elms, isValidHeader), headerTarget);
6572
    };
6573
    var getAnchorTargets = function (elms) {
6574
      return map(filter(elms, isValidAnchor), anchorTarget);
6575
    };
6576
    var getTargetElements = function (elm) {
6577
      var elms = select('h1,h2,h3,h4,h5,h6,a:not([href])', elm);
6578
      return elms;
6579
    };
6580
    var hasTitle = function (target) {
6581
      return trim$1(target.title).length > 0;
6582
    };
6583
    var find$3 = function (elm) {
6584
      var elms = getTargetElements(elm);
6585
      return filter(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
6586
    };
6587
    var LinkTargets = { find: find$3 };
6588
6589
    var getActiveEditor = function () {
6590
      return window.tinymce ? window.tinymce.activeEditor : global$1.activeEditor;
6591
    };
6592
    var history = {};
6593
    var HISTORY_LENGTH = 5;
6594
    var clearHistory = function () {
6595
      history = {};
6596
    };
6597
    var toMenuItem = function (target) {
6598
      return {
6599
        title: target.title,
6600
        value: {
6601
          title: { raw: target.title },
6602
          url: target.url,
6603
          attach: target.attach
6604
        }
6605
      };
6606
    };
6607
    var toMenuItems = function (targets) {
6608
      return global$2.map(targets, toMenuItem);
6609
    };
6610
    var staticMenuItem = function (title, url) {
6611
      return {
6612
        title: title,
6613
        value: {
6614
          title: title,
6615
          url: url,
6616
          attach: noop
6617
        }
6618
      };
6619
    };
6620
    var isUniqueUrl = function (url, targets) {
6621
      var foundTarget = exists(targets, function (target) {
6622
        return target.url === url;
6623
      });
6624
      return !foundTarget;
6625
    };
6626
    var getSetting = function (editorSettings, name, defaultValue) {
6627
      var value = name in editorSettings ? editorSettings[name] : defaultValue;
6628
      return value === false ? null : value;
6629
    };
6630 View Code Duplication
    var createMenuItems = function (term, targets, fileType, editorSettings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6631
      var separator = { title: '-' };
6632
      var fromHistoryMenuItems = function (history) {
6633
        var historyItems = history.hasOwnProperty(fileType) ? history[fileType] : [];
6634
        var uniqueHistory = filter(historyItems, function (url) {
6635
          return isUniqueUrl(url, targets);
6636
        });
6637
        return global$2.map(uniqueHistory, function (url) {
6638
          return {
6639
            title: url,
6640
            value: {
6641
              title: url,
6642
              url: url,
6643
              attach: noop
6644
            }
6645
          };
6646
        });
6647
      };
6648
      var fromMenuItems = function (type) {
6649
        var filteredTargets = filter(targets, function (target) {
6650
          return target.type === type;
6651
        });
6652
        return toMenuItems(filteredTargets);
6653
      };
6654
      var anchorMenuItems = function () {
6655
        var anchorMenuItems = fromMenuItems('anchor');
6656
        var topAnchor = getSetting(editorSettings, 'anchor_top', '#top');
6657
        var bottomAchor = getSetting(editorSettings, 'anchor_bottom', '#bottom');
6658
        if (topAnchor !== null) {
6659
          anchorMenuItems.unshift(staticMenuItem('<top>', topAnchor));
6660
        }
6661
        if (bottomAchor !== null) {
6662
          anchorMenuItems.push(staticMenuItem('<bottom>', bottomAchor));
6663
        }
6664
        return anchorMenuItems;
6665
      };
6666
      var join = function (items) {
6667
        return foldl(items, function (a, b) {
6668
          var bothEmpty = a.length === 0 || b.length === 0;
6669
          return bothEmpty ? a.concat(b) : a.concat(separator, b);
6670
        }, []);
6671
      };
6672
      if (editorSettings.typeahead_urls === false) {
6673
        return [];
6674
      }
6675
      return fileType === 'file' ? join([
6676
        filterByQuery(term, fromHistoryMenuItems(history)),
6677
        filterByQuery(term, fromMenuItems('header')),
6678
        filterByQuery(term, anchorMenuItems())
6679
      ]) : filterByQuery(term, fromHistoryMenuItems(history));
6680
    };
6681
    var addToHistory = function (url, fileType) {
6682
      var items = history[fileType];
6683
      if (!/^https?/.test(url)) {
6684
        return;
6685
      }
6686
      if (items) {
6687
        if (indexOf(items, url).isNone()) {
6688
          history[fileType] = items.slice(0, HISTORY_LENGTH).concat(url);
6689
        }
6690
      } else {
6691
        history[fileType] = [url];
6692
      }
6693
    };
6694
    var filterByQuery = function (term, menuItems) {
6695
      var lowerCaseTerm = term.toLowerCase();
6696
      var result = global$2.grep(menuItems, function (item) {
6697
        return item.title.toLowerCase().indexOf(lowerCaseTerm) !== -1;
6698
      });
6699
      return result.length === 1 && result[0].title === term ? [] : result;
6700
    };
6701
    var getTitle = function (linkDetails) {
6702
      var title = linkDetails.title;
6703
      return title.raw ? title.raw : title;
6704
    };
6705 View Code Duplication
    var setupAutoCompleteHandler = function (ctrl, editorSettings, bodyElm, fileType) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6706
      var autocomplete = function (term) {
6707
        var linkTargets = LinkTargets.find(bodyElm);
6708
        var menuItems = createMenuItems(term, linkTargets, fileType, editorSettings);
6709
        ctrl.showAutoComplete(menuItems, term);
6710
      };
6711
      ctrl.on('autocomplete', function () {
6712
        autocomplete(ctrl.value());
6713
      });
6714
      ctrl.on('selectitem', function (e) {
6715
        var linkDetails = e.value;
6716
        ctrl.value(linkDetails.url);
6717
        var title = getTitle(linkDetails);
6718
        if (fileType === 'image') {
6719
          ctrl.fire('change', {
6720
            meta: {
6721
              alt: title,
6722
              attach: linkDetails.attach
6723
            }
6724
          });
6725
        } else {
6726
          ctrl.fire('change', {
6727
            meta: {
6728
              text: title,
6729
              attach: linkDetails.attach
6730
            }
6731
          });
6732
        }
6733
        ctrl.focus();
6734
      });
6735
      ctrl.on('click', function (e) {
6736
        if (ctrl.value().length === 0 && e.target.nodeName === 'INPUT') {
6737
          autocomplete('');
6738
        }
6739
      });
6740
      ctrl.on('PostRender', function () {
6741
        ctrl.getRoot().on('submit', function (e) {
6742
          if (!e.isDefaultPrevented()) {
6743
            addToHistory(ctrl.value(), fileType);
6744
          }
6745
        });
6746
      });
6747
    };
6748 View Code Duplication
    var statusToUiState = function (result) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6749
      var status = result.status, message = result.message;
6750
      if (status === 'valid') {
6751
        return {
6752
          status: 'ok',
6753
          message: message
6754
        };
6755
      } else if (status === 'unknown') {
6756
        return {
6757
          status: 'warn',
6758
          message: message
6759
        };
6760
      } else if (status === 'invalid') {
6761
        return {
6762
          status: 'warn',
6763
          message: message
6764
        };
6765
      } else {
6766
        return {
6767
          status: 'none',
6768
          message: ''
6769
        };
6770
      }
6771
    };
6772
    var setupLinkValidatorHandler = function (ctrl, editorSettings, fileType) {
6773
      var validatorHandler = editorSettings.filepicker_validator_handler;
6774
      if (validatorHandler) {
6775
        var validateUrl_1 = function (url) {
6776
          if (url.length === 0) {
6777
            ctrl.statusLevel('none');
6778
            return;
6779
          }
6780
          validatorHandler({
6781
            url: url,
6782
            type: fileType
6783
          }, function (result) {
6784
            var uiState = statusToUiState(result);
6785
            ctrl.statusMessage(uiState.message);
6786
            ctrl.statusLevel(uiState.status);
6787
          });
6788
        };
6789
        ctrl.state.on('change:value', function (e) {
6790
          validateUrl_1(e.value);
6791
        });
6792
      }
6793
    };
6794
    var FilePicker = ComboBox.extend({
6795
      Statics: { clearHistory: clearHistory },
6796 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6797
        var self = this, editor = getActiveEditor(), editorSettings = editor.settings;
6798
        var actionCallback, fileBrowserCallback, fileBrowserCallbackTypes;
6799
        var fileType = settings.filetype;
6800
        settings.spellcheck = false;
6801
        fileBrowserCallbackTypes = editorSettings.file_picker_types || editorSettings.file_browser_callback_types;
6802
        if (fileBrowserCallbackTypes) {
6803
          fileBrowserCallbackTypes = global$2.makeMap(fileBrowserCallbackTypes, /[, ]/);
6804
        }
6805
        if (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType]) {
6806
          fileBrowserCallback = editorSettings.file_picker_callback;
6807
          if (fileBrowserCallback && (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType])) {
6808
            actionCallback = function () {
6809
              var meta = self.fire('beforecall').meta;
6810
              meta = global$2.extend({ filetype: fileType }, meta);
6811
              fileBrowserCallback.call(editor, function (value, meta) {
6812
                self.value(value).fire('change', { meta: meta });
6813
              }, self.value(), meta);
6814
            };
6815
          } else {
6816
            fileBrowserCallback = editorSettings.file_browser_callback;
6817
            if (fileBrowserCallback && (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType])) {
6818
              actionCallback = function () {
6819
                fileBrowserCallback(self.getEl('inp').id, self.value(), fileType, window);
6820
              };
6821
            }
6822
          }
6823
        }
6824
        if (actionCallback) {
6825
          settings.icon = 'browse';
6826
          settings.onaction = actionCallback;
6827
        }
6828
        self._super(settings);
6829
        self.classes.add('filepicker');
6830
        setupAutoCompleteHandler(self, editorSettings, editor.getBody(), fileType);
6831
        setupLinkValidatorHandler(self, editorSettings, fileType);
6832
      }
6833
    });
6834
6835
    var FitLayout = AbsoluteLayout.extend({
6836
      recalc: function (container) {
6837
        var contLayoutRect = container.layoutRect(), paddingBox = container.paddingBox;
6838
        container.items().filter(':visible').each(function (ctrl) {
6839
          ctrl.layoutRect({
6840
            x: paddingBox.left,
6841
            y: paddingBox.top,
6842
            w: contLayoutRect.innerW - paddingBox.right - paddingBox.left,
6843
            h: contLayoutRect.innerH - paddingBox.top - paddingBox.bottom
6844
          });
6845
          if (ctrl.recalc) {
6846
            ctrl.recalc();
6847
          }
6848
        });
6849
      }
6850
    });
6851
6852
    var FlexLayout = AbsoluteLayout.extend({
6853 View Code Duplication
      recalc: function (container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
6854
        var i, l, items, contLayoutRect, contPaddingBox, contSettings, align, pack, spacing, totalFlex, availableSpace, direction;
6855
        var ctrl, ctrlLayoutRect, ctrlSettings, flex;
6856
        var maxSizeItems = [];
6857
        var size, maxSize, ratio, rect, pos, maxAlignEndPos;
6858
        var sizeName, minSizeName, posName, maxSizeName, beforeName, innerSizeName, deltaSizeName, contentSizeName;
6859
        var alignAxisName, alignInnerSizeName, alignSizeName, alignMinSizeName, alignBeforeName, alignAfterName;
6860
        var alignDeltaSizeName, alignContentSizeName;
6861
        var max = Math.max, min = Math.min;
6862
        items = container.items().filter(':visible');
6863
        contLayoutRect = container.layoutRect();
6864
        contPaddingBox = container.paddingBox;
6865
        contSettings = container.settings;
6866
        direction = container.isRtl() ? contSettings.direction || 'row-reversed' : contSettings.direction;
6867
        align = contSettings.align;
6868
        pack = container.isRtl() ? contSettings.pack || 'end' : contSettings.pack;
6869
        spacing = contSettings.spacing || 0;
6870
        if (direction === 'row-reversed' || direction === 'column-reverse') {
6871
          items = items.set(items.toArray().reverse());
6872
          direction = direction.split('-')[0];
6873
        }
6874
        if (direction === 'column') {
6875
          posName = 'y';
6876
          sizeName = 'h';
6877
          minSizeName = 'minH';
6878
          maxSizeName = 'maxH';
6879
          innerSizeName = 'innerH';
6880
          beforeName = 'top';
6881
          deltaSizeName = 'deltaH';
6882
          contentSizeName = 'contentH';
6883
          alignBeforeName = 'left';
6884
          alignSizeName = 'w';
6885
          alignAxisName = 'x';
6886
          alignInnerSizeName = 'innerW';
6887
          alignMinSizeName = 'minW';
6888
          alignAfterName = 'right';
6889
          alignDeltaSizeName = 'deltaW';
6890
          alignContentSizeName = 'contentW';
6891
        } else {
6892
          posName = 'x';
6893
          sizeName = 'w';
6894
          minSizeName = 'minW';
6895
          maxSizeName = 'maxW';
6896
          innerSizeName = 'innerW';
6897
          beforeName = 'left';
6898
          deltaSizeName = 'deltaW';
6899
          contentSizeName = 'contentW';
6900
          alignBeforeName = 'top';
6901
          alignSizeName = 'h';
6902
          alignAxisName = 'y';
6903
          alignInnerSizeName = 'innerH';
6904
          alignMinSizeName = 'minH';
6905
          alignAfterName = 'bottom';
6906
          alignDeltaSizeName = 'deltaH';
6907
          alignContentSizeName = 'contentH';
6908
        }
6909
        availableSpace = contLayoutRect[innerSizeName] - contPaddingBox[beforeName] - contPaddingBox[beforeName];
6910
        maxAlignEndPos = totalFlex = 0;
6911
        for (i = 0, l = items.length; i < l; i++) {
6912
          ctrl = items[i];
6913
          ctrlLayoutRect = ctrl.layoutRect();
6914
          ctrlSettings = ctrl.settings;
6915
          flex = ctrlSettings.flex;
6916
          availableSpace -= i < l - 1 ? spacing : 0;
6917
          if (flex > 0) {
6918
            totalFlex += flex;
6919
            if (ctrlLayoutRect[maxSizeName]) {
6920
              maxSizeItems.push(ctrl);
6921
            }
6922
            ctrlLayoutRect.flex = flex;
6923
          }
6924
          availableSpace -= ctrlLayoutRect[minSizeName];
6925
          size = contPaddingBox[alignBeforeName] + ctrlLayoutRect[alignMinSizeName] + contPaddingBox[alignAfterName];
6926
          if (size > maxAlignEndPos) {
6927
            maxAlignEndPos = size;
6928
          }
6929
        }
6930
        rect = {};
6931
        if (availableSpace < 0) {
6932
          rect[minSizeName] = contLayoutRect[minSizeName] - availableSpace + contLayoutRect[deltaSizeName];
6933
        } else {
6934
          rect[minSizeName] = contLayoutRect[innerSizeName] - availableSpace + contLayoutRect[deltaSizeName];
6935
        }
6936
        rect[alignMinSizeName] = maxAlignEndPos + contLayoutRect[alignDeltaSizeName];
6937
        rect[contentSizeName] = contLayoutRect[innerSizeName] - availableSpace;
6938
        rect[alignContentSizeName] = maxAlignEndPos;
6939
        rect.minW = min(rect.minW, contLayoutRect.maxW);
6940
        rect.minH = min(rect.minH, contLayoutRect.maxH);
6941
        rect.minW = max(rect.minW, contLayoutRect.startMinWidth);
6942
        rect.minH = max(rect.minH, contLayoutRect.startMinHeight);
6943
        if (contLayoutRect.autoResize && (rect.minW !== contLayoutRect.minW || rect.minH !== contLayoutRect.minH)) {
6944
          rect.w = rect.minW;
6945
          rect.h = rect.minH;
6946
          container.layoutRect(rect);
6947
          this.recalc(container);
6948
          if (container._lastRect === null) {
6949
            var parentCtrl = container.parent();
6950
            if (parentCtrl) {
6951
              parentCtrl._lastRect = null;
6952
              parentCtrl.recalc();
6953
            }
6954
          }
6955
          return;
6956
        }
6957
        ratio = availableSpace / totalFlex;
6958
        for (i = 0, l = maxSizeItems.length; i < l; i++) {
6959
          ctrl = maxSizeItems[i];
6960
          ctrlLayoutRect = ctrl.layoutRect();
6961
          maxSize = ctrlLayoutRect[maxSizeName];
6962
          size = ctrlLayoutRect[minSizeName] + ctrlLayoutRect.flex * ratio;
6963
          if (size > maxSize) {
6964
            availableSpace -= ctrlLayoutRect[maxSizeName] - ctrlLayoutRect[minSizeName];
6965
            totalFlex -= ctrlLayoutRect.flex;
6966
            ctrlLayoutRect.flex = 0;
6967
            ctrlLayoutRect.maxFlexSize = maxSize;
6968
          } else {
6969
            ctrlLayoutRect.maxFlexSize = 0;
6970
          }
6971
        }
6972
        ratio = availableSpace / totalFlex;
6973
        pos = contPaddingBox[beforeName];
6974
        rect = {};
6975
        if (totalFlex === 0) {
6976
          if (pack === 'end') {
6977
            pos = availableSpace + contPaddingBox[beforeName];
6978
          } else if (pack === 'center') {
6979
            pos = Math.round(contLayoutRect[innerSizeName] / 2 - (contLayoutRect[innerSizeName] - availableSpace) / 2) + contPaddingBox[beforeName];
6980
            if (pos < 0) {
6981
              pos = contPaddingBox[beforeName];
6982
            }
6983
          } else if (pack === 'justify') {
6984
            pos = contPaddingBox[beforeName];
6985
            spacing = Math.floor(availableSpace / (items.length - 1));
6986
          }
6987
        }
6988
        rect[alignAxisName] = contPaddingBox[alignBeforeName];
6989
        for (i = 0, l = items.length; i < l; i++) {
6990
          ctrl = items[i];
6991
          ctrlLayoutRect = ctrl.layoutRect();
6992
          size = ctrlLayoutRect.maxFlexSize || ctrlLayoutRect[minSizeName];
6993
          if (align === 'center') {
6994
            rect[alignAxisName] = Math.round(contLayoutRect[alignInnerSizeName] / 2 - ctrlLayoutRect[alignSizeName] / 2);
6995
          } else if (align === 'stretch') {
6996
            rect[alignSizeName] = max(ctrlLayoutRect[alignMinSizeName] || 0, contLayoutRect[alignInnerSizeName] - contPaddingBox[alignBeforeName] - contPaddingBox[alignAfterName]);
6997
            rect[alignAxisName] = contPaddingBox[alignBeforeName];
6998
          } else if (align === 'end') {
6999
            rect[alignAxisName] = contLayoutRect[alignInnerSizeName] - ctrlLayoutRect[alignSizeName] - contPaddingBox.top;
7000
          }
7001
          if (ctrlLayoutRect.flex > 0) {
7002
            size += ctrlLayoutRect.flex * ratio;
7003
          }
7004
          rect[sizeName] = size;
7005
          rect[posName] = pos;
7006
          ctrl.layoutRect(rect);
7007
          if (ctrl.recalc) {
7008
            ctrl.recalc();
7009
          }
7010
          pos += size + spacing;
7011
        }
7012
      }
7013
    });
7014
7015
    var FlowLayout = Layout.extend({
7016
      Defaults: {
7017
        containerClass: 'flow-layout',
7018
        controlClass: 'flow-layout-item',
7019
        endClass: 'break'
7020
      },
7021
      recalc: function (container) {
7022
        container.items().filter(':visible').each(function (ctrl) {
7023
          if (ctrl.recalc) {
7024
            ctrl.recalc();
7025
          }
7026
        });
7027
      },
7028
      isNative: function () {
7029
        return true;
7030
      }
7031
    });
7032
7033
    var descendant$1 = function (scope, selector) {
7034
      return one(selector, scope);
7035
    };
7036
7037
    var toggleFormat = function (editor, fmt) {
7038
      return function () {
7039
        editor.execCommand('mceToggleFormat', false, fmt);
7040
      };
7041
    };
7042
    var addFormatChangedListener = function (editor, name, changed) {
7043
      var handler = function (state) {
7044
        changed(state, name);
7045
      };
7046
      if (editor.formatter) {
7047
        editor.formatter.formatChanged(name, handler);
7048
      } else {
7049
        editor.on('init', function () {
7050
          editor.formatter.formatChanged(name, handler);
7051
        });
7052
      }
7053
    };
7054
    var postRenderFormatToggle = function (editor, name) {
7055
      return function (e) {
7056
        addFormatChangedListener(editor, name, function (state) {
7057
          e.control.active(state);
7058
        });
7059
      };
7060
    };
7061
7062 View Code Duplication
    var register = function (editor) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7063
      var alignFormats = [
7064
        'alignleft',
7065
        'aligncenter',
7066
        'alignright',
7067
        'alignjustify'
7068
      ];
7069
      var defaultAlign = 'alignleft';
7070
      var alignMenuItems = [
7071
        {
7072
          text: 'Left',
7073
          icon: 'alignleft',
7074
          onclick: toggleFormat(editor, 'alignleft')
7075
        },
7076
        {
7077
          text: 'Center',
7078
          icon: 'aligncenter',
7079
          onclick: toggleFormat(editor, 'aligncenter')
7080
        },
7081
        {
7082
          text: 'Right',
7083
          icon: 'alignright',
7084
          onclick: toggleFormat(editor, 'alignright')
7085
        },
7086
        {
7087
          text: 'Justify',
7088
          icon: 'alignjustify',
7089
          onclick: toggleFormat(editor, 'alignjustify')
7090
        }
7091
      ];
7092
      editor.addMenuItem('align', {
7093
        text: 'Align',
7094
        menu: alignMenuItems
7095
      });
7096
      editor.addButton('align', {
7097
        type: 'menubutton',
7098
        icon: defaultAlign,
7099
        menu: alignMenuItems,
7100
        onShowMenu: function (e) {
7101
          var menu = e.control.menu;
7102
          global$2.each(alignFormats, function (formatName, idx) {
7103
            menu.items().eq(idx).each(function (item) {
7104
              return item.active(editor.formatter.match(formatName));
7105
            });
7106
          });
7107
        },
7108
        onPostRender: function (e) {
7109
          var ctrl = e.control;
7110
          global$2.each(alignFormats, function (formatName, idx) {
0 ignored issues
show
Unused Code introduced by
The parameter idx is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
7111
            addFormatChangedListener(editor, formatName, function (state) {
7112
              ctrl.icon(defaultAlign);
7113
              if (state) {
7114
                ctrl.icon(formatName);
7115
              }
7116
            });
7117
          });
7118
        }
7119
      });
7120
      global$2.each({
7121
        alignleft: [
7122
          'Align left',
7123
          'JustifyLeft'
7124
        ],
7125
        aligncenter: [
7126
          'Align center',
7127
          'JustifyCenter'
7128
        ],
7129
        alignright: [
7130
          'Align right',
7131
          'JustifyRight'
7132
        ],
7133
        alignjustify: [
7134
          'Justify',
7135
          'JustifyFull'
7136
        ],
7137
        alignnone: [
7138
          'No alignment',
7139
          'JustifyNone'
7140
        ]
7141
      }, function (item, name) {
7142
        editor.addButton(name, {
7143
          active: false,
7144
          tooltip: item[0],
7145
          cmd: item[1],
7146
          onPostRender: postRenderFormatToggle(editor, name)
7147
        });
7148
      });
7149
    };
7150
    var Align = { register: register };
7151
7152
    var getFirstFont = function (fontFamily) {
7153
      return fontFamily ? fontFamily.split(',')[0] : '';
7154
    };
7155
    var findMatchingValue = function (items, fontFamily) {
7156
      var font = fontFamily ? fontFamily.toLowerCase() : '';
7157
      var value;
7158
      global$2.each(items, function (item) {
7159
        if (item.value.toLowerCase() === font) {
7160
          value = item.value;
7161
        }
7162
      });
7163
      global$2.each(items, function (item) {
7164
        if (!value && getFirstFont(item.value).toLowerCase() === getFirstFont(font).toLowerCase()) {
7165
          value = item.value;
7166
        }
7167
      });
7168
      return value;
7169
    };
7170
    var createFontNameListBoxChangeHandler = function (editor, items) {
7171
      return function () {
7172
        var self = this;
7173
        self.state.set('value', null);
7174
        editor.on('init nodeChange', function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
7175
          var fontFamily = editor.queryCommandValue('FontName');
7176
          var match = findMatchingValue(items, fontFamily);
7177
          self.value(match ? match : null);
7178
          if (!match && fontFamily) {
7179
            self.text(getFirstFont(fontFamily));
7180
          }
7181
        });
7182
      };
7183
    };
7184
    var createFormats = function (formats) {
7185
      formats = formats.replace(/;$/, '').split(';');
7186
      var i = formats.length;
7187
      while (i--) {
7188
        formats[i] = formats[i].split('=');
7189
      }
7190
      return formats;
7191
    };
7192
    var getFontItems = function (editor) {
7193
      var defaultFontsFormats = 'Andale Mono=andale mono,monospace;' + 'Arial=arial,helvetica,sans-serif;' + 'Arial Black=arial black,sans-serif;' + 'Book Antiqua=book antiqua,palatino,serif;' + 'Comic Sans MS=comic sans ms,sans-serif;' + 'Courier New=courier new,courier,monospace;' + 'Georgia=georgia,palatino,serif;' + 'Helvetica=helvetica,arial,sans-serif;' + 'Impact=impact,sans-serif;' + 'Symbol=symbol;' + 'Tahoma=tahoma,arial,helvetica,sans-serif;' + 'Terminal=terminal,monaco,monospace;' + 'Times New Roman=times new roman,times,serif;' + 'Trebuchet MS=trebuchet ms,geneva,sans-serif;' + 'Verdana=verdana,geneva,sans-serif;' + 'Webdings=webdings;' + 'Wingdings=wingdings,zapf dingbats';
7194
      var fonts = createFormats(editor.settings.font_formats || defaultFontsFormats);
7195
      return global$2.map(fonts, function (font) {
7196
        return {
7197
          text: { raw: font[0] },
7198
          value: font[1],
7199
          textStyle: font[1].indexOf('dings') === -1 ? 'font-family:' + font[1] : ''
7200
        };
7201
      });
7202
    };
7203
    var registerButtons = function (editor) {
7204
      editor.addButton('fontselect', function () {
7205
        var items = getFontItems(editor);
7206
        return {
7207
          type: 'listbox',
7208
          text: 'Font Family',
7209
          tooltip: 'Font Family',
7210
          values: items,
7211
          fixedWidth: true,
7212
          onPostRender: createFontNameListBoxChangeHandler(editor, items),
7213
          onselect: function (e) {
7214
            if (e.control.settings.value) {
7215
              editor.execCommand('FontName', false, e.control.settings.value);
7216
            }
7217
          }
7218
        };
7219
      });
7220
    };
7221
    var register$1 = function (editor) {
7222
      registerButtons(editor);
7223
    };
7224
    var FontSelect = { register: register$1 };
7225
7226
    var round = function (number, precision) {
7227
      var factor = Math.pow(10, precision);
7228
      return Math.round(number * factor) / factor;
7229
    };
7230
    var toPt = function (fontSize, precision) {
7231
      if (/[0-9.]+px$/.test(fontSize)) {
7232
        return round(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
7233
      }
7234
      return fontSize;
7235
    };
7236
    var findMatchingValue$1 = function (items, pt, px) {
7237
      var value;
7238
      global$2.each(items, function (item) {
7239
        if (item.value === px) {
7240
          value = px;
7241
        } else if (item.value === pt) {
7242
          value = pt;
7243
        }
7244
      });
7245
      return value;
7246
    };
7247 View Code Duplication
    var createFontSizeListBoxChangeHandler = function (editor, items) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7248
      return function () {
7249
        var self = this;
7250
        editor.on('init nodeChange', function (e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
7251
          var px, pt, precision, match;
7252
          px = editor.queryCommandValue('FontSize');
7253
          if (px) {
7254
            for (precision = 3; !match && precision >= 0; precision--) {
7255
              pt = toPt(px, precision);
7256
              match = findMatchingValue$1(items, pt, px);
7257
            }
7258
          }
7259
          self.value(match ? match : null);
7260
          if (!match) {
7261
            self.text(pt);
0 ignored issues
show
Bug introduced by
The variable pt seems to not be initialized for all possible execution paths. Are you sure text handles undefined variables?
Loading history...
7262
          }
7263
        });
7264
      };
7265
    };
7266
    var getFontSizeItems = function (editor) {
7267
      var defaultFontsizeFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
7268
      var fontsizeFormats = editor.settings.fontsize_formats || defaultFontsizeFormats;
7269
      return global$2.map(fontsizeFormats.split(' '), function (item) {
7270
        var text = item, value = item;
7271
        var values = item.split('=');
7272
        if (values.length > 1) {
7273
          text = values[0];
7274
          value = values[1];
7275
        }
7276
        return {
7277
          text: text,
7278
          value: value
7279
        };
7280
      });
7281
    };
7282
    var registerButtons$1 = function (editor) {
7283
      editor.addButton('fontsizeselect', function () {
7284
        var items = getFontSizeItems(editor);
7285
        return {
7286
          type: 'listbox',
7287
          text: 'Font Sizes',
7288
          tooltip: 'Font Sizes',
7289
          values: items,
7290
          fixedWidth: true,
7291
          onPostRender: createFontSizeListBoxChangeHandler(editor, items),
7292
          onclick: function (e) {
7293
            if (e.control.settings.value) {
7294
              editor.execCommand('FontSize', false, e.control.settings.value);
7295
            }
7296
          }
7297
        };
7298
      });
7299
    };
7300
    var register$2 = function (editor) {
7301
      registerButtons$1(editor);
7302
    };
7303
    var FontSizeSelect = { register: register$2 };
7304
7305
    var hideMenuObjects = function (editor, menu) {
7306
      var count = menu.length;
7307
      global$2.each(menu, function (item) {
7308
        if (item.menu) {
7309
          item.hidden = hideMenuObjects(editor, item.menu) === 0;
7310
        }
7311
        var formatName = item.format;
7312
        if (formatName) {
7313
          item.hidden = !editor.formatter.canApply(formatName);
7314
        }
7315
        if (item.hidden) {
7316
          count--;
7317
        }
7318
      });
7319
      return count;
7320
    };
7321
    var hideFormatMenuItems = function (editor, menu) {
7322
      var count = menu.items().length;
7323
      menu.items().each(function (item) {
7324
        if (item.menu) {
7325
          item.visible(hideFormatMenuItems(editor, item.menu) > 0);
7326
        }
7327
        if (!item.menu && item.settings.menu) {
7328
          item.visible(hideMenuObjects(editor, item.settings.menu) > 0);
7329
        }
7330
        var formatName = item.settings.format;
7331
        if (formatName) {
7332
          item.visible(editor.formatter.canApply(formatName));
7333
        }
7334
        if (!item.visible()) {
7335
          count--;
7336
        }
7337
      });
7338
      return count;
7339
    };
7340 View Code Duplication
    var createFormatMenu = function (editor) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7341
      var count = 0;
7342
      var newFormats = [];
7343
      var defaultStyleFormats = [
7344
        {
7345
          title: 'Headings',
7346
          items: [
7347
            {
7348
              title: 'Heading 1',
7349
              format: 'h1'
7350
            },
7351
            {
7352
              title: 'Heading 2',
7353
              format: 'h2'
7354
            },
7355
            {
7356
              title: 'Heading 3',
7357
              format: 'h3'
7358
            },
7359
            {
7360
              title: 'Heading 4',
7361
              format: 'h4'
7362
            },
7363
            {
7364
              title: 'Heading 5',
7365
              format: 'h5'
7366
            },
7367
            {
7368
              title: 'Heading 6',
7369
              format: 'h6'
7370
            }
7371
          ]
7372
        },
7373
        {
7374
          title: 'Inline',
7375
          items: [
7376
            {
7377
              title: 'Bold',
7378
              icon: 'bold',
7379
              format: 'bold'
7380
            },
7381
            {
7382
              title: 'Italic',
7383
              icon: 'italic',
7384
              format: 'italic'
7385
            },
7386
            {
7387
              title: 'Underline',
7388
              icon: 'underline',
7389
              format: 'underline'
7390
            },
7391
            {
7392
              title: 'Strikethrough',
7393
              icon: 'strikethrough',
7394
              format: 'strikethrough'
7395
            },
7396
            {
7397
              title: 'Superscript',
7398
              icon: 'superscript',
7399
              format: 'superscript'
7400
            },
7401
            {
7402
              title: 'Subscript',
7403
              icon: 'subscript',
7404
              format: 'subscript'
7405
            },
7406
            {
7407
              title: 'Code',
7408
              icon: 'code',
7409
              format: 'code'
7410
            }
7411
          ]
7412
        },
7413
        {
7414
          title: 'Blocks',
7415
          items: [
7416
            {
7417
              title: 'Paragraph',
7418
              format: 'p'
7419
            },
7420
            {
7421
              title: 'Blockquote',
7422
              format: 'blockquote'
7423
            },
7424
            {
7425
              title: 'Div',
7426
              format: 'div'
7427
            },
7428
            {
7429
              title: 'Pre',
7430
              format: 'pre'
7431
            }
7432
          ]
7433
        },
7434
        {
7435
          title: 'Alignment',
7436
          items: [
7437
            {
7438
              title: 'Left',
7439
              icon: 'alignleft',
7440
              format: 'alignleft'
7441
            },
7442
            {
7443
              title: 'Center',
7444
              icon: 'aligncenter',
7445
              format: 'aligncenter'
7446
            },
7447
            {
7448
              title: 'Right',
7449
              icon: 'alignright',
7450
              format: 'alignright'
7451
            },
7452
            {
7453
              title: 'Justify',
7454
              icon: 'alignjustify',
7455
              format: 'alignjustify'
7456
            }
7457
          ]
7458
        }
7459
      ];
7460
      var createMenu = function (formats) {
7461
        var menu = [];
7462
        if (!formats) {
7463
          return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
7464
        }
7465
        global$2.each(formats, function (format) {
7466
          var menuItem = {
7467
            text: format.title,
7468
            icon: format.icon
7469
          };
7470
          if (format.items) {
7471
            menuItem.menu = createMenu(format.items);
7472
          } else {
7473
            var formatName = format.format || 'custom' + count++;
7474
            if (!format.format) {
7475
              format.name = formatName;
7476
              newFormats.push(format);
7477
            }
7478
            menuItem.format = formatName;
7479
            menuItem.cmd = format.cmd;
7480
          }
7481
          menu.push(menuItem);
7482
        });
7483
        return menu;
7484
      };
7485
      var createStylesMenu = function () {
7486
        var menu;
7487
        if (editor.settings.style_formats_merge) {
7488
          if (editor.settings.style_formats) {
7489
            menu = createMenu(defaultStyleFormats.concat(editor.settings.style_formats));
7490
          } else {
7491
            menu = createMenu(defaultStyleFormats);
7492
          }
7493
        } else {
7494
          menu = createMenu(editor.settings.style_formats || defaultStyleFormats);
7495
        }
7496
        return menu;
7497
      };
7498
      editor.on('init', function () {
7499
        global$2.each(newFormats, function (format) {
7500
          editor.formatter.register(format.name, format);
7501
        });
7502
      });
7503
      return {
7504
        type: 'menu',
7505
        items: createStylesMenu(),
7506
        onPostRender: function (e) {
7507
          editor.fire('renderFormatsMenu', { control: e.control });
7508
        },
7509
        itemDefaults: {
7510
          preview: true,
7511
          textStyle: function () {
7512
            if (this.settings.format) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.settings.format is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
7513
              return editor.formatter.getCssText(this.settings.format);
7514
            }
7515
          },
7516
          onPostRender: function () {
7517
            var self = this;
7518
            self.parent().on('show', function () {
7519
              var formatName, command;
7520
              formatName = self.settings.format;
7521
              if (formatName) {
7522
                self.disabled(!editor.formatter.canApply(formatName));
7523
                self.active(editor.formatter.match(formatName));
7524
              }
7525
              command = self.settings.cmd;
7526
              if (command) {
7527
                self.active(editor.queryCommandState(command));
7528
              }
7529
            });
7530
          },
7531
          onclick: function () {
7532
            if (this.settings.format) {
7533
              toggleFormat(editor, this.settings.format)();
7534
            }
7535
            if (this.settings.cmd) {
7536
              editor.execCommand(this.settings.cmd);
7537
            }
7538
          }
7539
        }
7540
      };
7541
    };
7542
    var registerMenuItems = function (editor, formatMenu) {
7543
      editor.addMenuItem('formats', {
7544
        text: 'Formats',
7545
        menu: formatMenu
7546
      });
7547
    };
7548
    var registerButtons$2 = function (editor, formatMenu) {
7549
      editor.addButton('styleselect', {
7550
        type: 'menubutton',
7551
        text: 'Formats',
7552
        menu: formatMenu,
7553
        onShowMenu: function () {
7554
          if (editor.settings.style_formats_autohide) {
7555
            hideFormatMenuItems(editor, this.menu);
7556
          }
7557
        }
7558
      });
7559
    };
7560
    var register$3 = function (editor) {
7561
      var formatMenu = createFormatMenu(editor);
7562
      registerMenuItems(editor, formatMenu);
7563
      registerButtons$2(editor, formatMenu);
7564
    };
7565
    var Formats = { register: register$3 };
7566
7567
    var defaultBlocks = 'Paragraph=p;' + 'Heading 1=h1;' + 'Heading 2=h2;' + 'Heading 3=h3;' + 'Heading 4=h4;' + 'Heading 5=h5;' + 'Heading 6=h6;' + 'Preformatted=pre';
7568
    var createFormats$1 = function (formats) {
7569
      formats = formats.replace(/;$/, '').split(';');
7570
      var i = formats.length;
7571
      while (i--) {
7572
        formats[i] = formats[i].split('=');
7573
      }
7574
      return formats;
7575
    };
7576
    var createListBoxChangeHandler = function (editor, items, formatName) {
7577
      return function () {
7578
        var self = this;
7579
        editor.on('nodeChange', function (e) {
7580
          var formatter = editor.formatter;
7581
          var value = null;
7582
          global$2.each(e.parents, function (node) {
7583
            global$2.each(items, function (item) {
7584
              if (formatName) {
7585
                if (formatter.matchNode(node, formatName, { value: item.value })) {
7586
                  value = item.value;
7587
                }
7588
              } else {
7589
                if (formatter.matchNode(node, item.value)) {
7590
                  value = item.value;
7591
                }
7592
              }
7593
              if (value) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if value is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
7594
                return false;
7595
              }
7596
            });
7597
            if (value) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if value is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
7598
              return false;
7599
            }
7600
          });
7601
          self.value(value);
7602
        });
7603
      };
7604
    };
7605
    var lazyFormatSelectBoxItems = function (editor, blocks) {
7606
      return function () {
7607
        var items = [];
7608
        global$2.each(blocks, function (block) {
7609
          items.push({
7610
            text: block[0],
7611
            value: block[1],
7612
            textStyle: function () {
7613
              return editor.formatter.getCssText(block[1]);
7614
            }
7615
          });
7616
        });
7617
        return {
7618
          type: 'listbox',
7619
          text: blocks[0][0],
7620
          values: items,
7621
          fixedWidth: true,
7622
          onselect: function (e) {
7623
            if (e.control) {
7624
              var fmt = e.control.value();
7625
              toggleFormat(editor, fmt)();
7626
            }
7627
          },
7628
          onPostRender: createListBoxChangeHandler(editor, items)
7629
        };
7630
      };
7631
    };
7632
    var buildMenuItems = function (editor, blocks) {
7633
      return global$2.map(blocks, function (block) {
7634
        return {
7635
          text: block[0],
7636
          onclick: toggleFormat(editor, block[1]),
7637
          textStyle: function () {
7638
            return editor.formatter.getCssText(block[1]);
7639
          }
7640
        };
7641
      });
7642
    };
7643
    var register$4 = function (editor) {
7644
      var blocks = createFormats$1(editor.settings.block_formats || defaultBlocks);
7645
      editor.addMenuItem('blockformats', {
7646
        text: 'Blocks',
7647
        menu: buildMenuItems(editor, blocks)
7648
      });
7649
      editor.addButton('formatselect', lazyFormatSelectBoxItems(editor, blocks));
7650
    };
7651
    var FormatSelect = { register: register$4 };
7652
7653
    var createCustomMenuItems = function (editor, names) {
7654
      var items, nameList;
7655
      if (typeof names === 'string') {
7656
        nameList = names.split(' ');
7657
      } else if (global$2.isArray(names)) {
7658
        return flatten(global$2.map(names, function (names) {
7659
          return createCustomMenuItems(editor, names);
7660
        }));
7661
      }
7662
      items = global$2.grep(nameList, function (name) {
0 ignored issues
show
Bug introduced by
The variable nameList does not seem to be initialized in case global$2.isArray(names) on line 7657 is false. Are you sure the function grep handles undefined variables?
Loading history...
7663
        return name === '|' || name in editor.menuItems;
7664
      });
7665
      return global$2.map(items, function (name) {
7666
        return name === '|' ? { text: '-' } : editor.menuItems[name];
7667
      });
7668
    };
7669
    var isSeparator$1 = function (menuItem) {
7670
      return menuItem && menuItem.text === '-';
7671
    };
7672
    var trimMenuItems = function (menuItems) {
7673
      var menuItems2 = filter(menuItems, function (menuItem, i, menuItems) {
7674
        return !isSeparator$1(menuItem) || !isSeparator$1(menuItems[i - 1]);
7675
      });
7676
      return filter(menuItems2, function (menuItem, i, menuItems) {
7677
        return !isSeparator$1(menuItem) || i > 0 && i < menuItems.length - 1;
7678
      });
7679
    };
7680
    var createContextMenuItems = function (editor, context) {
7681
      var outputMenuItems = [{ text: '-' }];
7682
      var menuItems = global$2.grep(editor.menuItems, function (menuItem) {
7683
        return menuItem.context === context;
7684
      });
7685
      global$2.each(menuItems, function (menuItem) {
7686
        if (menuItem.separator === 'before') {
7687
          outputMenuItems.push({ text: '|' });
7688
        }
7689
        if (menuItem.prependToContext) {
7690
          outputMenuItems.unshift(menuItem);
7691
        } else {
7692
          outputMenuItems.push(menuItem);
7693
        }
7694
        if (menuItem.separator === 'after') {
7695
          outputMenuItems.push({ text: '|' });
7696
        }
7697
      });
7698
      return outputMenuItems;
7699
    };
7700
    var createInsertMenu = function (editor) {
7701
      var insertButtonItems = editor.settings.insert_button_items;
7702
      if (insertButtonItems) {
7703
        return trimMenuItems(createCustomMenuItems(editor, insertButtonItems));
7704
      } else {
0 ignored issues
show
Comprehensibility introduced by
else is not necessary here since all if branches return, consider removing it to reduce nesting and make code more readable.
Loading history...
7705
        return trimMenuItems(createContextMenuItems(editor, 'insert'));
7706
      }
7707
    };
7708
    var registerButtons$3 = function (editor) {
7709
      editor.addButton('insert', {
7710
        type: 'menubutton',
7711
        icon: 'insert',
7712
        menu: [],
7713
        oncreatemenu: function () {
7714
          this.menu.add(createInsertMenu(editor));
7715
          this.menu.renderNew();
7716
        }
7717
      });
7718
    };
7719
    var register$5 = function (editor) {
7720
      registerButtons$3(editor);
7721
    };
7722
    var InsertButton = { register: register$5 };
7723
7724
    var registerFormatButtons = function (editor) {
7725
      global$2.each({
7726
        bold: 'Bold',
7727
        italic: 'Italic',
7728
        underline: 'Underline',
7729
        strikethrough: 'Strikethrough',
7730
        subscript: 'Subscript',
7731
        superscript: 'Superscript'
7732
      }, function (text, name) {
7733
        editor.addButton(name, {
7734
          active: false,
7735
          tooltip: text,
7736
          onPostRender: postRenderFormatToggle(editor, name),
7737
          onclick: toggleFormat(editor, name)
7738
        });
7739
      });
7740
    };
7741
    var registerCommandButtons = function (editor) {
7742
      global$2.each({
7743
        outdent: [
7744
          'Decrease indent',
7745
          'Outdent'
7746
        ],
7747
        indent: [
7748
          'Increase indent',
7749
          'Indent'
7750
        ],
7751
        cut: [
7752
          'Cut',
7753
          'Cut'
7754
        ],
7755
        copy: [
7756
          'Copy',
7757
          'Copy'
7758
        ],
7759
        paste: [
7760
          'Paste',
7761
          'Paste'
7762
        ],
7763
        help: [
7764
          'Help',
7765
          'mceHelp'
7766
        ],
7767
        selectall: [
7768
          'Select all',
7769
          'SelectAll'
7770
        ],
7771
        visualaid: [
7772
          'Visual aids',
7773
          'mceToggleVisualAid'
7774
        ],
7775
        newdocument: [
7776
          'New document',
7777
          'mceNewDocument'
7778
        ],
7779
        removeformat: [
7780
          'Clear formatting',
7781
          'RemoveFormat'
7782
        ],
7783
        remove: [
7784
          'Remove',
7785
          'Delete'
7786
        ]
7787
      }, function (item, name) {
7788
        editor.addButton(name, {
7789
          tooltip: item[0],
7790
          cmd: item[1]
7791
        });
7792
      });
7793
    };
7794
    var registerCommandToggleButtons = function (editor) {
7795
      global$2.each({
7796
        blockquote: [
7797
          'Blockquote',
7798
          'mceBlockQuote'
7799
        ],
7800
        subscript: [
7801
          'Subscript',
7802
          'Subscript'
7803
        ],
7804
        superscript: [
7805
          'Superscript',
7806
          'Superscript'
7807
        ]
7808
      }, function (item, name) {
7809
        editor.addButton(name, {
7810
          active: false,
7811
          tooltip: item[0],
7812
          cmd: item[1],
7813
          onPostRender: postRenderFormatToggle(editor, name)
7814
        });
7815
      });
7816
    };
7817
    var registerButtons$4 = function (editor) {
7818
      registerFormatButtons(editor);
7819
      registerCommandButtons(editor);
7820
      registerCommandToggleButtons(editor);
7821
    };
7822
    var registerMenuItems$1 = function (editor) {
7823
      global$2.each({
7824
        bold: [
7825
          'Bold',
7826
          'Bold',
7827
          'Meta+B'
7828
        ],
7829
        italic: [
7830
          'Italic',
7831
          'Italic',
7832
          'Meta+I'
7833
        ],
7834
        underline: [
7835
          'Underline',
7836
          'Underline',
7837
          'Meta+U'
7838
        ],
7839
        strikethrough: [
7840
          'Strikethrough',
7841
          'Strikethrough'
7842
        ],
7843
        subscript: [
7844
          'Subscript',
7845
          'Subscript'
7846
        ],
7847
        superscript: [
7848
          'Superscript',
7849
          'Superscript'
7850
        ],
7851
        removeformat: [
7852
          'Clear formatting',
7853
          'RemoveFormat'
7854
        ],
7855
        newdocument: [
7856
          'New document',
7857
          'mceNewDocument'
7858
        ],
7859
        cut: [
7860
          'Cut',
7861
          'Cut',
7862
          'Meta+X'
7863
        ],
7864
        copy: [
7865
          'Copy',
7866
          'Copy',
7867
          'Meta+C'
7868
        ],
7869
        paste: [
7870
          'Paste',
7871
          'Paste',
7872
          'Meta+V'
7873
        ],
7874
        selectall: [
7875
          'Select all',
7876
          'SelectAll',
7877
          'Meta+A'
7878
        ]
7879
      }, function (item, name) {
7880
        editor.addMenuItem(name, {
7881
          text: item[0],
7882
          icon: name,
7883
          shortcut: item[2],
7884
          cmd: item[1]
7885
        });
7886
      });
7887
      editor.addMenuItem('codeformat', {
7888
        text: 'Code',
7889
        icon: 'code',
7890
        onclick: toggleFormat(editor, 'code')
7891
      });
7892
    };
7893
    var register$6 = function (editor) {
7894
      registerButtons$4(editor);
7895
      registerMenuItems$1(editor);
7896
    };
7897
    var SimpleControls = { register: register$6 };
7898
7899
    var toggleUndoRedoState = function (editor, type) {
7900
      return function () {
7901
        var self = this;
7902
        var checkState = function () {
7903
          var typeFn = type === 'redo' ? 'hasRedo' : 'hasUndo';
7904
          return editor.undoManager ? editor.undoManager[typeFn]() : false;
7905
        };
7906
        self.disabled(!checkState());
7907
        editor.on('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', function () {
7908
          self.disabled(editor.readonly || !checkState());
7909
        });
7910
      };
7911
    };
7912
    var registerMenuItems$2 = function (editor) {
7913
      editor.addMenuItem('undo', {
7914
        text: 'Undo',
7915
        icon: 'undo',
7916
        shortcut: 'Meta+Z',
7917
        onPostRender: toggleUndoRedoState(editor, 'undo'),
7918
        cmd: 'undo'
7919
      });
7920
      editor.addMenuItem('redo', {
7921
        text: 'Redo',
7922
        icon: 'redo',
7923
        shortcut: 'Meta+Y',
7924
        onPostRender: toggleUndoRedoState(editor, 'redo'),
7925
        cmd: 'redo'
7926
      });
7927
    };
7928
    var registerButtons$5 = function (editor) {
7929
      editor.addButton('undo', {
7930
        tooltip: 'Undo',
7931
        onPostRender: toggleUndoRedoState(editor, 'undo'),
7932
        cmd: 'undo'
7933
      });
7934
      editor.addButton('redo', {
7935
        tooltip: 'Redo',
7936
        onPostRender: toggleUndoRedoState(editor, 'redo'),
7937
        cmd: 'redo'
7938
      });
7939
    };
7940
    var register$7 = function (editor) {
7941
      registerMenuItems$2(editor);
7942
      registerButtons$5(editor);
7943
    };
7944
    var UndoRedo = { register: register$7 };
7945
7946
    var toggleVisualAidState = function (editor) {
7947
      return function () {
7948
        var self = this;
7949
        editor.on('VisualAid', function (e) {
7950
          self.active(e.hasVisual);
7951
        });
7952
        self.active(editor.hasVisual);
7953
      };
7954
    };
7955
    var registerMenuItems$3 = function (editor) {
7956
      editor.addMenuItem('visualaid', {
7957
        text: 'Visual aids',
7958
        selectable: true,
7959
        onPostRender: toggleVisualAidState(editor),
7960
        cmd: 'mceToggleVisualAid'
7961
      });
7962
    };
7963
    var register$8 = function (editor) {
7964
      registerMenuItems$3(editor);
7965
    };
7966
    var VisualAid = { register: register$8 };
7967
7968
    var setupEnvironment = function () {
7969
      Widget.tooltips = !global$8.iOS;
7970
      Control$1.translate = function (text) {
7971
        return global$1.translate(text);
7972
      };
7973
    };
7974
    var setupUiContainer = function (editor) {
7975
      if (editor.settings.ui_container) {
7976
        global$8.container = descendant$1(Element$$1.fromDom(document.body), editor.settings.ui_container).fold(constant(null), function (elm) {
7977
          return elm.dom();
7978
        });
7979
      }
7980
    };
7981
    var setupRtlMode = function (editor) {
7982
      if (editor.rtl) {
7983
        Control$1.rtl = true;
7984
      }
7985
    };
7986
    var setupHideFloatPanels = function (editor) {
7987
      editor.on('mousedown', function () {
7988
        FloatPanel.hideAll();
7989
      });
7990
    };
7991
    var setup$1 = function (editor) {
7992
      setupRtlMode(editor);
7993
      setupHideFloatPanels(editor);
7994
      setupUiContainer(editor);
7995
      setupEnvironment();
7996
      FormatSelect.register(editor);
7997
      Align.register(editor);
7998
      SimpleControls.register(editor);
7999
      UndoRedo.register(editor);
8000
      FontSizeSelect.register(editor);
8001
      FontSelect.register(editor);
8002
      Formats.register(editor);
8003
      VisualAid.register(editor);
8004
      InsertButton.register(editor);
8005
    };
8006
    var FormatControls = { setup: setup$1 };
8007
8008
    var GridLayout = AbsoluteLayout.extend({
8009 View Code Duplication
      recalc: function (container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8010
        var settings, rows, cols, items, contLayoutRect, width, height, rect, ctrlLayoutRect, ctrl, x, y, posX, posY, ctrlSettings, contPaddingBox, align, spacingH, spacingV, alignH, alignV, maxX, maxY;
8011
        var colWidths = [];
8012
        var rowHeights = [];
8013
        var ctrlMinWidth, ctrlMinHeight, availableWidth, availableHeight, reverseRows, idx;
8014
        settings = container.settings;
8015
        items = container.items().filter(':visible');
8016
        contLayoutRect = container.layoutRect();
8017
        cols = settings.columns || Math.ceil(Math.sqrt(items.length));
8018
        rows = Math.ceil(items.length / cols);
8019
        spacingH = settings.spacingH || settings.spacing || 0;
8020
        spacingV = settings.spacingV || settings.spacing || 0;
8021
        alignH = settings.alignH || settings.align;
8022
        alignV = settings.alignV || settings.align;
8023
        contPaddingBox = container.paddingBox;
8024
        reverseRows = 'reverseRows' in settings ? settings.reverseRows : container.isRtl();
8025
        if (alignH && typeof alignH === 'string') {
8026
          alignH = [alignH];
8027
        }
8028
        if (alignV && typeof alignV === 'string') {
8029
          alignV = [alignV];
8030
        }
8031
        for (x = 0; x < cols; x++) {
8032
          colWidths.push(0);
8033
        }
8034
        for (y = 0; y < rows; y++) {
8035
          rowHeights.push(0);
8036
        }
8037
        for (y = 0; y < rows; y++) {
8038
          for (x = 0; x < cols; x++) {
8039
            ctrl = items[y * cols + x];
8040
            if (!ctrl) {
8041
              break;
8042
            }
8043
            ctrlLayoutRect = ctrl.layoutRect();
8044
            ctrlMinWidth = ctrlLayoutRect.minW;
8045
            ctrlMinHeight = ctrlLayoutRect.minH;
8046
            colWidths[x] = ctrlMinWidth > colWidths[x] ? ctrlMinWidth : colWidths[x];
8047
            rowHeights[y] = ctrlMinHeight > rowHeights[y] ? ctrlMinHeight : rowHeights[y];
8048
          }
8049
        }
8050
        availableWidth = contLayoutRect.innerW - contPaddingBox.left - contPaddingBox.right;
8051
        for (maxX = 0, x = 0; x < cols; x++) {
8052
          maxX += colWidths[x] + (x > 0 ? spacingH : 0);
8053
          availableWidth -= (x > 0 ? spacingH : 0) + colWidths[x];
8054
        }
8055
        availableHeight = contLayoutRect.innerH - contPaddingBox.top - contPaddingBox.bottom;
8056
        for (maxY = 0, y = 0; y < rows; y++) {
8057
          maxY += rowHeights[y] + (y > 0 ? spacingV : 0);
8058
          availableHeight -= (y > 0 ? spacingV : 0) + rowHeights[y];
8059
        }
8060
        maxX += contPaddingBox.left + contPaddingBox.right;
8061
        maxY += contPaddingBox.top + contPaddingBox.bottom;
8062
        rect = {};
8063
        rect.minW = maxX + (contLayoutRect.w - contLayoutRect.innerW);
8064
        rect.minH = maxY + (contLayoutRect.h - contLayoutRect.innerH);
8065
        rect.contentW = rect.minW - contLayoutRect.deltaW;
8066
        rect.contentH = rect.minH - contLayoutRect.deltaH;
8067
        rect.minW = Math.min(rect.minW, contLayoutRect.maxW);
8068
        rect.minH = Math.min(rect.minH, contLayoutRect.maxH);
8069
        rect.minW = Math.max(rect.minW, contLayoutRect.startMinWidth);
8070
        rect.minH = Math.max(rect.minH, contLayoutRect.startMinHeight);
8071
        if (contLayoutRect.autoResize && (rect.minW !== contLayoutRect.minW || rect.minH !== contLayoutRect.minH)) {
8072
          rect.w = rect.minW;
8073
          rect.h = rect.minH;
8074
          container.layoutRect(rect);
8075
          this.recalc(container);
8076
          if (container._lastRect === null) {
8077
            var parentCtrl = container.parent();
8078
            if (parentCtrl) {
8079
              parentCtrl._lastRect = null;
8080
              parentCtrl.recalc();
8081
            }
8082
          }
8083
          return;
8084
        }
8085
        if (contLayoutRect.autoResize) {
8086
          rect = container.layoutRect(rect);
8087
          rect.contentW = rect.minW - contLayoutRect.deltaW;
8088
          rect.contentH = rect.minH - contLayoutRect.deltaH;
8089
        }
8090
        var flexV;
8091
        if (settings.packV === 'start') {
8092
          flexV = 0;
8093
        } else {
8094
          flexV = availableHeight > 0 ? Math.floor(availableHeight / rows) : 0;
8095
        }
8096
        var totalFlex = 0;
8097
        var flexWidths = settings.flexWidths;
8098
        if (flexWidths) {
8099
          for (x = 0; x < flexWidths.length; x++) {
8100
            totalFlex += flexWidths[x];
8101
          }
8102
        } else {
8103
          totalFlex = cols;
8104
        }
8105
        var ratio = availableWidth / totalFlex;
8106
        for (x = 0; x < cols; x++) {
8107
          colWidths[x] += flexWidths ? flexWidths[x] * ratio : ratio;
8108
        }
8109
        posY = contPaddingBox.top;
8110
        for (y = 0; y < rows; y++) {
8111
          posX = contPaddingBox.left;
8112
          height = rowHeights[y] + flexV;
8113
          for (x = 0; x < cols; x++) {
8114
            if (reverseRows) {
8115
              idx = y * cols + cols - 1 - x;
8116
            } else {
8117
              idx = y * cols + x;
8118
            }
8119
            ctrl = items[idx];
8120
            if (!ctrl) {
8121
              break;
8122
            }
8123
            ctrlSettings = ctrl.settings;
8124
            ctrlLayoutRect = ctrl.layoutRect();
8125
            width = Math.max(colWidths[x], ctrlLayoutRect.startMinWidth);
8126
            ctrlLayoutRect.x = posX;
8127
            ctrlLayoutRect.y = posY;
8128
            align = ctrlSettings.alignH || (alignH ? alignH[x] || alignH[0] : null);
8129
            if (align === 'center') {
8130
              ctrlLayoutRect.x = posX + width / 2 - ctrlLayoutRect.w / 2;
8131
            } else if (align === 'right') {
8132
              ctrlLayoutRect.x = posX + width - ctrlLayoutRect.w;
8133
            } else if (align === 'stretch') {
8134
              ctrlLayoutRect.w = width;
8135
            }
8136
            align = ctrlSettings.alignV || (alignV ? alignV[x] || alignV[0] : null);
8137
            if (align === 'center') {
8138
              ctrlLayoutRect.y = posY + height / 2 - ctrlLayoutRect.h / 2;
8139
            } else if (align === 'bottom') {
8140
              ctrlLayoutRect.y = posY + height - ctrlLayoutRect.h;
8141
            } else if (align === 'stretch') {
8142
              ctrlLayoutRect.h = height;
8143
            }
8144
            ctrl.layoutRect(ctrlLayoutRect);
8145
            posX += width + spacingH;
8146
            if (ctrl.recalc) {
8147
              ctrl.recalc();
8148
            }
8149
          }
8150
          posY += height + spacingV;
8151
        }
8152
      }
8153
    });
8154
8155
    var Iframe$1 = Widget.extend({
8156
      renderHtml: function () {
8157
        var self = this;
8158
        self.classes.add('iframe');
8159
        self.canFocus = false;
8160
        return '<iframe id="' + self._id + '" class="' + self.classes + '" tabindex="-1" src="' + (self.settings.url || 'javascript:\'\'') + '" frameborder="0"></iframe>';
8161
      },
8162
      src: function (src) {
8163
        this.getEl().src = src;
8164
      },
8165
      html: function (html, callback) {
8166
        var self = this, body = this.getEl().contentWindow.document.body;
8167
        if (!body) {
8168
          global$7.setTimeout(function () {
8169
            self.html(html);
8170
          });
8171
        } else {
8172
          body.innerHTML = html;
8173
          if (callback) {
8174
            callback();
8175
          }
8176
        }
8177
        return this;
8178
      }
8179
    });
8180
8181
    var InfoBox = Widget.extend({
8182
      init: function (settings) {
8183
        var self = this;
8184
        self._super(settings);
8185
        self.classes.add('widget').add('infobox');
8186
        self.canFocus = false;
8187
      },
8188
      severity: function (level) {
8189
        this.classes.remove('error');
8190
        this.classes.remove('warning');
8191
        this.classes.remove('success');
8192
        this.classes.add(level);
8193
      },
8194
      help: function (state) {
8195
        this.state.set('help', state);
8196
      },
8197 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8198
        var self = this, prefix = self.classPrefix;
8199
        return '<div id="' + self._id + '" class="' + self.classes + '">' + '<div id="' + self._id + '-body">' + self.encode(self.state.get('text')) + '<button role="button" tabindex="-1">' + '<i class="' + prefix + 'ico ' + prefix + 'i-help"></i>' + '</button>' + '</div>' + '</div>';
8200
      },
8201
      bindStates: function () {
8202
        var self = this;
8203
        self.state.on('change:text', function (e) {
8204
          self.getEl('body').firstChild.data = self.encode(e.value);
8205
          if (self.state.get('rendered')) {
8206
            self.updateLayoutRect();
8207
          }
8208
        });
8209
        self.state.on('change:help', function (e) {
8210
          self.classes.toggle('has-help', e.value);
8211
          if (self.state.get('rendered')) {
8212
            self.updateLayoutRect();
8213
          }
8214
        });
8215
        return self._super();
8216
      }
8217
    });
8218
8219
    var Label = Widget.extend({
8220
      init: function (settings) {
8221
        var self = this;
8222
        self._super(settings);
8223
        self.classes.add('widget').add('label');
8224
        self.canFocus = false;
8225
        if (settings.multiline) {
8226
          self.classes.add('autoscroll');
8227
        }
8228
        if (settings.strong) {
8229
          self.classes.add('strong');
8230
        }
8231
      },
8232
      initLayoutRect: function () {
8233
        var self = this, layoutRect = self._super();
8234
        if (self.settings.multiline) {
8235
          var size = funcs.getSize(self.getEl());
8236
          if (size.width > layoutRect.maxW) {
8237
            layoutRect.minW = layoutRect.maxW;
8238
            self.classes.add('multiline');
8239
          }
8240
          self.getEl().style.width = layoutRect.minW + 'px';
8241
          layoutRect.startMinH = layoutRect.h = layoutRect.minH = Math.min(layoutRect.maxH, funcs.getSize(self.getEl()).height);
8242
        }
8243
        return layoutRect;
8244
      },
8245
      repaint: function () {
8246
        var self = this;
8247
        if (!self.settings.multiline) {
8248
          self.getEl().style.lineHeight = self.layoutRect().h + 'px';
8249
        }
8250
        return self._super();
8251
      },
8252
      severity: function (level) {
8253
        this.classes.remove('error');
8254
        this.classes.remove('warning');
8255
        this.classes.remove('success');
8256
        this.classes.add(level);
8257
      },
8258 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8259
        var self = this;
8260
        var targetCtrl, forName, forId = self.settings.forId;
8261
        var text = self.settings.html ? self.settings.html : self.encode(self.state.get('text'));
8262
        if (!forId && (forName = self.settings.forName)) {
8263
          targetCtrl = self.getRoot().find('#' + forName)[0];
8264
          if (targetCtrl) {
8265
            forId = targetCtrl._id;
8266
          }
8267
        }
8268
        if (forId) {
8269
          return '<label id="' + self._id + '" class="' + self.classes + '"' + (forId ? ' for="' + forId + '"' : '') + '>' + text + '</label>';
8270
        }
8271
        return '<span id="' + self._id + '" class="' + self.classes + '">' + text + '</span>';
8272
      },
8273
      bindStates: function () {
8274
        var self = this;
8275
        self.state.on('change:text', function (e) {
8276
          self.innerHtml(self.encode(e.value));
8277
          if (self.state.get('rendered')) {
8278
            self.updateLayoutRect();
8279
          }
8280
        });
8281
        return self._super();
8282
      }
8283
    });
8284
8285
    var Toolbar$1 = Container.extend({
8286
      Defaults: {
8287
        role: 'toolbar',
8288
        layout: 'flow'
8289
      },
8290
      init: function (settings) {
8291
        var self = this;
8292
        self._super(settings);
8293
        self.classes.add('toolbar');
8294
      },
8295
      postRender: function () {
8296
        var self = this;
8297
        self.items().each(function (ctrl) {
8298
          ctrl.classes.add('toolbar-item');
8299
        });
8300
        return self._super();
8301
      }
8302
    });
8303
8304
    var MenuBar = Toolbar$1.extend({
8305
      Defaults: {
8306
        role: 'menubar',
8307
        containerCls: 'menubar',
8308
        ariaRoot: true,
8309
        defaults: { type: 'menubutton' }
8310
      }
8311
    });
8312
8313
    function isChildOf$1(node, parent$$1) {
8314
      while (node) {
8315
        if (parent$$1 === node) {
8316
          return true;
8317
        }
8318
        node = node.parentNode;
8319
      }
8320
      return false;
8321
    }
8322
    var MenuButton = Button.extend({
8323
      init: function (settings) {
8324
        var self$$1 = this;
8325
        self$$1._renderOpen = true;
8326
        self$$1._super(settings);
8327
        settings = self$$1.settings;
8328
        self$$1.classes.add('menubtn');
8329
        if (settings.fixedWidth) {
8330
          self$$1.classes.add('fixed-width');
8331
        }
8332
        self$$1.aria('haspopup', true);
8333
        self$$1.state.set('menu', settings.menu || self$$1.render());
8334
      },
8335 View Code Duplication
      showMenu: function (toggle) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8336
        var self$$1 = this;
8337
        var menu;
8338
        if (self$$1.menu && self$$1.menu.visible() && toggle !== false) {
8339
          return self$$1.hideMenu();
8340
        }
8341
        if (!self$$1.menu) {
8342
          menu = self$$1.state.get('menu') || [];
8343
          self$$1.classes.add('opened');
8344
          if (menu.length) {
8345
            menu = {
8346
              type: 'menu',
8347
              animate: true,
8348
              items: menu
8349
            };
8350
          } else {
8351
            menu.type = menu.type || 'menu';
8352
            menu.animate = true;
8353
          }
8354
          if (!menu.renderTo) {
8355
            self$$1.menu = global$4.create(menu).parent(self$$1).renderTo();
8356
          } else {
8357
            self$$1.menu = menu.parent(self$$1).show().renderTo();
8358
          }
8359
          self$$1.fire('createmenu');
8360
          self$$1.menu.reflow();
8361
          self$$1.menu.on('cancel', function (e) {
8362
            if (e.control.parent() === self$$1.menu) {
8363
              e.stopPropagation();
8364
              self$$1.focus();
8365
              self$$1.hideMenu();
8366
            }
8367
          });
8368
          self$$1.menu.on('select', function () {
8369
            self$$1.focus();
8370
          });
8371
          self$$1.menu.on('show hide', function (e) {
8372
            if (e.type === 'hide' && e.control.parent() === self$$1) {
8373
              self$$1.classes.remove('opened-under');
8374
            }
8375
            if (e.control === self$$1.menu) {
8376
              self$$1.activeMenu(e.type === 'show');
8377
              self$$1.classes.toggle('opened', e.type === 'show');
8378
            }
8379
            self$$1.aria('expanded', e.type === 'show');
8380
          }).fire('show');
8381
        }
8382
        self$$1.menu.show();
8383
        self$$1.menu.layoutRect({ w: self$$1.layoutRect().w });
8384
        self$$1.menu.repaint();
8385
        self$$1.menu.moveRel(self$$1.getEl(), self$$1.isRtl() ? [
8386
          'br-tr',
8387
          'tr-br'
8388
        ] : [
8389
          'bl-tl',
8390
          'tl-bl'
8391
        ]);
8392
        var menuLayoutRect = self$$1.menu.layoutRect();
8393
        var selfBottom = self$$1.$el.offset().top + self$$1.layoutRect().h;
8394
        if (selfBottom > menuLayoutRect.y && selfBottom < menuLayoutRect.y + menuLayoutRect.h) {
8395
          self$$1.classes.add('opened-under');
8396
        }
8397
        self$$1.fire('showmenu');
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
8398
      },
8399
      hideMenu: function () {
8400
        var self$$1 = this;
8401
        if (self$$1.menu) {
8402
          self$$1.menu.items().each(function (item) {
8403
            if (item.hideMenu) {
8404
              item.hideMenu();
8405
            }
8406
          });
8407
          self$$1.menu.hide();
8408
        }
8409
      },
8410
      activeMenu: function (state) {
8411
        this.classes.toggle('active', state);
8412
      },
8413 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8414
        var self$$1 = this, id = self$$1._id, prefix = self$$1.classPrefix;
8415
        var icon = self$$1.settings.icon, image;
8416
        var text = self$$1.state.get('text');
8417
        var textHtml = '';
8418
        image = self$$1.settings.image;
8419
        if (image) {
8420
          icon = 'none';
8421
          if (typeof image !== 'string') {
8422
            image = window.getSelection ? image[0] : image[1];
8423
          }
8424
          image = ' style="background-image: url(\'' + image + '\')"';
8425
        } else {
8426
          image = '';
8427
        }
8428
        if (text) {
8429
          self$$1.classes.add('btn-has-text');
8430
          textHtml = '<span class="' + prefix + 'txt">' + self$$1.encode(text) + '</span>';
8431
        }
8432
        icon = self$$1.settings.icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
8433
        self$$1.aria('role', self$$1.parent() instanceof MenuBar ? 'menuitem' : 'button');
8434
        return '<div id="' + id + '" class="' + self$$1.classes + '" tabindex="-1" aria-labelledby="' + id + '">' + '<button id="' + id + '-open" role="presentation" type="button" tabindex="-1">' + (icon ? '<i class="' + icon + '"' + image + '></i>' : '') + textHtml + ' <i class="' + prefix + 'caret"></i>' + '</button>' + '</div>';
8435
      },
8436 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8437
        var self$$1 = this;
8438
        self$$1.on('click', function (e) {
8439
          if (e.control === self$$1 && isChildOf$1(e.target, self$$1.getEl())) {
8440
            self$$1.focus();
8441
            self$$1.showMenu(!e.aria);
8442
            if (e.aria) {
8443
              self$$1.menu.items().filter(':visible')[0].focus();
8444
            }
8445
          }
8446
        });
8447
        self$$1.on('mouseenter', function (e) {
8448
          var overCtrl = e.control;
8449
          var parent$$1 = self$$1.parent();
8450
          var hasVisibleSiblingMenu;
8451
          if (overCtrl && parent$$1 && overCtrl instanceof MenuButton && overCtrl.parent() === parent$$1) {
8452
            parent$$1.items().filter('MenuButton').each(function (ctrl) {
8453
              if (ctrl.hideMenu && ctrl !== overCtrl) {
8454
                if (ctrl.menu && ctrl.menu.visible()) {
8455
                  hasVisibleSiblingMenu = true;
8456
                }
8457
                ctrl.hideMenu();
8458
              }
8459
            });
8460
            if (hasVisibleSiblingMenu) {
8461
              overCtrl.focus();
8462
              overCtrl.showMenu();
8463
            }
8464
          }
8465
        });
8466
        return self$$1._super();
8467
      },
8468
      bindStates: function () {
8469
        var self$$1 = this;
8470
        self$$1.state.on('change:menu', function () {
8471
          if (self$$1.menu) {
8472
            self$$1.menu.remove();
8473
          }
8474
          self$$1.menu = null;
8475
        });
8476
        return self$$1._super();
8477
      },
8478
      remove: function () {
8479
        this._super();
8480
        if (this.menu) {
8481
          this.menu.remove();
8482
        }
8483
      }
8484
    });
8485
8486
    var Menu = FloatPanel.extend({
8487
      Defaults: {
8488
        defaultType: 'menuitem',
8489
        border: 1,
8490
        layout: 'stack',
8491
        role: 'application',
8492
        bodyRole: 'menu',
8493
        ariaRoot: true
8494
      },
8495
      init: function (settings) {
8496
        var self = this;
8497
        settings.autohide = true;
8498
        settings.constrainToViewport = true;
8499
        if (typeof settings.items === 'function') {
8500
          settings.itemsFactory = settings.items;
8501
          settings.items = [];
8502
        }
8503
        if (settings.itemDefaults) {
8504
          var items = settings.items;
8505
          var i = items.length;
8506
          while (i--) {
8507
            items[i] = global$2.extend({}, settings.itemDefaults, items[i]);
8508
          }
8509
        }
8510
        self._super(settings);
8511
        self.classes.add('menu');
8512
        if (settings.animate && global$8.ie !== 11) {
8513
          self.classes.add('animate');
8514
        }
8515
      },
8516
      repaint: function () {
8517
        this.classes.toggle('menu-align', true);
8518
        this._super();
8519
        this.getEl().style.height = '';
8520
        this.getEl('body').style.height = '';
8521
        return this;
8522
      },
8523
      cancel: function () {
8524
        var self = this;
8525
        self.hideAll();
8526
        self.fire('select');
8527
      },
8528 View Code Duplication
      load: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8529
        var self = this;
8530
        var time, factory;
8531
        function hideThrobber() {
8532
          if (self.throbber) {
8533
            self.throbber.hide();
8534
            self.throbber = null;
8535
          }
8536
        }
8537
        factory = self.settings.itemsFactory;
8538
        if (!factory) {
8539
          return;
8540
        }
8541
        if (!self.throbber) {
8542
          self.throbber = new Throbber(self.getEl('body'), true);
8543
          if (self.items().length === 0) {
8544
            self.throbber.show();
8545
            self.fire('loading');
8546
          } else {
8547
            self.throbber.show(100, function () {
8548
              self.items().remove();
8549
              self.fire('loading');
8550
            });
8551
          }
8552
          self.on('hide close', hideThrobber);
8553
        }
8554
        self.requestTime = time = new Date().getTime();
8555
        self.settings.itemsFactory(function (items) {
8556
          if (items.length === 0) {
8557
            self.hide();
8558
            return;
8559
          }
8560
          if (self.requestTime !== time) {
8561
            return;
8562
          }
8563
          self.getEl().style.width = '';
8564
          self.getEl('body').style.width = '';
8565
          hideThrobber();
8566
          self.items().remove();
8567
          self.getEl('body').innerHTML = '';
8568
          self.add(items);
8569
          self.renderNew();
8570
          self.fire('loaded');
8571
        });
8572
      },
8573
      hideAll: function () {
8574
        var self = this;
8575
        this.find('menuitem').exec('hideMenu');
8576
        return self._super();
8577
      },
8578
      preRender: function () {
8579
        var self = this;
8580
        self.items().each(function (ctrl) {
8581
          var settings = ctrl.settings;
8582
          if (settings.icon || settings.image || settings.selectable) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if settings.icon || setting... || settings.selectable is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
8583
            self._hasIcons = true;
8584
            return false;
8585
          }
8586
        });
8587
        if (self.settings.itemsFactory) {
8588
          self.on('postrender', function () {
8589
            if (self.settings.itemsFactory) {
8590
              self.load();
8591
            }
8592
          });
8593
        }
8594
        self.on('show hide', function (e) {
8595
          if (e.control === self) {
8596
            if (e.type === 'show') {
8597
              global$7.setTimeout(function () {
8598
                self.classes.add('in');
8599
              }, 0);
8600
            } else {
8601
              self.classes.remove('in');
8602
            }
8603
          }
8604
        });
8605
        return self._super();
8606
      }
8607
    });
8608
8609
    var ListBox = MenuButton.extend({
8610 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8611
        var self = this;
8612
        var values, selected, selectedText, lastItemCtrl;
8613
        function setSelected(menuValues) {
8614
          for (var i = 0; i < menuValues.length; i++) {
8615
            selected = menuValues[i].selected || settings.value === menuValues[i].value;
8616
            if (selected) {
0 ignored issues
show
Bug introduced by
The variable selected is changed as part of the for loop for example by menuValues.i.selected ||... === menuValues.i.value on line 8615. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
8617
              selectedText = selectedText || menuValues[i].text;
8618
              self.state.set('value', menuValues[i].value);
8619
              return true;
8620
            }
8621
            if (menuValues[i].menu) {
8622
              if (setSelected(menuValues[i].menu)) {
8623
                return true;
8624
              }
8625
            }
8626
          }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
8627
        }
8628
        self._super(settings);
8629
        settings = self.settings;
8630
        self._values = values = settings.values;
8631
        if (values) {
8632
          if (typeof settings.value !== 'undefined') {
8633
            setSelected(values);
8634
          }
8635
          if (!selected && values.length > 0) {
8636
            selectedText = values[0].text;
8637
            self.state.set('value', values[0].value);
8638
          }
8639
          self.state.set('menu', values);
8640
        }
8641
        self.state.set('text', settings.text || selectedText);
8642
        self.classes.add('listbox');
8643
        self.on('select', function (e) {
8644
          var ctrl = e.control;
8645
          if (lastItemCtrl) {
8646
            e.lastControl = lastItemCtrl;
8647
          }
8648
          if (settings.multiple) {
8649
            ctrl.active(!ctrl.active());
8650
          } else {
8651
            self.value(e.control.value());
8652
          }
8653
          lastItemCtrl = ctrl;
8654
        });
8655
      },
8656 View Code Duplication
      value: function (value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8657
        if (arguments.length === 0) {
8658
          return this.state.get('value');
8659
        }
8660
        if (typeof value === 'undefined') {
8661
          return this;
8662
        }
8663
        function valueExists(values) {
8664
          return exists(values, function (a) {
8665
            return a.menu ? valueExists(a.menu) : a.value === value;
8666
          });
8667
        }
8668
        if (this.settings.values) {
8669
          if (valueExists(this.settings.values)) {
8670
            this.state.set('value', value);
8671
          } else if (value === null) {
8672
            this.state.set('value', null);
8673
          }
8674
        } else {
8675
          this.state.set('value', value);
8676
        }
8677
        return this;
8678
      },
8679 View Code Duplication
      bindStates: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8680
        var self = this;
8681
        function activateMenuItemsByValue(menu, value) {
8682
          if (menu instanceof Menu) {
8683
            menu.items().each(function (ctrl) {
8684
              if (!ctrl.hasMenus()) {
8685
                ctrl.active(ctrl.value() === value);
8686
              }
8687
            });
8688
          }
8689
        }
8690
        function getSelectedItem(menuValues, value) {
8691
          var selectedItem;
8692
          if (!menuValues) {
8693
            return;
0 ignored issues
show
Comprehensibility Best Practice introduced by
Are you sure this return statement is not missing an argument? If this is intended, consider adding an explicit undefined like return undefined;.
Loading history...
8694
          }
8695
          for (var i = 0; i < menuValues.length; i++) {
8696
            if (menuValues[i].value === value) {
8697
              return menuValues[i];
8698
            }
8699
            if (menuValues[i].menu) {
8700
              selectedItem = getSelectedItem(menuValues[i].menu, value);
8701
              if (selectedItem) {
8702
                return selectedItem;
8703
              }
8704
            }
8705
          }
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
8706
        }
8707
        self.on('show', function (e) {
8708
          activateMenuItemsByValue(e.control, self.value());
8709
        });
8710
        self.state.on('change:value', function (e) {
8711
          var selectedItem = getSelectedItem(self.state.get('menu'), e.value);
8712
          if (selectedItem) {
8713
            self.text(selectedItem.text);
8714
          } else {
8715
            self.text(self.settings.text);
8716
          }
8717
        });
8718
        return self._super();
8719
      }
8720
    });
8721
8722
    var toggleTextStyle = function (ctrl, state) {
8723
      var textStyle = ctrl._textStyle;
8724
      if (textStyle) {
8725
        var textElm = ctrl.getEl('text');
8726
        textElm.setAttribute('style', textStyle);
8727
        if (state) {
8728
          textElm.style.color = '';
8729
          textElm.style.backgroundColor = '';
8730
        }
8731
      }
8732
    };
8733
    var MenuItem = Widget.extend({
8734
      Defaults: {
8735
        border: 0,
8736
        role: 'menuitem'
8737
      },
8738 View Code Duplication
      init: function (settings) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8739
        var self = this;
8740
        var text;
8741
        self._super(settings);
8742
        settings = self.settings;
8743
        self.classes.add('menu-item');
8744
        if (settings.menu) {
8745
          self.classes.add('menu-item-expand');
8746
        }
8747
        if (settings.preview) {
8748
          self.classes.add('menu-item-preview');
8749
        }
8750
        text = self.state.get('text');
8751
        if (text === '-' || text === '|') {
8752
          self.classes.add('menu-item-sep');
8753
          self.aria('role', 'separator');
8754
          self.state.set('text', '-');
8755
        }
8756
        if (settings.selectable) {
8757
          self.aria('role', 'menuitemcheckbox');
8758
          self.classes.add('menu-item-checkbox');
8759
          settings.icon = 'selected';
8760
        }
8761
        if (!settings.preview && !settings.selectable) {
8762
          self.classes.add('menu-item-normal');
8763
        }
8764
        self.on('mousedown', function (e) {
8765
          e.preventDefault();
8766
        });
8767
        if (settings.menu && !settings.ariaHideMenu) {
8768
          self.aria('haspopup', true);
8769
        }
8770
      },
8771
      hasMenus: function () {
8772
        return !!this.settings.menu;
8773
      },
8774 View Code Duplication
      showMenu: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8775
        var self = this;
8776
        var settings = self.settings;
8777
        var menu;
8778
        var parent = self.parent();
8779
        parent.items().each(function (ctrl) {
8780
          if (ctrl !== self) {
8781
            ctrl.hideMenu();
8782
          }
8783
        });
8784
        if (settings.menu) {
8785
          menu = self.menu;
8786
          if (!menu) {
8787
            menu = settings.menu;
8788
            if (menu.length) {
8789
              menu = {
8790
                type: 'menu',
8791
                items: menu
8792
              };
8793
            } else {
8794
              menu.type = menu.type || 'menu';
8795
            }
8796
            if (parent.settings.itemDefaults) {
8797
              menu.itemDefaults = parent.settings.itemDefaults;
8798
            }
8799
            menu = self.menu = global$4.create(menu).parent(self).renderTo();
8800
            menu.reflow();
8801
            menu.on('cancel', function (e) {
8802
              e.stopPropagation();
8803
              self.focus();
8804
              menu.hide();
8805
            });
8806
            menu.on('show hide', function (e) {
8807
              if (e.control.items) {
8808
                e.control.items().each(function (ctrl) {
8809
                  ctrl.active(ctrl.settings.selected);
8810
                });
8811
              }
8812
            }).fire('show');
8813
            menu.on('hide', function (e) {
8814
              if (e.control === menu) {
8815
                self.classes.remove('selected');
8816
              }
8817
            });
8818
            menu.submenu = true;
8819
          } else {
8820
            menu.show();
8821
          }
8822
          menu._parentMenu = parent;
8823
          menu.classes.add('menu-sub');
8824
          var rel = menu.testMoveRel(self.getEl(), self.isRtl() ? [
8825
            'tl-tr',
8826
            'bl-br',
8827
            'tr-tl',
8828
            'br-bl'
8829
          ] : [
8830
            'tr-tl',
8831
            'br-bl',
8832
            'tl-tr',
8833
            'bl-br'
8834
          ]);
8835
          menu.moveRel(self.getEl(), rel);
8836
          menu.rel = rel;
8837
          rel = 'menu-sub-' + rel;
8838
          menu.classes.remove(menu._lastRel).add(rel);
8839
          menu._lastRel = rel;
8840
          self.classes.add('selected');
8841
          self.aria('expanded', true);
8842
        }
8843
      },
8844
      hideMenu: function () {
8845
        var self = this;
8846
        if (self.menu) {
8847
          self.menu.items().each(function (item) {
8848
            if (item.hideMenu) {
8849
              item.hideMenu();
8850
            }
8851
          });
8852
          self.menu.hide();
8853
          self.aria('expanded', false);
8854
        }
8855
        return self;
8856
      },
8857 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8858
        var self = this;
8859
        var id = self._id;
8860
        var settings = self.settings;
8861
        var prefix = self.classPrefix;
8862
        var text = self.state.get('text');
8863
        var icon = self.settings.icon, image = '', shortcut = settings.shortcut;
8864
        var url = self.encode(settings.url), iconHtml = '';
8865
        function convertShortcut(shortcut) {
8866
          var i, value, replace = {};
0 ignored issues
show
Unused Code introduced by
The assignment to variable replace seems to be never used. Consider removing it.
Loading history...
8867
          if (global$8.mac) {
8868
            replace = {
8869
              alt: '&#x2325;',
8870
              ctrl: '&#x2318;',
8871
              shift: '&#x21E7;',
8872
              meta: '&#x2318;'
8873
            };
8874
          } else {
8875
            replace = { meta: 'Ctrl' };
8876
          }
8877
          shortcut = shortcut.split('+');
8878
          for (i = 0; i < shortcut.length; i++) {
8879
            value = replace[shortcut[i].toLowerCase()];
8880
            if (value) {
8881
              shortcut[i] = value;
8882
            }
8883
          }
8884
          return shortcut.join('+');
8885
        }
8886
        function escapeRegExp(str) {
8887
          return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
8888
        }
8889
        function markMatches(text) {
8890
          var match = settings.match || '';
8891
          return match ? text.replace(new RegExp(escapeRegExp(match), 'gi'), function (match) {
8892
            return '!mce~match[' + match + ']mce~match!';
8893
          }) : text;
8894
        }
8895
        function boldMatches(text) {
8896
          return text.replace(new RegExp(escapeRegExp('!mce~match['), 'g'), '<b>').replace(new RegExp(escapeRegExp(']mce~match!'), 'g'), '</b>');
8897
        }
8898
        if (icon) {
8899
          self.parent().classes.add('menu-has-icons');
8900
        }
8901
        if (settings.image) {
8902
          image = ' style="background-image: url(\'' + settings.image + '\')"';
8903
        }
8904
        if (shortcut) {
8905
          shortcut = convertShortcut(shortcut);
8906
        }
8907
        icon = prefix + 'ico ' + prefix + 'i-' + (self.settings.icon || 'none');
8908
        iconHtml = text !== '-' ? '<i class="' + icon + '"' + image + '></i>\xA0' : '';
8909
        text = boldMatches(self.encode(markMatches(text)));
8910
        url = boldMatches(self.encode(markMatches(url)));
8911
        return '<div id="' + id + '" class="' + self.classes + '" tabindex="-1">' + iconHtml + (text !== '-' ? '<span id="' + id + '-text" class="' + prefix + 'text">' + text + '</span>' : '') + (shortcut ? '<div id="' + id + '-shortcut" class="' + prefix + 'menu-shortcut">' + shortcut + '</div>' : '') + (settings.menu ? '<div class="' + prefix + 'caret"></div>' : '') + (url ? '<div class="' + prefix + 'menu-item-link">' + url + '</div>' : '') + '</div>';
8912
      },
8913
      postRender: function () {
8914
        var self = this, settings = self.settings;
8915
        var textStyle = settings.textStyle;
8916
        if (typeof textStyle === 'function') {
8917
          textStyle = textStyle.call(this);
8918
        }
8919
        if (textStyle) {
8920
          var textElm = self.getEl('text');
8921
          if (textElm) {
8922
            textElm.setAttribute('style', textStyle);
8923
            self._textStyle = textStyle;
8924
          }
8925
        }
8926
        self.on('mouseenter click', function (e) {
8927
          if (e.control === self) {
8928
            if (!settings.menu && e.type === 'click') {
8929
              self.fire('select');
8930
              global$7.requestAnimationFrame(function () {
8931
                self.parent().hideAll();
8932
              });
8933
            } else {
8934
              self.showMenu();
8935
              if (e.aria) {
8936
                self.menu.focus(true);
8937
              }
8938
            }
8939
          }
8940
        });
8941
        self._super();
8942
        return self;
8943
      },
8944
      hover: function () {
8945
        var self = this;
8946
        self.parent().items().each(function (ctrl) {
8947
          ctrl.classes.remove('selected');
8948
        });
8949
        self.classes.toggle('selected', true);
8950
        return self;
8951
      },
8952
      active: function (state) {
8953
        toggleTextStyle(this, state);
8954
        if (typeof state !== 'undefined') {
8955
          this.aria('checked', state);
8956
        }
8957
        return this._super(state);
8958
      },
8959
      remove: function () {
8960
        this._super();
8961
        if (this.menu) {
8962
          this.menu.remove();
8963
        }
8964
      }
8965
    });
8966
8967
    var Radio = Checkbox.extend({
8968
      Defaults: {
8969
        classes: 'radio',
8970
        role: 'radio'
8971
      }
8972
    });
8973
8974
    var ResizeHandle = Widget.extend({
8975 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
8976
        var self = this, prefix = self.classPrefix;
8977
        self.classes.add('resizehandle');
8978
        if (self.settings.direction === 'both') {
8979
          self.classes.add('resizehandle-both');
8980
        }
8981
        self.canFocus = false;
8982
        return '<div id="' + self._id + '" class="' + self.classes + '">' + '<i class="' + prefix + 'ico ' + prefix + 'i-resize"></i>' + '</div>';
8983
      },
8984
      postRender: function () {
8985
        var self = this;
8986
        self._super();
8987
        self.resizeDragHelper = new DragHelper(this._id, {
8988
          start: function () {
8989
            self.fire('ResizeStart');
8990
          },
8991
          drag: function (e) {
8992
            if (self.settings.direction !== 'both') {
8993
              e.deltaX = 0;
8994
            }
8995
            self.fire('Resize', e);
8996
          },
8997
          stop: function () {
8998
            self.fire('ResizeEnd');
8999
          }
9000
        });
9001
      },
9002
      remove: function () {
9003
        if (this.resizeDragHelper) {
9004
          this.resizeDragHelper.destroy();
9005
        }
9006
        return this._super();
9007
      }
9008
    });
9009
9010
    function createOptions(options) {
9011
      var strOptions = '';
9012
      if (options) {
9013
        for (var i = 0; i < options.length; i++) {
9014
          strOptions += '<option value="' + options[i] + '">' + options[i] + '</option>';
9015
        }
9016
      }
9017
      return strOptions;
9018
    }
9019
    var SelectBox = Widget.extend({
9020
      Defaults: {
9021
        classes: 'selectbox',
9022
        role: 'selectbox',
9023
        options: []
9024
      },
9025
      init: function (settings) {
9026
        var self = this;
9027
        self._super(settings);
9028
        if (self.settings.size) {
9029
          self.size = self.settings.size;
9030
        }
9031
        if (self.settings.options) {
9032
          self._options = self.settings.options;
9033
        }
9034
        self.on('keydown', function (e) {
9035
          var rootControl;
9036
          if (e.keyCode === 13) {
9037
            e.preventDefault();
9038
            self.parents().reverse().each(function (ctrl) {
9039
              if (ctrl.toJSON) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if ctrl.toJSON is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
9040
                rootControl = ctrl;
9041
                return false;
9042
              }
9043
            });
9044
            self.fire('submit', { data: rootControl.toJSON() });
9045
          }
9046
        });
9047
      },
9048
      options: function (state) {
9049
        if (!arguments.length) {
9050
          return this.state.get('options');
9051
        }
9052
        this.state.set('options', state);
9053
        return this;
9054
      },
9055 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9056
        var self = this;
9057
        var options, size = '';
9058
        options = createOptions(self._options);
9059
        if (self.size) {
9060
          size = ' size = "' + self.size + '"';
9061
        }
9062
        return '<select id="' + self._id + '" class="' + self.classes + '"' + size + '>' + options + '</select>';
9063
      },
9064
      bindStates: function () {
9065
        var self = this;
9066
        self.state.on('change:options', function (e) {
9067
          self.getEl().innerHTML = createOptions(e.value);
9068
        });
9069
        return self._super();
9070
      }
9071
    });
9072
9073
    function constrain(value, minVal, maxVal) {
9074
      if (value < minVal) {
9075
        value = minVal;
9076
      }
9077
      if (value > maxVal) {
9078
        value = maxVal;
9079
      }
9080
      return value;
9081
    }
9082
    function setAriaProp(el, name, value) {
9083
      el.setAttribute('aria-' + name, value);
9084
    }
9085 View Code Duplication
    function updateSliderHandle(ctrl, value) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9086
      var maxHandlePos, shortSizeName, sizeName, stylePosName, styleValue, handleEl;
9087
      if (ctrl.settings.orientation === 'v') {
9088
        stylePosName = 'top';
9089
        sizeName = 'height';
9090
        shortSizeName = 'h';
9091
      } else {
9092
        stylePosName = 'left';
9093
        sizeName = 'width';
9094
        shortSizeName = 'w';
9095
      }
9096
      handleEl = ctrl.getEl('handle');
9097
      maxHandlePos = (ctrl.layoutRect()[shortSizeName] || 100) - funcs.getSize(handleEl)[sizeName];
9098
      styleValue = maxHandlePos * ((value - ctrl._minValue) / (ctrl._maxValue - ctrl._minValue)) + 'px';
9099
      handleEl.style[stylePosName] = styleValue;
9100
      handleEl.style.height = ctrl.layoutRect().h + 'px';
9101
      setAriaProp(handleEl, 'valuenow', value);
9102
      setAriaProp(handleEl, 'valuetext', '' + ctrl.settings.previewFilter(value));
9103
      setAriaProp(handleEl, 'valuemin', ctrl._minValue);
9104
      setAriaProp(handleEl, 'valuemax', ctrl._maxValue);
9105
    }
9106
    var Slider = Widget.extend({
9107
      init: function (settings) {
9108
        var self = this;
9109
        if (!settings.previewFilter) {
9110
          settings.previewFilter = function (value) {
9111
            return Math.round(value * 100) / 100;
9112
          };
9113
        }
9114
        self._super(settings);
9115
        self.classes.add('slider');
9116
        if (settings.orientation === 'v') {
9117
          self.classes.add('vertical');
9118
        }
9119
        self._minValue = isNumber(settings.minValue) ? settings.minValue : 0;
9120
        self._maxValue = isNumber(settings.maxValue) ? settings.maxValue : 100;
9121
        self._initValue = self.state.get('value');
9122
      },
9123
      renderHtml: function () {
9124
        var self = this, id = self._id, prefix = self.classPrefix;
9125
        return '<div id="' + id + '" class="' + self.classes + '">' + '<div id="' + id + '-handle" class="' + prefix + 'slider-handle" role="slider" tabindex="-1"></div>' + '</div>';
9126
      },
9127
      reset: function () {
9128
        this.value(this._initValue).repaint();
9129
      },
9130 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9131
        var self = this;
9132
        var minValue, maxValue, screenCordName, stylePosName, sizeName, shortSizeName;
9133
        function toFraction(min, max, val) {
9134
          return (val + min) / (max - min);
9135
        }
9136
        function fromFraction(min, max, val) {
9137
          return val * (max - min) - min;
9138
        }
9139
        function handleKeyboard(minValue, maxValue) {
9140
          function alter(delta) {
9141
            var value;
9142
            value = self.value();
9143
            value = fromFraction(minValue, maxValue, toFraction(minValue, maxValue, value) + delta * 0.05);
9144
            value = constrain(value, minValue, maxValue);
9145
            self.value(value);
9146
            self.fire('dragstart', { value: value });
9147
            self.fire('drag', { value: value });
9148
            self.fire('dragend', { value: value });
9149
          }
9150
          self.on('keydown', function (e) {
9151
            switch (e.keyCode) {
9152
            case 37:
9153
            case 38:
9154
              alter(-1);
9155
              break;
9156
            case 39:
9157
            case 40:
9158
              alter(1);
9159
              break;
9160
            }
9161
          });
9162
        }
9163
        function handleDrag(minValue, maxValue, handleEl) {
9164
          var startPos, startHandlePos, maxHandlePos, handlePos, value;
9165
          self._dragHelper = new DragHelper(self._id, {
9166
            handle: self._id + '-handle',
9167
            start: function (e) {
9168
              startPos = e[screenCordName];
9169
              startHandlePos = parseInt(self.getEl('handle').style[stylePosName], 10);
9170
              maxHandlePos = (self.layoutRect()[shortSizeName] || 100) - funcs.getSize(handleEl)[sizeName];
9171
              self.fire('dragstart', { value: value });
9172
            },
9173
            drag: function (e) {
9174
              var delta = e[screenCordName] - startPos;
9175
              handlePos = constrain(startHandlePos + delta, 0, maxHandlePos);
9176
              handleEl.style[stylePosName] = handlePos + 'px';
9177
              value = minValue + handlePos / maxHandlePos * (maxValue - minValue);
9178
              self.value(value);
9179
              self.tooltip().text('' + self.settings.previewFilter(value)).show().moveRel(handleEl, 'bc tc');
9180
              self.fire('drag', { value: value });
9181
            },
9182
            stop: function () {
9183
              self.tooltip().hide();
9184
              self.fire('dragend', { value: value });
9185
            }
9186
          });
9187
        }
9188
        minValue = self._minValue;
9189
        maxValue = self._maxValue;
9190
        if (self.settings.orientation === 'v') {
9191
          screenCordName = 'screenY';
9192
          stylePosName = 'top';
9193
          sizeName = 'height';
9194
          shortSizeName = 'h';
9195
        } else {
9196
          screenCordName = 'screenX';
9197
          stylePosName = 'left';
9198
          sizeName = 'width';
9199
          shortSizeName = 'w';
9200
        }
9201
        self._super();
9202
        handleKeyboard(minValue, maxValue);
9203
        handleDrag(minValue, maxValue, self.getEl('handle'));
9204
      },
9205
      repaint: function () {
9206
        this._super();
9207
        updateSliderHandle(this, this.value());
9208
      },
9209
      bindStates: function () {
9210
        var self = this;
9211
        self.state.on('change:value', function (e) {
9212
          updateSliderHandle(self, e.value);
9213
        });
9214
        return self._super();
9215
      }
9216
    });
9217
9218
    var Spacer = Widget.extend({
9219
      renderHtml: function () {
9220
        var self = this;
9221
        self.classes.add('spacer');
9222
        self.canFocus = false;
9223
        return '<div id="' + self._id + '" class="' + self.classes + '"></div>';
9224
      }
9225
    });
9226
9227
    var SplitButton = MenuButton.extend({
9228
      Defaults: {
9229
        classes: 'widget btn splitbtn',
9230
        role: 'button'
9231
      },
9232
      repaint: function () {
9233
        var self$$1 = this;
9234
        var elm = self$$1.getEl();
9235
        var rect = self$$1.layoutRect();
9236
        var mainButtonElm, menuButtonElm;
9237
        self$$1._super();
9238
        mainButtonElm = elm.firstChild;
9239
        menuButtonElm = elm.lastChild;
9240
        global$9(mainButtonElm).css({
9241
          width: rect.w - funcs.getSize(menuButtonElm).width,
9242
          height: rect.h - 2
9243
        });
9244
        global$9(menuButtonElm).css({ height: rect.h - 2 });
9245
        return self$$1;
9246
      },
9247
      activeMenu: function (state) {
9248
        var self$$1 = this;
9249
        global$9(self$$1.getEl().lastChild).toggleClass(self$$1.classPrefix + 'active', state);
9250
      },
9251 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9252
        var self$$1 = this;
9253
        var id = self$$1._id;
9254
        var prefix = self$$1.classPrefix;
9255
        var image;
9256
        var icon = self$$1.state.get('icon');
9257
        var text = self$$1.state.get('text');
9258
        var settings = self$$1.settings;
9259
        var textHtml = '', ariaPressed;
9260
        image = settings.image;
9261
        if (image) {
9262
          icon = 'none';
9263
          if (typeof image !== 'string') {
9264
            image = window.getSelection ? image[0] : image[1];
9265
          }
9266
          image = ' style="background-image: url(\'' + image + '\')"';
9267
        } else {
9268
          image = '';
9269
        }
9270
        icon = settings.icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
9271
        if (text) {
9272
          self$$1.classes.add('btn-has-text');
9273
          textHtml = '<span class="' + prefix + 'txt">' + self$$1.encode(text) + '</span>';
9274
        }
9275
        ariaPressed = typeof settings.active === 'boolean' ? ' aria-pressed="' + settings.active + '"' : '';
9276
        return '<div id="' + id + '" class="' + self$$1.classes + '" role="button"' + ariaPressed + ' tabindex="-1">' + '<button type="button" hidefocus="1" tabindex="-1">' + (icon ? '<i class="' + icon + '"' + image + '></i>' : '') + textHtml + '</button>' + '<button type="button" class="' + prefix + 'open" hidefocus="1" tabindex="-1">' + (self$$1._menuBtnText ? (icon ? '\xA0' : '') + self$$1._menuBtnText : '') + ' <i class="' + prefix + 'caret"></i>' + '</button>' + '</div>';
9277
      },
9278 View Code Duplication
      postRender: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9279
        var self$$1 = this, onClickHandler = self$$1.settings.onclick;
9280
        self$$1.on('click', function (e) {
9281
          var node = e.target;
9282
          if (e.control === this) {
9283
            while (node) {
9284
              if (e.aria && e.aria.key !== 'down' || node.nodeName === 'BUTTON' && node.className.indexOf('open') === -1) {
9285
                e.stopImmediatePropagation();
9286
                if (onClickHandler) {
9287
                  onClickHandler.call(this, e);
9288
                }
9289
                return;
9290
              }
9291
              node = node.parentNode;
9292
            }
9293
          }
9294
        });
9295
        delete self$$1.settings.onclick;
9296
        return self$$1._super();
9297
      }
9298
    });
9299
9300
    var StackLayout = FlowLayout.extend({
9301
      Defaults: {
9302
        containerClass: 'stack-layout',
9303
        controlClass: 'stack-layout-item',
9304
        endClass: 'break'
9305
      },
9306
      isNative: function () {
9307
        return true;
9308
      }
9309
    });
9310
9311
    var TabPanel = Panel.extend({
9312
      Defaults: {
9313
        layout: 'absolute',
9314
        defaults: { type: 'panel' }
9315
      },
9316
      activateTab: function (idx) {
9317
        var activeTabElm;
9318
        if (this.activeTabId) {
9319
          activeTabElm = this.getEl(this.activeTabId);
9320
          global$9(activeTabElm).removeClass(this.classPrefix + 'active');
9321
          activeTabElm.setAttribute('aria-selected', 'false');
9322
        }
9323
        this.activeTabId = 't' + idx;
9324
        activeTabElm = this.getEl('t' + idx);
9325
        activeTabElm.setAttribute('aria-selected', 'true');
9326
        global$9(activeTabElm).addClass(this.classPrefix + 'active');
9327
        this.items()[idx].show().fire('showtab');
9328
        this.reflow();
9329
        this.items().each(function (item, i) {
9330
          if (idx !== i) {
9331
            item.hide();
9332
          }
9333
        });
9334
      },
9335 View Code Duplication
      renderHtml: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9336
        var self = this;
9337
        var layout = self._layout;
9338
        var tabsHtml = '';
9339
        var prefix = self.classPrefix;
9340
        self.preRender();
9341
        layout.preRender(self);
9342
        self.items().each(function (ctrl, i) {
9343
          var id = self._id + '-t' + i;
9344
          ctrl.aria('role', 'tabpanel');
9345
          ctrl.aria('labelledby', id);
9346
          tabsHtml += '<div id="' + id + '" class="' + prefix + 'tab" ' + 'unselectable="on" role="tab" aria-controls="' + ctrl._id + '" aria-selected="false" tabIndex="-1">' + self.encode(ctrl.settings.title) + '</div>';
9347
        });
9348
        return '<div id="' + self._id + '" class="' + self.classes + '" hidefocus="1" tabindex="-1">' + '<div id="' + self._id + '-head" class="' + prefix + 'tabs" role="tablist">' + tabsHtml + '</div>' + '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + layout.renderHtml(self) + '</div>' + '</div>';
9349
      },
9350
      postRender: function () {
9351
        var self = this;
9352
        self._super();
9353
        self.settings.activeTab = self.settings.activeTab || 0;
9354
        self.activateTab(self.settings.activeTab);
9355
        this.on('click', function (e) {
9356
          var targetParent = e.target.parentNode;
9357
          if (targetParent && targetParent.id === self._id + '-head') {
9358
            var i = targetParent.childNodes.length;
9359
            while (i--) {
9360
              if (targetParent.childNodes[i] === e.target) {
9361
                self.activateTab(i);
9362
              }
9363
            }
9364
          }
9365
        });
9366
      },
9367 View Code Duplication
      initLayoutRect: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9368
        var self = this;
9369
        var rect, minW, minH;
9370
        minW = funcs.getSize(self.getEl('head')).width;
9371
        minW = minW < 0 ? 0 : minW;
9372
        minH = 0;
9373
        self.items().each(function (item) {
9374
          minW = Math.max(minW, item.layoutRect().minW);
9375
          minH = Math.max(minH, item.layoutRect().minH);
9376
        });
9377
        self.items().each(function (ctrl) {
9378
          ctrl.settings.x = 0;
9379
          ctrl.settings.y = 0;
9380
          ctrl.settings.w = minW;
9381
          ctrl.settings.h = minH;
9382
          ctrl.layoutRect({
9383
            x: 0,
9384
            y: 0,
9385
            w: minW,
9386
            h: minH
9387
          });
9388
        });
9389
        var headH = funcs.getSize(self.getEl('head')).height;
9390
        self.settings.minWidth = minW;
9391
        self.settings.minHeight = minH + headH;
9392
        rect = self._super();
9393
        rect.deltaH += headH;
9394
        rect.innerH = rect.h - rect.deltaH;
9395
        return rect;
9396
      }
9397
    });
9398
9399
    var TextBox = Widget.extend({
9400
      init: function (settings) {
9401
        var self$$1 = this;
9402
        self$$1._super(settings);
9403
        self$$1.classes.add('textbox');
9404
        if (settings.multiline) {
9405
          self$$1.classes.add('multiline');
9406
        } else {
9407
          self$$1.on('keydown', function (e) {
9408
            var rootControl;
9409
            if (e.keyCode === 13) {
9410
              e.preventDefault();
9411
              self$$1.parents().reverse().each(function (ctrl) {
9412
                if (ctrl.toJSON) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if ctrl.toJSON is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
9413
                  rootControl = ctrl;
9414
                  return false;
9415
                }
9416
              });
9417
              self$$1.fire('submit', { data: rootControl.toJSON() });
9418
            }
9419
          });
9420
          self$$1.on('keyup', function (e) {
9421
            self$$1.state.set('value', e.target.value);
9422
          });
9423
        }
9424
      },
9425 View Code Duplication
      repaint: function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
9426
        var self$$1 = this;
9427
        var style, rect, borderBox, borderW, borderH = 0, lastRepaintRect;
9428
        style = self$$1.getEl().style;
9429
        rect = self$$1._layoutRect;
9430
        lastRepaintRect = self$$1._lastRepaintRect || {};
9431
        var doc = document;
9432
        if (!self$$1.settings.multiline && doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
9433
          style.lineHeight = rect.h - borderH + 'px';
9434
        }
9435
        borderBox = self$$1.borderBox;
9436
        borderW = borderBox.left + borderBox.right + 8;
9437
        borderH = borderBox.top + borderBox.bottom + (self$$1.settings.multiline ? 8 : 0);
9438
        if (rect.x !== lastRepaintRect.x) {
9439
          style.left = rect.x + 'px';
9440
          lastRepaintRect.x = rect.x;
9441
        }
9442
        if (rect.y !== lastRepaintRect.y) {
9443
          style.top = rect.y + 'px';
9444
          lastRepaintRect.y = rect.y;
9445
        }
9446
        if (rect.w !== lastRepaintRect.w) {
9447
          style.width = rect.w - borderW + 'px';
9448
          lastRepaintRect.w = rect.w;
9449
        }
9450
        if (rect.h !== lastRepaintRect.h) {
9451
          style.height = rect.h - borderH + 'px';
9452
          lastRepaintRect.h = rect.h;
9453
        }
9454
        self$$1._lastRepaintRect = lastRepaintRect;
9455
        self$$1.fire('repaint', {}, false);
9456
        return self$$1;
9457
      },
9458
      renderHtml: function () {
9459
        var self$$1 = this;
9460
        var settings = self$$1.settings;
9461
        var attrs, elm;
9462
        attrs = {
9463
          id: self$$1._id,
9464
          hidefocus: '1'
9465
        };
9466
        global$2.each([
9467
          'rows',
9468
          'spellcheck',
9469
          'maxLength',
9470
          'size',
9471
          'readonly',
9472
          'min',
9473
          'max',
9474
          'step',
9475
          'list',
9476
          'pattern',
9477
          'placeholder',
9478
          'required',
9479
          'multiple'
9480
        ], function (name$$1) {
9481
          attrs[name$$1] = settings[name$$1];
9482
        });
9483
        if (self$$1.disabled()) {
9484
          attrs.disabled = 'disabled';
9485
        }
9486
        if (settings.subtype) {
9487
          attrs.type = settings.subtype;
9488
        }
9489
        elm = funcs.create(settings.multiline ? 'textarea' : 'input', attrs);
9490
        elm.value = self$$1.state.get('value');
9491
        elm.className = self$$1.classes.toString();
9492
        return elm.outerHTML;
9493
      },
9494
      value: function (value) {
9495
        if (arguments.length) {
9496
          this.state.set('value', value);
9497
          return this;
9498
        }
9499
        if (this.state.get('rendered')) {
9500
          this.state.set('value', this.getEl().value);
9501
        }
9502
        return this.state.get('value');
9503
      },
9504
      postRender: function () {
9505
        var self$$1 = this;
9506
        self$$1.getEl().value = self$$1.state.get('value');
9507
        self$$1._super();
9508
        self$$1.$el.on('change', function (e) {
9509
          self$$1.state.set('value', e.target.value);
9510
          self$$1.fire('change', e);
9511
        });
9512
      },
9513
      bindStates: function () {
9514
        var self$$1 = this;
9515
        self$$1.state.on('change:value', function (e) {
9516
          if (self$$1.getEl().value !== e.value) {
9517
            self$$1.getEl().value = e.value;
9518
          }
9519
        });
9520
        self$$1.state.on('change:disabled', function (e) {
9521
          self$$1.getEl().disabled = e.value;
9522
        });
9523
        return self$$1._super();
9524
      },
9525
      remove: function () {
9526
        this.$el.off();
9527
        this._super();
9528
      }
9529
    });
9530
9531
    var getApi = function () {
9532
      return {
9533
        Selector: Selector,
9534
        Collection: Collection$2,
9535
        ReflowQueue: ReflowQueue,
9536
        Control: Control$1,
9537
        Factory: global$4,
9538
        KeyboardNavigation: KeyboardNavigation,
9539
        Container: Container,
9540
        DragHelper: DragHelper,
9541
        Scrollable: Scrollable,
9542
        Panel: Panel,
9543
        Movable: Movable,
9544
        Resizable: Resizable,
9545
        FloatPanel: FloatPanel,
9546
        Window: Window$$1,
9547
        MessageBox: MessageBox,
9548
        Tooltip: Tooltip,
9549
        Widget: Widget,
9550
        Progress: Progress,
9551
        Notification: Notification,
9552
        Layout: Layout,
9553
        AbsoluteLayout: AbsoluteLayout,
9554
        Button: Button,
9555
        ButtonGroup: ButtonGroup,
9556
        Checkbox: Checkbox,
9557
        ComboBox: ComboBox,
9558
        ColorBox: ColorBox,
9559
        PanelButton: PanelButton,
9560
        ColorButton: ColorButton,
9561
        ColorPicker: ColorPicker,
9562
        Path: Path,
9563
        ElementPath: ElementPath,
9564
        FormItem: FormItem,
9565
        Form: Form,
9566
        FieldSet: FieldSet,
9567
        FilePicker: FilePicker,
9568
        FitLayout: FitLayout,
9569
        FlexLayout: FlexLayout,
9570
        FlowLayout: FlowLayout,
9571
        FormatControls: FormatControls,
9572
        GridLayout: GridLayout,
9573
        Iframe: Iframe$1,
9574
        InfoBox: InfoBox,
9575
        Label: Label,
9576
        Toolbar: Toolbar$1,
9577
        MenuBar: MenuBar,
9578
        MenuButton: MenuButton,
9579
        MenuItem: MenuItem,
9580
        Throbber: Throbber,
9581
        Menu: Menu,
9582
        ListBox: ListBox,
9583
        Radio: Radio,
9584
        ResizeHandle: ResizeHandle,
9585
        SelectBox: SelectBox,
9586
        Slider: Slider,
9587
        Spacer: Spacer,
9588
        SplitButton: SplitButton,
9589
        StackLayout: StackLayout,
9590
        TabPanel: TabPanel,
9591
        TextBox: TextBox,
9592
        DropZone: DropZone,
9593
        BrowseButton: BrowseButton
9594
      };
9595
    };
9596
    var appendTo = function (target) {
9597
      if (target.ui) {
9598
        global$2.each(getApi(), function (ref, key) {
9599
          target.ui[key] = ref;
9600
        });
9601
      } else {
9602
        target.ui = getApi();
9603
      }
9604
    };
9605
    var registerToFactory = function () {
9606
      global$2.each(getApi(), function (ref, key) {
9607
        global$4.add(key, ref);
9608
      });
9609
    };
9610
    var Api = {
9611
      appendTo: appendTo,
9612
      registerToFactory: registerToFactory
9613
    };
9614
9615
    Api.registerToFactory();
9616
    Api.appendTo(window.tinymce ? window.tinymce : {});
9617
    global.add('modern', function (editor) {
9618
      FormatControls.setup(editor);
9619
      return ThemeApi.get(editor);
9620
    });
9621
    function Theme () {
9622
    }
9623
9624
    return Theme;
9625
9626
}());
9627
})();
9628