[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/js/tinymce/themes/modern/ -> theme.js (source)

   1  (function () {
   2  var modern = (function (domGlobals) {
   3      'use strict';
   4  
   5      var global = tinymce.util.Tools.resolve('tinymce.ThemeManager');
   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      };
 154      var constant = function (value) {
 155        return function () {
 156          return value;
 157        };
 158      };
 159      var never = constant(false);
 160      var always = constant(true);
 161  
 162      var never$1 = never;
 163      var always$1 = always;
 164      var none = function () {
 165        return NONE;
 166      };
 167      var NONE = function () {
 168        var eq = function (o) {
 169          return o.isNone();
 170        };
 171        var call = function (thunk) {
 172          return thunk();
 173        };
 174        var id = function (n) {
 175          return n;
 176        };
 177        var noop = function () {
 178        };
 179        var nul = function () {
 180          return null;
 181        };
 182        var undef = function () {
 183          return undefined;
 184        };
 185        var me = {
 186          fold: function (n, s) {
 187            return n();
 188          },
 189          is: never$1,
 190          isSome: never$1,
 191          isNone: always$1,
 192          getOr: id,
 193          getOrThunk: call,
 194          getOrDie: function (msg) {
 195            throw new Error(msg || 'error: getOrDie called on none.');
 196          },
 197          getOrNull: nul,
 198          getOrUndefined: undef,
 199          or: id,
 200          orThunk: call,
 201          map: none,
 202          ap: none,
 203          each: noop,
 204          bind: none,
 205          flatten: none,
 206          exists: never$1,
 207          forall: always$1,
 208          filter: none,
 209          equals: eq,
 210          equals_: eq,
 211          toArray: function () {
 212            return [];
 213          },
 214          toString: constant('none()')
 215        };
 216        if (Object.freeze) {
 217          Object.freeze(me);
 218        }
 219        return me;
 220      }();
 221      var some = function (a) {
 222        var constant_a = function () {
 223          return a;
 224        };
 225        var self = function () {
 226          return me;
 227        };
 228        var map = function (f) {
 229          return some(f(a));
 230        };
 231        var bind = function (f) {
 232          return f(a);
 233        };
 234        var me = {
 235          fold: function (n, s) {
 236            return s(a);
 237          },
 238          is: function (v) {
 239            return a === v;
 240          },
 241          isSome: always$1,
 242          isNone: never$1,
 243          getOr: constant_a,
 244          getOrThunk: constant_a,
 245          getOrDie: constant_a,
 246          getOrNull: constant_a,
 247          getOrUndefined: constant_a,
 248          or: self,
 249          orThunk: self,
 250          map: map,
 251          ap: function (optfab) {
 252            return optfab.fold(none, function (fab) {
 253              return some(fab(a));
 254            });
 255          },
 256          each: function (f) {
 257            f(a);
 258          },
 259          bind: bind,
 260          flatten: constant_a,
 261          exists: bind,
 262          forall: bind,
 263          filter: function (f) {
 264            return f(a) ? me : NONE;
 265          },
 266          equals: function (o) {
 267            return o.is(a);
 268          },
 269          equals_: function (o, elementEq) {
 270            return o.fold(never$1, function (b) {
 271              return elementEq(a, b);
 272            });
 273          },
 274          toArray: function () {
 275            return [a];
 276          },
 277          toString: function () {
 278            return 'some(' + a + ')';
 279          }
 280        };
 281        return me;
 282      };
 283      var from = function (value) {
 284        return value === null || value === undefined ? NONE : some(value);
 285      };
 286      var Option = {
 287        some: some,
 288        none: none,
 289        from: from
 290      };
 291  
 292      var getUiContainerDelta = function (ctrl) {
 293        var uiContainer = getUiContainer(ctrl);
 294        if (uiContainer && global$3.DOM.getStyle(uiContainer, 'position', true) !== 'static') {
 295          var containerPos = global$3.DOM.getPos(uiContainer);
 296          var dx = uiContainer.scrollLeft - containerPos.x;
 297          var dy = uiContainer.scrollTop - containerPos.y;
 298          return Option.some({
 299            x: dx,
 300            y: dy
 301          });
 302        } else {
 303          return Option.none();
 304        }
 305      };
 306      var setUiContainer = function (editor, ctrl) {
 307        var uiContainer = global$3.DOM.select(editor.settings.ui_container)[0];
 308        ctrl.getRoot().uiContainer = uiContainer;
 309      };
 310      var getUiContainer = function (ctrl) {
 311        return ctrl ? ctrl.getRoot().uiContainer : null;
 312      };
 313      var inheritUiContainer = function (fromCtrl, toCtrl) {
 314        return toCtrl.uiContainer = getUiContainer(fromCtrl);
 315      };
 316      var UiContainer = {
 317        getUiContainerDelta: getUiContainerDelta,
 318        setUiContainer: setUiContainer,
 319        getUiContainer: getUiContainer,
 320        inheritUiContainer: inheritUiContainer
 321      };
 322  
 323      var createToolbar = function (editor, items, size) {
 324        var toolbarItems = [];
 325        var buttonGroup;
 326        if (!items) {
 327          return;
 328        }
 329        global$2.each(items.split(/[ ,]/), function (item) {
 330          var itemName;
 331          var bindSelectorChanged = function () {
 332            var selection = editor.selection;
 333            if (item.settings.stateSelector) {
 334              selection.selectorChanged(item.settings.stateSelector, function (state) {
 335                item.active(state);
 336              }, true);
 337            }
 338            if (item.settings.disabledStateSelector) {
 339              selection.selectorChanged(item.settings.disabledStateSelector, function (state) {
 340                item.disabled(state);
 341              });
 342            }
 343          };
 344          if (item === '|') {
 345            buttonGroup = null;
 346          } else {
 347            if (!buttonGroup) {
 348              buttonGroup = {
 349                type: 'buttongroup',
 350                items: []
 351              };
 352              toolbarItems.push(buttonGroup);
 353            }
 354            if (editor.buttons[item]) {
 355              itemName = item;
 356              item = editor.buttons[itemName];
 357              if (typeof item === 'function') {
 358                item = item();
 359              }
 360              item.type = item.type || 'button';
 361              item.size = size;
 362              item = global$4.create(item);
 363              buttonGroup.items.push(item);
 364              if (editor.initialized) {
 365                bindSelectorChanged();
 366              } else {
 367                editor.on('init', bindSelectorChanged);
 368              }
 369            }
 370          }
 371        });
 372        return {
 373          type: 'toolbar',
 374          layout: 'flow',
 375          items: toolbarItems
 376        };
 377      };
 378      var createToolbars = function (editor, size) {
 379        var toolbars = [];
 380        var addToolbar = function (items) {
 381          if (items) {
 382            toolbars.push(createToolbar(editor, items, size));
 383          }
 384        };
 385        global$2.each(getToolbars(editor), function (toolbar) {
 386          addToolbar(toolbar);
 387        });
 388        if (toolbars.length) {
 389          return {
 390            type: 'panel',
 391            layout: 'stack',
 392            classes: 'toolbar-grp',
 393            ariaRoot: true,
 394            ariaRemember: true,
 395            items: toolbars
 396          };
 397        }
 398      };
 399      var Toolbar = {
 400        createToolbar: createToolbar,
 401        createToolbars: createToolbars
 402      };
 403  
 404      var DOM = global$3.DOM;
 405      var toClientRect = function (geomRect) {
 406        return {
 407          left: geomRect.x,
 408          top: geomRect.y,
 409          width: geomRect.w,
 410          height: geomRect.h,
 411          right: geomRect.x + geomRect.w,
 412          bottom: geomRect.y + geomRect.h
 413        };
 414      };
 415      var hideAllFloatingPanels = function (editor) {
 416        global$2.each(editor.contextToolbars, function (toolbar) {
 417          if (toolbar.panel) {
 418            toolbar.panel.hide();
 419          }
 420        });
 421      };
 422      var movePanelTo = function (panel, pos) {
 423        panel.moveTo(pos.left, pos.top);
 424      };
 425      var togglePositionClass = function (panel, relPos, predicate) {
 426        relPos = relPos ? relPos.substr(0, 2) : '';
 427        global$2.each({
 428          t: 'down',
 429          b: 'up'
 430        }, function (cls, pos) {
 431          panel.classes.toggle('arrow-' + cls, predicate(pos, relPos.substr(0, 1)));
 432        });
 433        global$2.each({
 434          l: 'left',
 435          r: 'right'
 436        }, function (cls, pos) {
 437          panel.classes.toggle('arrow-' + cls, predicate(pos, relPos.substr(1, 1)));
 438        });
 439      };
 440      var userConstrain = function (handler, x, y, elementRect, contentAreaRect, panelRect) {
 441        panelRect = toClientRect({
 442          x: x,
 443          y: y,
 444          w: panelRect.w,
 445          h: panelRect.h
 446        });
 447        if (handler) {
 448          panelRect = handler({
 449            elementRect: toClientRect(elementRect),
 450            contentAreaRect: toClientRect(contentAreaRect),
 451            panelRect: panelRect
 452          });
 453        }
 454        return panelRect;
 455      };
 456      var addContextualToolbars = function (editor) {
 457        var scrollContainer;
 458        var getContextToolbars = function () {
 459          return editor.contextToolbars || [];
 460        };
 461        var getElementRect = function (elm) {
 462          var pos, targetRect, root;
 463          pos = DOM.getPos(editor.getContentAreaContainer());
 464          targetRect = editor.dom.getRect(elm);
 465          root = editor.dom.getRoot();
 466          if (root.nodeName === 'BODY') {
 467            targetRect.x -= root.ownerDocument.documentElement.scrollLeft || root.scrollLeft;
 468            targetRect.y -= root.ownerDocument.documentElement.scrollTop || root.scrollTop;
 469          }
 470          targetRect.x += pos.x;
 471          targetRect.y += pos.y;
 472          return targetRect;
 473        };
 474        var reposition = function (match, shouldShow) {
 475          var relPos, panelRect, elementRect, contentAreaRect, panel, relRect, testPositions, smallElementWidthThreshold;
 476          var handler = getInlineToolbarPositionHandler(editor);
 477          if (editor.removed) {
 478            return;
 479          }
 480          if (!match || !match.toolbar.panel) {
 481            hideAllFloatingPanels(editor);
 482            return;
 483          }
 484          testPositions = [
 485            'bc-tc',
 486            'tc-bc',
 487            'tl-bl',
 488            'bl-tl',
 489            'tr-br',
 490            'br-tr'
 491          ];
 492          panel = match.toolbar.panel;
 493          if (shouldShow) {
 494            panel.show();
 495          }
 496          elementRect = getElementRect(match.element);
 497          panelRect = DOM.getRect(panel.getEl());
 498          contentAreaRect = DOM.getRect(editor.getContentAreaContainer() || editor.getBody());
 499          var delta = UiContainer.getUiContainerDelta(panel).getOr({
 500            x: 0,
 501            y: 0
 502          });
 503          elementRect.x += delta.x;
 504          elementRect.y += delta.y;
 505          panelRect.x += delta.x;
 506          panelRect.y += delta.y;
 507          contentAreaRect.x += delta.x;
 508          contentAreaRect.y += delta.y;
 509          smallElementWidthThreshold = 25;
 510          if (DOM.getStyle(match.element, 'display', true) !== 'inline') {
 511            var clientRect = match.element.getBoundingClientRect();
 512            elementRect.w = clientRect.width;
 513            elementRect.h = clientRect.height;
 514          }
 515          if (!editor.inline) {
 516            contentAreaRect.w = editor.getDoc().documentElement.offsetWidth;
 517          }
 518          if (editor.selection.controlSelection.isResizable(match.element) && elementRect.w < smallElementWidthThreshold) {
 519            elementRect = global$6.inflate(elementRect, 0, 8);
 520          }
 521          relPos = global$6.findBestRelativePosition(panelRect, elementRect, contentAreaRect, testPositions);
 522          elementRect = global$6.clamp(elementRect, contentAreaRect);
 523          if (relPos) {
 524            relRect = global$6.relativePosition(panelRect, elementRect, relPos);
 525            movePanelTo(panel, userConstrain(handler, relRect.x, relRect.y, elementRect, contentAreaRect, panelRect));
 526          } else {
 527            contentAreaRect.h += panelRect.h;
 528            elementRect = global$6.intersect(contentAreaRect, elementRect);
 529            if (elementRect) {
 530              relPos = global$6.findBestRelativePosition(panelRect, elementRect, contentAreaRect, [
 531                'bc-tc',
 532                'bl-tl',
 533                'br-tr'
 534              ]);
 535              if (relPos) {
 536                relRect = global$6.relativePosition(panelRect, elementRect, relPos);
 537                movePanelTo(panel, userConstrain(handler, relRect.x, relRect.y, elementRect, contentAreaRect, panelRect));
 538              } else {
 539                movePanelTo(panel, userConstrain(handler, elementRect.x, elementRect.y, elementRect, contentAreaRect, panelRect));
 540              }
 541            } else {
 542              panel.hide();
 543            }
 544          }
 545          togglePositionClass(panel, relPos, function (pos1, pos2) {
 546            return pos1 === pos2;
 547          });
 548        };
 549        var repositionHandler = function (show) {
 550          return function () {
 551            var execute = function () {
 552              if (editor.selection) {
 553                reposition(findFrontMostMatch(editor.selection.getNode()), show);
 554              }
 555            };
 556            global$7.requestAnimationFrame(execute);
 557          };
 558        };
 559        var bindScrollEvent = function (panel) {
 560          if (!scrollContainer) {
 561            var reposition_1 = repositionHandler(true);
 562            var uiContainer_1 = UiContainer.getUiContainer(panel);
 563            scrollContainer = editor.selection.getScrollContainer() || editor.getWin();
 564            DOM.bind(scrollContainer, 'scroll', reposition_1);
 565            DOM.bind(uiContainer_1, 'scroll', reposition_1);
 566            editor.on('remove', function () {
 567              DOM.unbind(scrollContainer, 'scroll', reposition_1);
 568              DOM.unbind(uiContainer_1, 'scroll', reposition_1);
 569            });
 570          }
 571        };
 572        var showContextToolbar = function (match) {
 573          var panel;
 574          if (match.toolbar.panel) {
 575            match.toolbar.panel.show();
 576            reposition(match);
 577            return;
 578          }
 579          panel = global$4.create({
 580            type: 'floatpanel',
 581            role: 'dialog',
 582            classes: 'tinymce tinymce-inline arrow',
 583            ariaLabel: 'Inline toolbar',
 584            layout: 'flex',
 585            direction: 'column',
 586            align: 'stretch',
 587            autohide: false,
 588            autofix: true,
 589            fixed: true,
 590            border: 1,
 591            items: Toolbar.createToolbar(editor, match.toolbar.items),
 592            oncancel: function () {
 593              editor.focus();
 594            }
 595          });
 596          UiContainer.setUiContainer(editor, panel);
 597          bindScrollEvent(panel);
 598          match.toolbar.panel = panel;
 599          panel.renderTo().reflow();
 600          reposition(match);
 601        };
 602        var hideAllContextToolbars = function () {
 603          global$2.each(getContextToolbars(), function (toolbar) {
 604            if (toolbar.panel) {
 605              toolbar.panel.hide();
 606            }
 607          });
 608        };
 609        var findFrontMostMatch = function (targetElm) {
 610          var i, y, parentsAndSelf;
 611          var toolbars = getContextToolbars();
 612          parentsAndSelf = editor.$(targetElm).parents().add(targetElm);
 613          for (i = parentsAndSelf.length - 1; i >= 0; i--) {
 614            for (y = toolbars.length - 1; y >= 0; y--) {
 615              if (toolbars[y].predicate(parentsAndSelf[i])) {
 616                return {
 617                  toolbar: toolbars[y],
 618                  element: parentsAndSelf[i]
 619                };
 620              }
 621            }
 622          }
 623          return null;
 624        };
 625        editor.on('click keyup setContent ObjectResized', function (e) {
 626          if (e.type === 'setcontent' && !e.selection) {
 627            return;
 628          }
 629          global$7.setEditorTimeout(editor, function () {
 630            var match;
 631            match = findFrontMostMatch(editor.selection.getNode());
 632            if (match) {
 633              hideAllContextToolbars();
 634              showContextToolbar(match);
 635            } else {
 636              hideAllContextToolbars();
 637            }
 638          });
 639        });
 640        editor.on('blur hide contextmenu', hideAllContextToolbars);
 641        editor.on('ObjectResizeStart', function () {
 642          var match = findFrontMostMatch(editor.selection.getNode());
 643          if (match && match.toolbar.panel) {
 644            match.toolbar.panel.hide();
 645          }
 646        });
 647        editor.on('ResizeEditor ResizeWindow', repositionHandler(true));
 648        editor.on('nodeChange', repositionHandler(false));
 649        editor.on('remove', function () {
 650          global$2.each(getContextToolbars(), function (toolbar) {
 651            if (toolbar.panel) {
 652              toolbar.panel.remove();
 653            }
 654          });
 655          editor.contextToolbars = {};
 656        });
 657        editor.shortcuts.add('ctrl+F9', '', function () {
 658          var match = findFrontMostMatch(editor.selection.getNode());
 659          if (match && match.toolbar.panel) {
 660            match.toolbar.panel.items()[0].focus();
 661          }
 662        });
 663      };
 664      var ContextToolbars = { addContextualToolbars: addContextualToolbars };
 665  
 666      var typeOf = function (x) {
 667        if (x === null) {
 668          return 'null';
 669        }
 670        var t = typeof x;
 671        if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
 672          return 'array';
 673        }
 674        if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
 675          return 'string';
 676        }
 677        return t;
 678      };
 679      var isType = function (type) {
 680        return function (value) {
 681          return typeOf(value) === type;
 682        };
 683      };
 684      var isArray = isType('array');
 685      var isFunction = isType('function');
 686      var isNumber = isType('number');
 687  
 688      var slice = Array.prototype.slice;
 689      var rawIndexOf = function () {
 690        var pIndexOf = Array.prototype.indexOf;
 691        var fastIndex = function (xs, x) {
 692          return pIndexOf.call(xs, x);
 693        };
 694        var slowIndex = function (xs, x) {
 695          return slowIndexOf(xs, x);
 696        };
 697        return pIndexOf === undefined ? slowIndex : fastIndex;
 698      }();
 699      var indexOf = function (xs, x) {
 700        var r = rawIndexOf(xs, x);
 701        return r === -1 ? Option.none() : Option.some(r);
 702      };
 703      var exists = function (xs, pred) {
 704        return findIndex(xs, pred).isSome();
 705      };
 706      var map = function (xs, f) {
 707        var len = xs.length;
 708        var r = new Array(len);
 709        for (var i = 0; i < len; i++) {
 710          var x = xs[i];
 711          r[i] = f(x, i, xs);
 712        }
 713        return r;
 714      };
 715      var each = function (xs, f) {
 716        for (var i = 0, len = xs.length; i < len; i++) {
 717          var x = xs[i];
 718          f(x, i, xs);
 719        }
 720      };
 721      var filter = function (xs, pred) {
 722        var r = [];
 723        for (var i = 0, len = xs.length; i < len; i++) {
 724          var x = xs[i];
 725          if (pred(x, i, xs)) {
 726            r.push(x);
 727          }
 728        }
 729        return r;
 730      };
 731      var foldl = function (xs, f, acc) {
 732        each(xs, function (x) {
 733          acc = f(acc, x);
 734        });
 735        return acc;
 736      };
 737      var find = function (xs, pred) {
 738        for (var i = 0, len = xs.length; i < len; i++) {
 739          var x = xs[i];
 740          if (pred(x, i, xs)) {
 741            return Option.some(x);
 742          }
 743        }
 744        return Option.none();
 745      };
 746      var findIndex = function (xs, pred) {
 747        for (var i = 0, len = xs.length; i < len; i++) {
 748          var x = xs[i];
 749          if (pred(x, i, xs)) {
 750            return Option.some(i);
 751          }
 752        }
 753        return Option.none();
 754      };
 755      var slowIndexOf = function (xs, x) {
 756        for (var i = 0, len = xs.length; i < len; ++i) {
 757          if (xs[i] === x) {
 758            return i;
 759          }
 760        }
 761        return -1;
 762      };
 763      var push = Array.prototype.push;
 764      var flatten = function (xs) {
 765        var r = [];
 766        for (var i = 0, len = xs.length; i < len; ++i) {
 767          if (!isArray(xs[i])) {
 768            throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
 769          }
 770          push.apply(r, xs[i]);
 771        }
 772        return r;
 773      };
 774      var from$1 = isFunction(Array.from) ? Array.from : function (x) {
 775        return slice.call(x);
 776      };
 777  
 778      var defaultMenus = {
 779        file: {
 780          title: 'File',
 781          items: 'newdocument restoredraft | preview | print'
 782        },
 783        edit: {
 784          title: 'Edit',
 785          items: 'undo redo | cut copy paste pastetext | selectall'
 786        },
 787        view: {
 788          title: 'View',
 789          items: 'code | visualaid visualchars visualblocks | spellchecker | preview fullscreen'
 790        },
 791        insert: {
 792          title: 'Insert',
 793          items: 'image link media template codesample inserttable | charmap hr | pagebreak nonbreaking anchor toc | insertdatetime'
 794        },
 795        format: {
 796          title: 'Format',
 797          items: 'bold italic underline strikethrough superscript subscript codeformat | blockformats align | removeformat'
 798        },
 799        tools: {
 800          title: 'Tools',
 801          items: 'spellchecker spellcheckerlanguage | a11ycheck code'
 802        },
 803        table: { title: 'Table' },
 804        help: { title: 'Help' }
 805      };
 806      var delimiterMenuNamePair = function () {
 807        return {
 808          name: '|',
 809          item: { text: '|' }
 810        };
 811      };
 812      var createMenuNameItemPair = function (name, item) {
 813        var menuItem = item ? {
 814          name: name,
 815          item: item
 816        } : null;
 817        return name === '|' ? delimiterMenuNamePair() : menuItem;
 818      };
 819      var hasItemName = function (namedMenuItems, name) {
 820        return findIndex(namedMenuItems, function (namedMenuItem) {
 821          return namedMenuItem.name === name;
 822        }).isSome();
 823      };
 824      var isSeparator = function (namedMenuItem) {
 825        return namedMenuItem && namedMenuItem.item.text === '|';
 826      };
 827      var cleanupMenu = function (namedMenuItems, removedMenuItems) {
 828        var menuItemsPass1 = filter(namedMenuItems, function (namedMenuItem) {
 829          return removedMenuItems.hasOwnProperty(namedMenuItem.name) === false;
 830        });
 831        var menuItemsPass2 = filter(menuItemsPass1, function (namedMenuItem, i, namedMenuItems) {
 832          return !isSeparator(namedMenuItem) || !isSeparator(namedMenuItems[i - 1]);
 833        });
 834        return filter(menuItemsPass2, function (namedMenuItem, i, namedMenuItems) {
 835          return !isSeparator(namedMenuItem) || i > 0 && i < namedMenuItems.length - 1;
 836        });
 837      };
 838      var createMenu = function (editorMenuItems, menus, removedMenuItems, context) {
 839        var menuButton, menu, namedMenuItems, isUserDefined;
 840        if (menus) {
 841          menu = menus[context];
 842          isUserDefined = true;
 843        } else {
 844          menu = defaultMenus[context];
 845        }
 846        if (menu) {
 847          menuButton = { text: menu.title };
 848          namedMenuItems = [];
 849          global$2.each((menu.items || '').split(/[ ,]/), function (name) {
 850            var namedMenuItem = createMenuNameItemPair(name, editorMenuItems[name]);
 851            if (namedMenuItem) {
 852              namedMenuItems.push(namedMenuItem);
 853            }
 854          });
 855          if (!isUserDefined) {
 856            global$2.each(editorMenuItems, function (item, name) {
 857              if (item.context === context && !hasItemName(namedMenuItems, name)) {
 858                if (item.separator === 'before') {
 859                  namedMenuItems.push(delimiterMenuNamePair());
 860                }
 861                if (item.prependToContext) {
 862                  namedMenuItems.unshift(createMenuNameItemPair(name, item));
 863                } else {
 864                  namedMenuItems.push(createMenuNameItemPair(name, item));
 865                }
 866                if (item.separator === 'after') {
 867                  namedMenuItems.push(delimiterMenuNamePair());
 868                }
 869              }
 870            });
 871          }
 872          menuButton.menu = map(cleanupMenu(namedMenuItems, removedMenuItems), function (menuItem) {
 873            return menuItem.item;
 874          });
 875          if (!menuButton.menu.length) {
 876            return null;
 877          }
 878        }
 879        return menuButton;
 880      };
 881      var getDefaultMenubar = function (editor) {
 882        var name;
 883        var defaultMenuBar = [];
 884        var menu = getMenu(editor);
 885        if (menu) {
 886          for (name in menu) {
 887            defaultMenuBar.push(name);
 888          }
 889        } else {
 890          for (name in defaultMenus) {
 891            defaultMenuBar.push(name);
 892          }
 893        }
 894        return defaultMenuBar;
 895      };
 896      var createMenuButtons = function (editor) {
 897        var menuButtons = [];
 898        var defaultMenuBar = getDefaultMenubar(editor);
 899        var removedMenuItems = global$2.makeMap(getRemovedMenuItems(editor).split(/[ ,]/));
 900        var menubar = getMenubar(editor);
 901        var enabledMenuNames = typeof menubar === 'string' ? menubar.split(/[ ,]/) : defaultMenuBar;
 902        for (var i = 0; i < enabledMenuNames.length; i++) {
 903          var menuItems = enabledMenuNames[i];
 904          var menu = createMenu(editor.menuItems, getMenu(editor), removedMenuItems, menuItems);
 905          if (menu) {
 906            menuButtons.push(menu);
 907          }
 908        }
 909        return menuButtons;
 910      };
 911      var Menubar = { createMenuButtons: createMenuButtons };
 912  
 913      var DOM$1 = global$3.DOM;
 914      var getSize = function (elm) {
 915        return {
 916          width: elm.clientWidth,
 917          height: elm.clientHeight
 918        };
 919      };
 920      var resizeTo = function (editor, width, height) {
 921        var containerElm, iframeElm, containerSize, iframeSize;
 922        containerElm = editor.getContainer();
 923        iframeElm = editor.getContentAreaContainer().firstChild;
 924        containerSize = getSize(containerElm);
 925        iframeSize = getSize(iframeElm);
 926        if (width !== null) {
 927          width = Math.max(getMinWidth(editor), width);
 928          width = Math.min(getMaxWidth(editor), width);
 929          DOM$1.setStyle(containerElm, 'width', width + (containerSize.width - iframeSize.width));
 930          DOM$1.setStyle(iframeElm, 'width', width);
 931        }
 932        height = Math.max(getMinHeight(editor), height);
 933        height = Math.min(getMaxHeight(editor), height);
 934        DOM$1.setStyle(iframeElm, 'height', height);
 935        Events.fireResizeEditor(editor);
 936      };
 937      var resizeBy = function (editor, dw, dh) {
 938        var elm = editor.getContentAreaContainer();
 939        resizeTo(editor, elm.clientWidth + dw, elm.clientHeight + dh);
 940      };
 941      var Resize = {
 942        resizeTo: resizeTo,
 943        resizeBy: resizeBy
 944      };
 945  
 946      var global$8 = tinymce.util.Tools.resolve('tinymce.Env');
 947  
 948      var api = function (elm) {
 949        return {
 950          element: function () {
 951            return elm;
 952          }
 953        };
 954      };
 955      var trigger = function (sidebar, panel, callbackName) {
 956        var callback = sidebar.settings[callbackName];
 957        if (callback) {
 958          callback(api(panel.getEl('body')));
 959        }
 960      };
 961      var hidePanels = function (name, container, sidebars) {
 962        global$2.each(sidebars, function (sidebar) {
 963          var panel = container.items().filter('#' + sidebar.name)[0];
 964          if (panel && panel.visible() && sidebar.name !== name) {
 965            trigger(sidebar, panel, 'onhide');
 966            panel.visible(false);
 967          }
 968        });
 969      };
 970      var deactivateButtons = function (toolbar) {
 971        toolbar.items().each(function (ctrl) {
 972          ctrl.active(false);
 973        });
 974      };
 975      var findSidebar = function (sidebars, name) {
 976        return global$2.grep(sidebars, function (sidebar) {
 977          return sidebar.name === name;
 978        })[0];
 979      };
 980      var showPanel = function (editor, name, sidebars) {
 981        return function (e) {
 982          var btnCtrl = e.control;
 983          var container = btnCtrl.parents().filter('panel')[0];
 984          var panel = container.find('#' + name)[0];
 985          var sidebar = findSidebar(sidebars, name);
 986          hidePanels(name, container, sidebars);
 987          deactivateButtons(btnCtrl.parent());
 988          if (panel && panel.visible()) {
 989            trigger(sidebar, panel, 'onhide');
 990            panel.hide();
 991            btnCtrl.active(false);
 992          } else {
 993            if (panel) {
 994              panel.show();
 995              trigger(sidebar, panel, 'onshow');
 996            } else {
 997              panel = global$4.create({
 998                type: 'container',
 999                name: name,
1000                layout: 'stack',
1001                classes: 'sidebar-panel',
1002                html: ''
1003              });
1004              container.prepend(panel);
1005              trigger(sidebar, panel, 'onrender');
1006              trigger(sidebar, panel, 'onshow');
1007            }
1008            btnCtrl.active(true);
1009          }
1010          Events.fireResizeEditor(editor);
1011        };
1012      };
1013      var isModernBrowser = function () {
1014        return !global$8.ie || global$8.ie >= 11;
1015      };
1016      var hasSidebar = function (editor) {
1017        return isModernBrowser() && editor.sidebars ? editor.sidebars.length > 0 : false;
1018      };
1019      var createSidebar = function (editor) {
1020        var buttons = global$2.map(editor.sidebars, function (sidebar) {
1021          var settings = sidebar.settings;
1022          return {
1023            type: 'button',
1024            icon: settings.icon,
1025            image: settings.image,
1026            tooltip: settings.tooltip,
1027            onclick: showPanel(editor, sidebar.name, editor.sidebars)
1028          };
1029        });
1030        return {
1031          type: 'panel',
1032          name: 'sidebar',
1033          layout: 'stack',
1034          classes: 'sidebar',
1035          items: [{
1036              type: 'toolbar',
1037              layout: 'stack',
1038              classes: 'sidebar-toolbar',
1039              items: buttons
1040            }]
1041        };
1042      };
1043      var Sidebar = {
1044        hasSidebar: hasSidebar,
1045        createSidebar: createSidebar
1046      };
1047  
1048      var fireSkinLoaded$1 = function (editor) {
1049        var done = function () {
1050          editor._skinLoaded = true;
1051          Events.fireSkinLoaded(editor);
1052        };
1053        return function () {
1054          if (editor.initialized) {
1055            done();
1056          } else {
1057            editor.on('init', done);
1058          }
1059        };
1060      };
1061      var SkinLoaded = { fireSkinLoaded: fireSkinLoaded$1 };
1062  
1063      var DOM$2 = global$3.DOM;
1064      var switchMode = function (panel) {
1065        return function (e) {
1066          panel.find('*').disabled(e.mode === 'readonly');
1067        };
1068      };
1069      var editArea = function (border) {
1070        return {
1071          type: 'panel',
1072          name: 'iframe',
1073          layout: 'stack',
1074          classes: 'edit-area',
1075          border: border,
1076          html: ''
1077        };
1078      };
1079      var editAreaContainer = function (editor) {
1080        return {
1081          type: 'panel',
1082          layout: 'stack',
1083          classes: 'edit-aria-container',
1084          border: '1 0 0 0',
1085          items: [
1086            editArea('0'),
1087            Sidebar.createSidebar(editor)
1088          ]
1089        };
1090      };
1091      var render = function (editor, theme, args) {
1092        var panel, resizeHandleCtrl, startSize;
1093        if (isSkinDisabled(editor) === false && args.skinUiCss) {
1094          DOM$2.styleSheetLoader.load(args.skinUiCss, SkinLoaded.fireSkinLoaded(editor));
1095        } else {
1096          SkinLoaded.fireSkinLoaded(editor)();
1097        }
1098        panel = theme.panel = global$4.create({
1099          type: 'panel',
1100          role: 'application',
1101          classes: 'tinymce',
1102          style: 'visibility: hidden',
1103          layout: 'stack',
1104          border: 1,
1105          items: [
1106            {
1107              type: 'container',
1108              classes: 'top-part',
1109              items: [
1110                hasMenubar(editor) === false ? null : {
1111                  type: 'menubar',
1112                  border: '0 0 1 0',
1113                  items: Menubar.createMenuButtons(editor)
1114                },
1115                Toolbar.createToolbars(editor, getToolbarSize(editor))
1116              ]
1117            },
1118            Sidebar.hasSidebar(editor) ? editAreaContainer(editor) : editArea('1 0 0 0')
1119          ]
1120        });
1121        UiContainer.setUiContainer(editor, panel);
1122        if (getResize(editor) !== 'none') {
1123          resizeHandleCtrl = {
1124            type: 'resizehandle',
1125            direction: getResize(editor),
1126            onResizeStart: function () {
1127              var elm = editor.getContentAreaContainer().firstChild;
1128              startSize = {
1129                width: elm.clientWidth,
1130                height: elm.clientHeight
1131              };
1132            },
1133            onResize: function (e) {
1134              if (getResize(editor) === 'both') {
1135                Resize.resizeTo(editor, startSize.width + e.deltaX, startSize.height + e.deltaY);
1136              } else {
1137                Resize.resizeTo(editor, null, startSize.height + e.deltaY);
1138              }
1139            }
1140          };
1141        }
1142        if (hasStatusbar(editor)) {
1143          var linkHtml = '<a href="https://www.tiny.cloud/?utm_campaign=editor_referral&amp;utm_medium=poweredby&amp;utm_source=tinymce" rel="noopener" target="_blank" role="presentation" tabindex="-1">Tiny</a>';
1144          var html = global$5.translate([
1145            'Powered by {0}',
1146            linkHtml
1147          ]);
1148          var brandingLabel = isBrandingEnabled(editor) ? {
1149            type: 'label',
1150            classes: 'branding',
1151            html: ' ' + html
1152          } : null;
1153          panel.add({
1154            type: 'panel',
1155            name: 'statusbar',
1156            classes: 'statusbar',
1157            layout: 'flow',
1158            border: '1 0 0 0',
1159            ariaRoot: true,
1160            items: [
1161              {
1162                type: 'elementpath',
1163                editor: editor
1164              },
1165              resizeHandleCtrl,
1166              brandingLabel
1167            ]
1168          });
1169        }
1170        Events.fireBeforeRenderUI(editor);
1171        editor.on('SwitchMode', switchMode(panel));
1172        panel.renderBefore(args.targetNode).reflow();
1173        if (isReadOnly(editor)) {
1174          editor.setMode('readonly');
1175        }
1176        if (args.width) {
1177          DOM$2.setStyle(panel.getEl(), 'width', args.width);
1178        }
1179        editor.on('remove', function () {
1180          panel.remove();
1181          panel = null;
1182        });
1183        A11y.addKeys(editor, panel);
1184        ContextToolbars.addContextualToolbars(editor);
1185        return {
1186          iframeContainer: panel.find('#iframe')[0].getEl(),
1187          editorContainer: panel.getEl()
1188        };
1189      };
1190      var Iframe = { render: render };
1191  
1192      var global$9 = tinymce.util.Tools.resolve('tinymce.dom.DomQuery');
1193  
1194      var count = 0;
1195      var funcs = {
1196        id: function () {
1197          return 'mceu_' + count++;
1198        },
1199        create: function (name, attrs, children) {
1200          var elm = domGlobals.document.createElement(name);
1201          global$3.DOM.setAttribs(elm, attrs);
1202          if (typeof children === 'string') {
1203            elm.innerHTML = children;
1204          } else {
1205            global$2.each(children, function (child) {
1206              if (child.nodeType) {
1207                elm.appendChild(child);
1208              }
1209            });
1210          }
1211          return elm;
1212        },
1213        createFragment: function (html) {
1214          return global$3.DOM.createFragment(html);
1215        },
1216        getWindowSize: function () {
1217          return global$3.DOM.getViewPort();
1218        },
1219        getSize: function (elm) {
1220          var width, height;
1221          if (elm.getBoundingClientRect) {
1222            var rect = elm.getBoundingClientRect();
1223            width = Math.max(rect.width || rect.right - rect.left, elm.offsetWidth);
1224            height = Math.max(rect.height || rect.bottom - rect.bottom, elm.offsetHeight);
1225          } else {
1226            width = elm.offsetWidth;
1227            height = elm.offsetHeight;
1228          }
1229          return {
1230            width: width,
1231            height: height
1232          };
1233        },
1234        getPos: function (elm, root) {
1235          return global$3.DOM.getPos(elm, root || funcs.getContainer());
1236        },
1237        getContainer: function () {
1238          return global$8.container ? global$8.container : domGlobals.document.body;
1239        },
1240        getViewPort: function (win) {
1241          return global$3.DOM.getViewPort(win);
1242        },
1243        get: function (id) {
1244          return domGlobals.document.getElementById(id);
1245        },
1246        addClass: function (elm, cls) {
1247          return global$3.DOM.addClass(elm, cls);
1248        },
1249        removeClass: function (elm, cls) {
1250          return global$3.DOM.removeClass(elm, cls);
1251        },
1252        hasClass: function (elm, cls) {
1253          return global$3.DOM.hasClass(elm, cls);
1254        },
1255        toggleClass: function (elm, cls, state) {
1256          return global$3.DOM.toggleClass(elm, cls, state);
1257        },
1258        css: function (elm, name, value) {
1259          return global$3.DOM.setStyle(elm, name, value);
1260        },
1261        getRuntimeStyle: function (elm, name) {
1262          return global$3.DOM.getStyle(elm, name, true);
1263        },
1264        on: function (target, name, callback, scope) {
1265          return global$3.DOM.bind(target, name, callback, scope);
1266        },
1267        off: function (target, name, callback) {
1268          return global$3.DOM.unbind(target, name, callback);
1269        },
1270        fire: function (target, name, args) {
1271          return global$3.DOM.fire(target, name, args);
1272        },
1273        innerHtml: function (elm, html) {
1274          global$3.DOM.setHTML(elm, html);
1275        }
1276      };
1277  
1278      var isStatic = function (elm) {
1279        return funcs.getRuntimeStyle(elm, 'position') === 'static';
1280      };
1281      var isFixed = function (ctrl) {
1282        return ctrl.state.get('fixed');
1283      };
1284      function calculateRelativePosition(ctrl, targetElm, rel) {
1285        var ctrlElm, pos, x, y, selfW, selfH, targetW, targetH, viewport, size;
1286        viewport = getWindowViewPort();
1287        pos = funcs.getPos(targetElm, UiContainer.getUiContainer(ctrl));
1288        x = pos.x;
1289        y = pos.y;
1290        if (isFixed(ctrl) && isStatic(domGlobals.document.body)) {
1291          x -= viewport.x;
1292          y -= viewport.y;
1293        }
1294        ctrlElm = ctrl.getEl();
1295        size = funcs.getSize(ctrlElm);
1296        selfW = size.width;
1297        selfH = size.height;
1298        size = funcs.getSize(targetElm);
1299        targetW = size.width;
1300        targetH = size.height;
1301        rel = (rel || '').split('');
1302        if (rel[0] === 'b') {
1303          y += targetH;
1304        }
1305        if (rel[1] === 'r') {
1306          x += targetW;
1307        }
1308        if (rel[0] === 'c') {
1309          y += Math.round(targetH / 2);
1310        }
1311        if (rel[1] === 'c') {
1312          x += Math.round(targetW / 2);
1313        }
1314        if (rel[3] === 'b') {
1315          y -= selfH;
1316        }
1317        if (rel[4] === 'r') {
1318          x -= selfW;
1319        }
1320        if (rel[3] === 'c') {
1321          y -= Math.round(selfH / 2);
1322        }
1323        if (rel[4] === 'c') {
1324          x -= Math.round(selfW / 2);
1325        }
1326        return {
1327          x: x,
1328          y: y,
1329          w: selfW,
1330          h: selfH
1331        };
1332      }
1333      var getUiContainerViewPort = function (customUiContainer) {
1334        return {
1335          x: 0,
1336          y: 0,
1337          w: customUiContainer.scrollWidth - 1,
1338          h: customUiContainer.scrollHeight - 1
1339        };
1340      };
1341      var getWindowViewPort = function () {
1342        var win = domGlobals.window;
1343        var x = Math.max(win.pageXOffset, domGlobals.document.body.scrollLeft, domGlobals.document.documentElement.scrollLeft);
1344        var y = Math.max(win.pageYOffset, domGlobals.document.body.scrollTop, domGlobals.document.documentElement.scrollTop);
1345        var w = win.innerWidth || domGlobals.document.documentElement.clientWidth;
1346        var h = win.innerHeight || domGlobals.document.documentElement.clientHeight;
1347        return {
1348          x: x,
1349          y: y,
1350          w: w,
1351          h: h
1352        };
1353      };
1354      var getViewPortRect = function (ctrl) {
1355        var customUiContainer = UiContainer.getUiContainer(ctrl);
1356        return customUiContainer && !isFixed(ctrl) ? getUiContainerViewPort(customUiContainer) : getWindowViewPort();
1357      };
1358      var Movable = {
1359        testMoveRel: function (elm, rels) {
1360          var viewPortRect = getViewPortRect(this);
1361          for (var i = 0; i < rels.length; i++) {
1362            var pos = calculateRelativePosition(this, elm, rels[i]);
1363            if (isFixed(this)) {
1364              if (pos.x > 0 && pos.x + pos.w < viewPortRect.w && pos.y > 0 && pos.y + pos.h < viewPortRect.h) {
1365                return rels[i];
1366              }
1367            } else {
1368              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) {
1369                return rels[i];
1370              }
1371            }
1372          }
1373          return rels[0];
1374        },
1375        moveRel: function (elm, rel) {
1376          if (typeof rel !== 'string') {
1377            rel = this.testMoveRel(elm, rel);
1378          }
1379          var pos = calculateRelativePosition(this, elm, rel);
1380          return this.moveTo(pos.x, pos.y);
1381        },
1382        moveBy: function (dx, dy) {
1383          var self = this, rect = self.layoutRect();
1384          self.moveTo(rect.x + dx, rect.y + dy);
1385          return self;
1386        },
1387        moveTo: function (x, y) {
1388          var self = this;
1389          function constrain(value, max, size) {
1390            if (value < 0) {
1391              return 0;
1392            }
1393            if (value + size > max) {
1394              value = max - size;
1395              return value < 0 ? 0 : value;
1396            }
1397            return value;
1398          }
1399          if (self.settings.constrainToViewport) {
1400            var viewPortRect = getViewPortRect(this);
1401            var layoutRect = self.layoutRect();
1402            x = constrain(x, viewPortRect.w + viewPortRect.x, layoutRect.w);
1403            y = constrain(y, viewPortRect.h + viewPortRect.y, layoutRect.h);
1404          }
1405          var uiContainer = UiContainer.getUiContainer(self);
1406          if (uiContainer && isStatic(uiContainer) && !isFixed(self)) {
1407            x -= uiContainer.scrollLeft;
1408            y -= uiContainer.scrollTop;
1409          }
1410          if (uiContainer) {
1411            x += 1;
1412            y += 1;
1413          }
1414          if (self.state.get('rendered')) {
1415            self.layoutRect({
1416              x: x,
1417              y: y
1418            }).repaint();
1419          } else {
1420            self.settings.x = x;
1421            self.settings.y = y;
1422          }
1423          self.fire('move', {
1424            x: x,
1425            y: y
1426          });
1427          return self;
1428        }
1429      };
1430  
1431      var global$a = tinymce.util.Tools.resolve('tinymce.util.Class');
1432  
1433      var global$b = tinymce.util.Tools.resolve('tinymce.util.EventDispatcher');
1434  
1435      var BoxUtils = {
1436        parseBox: function (value) {
1437          var len;
1438          var radix = 10;
1439          if (!value) {
1440            return;
1441          }
1442          if (typeof value === 'number') {
1443            value = value || 0;
1444            return {
1445              top: value,
1446              left: value,
1447              bottom: value,
1448              right: value
1449            };
1450          }
1451          value = value.split(' ');
1452          len = value.length;
1453          if (len === 1) {
1454            value[1] = value[2] = value[3] = value[0];
1455          } else if (len === 2) {
1456            value[2] = value[0];
1457            value[3] = value[1];
1458          } else if (len === 3) {
1459            value[3] = value[1];
1460          }
1461          return {
1462            top: parseInt(value[0], radix) || 0,
1463            right: parseInt(value[1], radix) || 0,
1464            bottom: parseInt(value[2], radix) || 0,
1465            left: parseInt(value[3], radix) || 0
1466          };
1467        },
1468        measureBox: function (elm, prefix) {
1469          function getStyle(name) {
1470            var defaultView = elm.ownerDocument.defaultView;
1471            if (defaultView) {
1472              var computedStyle = defaultView.getComputedStyle(elm, null);
1473              if (computedStyle) {
1474                name = name.replace(/[A-Z]/g, function (a) {
1475                  return '-' + a;
1476                });
1477                return computedStyle.getPropertyValue(name);
1478              } else {
1479                return null;
1480              }
1481            }
1482            return elm.currentStyle[name];
1483          }
1484          function getSide(name) {
1485            var val = parseFloat(getStyle(name));
1486            return isNaN(val) ? 0 : val;
1487          }
1488          return {
1489            top: getSide(prefix + 'TopWidth'),
1490            right: getSide(prefix + 'RightWidth'),
1491            bottom: getSide(prefix + 'BottomWidth'),
1492            left: getSide(prefix + 'LeftWidth')
1493          };
1494        }
1495      };
1496  
1497      function noop$1() {
1498      }
1499      function ClassList(onchange) {
1500        this.cls = [];
1501        this.cls._map = {};
1502        this.onchange = onchange || noop$1;
1503        this.prefix = '';
1504      }
1505      global$2.extend(ClassList.prototype, {
1506        add: function (cls) {
1507          if (cls && !this.contains(cls)) {
1508            this.cls._map[cls] = true;
1509            this.cls.push(cls);
1510            this._change();
1511          }
1512          return this;
1513        },
1514        remove: function (cls) {
1515          if (this.contains(cls)) {
1516            var i = void 0;
1517            for (i = 0; i < this.cls.length; i++) {
1518              if (this.cls[i] === cls) {
1519                break;
1520              }
1521            }
1522            this.cls.splice(i, 1);
1523            delete this.cls._map[cls];
1524            this._change();
1525          }
1526          return this;
1527        },
1528        toggle: function (cls, state) {
1529          var curState = this.contains(cls);
1530          if (curState !== state) {
1531            if (curState) {
1532              this.remove(cls);
1533            } else {
1534              this.add(cls);
1535            }
1536            this._change();
1537          }
1538          return this;
1539        },
1540        contains: function (cls) {
1541          return !!this.cls._map[cls];
1542        },
1543        _change: function () {
1544          delete this.clsValue;
1545          this.onchange.call(this);
1546        }
1547      });
1548      ClassList.prototype.toString = function () {
1549        var value;
1550        if (this.clsValue) {
1551          return this.clsValue;
1552        }
1553        value = '';
1554        for (var i = 0; i < this.cls.length; i++) {
1555          if (i > 0) {
1556            value += ' ';
1557          }
1558          value += this.prefix + this.cls[i];
1559        }
1560        return value;
1561      };
1562  
1563      function unique(array) {
1564        var uniqueItems = [];
1565        var i = array.length, item;
1566        while (i--) {
1567          item = array[i];
1568          if (!item.__checked) {
1569            uniqueItems.push(item);
1570            item.__checked = 1;
1571          }
1572        }
1573        i = uniqueItems.length;
1574        while (i--) {
1575          delete uniqueItems[i].__checked;
1576        }
1577        return uniqueItems;
1578      }
1579      var expression = /^([\w\\*]+)?(?:#([\w\-\\]+))?(?:\.([\w\\\.]+))?(?:\[\@?([\w\\]+)([\^\$\*!~]?=)([\w\\]+)\])?(?:\:(.+))?/i;
1580      var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g;
1581      var whiteSpace = /^\s*|\s*$/g;
1582      var Collection;
1583      var Selector = global$a.extend({
1584        init: function (selector) {
1585          var match = this.match;
1586          function compileNameFilter(name) {
1587            if (name) {
1588              name = name.toLowerCase();
1589              return function (item) {
1590                return name === '*' || item.type === name;
1591              };
1592            }
1593          }
1594          function compileIdFilter(id) {
1595            if (id) {
1596              return function (item) {
1597                return item._name === id;
1598              };
1599            }
1600          }
1601          function compileClassesFilter(classes) {
1602            if (classes) {
1603              classes = classes.split('.');
1604              return function (item) {
1605                var i = classes.length;
1606                while (i--) {
1607                  if (!item.classes.contains(classes[i])) {
1608                    return false;
1609                  }
1610                }
1611                return true;
1612              };
1613            }
1614          }
1615          function compileAttrFilter(name, cmp, check) {
1616            if (name) {
1617              return function (item) {
1618                var value = item[name] ? item[name]() : '';
1619                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;
1620              };
1621            }
1622          }
1623          function compilePsuedoFilter(name) {
1624            var notSelectors;
1625            if (name) {
1626              name = /(?:not\((.+)\))|(.+)/i.exec(name);
1627              if (!name[1]) {
1628                name = name[2];
1629                return function (item, index, length) {
1630                  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;
1631                };
1632              }
1633              notSelectors = parseChunks(name[1], []);
1634              return function (item) {
1635                return !match(item, notSelectors);
1636              };
1637            }
1638          }
1639          function compile(selector, filters, direct) {
1640            var parts;
1641            function add(filter) {
1642              if (filter) {
1643                filters.push(filter);
1644              }
1645            }
1646            parts = expression.exec(selector.replace(whiteSpace, ''));
1647            add(compileNameFilter(parts[1]));
1648            add(compileIdFilter(parts[2]));
1649            add(compileClassesFilter(parts[3]));
1650            add(compileAttrFilter(parts[4], parts[5], parts[6]));
1651            add(compilePsuedoFilter(parts[7]));
1652            filters.pseudo = !!parts[7];
1653            filters.direct = direct;
1654            return filters;
1655          }
1656          function parseChunks(selector, selectors) {
1657            var parts = [];
1658            var extra, matches, i;
1659            do {
1660              chunker.exec('');
1661              matches = chunker.exec(selector);
1662              if (matches) {
1663                selector = matches[3];
1664                parts.push(matches[1]);
1665                if (matches[2]) {
1666                  extra = matches[3];
1667                  break;
1668                }
1669              }
1670            } while (matches);
1671            if (extra) {
1672              parseChunks(extra, selectors);
1673            }
1674            selector = [];
1675            for (i = 0; i < parts.length; i++) {
1676              if (parts[i] !== '>') {
1677                selector.push(compile(parts[i], [], parts[i - 1] === '>'));
1678              }
1679            }
1680            selectors.push(selector);
1681            return selectors;
1682          }
1683          this._selectors = parseChunks(selector, []);
1684        },
1685        match: function (control, selectors) {
1686          var i, l, si, sl, selector, fi, fl, filters, index, length, siblings, count, item;
1687          selectors = selectors || this._selectors;
1688          for (i = 0, l = selectors.length; i < l; i++) {
1689            selector = selectors[i];
1690            sl = selector.length;
1691            item = control;
1692            count = 0;
1693            for (si = sl - 1; si >= 0; si--) {
1694              filters = selector[si];
1695              while (item) {
1696                if (filters.pseudo) {
1697                  siblings = item.parent().items();
1698                  index = length = siblings.length;
1699                  while (index--) {
1700                    if (siblings[index] === item) {
1701                      break;
1702                    }
1703                  }
1704                }
1705                for (fi = 0, fl = filters.length; fi < fl; fi++) {
1706                  if (!filters[fi](item, index, length)) {
1707                    fi = fl + 1;
1708                    break;
1709                  }
1710                }
1711                if (fi === fl) {
1712                  count++;
1713                  break;
1714                } else {
1715                  if (si === sl - 1) {
1716                    break;
1717                  }
1718                }
1719                item = item.parent();
1720              }
1721            }
1722            if (count === sl) {
1723              return true;
1724            }
1725          }
1726          return false;
1727        },
1728        find: function (container) {
1729          var matches = [], i, l;
1730          var selectors = this._selectors;
1731          function collect(items, selector, index) {
1732            var i, l, fi, fl, item;
1733            var filters = selector[index];
1734            for (i = 0, l = items.length; i < l; i++) {
1735              item = items[i];
1736              for (fi = 0, fl = filters.length; fi < fl; fi++) {
1737                if (!filters[fi](item, i, l)) {
1738                  fi = fl + 1;
1739                  break;
1740                }
1741              }
1742              if (fi === fl) {
1743                if (index === selector.length - 1) {
1744                  matches.push(item);
1745                } else {
1746                  if (item.items) {
1747                    collect(item.items(), selector, index + 1);
1748                  }
1749                }
1750              } else if (filters.direct) {
1751                return;
1752              }
1753              if (item.items) {
1754                collect(item.items(), selector, index);
1755              }
1756            }
1757          }
1758          if (container.items) {
1759            for (i = 0, l = selectors.length; i < l; i++) {
1760              collect(container.items(), selectors[i], 0);
1761            }
1762            if (l > 1) {
1763              matches = unique(matches);
1764            }
1765          }
1766          if (!Collection) {
1767            Collection = Selector.Collection;
1768          }
1769          return new Collection(matches);
1770        }
1771      });
1772  
1773      var Collection$1, proto;
1774      var push$1 = Array.prototype.push, slice$1 = Array.prototype.slice;
1775      proto = {
1776        length: 0,
1777        init: function (items) {
1778          if (items) {
1779            this.add(items);
1780          }
1781        },
1782        add: function (items) {
1783          var self = this;
1784          if (!global$2.isArray(items)) {
1785            if (items instanceof Collection$1) {
1786              self.add(items.toArray());
1787            } else {
1788              push$1.call(self, items);
1789            }
1790          } else {
1791            push$1.apply(self, items);
1792          }
1793          return self;
1794        },
1795        set: function (items) {
1796          var self = this;
1797          var len = self.length;
1798          var i;
1799          self.length = 0;
1800          self.add(items);
1801          for (i = self.length; i < len; i++) {
1802            delete self[i];
1803          }
1804          return self;
1805        },
1806        filter: function (selector) {
1807          var self = this;
1808          var i, l;
1809          var matches = [];
1810          var item, match;
1811          if (typeof selector === 'string') {
1812            selector = new Selector(selector);
1813            match = function (item) {
1814              return selector.match(item);
1815            };
1816          } else {
1817            match = selector;
1818          }
1819          for (i = 0, l = self.length; i < l; i++) {
1820            item = self[i];
1821            if (match(item)) {
1822              matches.push(item);
1823            }
1824          }
1825          return new Collection$1(matches);
1826        },
1827        slice: function () {
1828          return new Collection$1(slice$1.apply(this, arguments));
1829        },
1830        eq: function (index) {
1831          return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
1832        },
1833        each: function (callback) {
1834          global$2.each(this, callback);
1835          return this;
1836        },
1837        toArray: function () {
1838          return global$2.toArray(this);
1839        },
1840        indexOf: function (ctrl) {
1841          var self = this;
1842          var i = self.length;
1843          while (i--) {
1844            if (self[i] === ctrl) {
1845              break;
1846            }
1847          }
1848          return i;
1849        },
1850        reverse: function () {
1851          return new Collection$1(global$2.toArray(this).reverse());
1852        },
1853        hasClass: function (cls) {
1854          return this[0] ? this[0].classes.contains(cls) : false;
1855        },
1856        prop: function (name, value) {
1857          var self = this;
1858          var item;
1859          if (value !== undefined) {
1860            self.each(function (item) {
1861              if (item[name]) {
1862                item[name](value);
1863              }
1864            });
1865            return self;
1866          }
1867          item = self[0];
1868          if (item && item[name]) {
1869            return item[name]();
1870          }
1871        },
1872        exec: function (name) {
1873          var self = this, args = global$2.toArray(arguments).slice(1);
1874          self.each(function (item) {
1875            if (item[name]) {
1876              item[name].apply(item, args);
1877            }
1878          });
1879          return self;
1880        },
1881        remove: function () {
1882          var i = this.length;
1883          while (i--) {
1884            this[i].remove();
1885          }
1886          return this;
1887        },
1888        addClass: function (cls) {
1889          return this.each(function (item) {
1890            item.classes.add(cls);
1891          });
1892        },
1893        removeClass: function (cls) {
1894          return this.each(function (item) {
1895            item.classes.remove(cls);
1896          });
1897        }
1898      };
1899      global$2.each('fire on off show hide append prepend before after reflow'.split(' '), function (name) {
1900        proto[name] = function () {
1901          var args = global$2.toArray(arguments);
1902          this.each(function (ctrl) {
1903            if (name in ctrl) {
1904              ctrl[name].apply(ctrl, args);
1905            }
1906          });
1907          return this;
1908        };
1909      });
1910      global$2.each('text name disabled active selected checked visible parent value data'.split(' '), function (name) {
1911        proto[name] = function (value) {
1912          return this.prop(name, value);
1913        };
1914      });
1915      Collection$1 = global$a.extend(proto);
1916      Selector.Collection = Collection$1;
1917      var Collection$2 = Collection$1;
1918  
1919      var Binding = function (settings) {
1920        this.create = settings.create;
1921      };
1922      Binding.create = function (model, name) {
1923        return new Binding({
1924          create: function (otherModel, otherName) {
1925            var bindings;
1926            var fromSelfToOther = function (e) {
1927              otherModel.set(otherName, e.value);
1928            };
1929            var fromOtherToSelf = function (e) {
1930              model.set(name, e.value);
1931            };
1932            otherModel.on('change:' + otherName, fromOtherToSelf);
1933            model.on('change:' + name, fromSelfToOther);
1934            bindings = otherModel._bindings;
1935            if (!bindings) {
1936              bindings = otherModel._bindings = [];
1937              otherModel.on('destroy', function () {
1938                var i = bindings.length;
1939                while (i--) {
1940                  bindings[i]();
1941                }
1942              });
1943            }
1944            bindings.push(function () {
1945              model.off('change:' + name, fromSelfToOther);
1946            });
1947            return model.get(name);
1948          }
1949        });
1950      };
1951  
1952      var global$c = tinymce.util.Tools.resolve('tinymce.util.Observable');
1953  
1954      function isNode(node) {
1955        return node.nodeType > 0;
1956      }
1957      function isEqual(a, b) {
1958        var k, checked;
1959        if (a === b) {
1960          return true;
1961        }
1962        if (a === null || b === null) {
1963          return a === b;
1964        }
1965        if (typeof a !== 'object' || typeof b !== 'object') {
1966          return a === b;
1967        }
1968        if (global$2.isArray(b)) {
1969          if (a.length !== b.length) {
1970            return false;
1971          }
1972          k = a.length;
1973          while (k--) {
1974            if (!isEqual(a[k], b[k])) {
1975              return false;
1976            }
1977          }
1978        }
1979        if (isNode(a) || isNode(b)) {
1980          return a === b;
1981        }
1982        checked = {};
1983        for (k in b) {
1984          if (!isEqual(a[k], b[k])) {
1985            return false;
1986          }
1987          checked[k] = true;
1988        }
1989        for (k in a) {
1990          if (!checked[k] && !isEqual(a[k], b[k])) {
1991            return false;
1992          }
1993        }
1994        return true;
1995      }
1996      var ObservableObject = global$a.extend({
1997        Mixins: [global$c],
1998        init: function (data) {
1999          var name, value;
2000          data = data || {};
2001          for (name in data) {
2002            value = data[name];
2003            if (value instanceof Binding) {
2004              data[name] = value.create(this, name);
2005            }
2006          }
2007          this.data = data;
2008        },
2009        set: function (name, value) {
2010          var key, args;
2011          var oldValue = this.data[name];
2012          if (value instanceof Binding) {
2013            value = value.create(this, name);
2014          }
2015          if (typeof name === 'object') {
2016            for (key in name) {
2017              this.set(key, name[key]);
2018            }
2019            return this;
2020          }
2021          if (!isEqual(oldValue, value)) {
2022            this.data[name] = value;
2023            args = {
2024              target: this,
2025              name: name,
2026              value: value,
2027              oldValue: oldValue
2028            };
2029            this.fire('change:' + name, args);
2030            this.fire('change', args);
2031          }
2032          return this;
2033        },
2034        get: function (name) {
2035          return this.data[name];
2036        },
2037        has: function (name) {
2038          return name in this.data;
2039        },
2040        bind: function (name) {
2041          return Binding.create(this, name);
2042        },
2043        destroy: function () {
2044          this.fire('destroy');
2045        }
2046      });
2047  
2048      var dirtyCtrls = {}, animationFrameRequested;
2049      var ReflowQueue = {
2050        add: function (ctrl) {
2051          var parent = ctrl.parent();
2052          if (parent) {
2053            if (!parent._layout || parent._layout.isNative()) {
2054              return;
2055            }
2056            if (!dirtyCtrls[parent._id]) {
2057              dirtyCtrls[parent._id] = parent;
2058            }
2059            if (!animationFrameRequested) {
2060              animationFrameRequested = true;
2061              global$7.requestAnimationFrame(function () {
2062                var id, ctrl;
2063                animationFrameRequested = false;
2064                for (id in dirtyCtrls) {
2065                  ctrl = dirtyCtrls[id];
2066                  if (ctrl.state.get('rendered')) {
2067                    ctrl.reflow();
2068                  }
2069                }
2070                dirtyCtrls = {};
2071              }, domGlobals.document.body);
2072            }
2073          }
2074        },
2075        remove: function (ctrl) {
2076          if (dirtyCtrls[ctrl._id]) {
2077            delete dirtyCtrls[ctrl._id];
2078          }
2079        }
2080      };
2081  
2082      var hasMouseWheelEventSupport = 'onmousewheel' in domGlobals.document;
2083      var hasWheelEventSupport = false;
2084      var classPrefix = 'mce-';
2085      var Control, idCounter = 0;
2086      var proto$1 = {
2087        Statics: { classPrefix: classPrefix },
2088        isRtl: function () {
2089          return Control.rtl;
2090        },
2091        classPrefix: classPrefix,
2092        init: function (settings) {
2093          var self = this;
2094          var classes, defaultClasses;
2095          function applyClasses(classes) {
2096            var i;
2097            classes = classes.split(' ');
2098            for (i = 0; i < classes.length; i++) {
2099              self.classes.add(classes[i]);
2100            }
2101          }
2102          self.settings = settings = global$2.extend({}, self.Defaults, settings);
2103          self._id = settings.id || 'mceu_' + idCounter++;
2104          self._aria = { role: settings.role };
2105          self._elmCache = {};
2106          self.$ = global$9;
2107          self.state = new ObservableObject({
2108            visible: true,
2109            active: false,
2110            disabled: false,
2111            value: ''
2112          });
2113          self.data = new ObservableObject(settings.data);
2114          self.classes = new ClassList(function () {
2115            if (self.state.get('rendered')) {
2116              self.getEl().className = this.toString();
2117            }
2118          });
2119          self.classes.prefix = self.classPrefix;
2120          classes = settings.classes;
2121          if (classes) {
2122            if (self.Defaults) {
2123              defaultClasses = self.Defaults.classes;
2124              if (defaultClasses && classes !== defaultClasses) {
2125                applyClasses(defaultClasses);
2126              }
2127            }
2128            applyClasses(classes);
2129          }
2130          global$2.each('title text name visible disabled active value'.split(' '), function (name) {
2131            if (name in settings) {
2132              self[name](settings[name]);
2133            }
2134          });
2135          self.on('click', function () {
2136            if (self.disabled()) {
2137              return false;
2138            }
2139          });
2140          self.settings = settings;
2141          self.borderBox = BoxUtils.parseBox(settings.border);
2142          self.paddingBox = BoxUtils.parseBox(settings.padding);
2143          self.marginBox = BoxUtils.parseBox(settings.margin);
2144          if (settings.hidden) {
2145            self.hide();
2146          }
2147        },
2148        Properties: 'parent,name',
2149        getContainerElm: function () {
2150          var uiContainer = UiContainer.getUiContainer(this);
2151          return uiContainer ? uiContainer : funcs.getContainer();
2152        },
2153        getParentCtrl: function (elm) {
2154          var ctrl;
2155          var lookup = this.getRoot().controlIdLookup;
2156          while (elm && lookup) {
2157            ctrl = lookup[elm.id];
2158            if (ctrl) {
2159              break;
2160            }
2161            elm = elm.parentNode;
2162          }
2163          return ctrl;
2164        },
2165        initLayoutRect: function () {
2166          var self = this;
2167          var settings = self.settings;
2168          var borderBox, layoutRect;
2169          var elm = self.getEl();
2170          var width, height, minWidth, minHeight, autoResize;
2171          var startMinWidth, startMinHeight, initialSize;
2172          borderBox = self.borderBox = self.borderBox || BoxUtils.measureBox(elm, 'border');
2173          self.paddingBox = self.paddingBox || BoxUtils.measureBox(elm, 'padding');
2174          self.marginBox = self.marginBox || BoxUtils.measureBox(elm, 'margin');
2175          initialSize = funcs.getSize(elm);
2176          startMinWidth = settings.minWidth;
2177          startMinHeight = settings.minHeight;
2178          minWidth = startMinWidth || initialSize.width;
2179          minHeight = startMinHeight || initialSize.height;
2180          width = settings.width;
2181          height = settings.height;
2182          autoResize = settings.autoResize;
2183          autoResize = typeof autoResize !== 'undefined' ? autoResize : !width && !height;
2184          width = width || minWidth;
2185          height = height || minHeight;
2186          var deltaW = borderBox.left + borderBox.right;
2187          var deltaH = borderBox.top + borderBox.bottom;
2188          var maxW = settings.maxWidth || 65535;
2189          var maxH = settings.maxHeight || 65535;
2190          self._layoutRect = layoutRect = {
2191            x: settings.x || 0,
2192            y: settings.y || 0,
2193            w: width,
2194            h: height,
2195            deltaW: deltaW,
2196            deltaH: deltaH,
2197            contentW: width - deltaW,
2198            contentH: height - deltaH,
2199            innerW: width - deltaW,
2200            innerH: height - deltaH,
2201            startMinWidth: startMinWidth || 0,
2202            startMinHeight: startMinHeight || 0,
2203            minW: Math.min(minWidth, maxW),
2204            minH: Math.min(minHeight, maxH),
2205            maxW: maxW,
2206            maxH: maxH,
2207            autoResize: autoResize,
2208            scrollW: 0
2209          };
2210          self._lastLayoutRect = {};
2211          return layoutRect;
2212        },
2213        layoutRect: function (newRect) {
2214          var self = this;
2215          var curRect = self._layoutRect, lastLayoutRect, size, deltaWidth, deltaHeight, repaintControls;
2216          if (!curRect) {
2217            curRect = self.initLayoutRect();
2218          }
2219          if (newRect) {
2220            deltaWidth = curRect.deltaW;
2221            deltaHeight = curRect.deltaH;
2222            if (newRect.x !== undefined) {
2223              curRect.x = newRect.x;
2224            }
2225            if (newRect.y !== undefined) {
2226              curRect.y = newRect.y;
2227            }
2228            if (newRect.minW !== undefined) {
2229              curRect.minW = newRect.minW;
2230            }
2231            if (newRect.minH !== undefined) {
2232              curRect.minH = newRect.minH;
2233            }
2234            size = newRect.w;
2235            if (size !== undefined) {
2236              size = size < curRect.minW ? curRect.minW : size;
2237              size = size > curRect.maxW ? curRect.maxW : size;
2238              curRect.w = size;
2239              curRect.innerW = size - deltaWidth;
2240            }
2241            size = newRect.h;
2242            if (size !== undefined) {
2243              size = size < curRect.minH ? curRect.minH : size;
2244              size = size > curRect.maxH ? curRect.maxH : size;
2245              curRect.h = size;
2246              curRect.innerH = size - deltaHeight;
2247            }
2248            size = newRect.innerW;
2249            if (size !== undefined) {
2250              size = size < curRect.minW - deltaWidth ? curRect.minW - deltaWidth : size;
2251              size = size > curRect.maxW - deltaWidth ? curRect.maxW - deltaWidth : size;
2252              curRect.innerW = size;
2253              curRect.w = size + deltaWidth;
2254            }
2255            size = newRect.innerH;
2256            if (size !== undefined) {
2257              size = size < curRect.minH - deltaHeight ? curRect.minH - deltaHeight : size;
2258              size = size > curRect.maxH - deltaHeight ? curRect.maxH - deltaHeight : size;
2259              curRect.innerH = size;
2260              curRect.h = size + deltaHeight;
2261            }
2262            if (newRect.contentW !== undefined) {
2263              curRect.contentW = newRect.contentW;
2264            }
2265            if (newRect.contentH !== undefined) {
2266              curRect.contentH = newRect.contentH;
2267            }
2268            lastLayoutRect = self._lastLayoutRect;
2269            if (lastLayoutRect.x !== curRect.x || lastLayoutRect.y !== curRect.y || lastLayoutRect.w !== curRect.w || lastLayoutRect.h !== curRect.h) {
2270              repaintControls = Control.repaintControls;
2271              if (repaintControls) {
2272                if (repaintControls.map && !repaintControls.map[self._id]) {
2273                  repaintControls.push(self);
2274                  repaintControls.map[self._id] = true;
2275                }
2276              }
2277              lastLayoutRect.x = curRect.x;
2278              lastLayoutRect.y = curRect.y;
2279              lastLayoutRect.w = curRect.w;
2280              lastLayoutRect.h = curRect.h;
2281            }
2282            return self;
2283          }
2284          return curRect;
2285        },
2286        repaint: function () {
2287          var self = this;
2288          var style, bodyStyle, bodyElm, rect, borderBox;
2289          var borderW, borderH, lastRepaintRect, round, value;
2290          round = !domGlobals.document.createRange ? Math.round : function (value) {
2291            return value;
2292          };
2293          style = self.getEl().style;
2294          rect = self._layoutRect;
2295          lastRepaintRect = self._lastRepaintRect || {};
2296          borderBox = self.borderBox;
2297          borderW = borderBox.left + borderBox.right;
2298          borderH = borderBox.top + borderBox.bottom;
2299          if (rect.x !== lastRepaintRect.x) {
2300            style.left = round(rect.x) + 'px';
2301            lastRepaintRect.x = rect.x;
2302          }
2303          if (rect.y !== lastRepaintRect.y) {
2304            style.top = round(rect.y) + 'px';
2305            lastRepaintRect.y = rect.y;
2306          }
2307          if (rect.w !== lastRepaintRect.w) {
2308            value = round(rect.w - borderW);
2309            style.width = (value >= 0 ? value : 0) + 'px';
2310            lastRepaintRect.w = rect.w;
2311          }
2312          if (rect.h !== lastRepaintRect.h) {
2313            value = round(rect.h - borderH);
2314            style.height = (value >= 0 ? value : 0) + 'px';
2315            lastRepaintRect.h = rect.h;
2316          }
2317          if (self._hasBody && rect.innerW !== lastRepaintRect.innerW) {
2318            value = round(rect.innerW);
2319            bodyElm = self.getEl('body');
2320            if (bodyElm) {
2321              bodyStyle = bodyElm.style;
2322              bodyStyle.width = (value >= 0 ? value : 0) + 'px';
2323            }
2324            lastRepaintRect.innerW = rect.innerW;
2325          }
2326          if (self._hasBody && rect.innerH !== lastRepaintRect.innerH) {
2327            value = round(rect.innerH);
2328            bodyElm = bodyElm || self.getEl('body');
2329            if (bodyElm) {
2330              bodyStyle = bodyStyle || bodyElm.style;
2331              bodyStyle.height = (value >= 0 ? value : 0) + 'px';
2332            }
2333            lastRepaintRect.innerH = rect.innerH;
2334          }
2335          self._lastRepaintRect = lastRepaintRect;
2336          self.fire('repaint', {}, false);
2337        },
2338        updateLayoutRect: function () {
2339          var self = this;
2340          self.parent()._lastRect = null;
2341          funcs.css(self.getEl(), {
2342            width: '',
2343            height: ''
2344          });
2345          self._layoutRect = self._lastRepaintRect = self._lastLayoutRect = null;
2346          self.initLayoutRect();
2347        },
2348        on: function (name, callback) {
2349          var self = this;
2350          function resolveCallbackName(name) {
2351            var callback, scope;
2352            if (typeof name !== 'string') {
2353              return name;
2354            }
2355            return function (e) {
2356              if (!callback) {
2357                self.parentsAndSelf().each(function (ctrl) {
2358                  var callbacks = ctrl.settings.callbacks;
2359                  if (callbacks && (callback = callbacks[name])) {
2360                    scope = ctrl;
2361                    return false;
2362                  }
2363                });
2364              }
2365              if (!callback) {
2366                e.action = name;
2367                this.fire('execute', e);
2368                return;
2369              }
2370              return callback.call(scope, e);
2371            };
2372          }
2373          getEventDispatcher(self).on(name, resolveCallbackName(callback));
2374          return self;
2375        },
2376        off: function (name, callback) {
2377          getEventDispatcher(this).off(name, callback);
2378          return this;
2379        },
2380        fire: function (name, args, bubble) {
2381          var self = this;
2382          args = args || {};
2383          if (!args.control) {
2384            args.control = self;
2385          }
2386          args = getEventDispatcher(self).fire(name, args);
2387          if (bubble !== false && self.parent) {
2388            var parent = self.parent();
2389            while (parent && !args.isPropagationStopped()) {
2390              parent.fire(name, args, false);
2391              parent = parent.parent();
2392            }
2393          }
2394          return args;
2395        },
2396        hasEventListeners: function (name) {
2397          return getEventDispatcher(this).has(name);
2398        },
2399        parents: function (selector) {
2400          var self = this;
2401          var ctrl, parents = new Collection$2();
2402          for (ctrl = self.parent(); ctrl; ctrl = ctrl.parent()) {
2403            parents.add(ctrl);
2404          }
2405          if (selector) {
2406            parents = parents.filter(selector);
2407          }
2408          return parents;
2409        },
2410        parentsAndSelf: function (selector) {
2411          return new Collection$2(this).add(this.parents(selector));
2412        },
2413        next: function () {
2414          var parentControls = this.parent().items();
2415          return parentControls[parentControls.indexOf(this) + 1];
2416        },
2417        prev: function () {
2418          var parentControls = this.parent().items();
2419          return parentControls[parentControls.indexOf(this) - 1];
2420        },
2421        innerHtml: function (html) {
2422          this.$el.html(html);
2423          return this;
2424        },
2425        getEl: function (suffix) {
2426          var id = suffix ? this._id + '-' + suffix : this._id;
2427          if (!this._elmCache[id]) {
2428            this._elmCache[id] = global$9('#' + id)[0];
2429          }
2430          return this._elmCache[id];
2431        },
2432        show: function () {
2433          return this.visible(true);
2434        },
2435        hide: function () {
2436          return this.visible(false);
2437        },
2438        focus: function () {
2439          try {
2440            this.getEl().focus();
2441          } catch (ex) {
2442          }
2443          return this;
2444        },
2445        blur: function () {
2446          this.getEl().blur();
2447          return this;
2448        },
2449        aria: function (name, value) {
2450          var self = this, elm = self.getEl(self.ariaTarget);
2451          if (typeof value === 'undefined') {
2452            return self._aria[name];
2453          }
2454          self._aria[name] = value;
2455          if (self.state.get('rendered')) {
2456            elm.setAttribute(name === 'role' ? name : 'aria-' + name, value);
2457          }
2458          return self;
2459        },
2460        encode: function (text, translate) {
2461          if (translate !== false) {
2462            text = this.translate(text);
2463          }
2464          return (text || '').replace(/[&<>"]/g, function (match) {
2465            return '&#' + match.charCodeAt(0) + ';';
2466          });
2467        },
2468        translate: function (text) {
2469          return Control.translate ? Control.translate(text) : text;
2470        },
2471        before: function (items) {
2472          var self = this, parent = self.parent();
2473          if (parent) {
2474            parent.insert(items, parent.items().indexOf(self), true);
2475          }
2476          return self;
2477        },
2478        after: function (items) {
2479          var self = this, parent = self.parent();
2480          if (parent) {
2481            parent.insert(items, parent.items().indexOf(self));
2482          }
2483          return self;
2484        },
2485        remove: function () {
2486          var self = this;
2487          var elm = self.getEl();
2488          var parent = self.parent();
2489          var newItems, i;
2490          if (self.items) {
2491            var controls = self.items().toArray();
2492            i = controls.length;
2493            while (i--) {
2494              controls[i].remove();
2495            }
2496          }
2497          if (parent && parent.items) {
2498            newItems = [];
2499            parent.items().each(function (item) {
2500              if (item !== self) {
2501                newItems.push(item);
2502              }
2503            });
2504            parent.items().set(newItems);
2505            parent._lastRect = null;
2506          }
2507          if (self._eventsRoot && self._eventsRoot === self) {
2508            global$9(elm).off();
2509          }
2510          var lookup = self.getRoot().controlIdLookup;
2511          if (lookup) {
2512            delete lookup[self._id];
2513          }
2514          if (elm && elm.parentNode) {
2515            elm.parentNode.removeChild(elm);
2516          }
2517          self.state.set('rendered', false);
2518          self.state.destroy();
2519          self.fire('remove');
2520          return self;
2521        },
2522        renderBefore: function (elm) {
2523          global$9(elm).before(this.renderHtml());
2524          this.postRender();
2525          return this;
2526        },
2527        renderTo: function (elm) {
2528          global$9(elm || this.getContainerElm()).append(this.renderHtml());
2529          this.postRender();
2530          return this;
2531        },
2532        preRender: function () {
2533        },
2534        render: function () {
2535        },
2536        renderHtml: function () {
2537          return '<div id="' + this._id + '" class="' + this.classes + '"></div>';
2538        },
2539        postRender: function () {
2540          var self = this;
2541          var settings = self.settings;
2542          var elm, box, parent, name, parentEventsRoot;
2543          self.$el = global$9(self.getEl());
2544          self.state.set('rendered', true);
2545          for (name in settings) {
2546            if (name.indexOf('on') === 0) {
2547              self.on(name.substr(2), settings[name]);
2548            }
2549          }
2550          if (self._eventsRoot) {
2551            for (parent = self.parent(); !parentEventsRoot && parent; parent = parent.parent()) {
2552              parentEventsRoot = parent._eventsRoot;
2553            }
2554            if (parentEventsRoot) {
2555              for (name in parentEventsRoot._nativeEvents) {
2556                self._nativeEvents[name] = true;
2557              }
2558            }
2559          }
2560          bindPendingEvents(self);
2561          if (settings.style) {
2562            elm = self.getEl();
2563            if (elm) {
2564              elm.setAttribute('style', settings.style);
2565              elm.style.cssText = settings.style;
2566            }
2567          }
2568          if (self.settings.border) {
2569            box = self.borderBox;
2570            self.$el.css({
2571              'border-top-width': box.top,
2572              'border-right-width': box.right,
2573              'border-bottom-width': box.bottom,
2574              'border-left-width': box.left
2575            });
2576          }
2577          var root = self.getRoot();
2578          if (!root.controlIdLookup) {
2579            root.controlIdLookup = {};
2580          }
2581          root.controlIdLookup[self._id] = self;
2582          for (var key in self._aria) {
2583            self.aria(key, self._aria[key]);
2584          }
2585          if (self.state.get('visible') === false) {
2586            self.getEl().style.display = 'none';
2587          }
2588          self.bindStates();
2589          self.state.on('change:visible', function (e) {
2590            var state = e.value;
2591            var parentCtrl;
2592            if (self.state.get('rendered')) {
2593              self.getEl().style.display = state === false ? 'none' : '';
2594              self.getEl().getBoundingClientRect();
2595            }
2596            parentCtrl = self.parent();
2597            if (parentCtrl) {
2598              parentCtrl._lastRect = null;
2599            }
2600            self.fire(state ? 'show' : 'hide');
2601            ReflowQueue.add(self);
2602          });
2603          self.fire('postrender', {}, false);
2604        },
2605        bindStates: function () {
2606        },
2607        scrollIntoView: function (align) {
2608          function getOffset(elm, rootElm) {
2609            var x, y, parent = elm;
2610            x = y = 0;
2611            while (parent && parent !== rootElm && parent.nodeType) {
2612              x += parent.offsetLeft || 0;
2613              y += parent.offsetTop || 0;
2614              parent = parent.offsetParent;
2615            }
2616            return {
2617              x: x,
2618              y: y
2619            };
2620          }
2621          var elm = this.getEl(), parentElm = elm.parentNode;
2622          var x, y, width, height, parentWidth, parentHeight;
2623          var pos = getOffset(elm, parentElm);
2624          x = pos.x;
2625          y = pos.y;
2626          width = elm.offsetWidth;
2627          height = elm.offsetHeight;
2628          parentWidth = parentElm.clientWidth;
2629          parentHeight = parentElm.clientHeight;
2630          if (align === 'end') {
2631            x -= parentWidth - width;
2632            y -= parentHeight - height;
2633          } else if (align === 'center') {
2634            x -= parentWidth / 2 - width / 2;
2635            y -= parentHeight / 2 - height / 2;
2636          }
2637          parentElm.scrollLeft = x;
2638          parentElm.scrollTop = y;
2639          return this;
2640        },
2641        getRoot: function () {
2642          var ctrl = this, rootControl;
2643          var parents = [];
2644          while (ctrl) {
2645            if (ctrl.rootControl) {
2646              rootControl = ctrl.rootControl;
2647              break;
2648            }
2649            parents.push(ctrl);
2650            rootControl = ctrl;
2651            ctrl = ctrl.parent();
2652          }
2653          if (!rootControl) {
2654            rootControl = this;
2655          }
2656          var i = parents.length;
2657          while (i--) {
2658            parents[i].rootControl = rootControl;
2659          }
2660          return rootControl;
2661        },
2662        reflow: function () {
2663          ReflowQueue.remove(this);
2664          var parent = this.parent();
2665          if (parent && parent._layout && !parent._layout.isNative()) {
2666            parent.reflow();
2667          }
2668          return this;
2669        }
2670      };
2671      global$2.each('text title visible disabled active value'.split(' '), function (name) {
2672        proto$1[name] = function (value) {
2673          if (arguments.length === 0) {
2674            return this.state.get(name);
2675          }
2676          if (typeof value !== 'undefined') {
2677            this.state.set(name, value);
2678          }
2679          return this;
2680        };
2681      });
2682      Control = global$a.extend(proto$1);
2683      function getEventDispatcher(obj) {
2684        if (!obj._eventDispatcher) {
2685          obj._eventDispatcher = new global$b({
2686            scope: obj,
2687            toggleEvent: function (name, state) {
2688              if (state && global$b.isNative(name)) {
2689                if (!obj._nativeEvents) {
2690                  obj._nativeEvents = {};
2691                }
2692                obj._nativeEvents[name] = true;
2693                if (obj.state.get('rendered')) {
2694                  bindPendingEvents(obj);
2695                }
2696              }
2697            }
2698          });
2699        }
2700        return obj._eventDispatcher;
2701      }
2702      function bindPendingEvents(eventCtrl) {
2703        var i, l, parents, eventRootCtrl, nativeEvents, name;
2704        function delegate(e) {
2705          var control = eventCtrl.getParentCtrl(e.target);
2706          if (control) {
2707            control.fire(e.type, e);
2708          }
2709        }
2710        function mouseLeaveHandler() {
2711          var ctrl = eventRootCtrl._lastHoverCtrl;
2712          if (ctrl) {
2713            ctrl.fire('mouseleave', { target: ctrl.getEl() });
2714            ctrl.parents().each(function (ctrl) {
2715              ctrl.fire('mouseleave', { target: ctrl.getEl() });
2716            });
2717            eventRootCtrl._lastHoverCtrl = null;
2718          }
2719        }
2720        function mouseEnterHandler(e) {
2721          var ctrl = eventCtrl.getParentCtrl(e.target), lastCtrl = eventRootCtrl._lastHoverCtrl, idx = 0, i, parents, lastParents;
2722          if (ctrl !== lastCtrl) {
2723            eventRootCtrl._lastHoverCtrl = ctrl;
2724            parents = ctrl.parents().toArray().reverse();
2725            parents.push(ctrl);
2726            if (lastCtrl) {
2727              lastParents = lastCtrl.parents().toArray().reverse();
2728              lastParents.push(lastCtrl);
2729              for (idx = 0; idx < lastParents.length; idx++) {
2730                if (parents[idx] !== lastParents[idx]) {
2731                  break;
2732                }
2733              }
2734              for (i = lastParents.length - 1; i >= idx; i--) {
2735                lastCtrl = lastParents[i];
2736                lastCtrl.fire('mouseleave', { target: lastCtrl.getEl() });
2737              }
2738            }
2739            for (i = idx; i < parents.length; i++) {
2740              ctrl = parents[i];
2741              ctrl.fire('mouseenter', { target: ctrl.getEl() });
2742            }
2743          }
2744        }
2745        function fixWheelEvent(e) {
2746          e.preventDefault();
2747          if (e.type === 'mousewheel') {
2748            e.deltaY = -1 / 40 * e.wheelDelta;
2749            if (e.wheelDeltaX) {
2750              e.deltaX = -1 / 40 * e.wheelDeltaX;
2751            }
2752          } else {
2753            e.deltaX = 0;
2754            e.deltaY = e.detail;
2755          }
2756          e = eventCtrl.fire('wheel', e);
2757        }
2758        nativeEvents = eventCtrl._nativeEvents;
2759        if (nativeEvents) {
2760          parents = eventCtrl.parents().toArray();
2761          parents.unshift(eventCtrl);
2762          for (i = 0, l = parents.length; !eventRootCtrl && i < l; i++) {
2763            eventRootCtrl = parents[i]._eventsRoot;
2764          }
2765          if (!eventRootCtrl) {
2766            eventRootCtrl = parents[parents.length - 1] || eventCtrl;
2767          }
2768          eventCtrl._eventsRoot = eventRootCtrl;
2769          for (l = i, i = 0; i < l; i++) {
2770            parents[i]._eventsRoot = eventRootCtrl;
2771          }
2772          var eventRootDelegates = eventRootCtrl._delegates;
2773          if (!eventRootDelegates) {
2774            eventRootDelegates = eventRootCtrl._delegates = {};
2775          }
2776          for (name in nativeEvents) {
2777            if (!nativeEvents) {
2778              return false;
2779            }
2780            if (name === 'wheel' && !hasWheelEventSupport) {
2781              if (hasMouseWheelEventSupport) {
2782                global$9(eventCtrl.getEl()).on('mousewheel', fixWheelEvent);
2783              } else {
2784                global$9(eventCtrl.getEl()).on('DOMMouseScroll', fixWheelEvent);
2785              }
2786              continue;
2787            }
2788            if (name === 'mouseenter' || name === 'mouseleave') {
2789              if (!eventRootCtrl._hasMouseEnter) {
2790                global$9(eventRootCtrl.getEl()).on('mouseleave', mouseLeaveHandler).on('mouseover', mouseEnterHandler);
2791                eventRootCtrl._hasMouseEnter = 1;
2792              }
2793            } else if (!eventRootDelegates[name]) {
2794              global$9(eventRootCtrl.getEl()).on(name, delegate);
2795              eventRootDelegates[name] = true;
2796            }
2797            nativeEvents[name] = false;
2798          }
2799        }
2800      }
2801      var Control$1 = Control;
2802  
2803      var hasTabstopData = function (elm) {
2804        return elm.getAttribute('data-mce-tabstop') ? true : false;
2805      };
2806      function KeyboardNavigation (settings) {
2807        var root = settings.root;
2808        var focusedElement, focusedControl;
2809        function isElement(node) {
2810          return node && node.nodeType === 1;
2811        }
2812        try {
2813          focusedElement = domGlobals.document.activeElement;
2814        } catch (ex) {
2815          focusedElement = domGlobals.document.body;
2816        }
2817        focusedControl = root.getParentCtrl(focusedElement);
2818        function getRole(elm) {
2819          elm = elm || focusedElement;
2820          if (isElement(elm)) {
2821            return elm.getAttribute('role');
2822          }
2823          return null;
2824        }
2825        function getParentRole(elm) {
2826          var role, parent = elm || focusedElement;
2827          while (parent = parent.parentNode) {
2828            if (role = getRole(parent)) {
2829              return role;
2830            }
2831          }
2832        }
2833        function getAriaProp(name) {
2834          var elm = focusedElement;
2835          if (isElement(elm)) {
2836            return elm.getAttribute('aria-' + name);
2837          }
2838        }
2839        function isTextInputElement(elm) {
2840          var tagName = elm.tagName.toUpperCase();
2841          return tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT';
2842        }
2843        function canFocus(elm) {
2844          if (isTextInputElement(elm) && !elm.hidden) {
2845            return true;
2846          }
2847          if (hasTabstopData(elm)) {
2848            return true;
2849          }
2850          if (/^(button|menuitem|checkbox|tab|menuitemcheckbox|option|gridcell|slider)$/.test(getRole(elm))) {
2851            return true;
2852          }
2853          return false;
2854        }
2855        function getFocusElements(elm) {
2856          var elements = [];
2857          function collect(elm) {
2858            if (elm.nodeType !== 1 || elm.style.display === 'none' || elm.disabled) {
2859              return;
2860            }
2861            if (canFocus(elm)) {
2862              elements.push(elm);
2863            }
2864            for (var i = 0; i < elm.childNodes.length; i++) {
2865              collect(elm.childNodes[i]);
2866            }
2867          }
2868          collect(elm || root.getEl());
2869          return elements;
2870        }
2871        function getNavigationRoot(targetControl) {
2872          var navigationRoot, controls;
2873          targetControl = targetControl || focusedControl;
2874          controls = targetControl.parents().toArray();
2875          controls.unshift(targetControl);
2876          for (var i = 0; i < controls.length; i++) {
2877            navigationRoot = controls[i];
2878            if (navigationRoot.settings.ariaRoot) {
2879              break;
2880            }
2881          }
2882          return navigationRoot;
2883        }
2884        function focusFirst(targetControl) {
2885          var navigationRoot = getNavigationRoot(targetControl);
2886          var focusElements = getFocusElements(navigationRoot.getEl());
2887          if (navigationRoot.settings.ariaRemember && 'lastAriaIndex' in navigationRoot) {
2888            moveFocusToIndex(navigationRoot.lastAriaIndex, focusElements);
2889          } else {
2890            moveFocusToIndex(0, focusElements);
2891          }
2892        }
2893        function moveFocusToIndex(idx, elements) {
2894          if (idx < 0) {
2895            idx = elements.length - 1;
2896          } else if (idx >= elements.length) {
2897            idx = 0;
2898          }
2899          if (elements[idx]) {
2900            elements[idx].focus();
2901          }
2902          return idx;
2903        }
2904        function moveFocus(dir, elements) {
2905          var idx = -1;
2906          var navigationRoot = getNavigationRoot();
2907          elements = elements || getFocusElements(navigationRoot.getEl());
2908          for (var i = 0; i < elements.length; i++) {
2909            if (elements[i] === focusedElement) {
2910              idx = i;
2911            }
2912          }
2913          idx += dir;
2914          navigationRoot.lastAriaIndex = moveFocusToIndex(idx, elements);
2915        }
2916        function left() {
2917          var parentRole = getParentRole();
2918          if (parentRole === 'tablist') {
2919            moveFocus(-1, getFocusElements(focusedElement.parentNode));
2920          } else if (focusedControl.parent().submenu) {
2921            cancel();
2922          } else {
2923            moveFocus(-1);
2924          }
2925        }
2926        function right() {
2927          var role = getRole(), parentRole = getParentRole();
2928          if (parentRole === 'tablist') {
2929            moveFocus(1, getFocusElements(focusedElement.parentNode));
2930          } else if (role === 'menuitem' && parentRole === 'menu' && getAriaProp('haspopup')) {
2931            enter();
2932          } else {
2933            moveFocus(1);
2934          }
2935        }
2936        function up() {
2937          moveFocus(-1);
2938        }
2939        function down() {
2940          var role = getRole(), parentRole = getParentRole();
2941          if (role === 'menuitem' && parentRole === 'menubar') {
2942            enter();
2943          } else if (role === 'button' && getAriaProp('haspopup')) {
2944            enter({ key: 'down' });
2945          } else {
2946            moveFocus(1);
2947          }
2948        }
2949        function tab(e) {
2950          var parentRole = getParentRole();
2951          if (parentRole === 'tablist') {
2952            var elm = getFocusElements(focusedControl.getEl('body'))[0];
2953            if (elm) {
2954              elm.focus();
2955            }
2956          } else {
2957            moveFocus(e.shiftKey ? -1 : 1);
2958          }
2959        }
2960        function cancel() {
2961          focusedControl.fire('cancel');
2962        }
2963        function enter(aria) {
2964          aria = aria || {};
2965          focusedControl.fire('click', {
2966            target: focusedElement,
2967            aria: aria
2968          });
2969        }
2970        root.on('keydown', function (e) {
2971          function handleNonTabOrEscEvent(e, handler) {
2972            if (isTextInputElement(focusedElement) || hasTabstopData(focusedElement)) {
2973              return;
2974            }
2975            if (getRole(focusedElement) === 'slider') {
2976              return;
2977            }
2978            if (handler(e) !== false) {
2979              e.preventDefault();
2980            }
2981          }
2982          if (e.isDefaultPrevented()) {
2983            return;
2984          }
2985          switch (e.keyCode) {
2986          case 37:
2987            handleNonTabOrEscEvent(e, left);
2988            break;
2989          case 39:
2990            handleNonTabOrEscEvent(e, right);
2991            break;
2992          case 38:
2993            handleNonTabOrEscEvent(e, up);
2994            break;
2995          case 40:
2996            handleNonTabOrEscEvent(e, down);
2997            break;
2998          case 27:
2999            cancel();
3000            break;
3001          case 14:
3002          case 13:
3003          case 32:
3004            handleNonTabOrEscEvent(e, enter);
3005            break;
3006          case 9:
3007            tab(e);
3008            e.preventDefault();
3009            break;
3010          }
3011        });
3012        root.on('focusin', function (e) {
3013          focusedElement = e.target;
3014          focusedControl = e.control;
3015        });
3016        return { focusFirst: focusFirst };
3017      }
3018  
3019      var selectorCache = {};
3020      var Container = Control$1.extend({
3021        init: function (settings) {
3022          var self = this;
3023          self._super(settings);
3024          settings = self.settings;
3025          if (settings.fixed) {
3026            self.state.set('fixed', true);
3027          }
3028          self._items = new Collection$2();
3029          if (self.isRtl()) {
3030            self.classes.add('rtl');
3031          }
3032          self.bodyClasses = new ClassList(function () {
3033            if (self.state.get('rendered')) {
3034              self.getEl('body').className = this.toString();
3035            }
3036          });
3037          self.bodyClasses.prefix = self.classPrefix;
3038          self.classes.add('container');
3039          self.bodyClasses.add('container-body');
3040          if (settings.containerCls) {
3041            self.classes.add(settings.containerCls);
3042          }
3043          self._layout = global$4.create((settings.layout || '') + 'layout');
3044          if (self.settings.items) {
3045            self.add(self.settings.items);
3046          } else {
3047            self.add(self.render());
3048          }
3049          self._hasBody = true;
3050        },
3051        items: function () {
3052          return this._items;
3053        },
3054        find: function (selector) {
3055          selector = selectorCache[selector] = selectorCache[selector] || new Selector(selector);
3056          return selector.find(this);
3057        },
3058        add: function (items) {
3059          var self = this;
3060          self.items().add(self.create(items)).parent(self);
3061          return self;
3062        },
3063        focus: function (keyboard) {
3064          var self = this;
3065          var focusCtrl, keyboardNav, items;
3066          if (keyboard) {
3067            keyboardNav = self.keyboardNav || self.parents().eq(-1)[0].keyboardNav;
3068            if (keyboardNav) {
3069              keyboardNav.focusFirst(self);
3070              return;
3071            }
3072          }
3073          items = self.find('*');
3074          if (self.statusbar) {
3075            items.add(self.statusbar.items());
3076          }
3077          items.each(function (ctrl) {
3078            if (ctrl.settings.autofocus) {
3079              focusCtrl = null;
3080              return false;
3081            }
3082            if (ctrl.canFocus) {
3083              focusCtrl = focusCtrl || ctrl;
3084            }
3085          });
3086          if (focusCtrl) {
3087            focusCtrl.focus();
3088          }
3089          return self;
3090        },
3091        replace: function (oldItem, newItem) {
3092          var ctrlElm;
3093          var items = this.items();
3094          var i = items.length;
3095          while (i--) {
3096            if (items[i] === oldItem) {
3097              items[i] = newItem;
3098              break;
3099            }
3100          }
3101          if (i >= 0) {
3102            ctrlElm = newItem.getEl();
3103            if (ctrlElm) {
3104              ctrlElm.parentNode.removeChild(ctrlElm);
3105            }
3106            ctrlElm = oldItem.getEl();
3107            if (ctrlElm) {
3108              ctrlElm.parentNode.removeChild(ctrlElm);
3109            }
3110          }
3111          newItem.parent(this);
3112        },
3113        create: function (items) {
3114          var self = this;
3115          var settings;
3116          var ctrlItems = [];
3117          if (!global$2.isArray(items)) {
3118            items = [items];
3119          }
3120          global$2.each(items, function (item) {
3121            if (item) {
3122              if (!(item instanceof Control$1)) {
3123                if (typeof item === 'string') {
3124                  item = { type: item };
3125                }
3126                settings = global$2.extend({}, self.settings.defaults, item);
3127                item.type = settings.type = settings.type || item.type || self.settings.defaultType || (settings.defaults ? settings.defaults.type : null);
3128                item = global$4.create(settings);
3129              }
3130              ctrlItems.push(item);
3131            }
3132          });
3133          return ctrlItems;
3134        },
3135        renderNew: function () {
3136          var self = this;
3137          self.items().each(function (ctrl, index) {
3138            var containerElm;
3139            ctrl.parent(self);
3140            if (!ctrl.state.get('rendered')) {
3141              containerElm = self.getEl('body');
3142              if (containerElm.hasChildNodes() && index <= containerElm.childNodes.length - 1) {
3143                global$9(containerElm.childNodes[index]).before(ctrl.renderHtml());
3144              } else {
3145                global$9(containerElm).append(ctrl.renderHtml());
3146              }
3147              ctrl.postRender();
3148              ReflowQueue.add(ctrl);
3149            }
3150          });
3151          self._layout.applyClasses(self.items().filter(':visible'));
3152          self._lastRect = null;
3153          return self;
3154        },
3155        append: function (items) {
3156          return this.add(items).renderNew();
3157        },
3158        prepend: function (items) {
3159          var self = this;
3160          self.items().set(self.create(items).concat(self.items().toArray()));
3161          return self.renderNew();
3162        },
3163        insert: function (items, index, before) {
3164          var self = this;
3165          var curItems, beforeItems, afterItems;
3166          items = self.create(items);
3167          curItems = self.items();
3168          if (!before && index < curItems.length - 1) {
3169            index += 1;
3170          }
3171          if (index >= 0 && index < curItems.length) {
3172            beforeItems = curItems.slice(0, index).toArray();
3173            afterItems = curItems.slice(index).toArray();
3174            curItems.set(beforeItems.concat(items, afterItems));
3175          }
3176          return self.renderNew();
3177        },
3178        fromJSON: function (data) {
3179          var self = this;
3180          for (var name in data) {
3181            self.find('#' + name).value(data[name]);
3182          }
3183          return self;
3184        },
3185        toJSON: function () {
3186          var self = this, data = {};
3187          self.find('*').each(function (ctrl) {
3188            var name = ctrl.name(), value = ctrl.value();
3189            if (name && typeof value !== 'undefined') {
3190              data[name] = value;
3191            }
3192          });
3193          return data;
3194        },
3195        renderHtml: function () {
3196          var self = this, layout = self._layout, role = this.settings.role;
3197          self.preRender();
3198          layout.preRender(self);
3199          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>';
3200        },
3201        postRender: function () {
3202          var self = this;
3203          var box;
3204          self.items().exec('postRender');
3205          self._super();
3206          self._layout.postRender(self);
3207          self.state.set('rendered', true);
3208          if (self.settings.style) {
3209            self.$el.css(self.settings.style);
3210          }
3211          if (self.settings.border) {
3212            box = self.borderBox;
3213            self.$el.css({
3214              'border-top-width': box.top,
3215              'border-right-width': box.right,
3216              'border-bottom-width': box.bottom,
3217              'border-left-width': box.left
3218            });
3219          }
3220          if (!self.parent()) {
3221            self.keyboardNav = KeyboardNavigation({ root: self });
3222          }
3223          return self;
3224        },
3225        initLayoutRect: function () {
3226          var self = this, layoutRect = self._super();
3227          self._layout.recalc(self);
3228          return layoutRect;
3229        },
3230        recalc: function () {
3231          var self = this;
3232          var rect = self._layoutRect;
3233          var lastRect = self._lastRect;
3234          if (!lastRect || lastRect.w !== rect.w || lastRect.h !== rect.h) {
3235            self._layout.recalc(self);
3236            rect = self.layoutRect();
3237            self._lastRect = {
3238              x: rect.x,
3239              y: rect.y,
3240              w: rect.w,
3241              h: rect.h
3242            };
3243            return true;
3244          }
3245        },
3246        reflow: function () {
3247          var i;
3248          ReflowQueue.remove(this);
3249          if (this.visible()) {
3250            Control$1.repaintControls = [];
3251            Control$1.repaintControls.map = {};
3252            this.recalc();
3253            i = Control$1.repaintControls.length;
3254            while (i--) {
3255              Control$1.repaintControls[i].repaint();
3256            }
3257            if (this.settings.layout !== 'flow' && this.settings.layout !== 'stack') {
3258              this.repaint();
3259            }
3260            Control$1.repaintControls = [];
3261          }
3262          return this;
3263        }
3264      });
3265  
3266      function getDocumentSize(doc) {
3267        var documentElement, body, scrollWidth, clientWidth;
3268        var offsetWidth, scrollHeight, clientHeight, offsetHeight;
3269        var max = Math.max;
3270        documentElement = doc.documentElement;
3271        body = doc.body;
3272        scrollWidth = max(documentElement.scrollWidth, body.scrollWidth);
3273        clientWidth = max(documentElement.clientWidth, body.clientWidth);
3274        offsetWidth = max(documentElement.offsetWidth, body.offsetWidth);
3275        scrollHeight = max(documentElement.scrollHeight, body.scrollHeight);
3276        clientHeight = max(documentElement.clientHeight, body.clientHeight);
3277        offsetHeight = max(documentElement.offsetHeight, body.offsetHeight);
3278        return {
3279          width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
3280          height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
3281        };
3282      }
3283      function updateWithTouchData(e) {
3284        var keys, i;
3285        if (e.changedTouches) {
3286          keys = 'screenX screenY pageX pageY clientX clientY'.split(' ');
3287          for (i = 0; i < keys.length; i++) {
3288            e[keys[i]] = e.changedTouches[0][keys[i]];
3289          }
3290        }
3291      }
3292      function DragHelper (id, settings) {
3293        var $eventOverlay;
3294        var doc = settings.document || domGlobals.document;
3295        var downButton;
3296        var start, stop, drag, startX, startY;
3297        settings = settings || {};
3298        var handleElement = doc.getElementById(settings.handle || id);
3299        start = function (e) {
3300          var docSize = getDocumentSize(doc);
3301          var handleElm, cursor;
3302          updateWithTouchData(e);
3303          e.preventDefault();
3304          downButton = e.button;
3305          handleElm = handleElement;
3306          startX = e.screenX;
3307          startY = e.screenY;
3308          if (domGlobals.window.getComputedStyle) {
3309            cursor = domGlobals.window.getComputedStyle(handleElm, null).getPropertyValue('cursor');
3310          } else {
3311            cursor = handleElm.runtimeStyle.cursor;
3312          }
3313          $eventOverlay = global$9('<div></div>').css({
3314            position: 'absolute',
3315            top: 0,
3316            left: 0,
3317            width: docSize.width,
3318            height: docSize.height,
3319            zIndex: 2147483647,
3320            opacity: 0.0001,
3321            cursor: cursor
3322          }).appendTo(doc.body);
3323          global$9(doc).on('mousemove touchmove', drag).on('mouseup touchend', stop);
3324          settings.start(e);
3325        };
3326        drag = function (e) {
3327          updateWithTouchData(e);
3328          if (e.button !== downButton) {
3329            return stop(e);
3330          }
3331          e.deltaX = e.screenX - startX;
3332          e.deltaY = e.screenY - startY;
3333          e.preventDefault();
3334          settings.drag(e);
3335        };
3336        stop = function (e) {
3337          updateWithTouchData(e);
3338          global$9(doc).off('mousemove touchmove', drag).off('mouseup touchend', stop);
3339          $eventOverlay.remove();
3340          if (settings.stop) {
3341            settings.stop(e);
3342          }
3343        };
3344        this.destroy = function () {
3345          global$9(handleElement).off();
3346        };
3347        global$9(handleElement).on('mousedown touchstart', start);
3348      }
3349  
3350      var Scrollable = {
3351        init: function () {
3352          var self = this;
3353          self.on('repaint', self.renderScroll);
3354        },
3355        renderScroll: function () {
3356          var self = this, margin = 2;
3357          function repaintScroll() {
3358            var hasScrollH, hasScrollV, bodyElm;
3359            function repaintAxis(axisName, posName, sizeName, contentSizeName, hasScroll, ax) {
3360              var containerElm, scrollBarElm, scrollThumbElm;
3361              var containerSize, scrollSize, ratio, rect;
3362              var posNameLower, sizeNameLower;
3363              scrollBarElm = self.getEl('scroll' + axisName);
3364              if (scrollBarElm) {
3365                posNameLower = posName.toLowerCase();
3366                sizeNameLower = sizeName.toLowerCase();
3367                global$9(self.getEl('absend')).css(posNameLower, self.layoutRect()[contentSizeName] - 1);
3368                if (!hasScroll) {
3369                  global$9(scrollBarElm).css('display', 'none');
3370                  return;
3371                }
3372                global$9(scrollBarElm).css('display', 'block');
3373                containerElm = self.getEl('body');
3374                scrollThumbElm = self.getEl('scroll' + axisName + 't');
3375                containerSize = containerElm['client' + sizeName] - margin * 2;
3376                containerSize -= hasScrollH && hasScrollV ? scrollBarElm['client' + ax] : 0;
3377                scrollSize = containerElm['scroll' + sizeName];
3378                ratio = containerSize / scrollSize;
3379                rect = {};
3380                rect[posNameLower] = containerElm['offset' + posName] + margin;
3381                rect[sizeNameLower] = containerSize;
3382                global$9(scrollBarElm).css(rect);
3383                rect = {};
3384                rect[posNameLower] = containerElm['scroll' + posName] * ratio;
3385                rect[sizeNameLower] = containerSize * ratio;
3386                global$9(scrollThumbElm).css(rect);
3387              }
3388            }
3389            bodyElm = self.getEl('body');
3390            hasScrollH = bodyElm.scrollWidth > bodyElm.clientWidth;
3391            hasScrollV = bodyElm.scrollHeight > bodyElm.clientHeight;
3392            repaintAxis('h', 'Left', 'Width', 'contentW', hasScrollH, 'Height');
3393            repaintAxis('v', 'Top', 'Height', 'contentH', hasScrollV, 'Width');
3394          }
3395          function addScroll() {
3396            function addScrollAxis(axisName, posName, sizeName, deltaPosName, ax) {
3397              var scrollStart;
3398              var axisId = self._id + '-scroll' + axisName, prefix = self.classPrefix;
3399              global$9(self.getEl()).append('<div id="' + axisId + '" class="' + prefix + 'scrollbar ' + prefix + 'scrollbar-' + axisName + '">' + '<div id="' + axisId + 't" class="' + prefix + 'scrollbar-thumb"></div>' + '</div>');
3400              self.draghelper = new DragHelper(axisId + 't', {
3401                start: function () {
3402                  scrollStart = self.getEl('body')['scroll' + posName];
3403                  global$9('#' + axisId).addClass(prefix + 'active');
3404                },
3405                drag: function (e) {
3406                  var ratio, hasScrollH, hasScrollV, containerSize;
3407                  var layoutRect = self.layoutRect();
3408                  hasScrollH = layoutRect.contentW > layoutRect.innerW;
3409                  hasScrollV = layoutRect.contentH > layoutRect.innerH;
3410                  containerSize = self.getEl('body')['client' + sizeName] - margin * 2;
3411                  containerSize -= hasScrollH && hasScrollV ? self.getEl('scroll' + axisName)['client' + ax] : 0;
3412                  ratio = containerSize / self.getEl('body')['scroll' + sizeName];
3413                  self.getEl('body')['scroll' + posName] = scrollStart + e['delta' + deltaPosName] / ratio;
3414                },
3415                stop: function () {
3416                  global$9('#' + axisId).removeClass(prefix + 'active');
3417                }
3418              });
3419            }
3420            self.classes.add('scroll');
3421            addScrollAxis('v', 'Top', 'Height', 'Y', 'Width');
3422            addScrollAxis('h', 'Left', 'Width', 'X', 'Height');
3423          }
3424          if (self.settings.autoScroll) {
3425            if (!self._hasScroll) {
3426              self._hasScroll = true;
3427              addScroll();
3428              self.on('wheel', function (e) {
3429                var bodyEl = self.getEl('body');
3430                bodyEl.scrollLeft += (e.deltaX || 0) * 10;
3431                bodyEl.scrollTop += e.deltaY * 10;
3432                repaintScroll();
3433              });
3434              global$9(self.getEl('body')).on('scroll', repaintScroll);
3435            }
3436            repaintScroll();
3437          }
3438        }
3439      };
3440  
3441      var Panel = Container.extend({
3442        Defaults: {
3443          layout: 'fit',
3444          containerCls: 'panel'
3445        },
3446        Mixins: [Scrollable],
3447        renderHtml: function () {
3448          var self = this;
3449          var layout = self._layout;
3450          var innerHtml = self.settings.html;
3451          self.preRender();
3452          layout.preRender(self);
3453          if (typeof innerHtml === 'undefined') {
3454            innerHtml = '<div id="' + self._id + '-body" class="' + self.bodyClasses + '">' + layout.renderHtml(self) + '</div>';
3455          } else {
3456            if (typeof innerHtml === 'function') {
3457              innerHtml = innerHtml.call(self);
3458            }
3459            self._hasBody = false;
3460          }
3461          return '<div id="' + self._id + '" class="' + self.classes + '" hidefocus="1" tabindex="-1" role="group">' + (self._preBodyHtml || '') + innerHtml + '</div>';
3462        }
3463      });
3464  
3465      var Resizable = {
3466        resizeToContent: function () {
3467          this._layoutRect.autoResize = true;
3468          this._lastRect = null;
3469          this.reflow();
3470        },
3471        resizeTo: function (w, h) {
3472          if (w <= 1 || h <= 1) {
3473            var rect = funcs.getWindowSize();
3474            w = w <= 1 ? w * rect.w : w;
3475            h = h <= 1 ? h * rect.h : h;
3476          }
3477          this._layoutRect.autoResize = false;
3478          return this.layoutRect({
3479            minW: w,
3480            minH: h,
3481            w: w,
3482            h: h
3483          }).reflow();
3484        },
3485        resizeBy: function (dw, dh) {
3486          var self = this, rect = self.layoutRect();
3487          return self.resizeTo(rect.w + dw, rect.h + dh);
3488        }
3489      };
3490  
3491      var documentClickHandler, documentScrollHandler, windowResizeHandler;
3492      var visiblePanels = [];
3493      var zOrder = [];
3494      var hasModal;
3495      function isChildOf(ctrl, parent) {
3496        while (ctrl) {
3497          if (ctrl === parent) {
3498            return true;
3499          }
3500          ctrl = ctrl.parent();
3501        }
3502      }
3503      function skipOrHidePanels(e) {
3504        var i = visiblePanels.length;
3505        while (i--) {
3506          var panel = visiblePanels[i], clickCtrl = panel.getParentCtrl(e.target);
3507          if (panel.settings.autohide) {
3508            if (clickCtrl) {
3509              if (isChildOf(clickCtrl, panel) || panel.parent() === clickCtrl) {
3510                continue;
3511              }
3512            }
3513            e = panel.fire('autohide', { target: e.target });
3514            if (!e.isDefaultPrevented()) {
3515              panel.hide();
3516            }
3517          }
3518        }
3519      }
3520      function bindDocumentClickHandler() {
3521        if (!documentClickHandler) {
3522          documentClickHandler = function (e) {
3523            if (e.button === 2) {
3524              return;
3525            }
3526            skipOrHidePanels(e);
3527          };
3528          global$9(domGlobals.document).on('click touchstart', documentClickHandler);
3529        }
3530      }
3531      function bindDocumentScrollHandler() {
3532        if (!documentScrollHandler) {
3533          documentScrollHandler = function () {
3534            var i;
3535            i = visiblePanels.length;
3536            while (i--) {
3537              repositionPanel(visiblePanels[i]);
3538            }
3539          };
3540          global$9(domGlobals.window).on('scroll', documentScrollHandler);
3541        }
3542      }
3543      function bindWindowResizeHandler() {
3544        if (!windowResizeHandler) {
3545          var docElm_1 = domGlobals.document.documentElement;
3546          var clientWidth_1 = docElm_1.clientWidth, clientHeight_1 = docElm_1.clientHeight;
3547          windowResizeHandler = function () {
3548            if (!domGlobals.document.all || clientWidth_1 !== docElm_1.clientWidth || clientHeight_1 !== docElm_1.clientHeight) {
3549              clientWidth_1 = docElm_1.clientWidth;
3550              clientHeight_1 = docElm_1.clientHeight;
3551              FloatPanel.hideAll();
3552            }
3553          };
3554          global$9(domGlobals.window).on('resize', windowResizeHandler);
3555        }
3556      }
3557      function repositionPanel(panel) {
3558        var scrollY = funcs.getViewPort().y;
3559        function toggleFixedChildPanels(fixed, deltaY) {
3560          var parent;
3561          for (var i = 0; i < visiblePanels.length; i++) {
3562            if (visiblePanels[i] !== panel) {
3563              parent = visiblePanels[i].parent();
3564              while (parent && (parent = parent.parent())) {
3565                if (parent === panel) {
3566                  visiblePanels[i].fixed(fixed).moveBy(0, deltaY).repaint();
3567                }
3568              }
3569            }
3570          }
3571        }
3572        if (panel.settings.autofix) {
3573          if (!panel.state.get('fixed')) {
3574            panel._autoFixY = panel.layoutRect().y;
3575            if (panel._autoFixY < scrollY) {
3576              panel.fixed(true).layoutRect({ y: 0 }).repaint();
3577              toggleFixedChildPanels(true, scrollY - panel._autoFixY);
3578            }
3579          } else {
3580            if (panel._autoFixY > scrollY) {
3581              panel.fixed(false).layoutRect({ y: panel._autoFixY }).repaint();
3582              toggleFixedChildPanels(false, panel._autoFixY - scrollY);
3583            }
3584          }
3585        }
3586      }
3587      function addRemove(add, ctrl) {
3588        var i, zIndex = FloatPanel.zIndex || 65535, topModal;
3589        if (add) {
3590          zOrder.push(ctrl);
3591        } else {
3592          i = zOrder.length;
3593          while (i--) {
3594            if (zOrder[i] === ctrl) {
3595              zOrder.splice(i, 1);
3596            }
3597          }
3598        }
3599        if (zOrder.length) {
3600          for (i = 0; i < zOrder.length; i++) {
3601            if (zOrder[i].modal) {
3602              zIndex++;
3603              topModal = zOrder[i];
3604            }
3605            zOrder[i].getEl().style.zIndex = zIndex;
3606            zOrder[i].zIndex = zIndex;
3607            zIndex++;
3608          }
3609        }
3610        var modalBlockEl = global$9('#' + ctrl.classPrefix + 'modal-block', ctrl.getContainerElm())[0];
3611        if (topModal) {
3612          global$9(modalBlockEl).css('z-index', topModal.zIndex - 1);
3613        } else if (modalBlockEl) {
3614          modalBlockEl.parentNode.removeChild(modalBlockEl);
3615          hasModal = false;
3616        }
3617        FloatPanel.currentZIndex = zIndex;
3618      }
3619      var FloatPanel = Panel.extend({
3620        Mixins: [
3621          Movable,
3622          Resizable
3623        ],
3624        init: function (settings) {
3625          var self = this;
3626          self._super(settings);
3627          self._eventsRoot = self;
3628          self.classes.add('floatpanel');
3629          if (settings.autohide) {
3630            bindDocumentClickHandler();
3631            bindWindowResizeHandler();
3632            visiblePanels.push(self);
3633          }
3634          if (settings.autofix) {
3635            bindDocumentScrollHandler();
3636            self.on('move', function () {
3637              repositionPanel(this);
3638            });
3639          }
3640          self.on('postrender show', function (e) {
3641            if (e.control === self) {
3642              var $modalBlockEl_1;
3643              var prefix_1 = self.classPrefix;
3644              if (self.modal && !hasModal) {
3645                $modalBlockEl_1 = global$9('#' + prefix_1 + 'modal-block', self.getContainerElm());
3646                if (!$modalBlockEl_1[0]) {
3647                  $modalBlockEl_1 = global$9('<div id="' + prefix_1 + 'modal-block" class="' + prefix_1 + 'reset ' + prefix_1 + 'fade"></div>').appendTo(self.getContainerElm());
3648                }
3649                global$7.setTimeout(function () {
3650                  $modalBlockEl_1.addClass(prefix_1 + 'in');
3651                  global$9(self.getEl()).addClass(prefix_1 + 'in');
3652                });
3653                hasModal = true;
3654              }
3655              addRemove(true, self);
3656            }
3657          });
3658          self.on('show', function () {
3659            self.parents().each(function (ctrl) {
3660              if (ctrl.state.get('fixed')) {
3661                self.fixed(true);
3662                return false;
3663              }
3664            });
3665          });
3666          if (settings.popover) {
3667            self._preBodyHtml = '<div class="' + self.classPrefix + 'arrow"></div>';
3668            self.classes.add('popover').add('bottom').add(self.isRtl() ? 'end' : 'start');
3669          }
3670          self.aria('label', settings.ariaLabel);
3671          self.aria('labelledby', self._id);
3672          self.aria('describedby', self.describedBy || self._id + '-none');
3673        },
3674        fixed: function (state) {
3675          var self = this;
3676          if (self.state.get('fixed') !== state) {
3677            if (self.state.get('rendered')) {
3678              var viewport = funcs.getViewPort();
3679              if (state) {
3680                self.layoutRect().y -= viewport.y;
3681              } else {
3682                self.layoutRect().y += viewport.y;
3683              }
3684            }
3685            self.classes.toggle('fixed', state);
3686            self.state.set('fixed', state);
3687          }
3688          return self;
3689        },
3690        show: function () {
3691          var self = this;
3692          var i;
3693          var state = self._super();
3694          i = visiblePanels.length;
3695          while (i--) {
3696            if (visiblePanels[i] === self) {
3697              break;
3698            }
3699          }
3700          if (i === -1) {
3701            visiblePanels.push(self);
3702          }
3703          return state;
3704        },
3705        hide: function () {
3706          removeVisiblePanel(this);
3707          addRemove(false, this);
3708          return this._super();
3709        },
3710        hideAll: function () {
3711          FloatPanel.hideAll();
3712        },
3713        close: function () {
3714          var self = this;
3715          if (!self.fire('close').isDefaultPrevented()) {
3716            self.remove();
3717            addRemove(false, self);
3718          }
3719          return self;
3720        },
3721        remove: function () {
3722          removeVisiblePanel(this);
3723          this._super();
3724        },
3725        postRender: function () {
3726          var self = this;
3727          if (self.settings.bodyRole) {
3728            this.getEl('body').setAttribute('role', self.settings.bodyRole);
3729          }
3730          return self._super();
3731        }
3732      });
3733      FloatPanel.hideAll = function () {
3734        var i = visiblePanels.length;
3735        while (i--) {
3736          var panel = visiblePanels[i];
3737          if (panel && panel.settings.autohide) {
3738            panel.hide();
3739            visiblePanels.splice(i, 1);
3740          }
3741        }
3742      };
3743      function removeVisiblePanel(panel) {
3744        var i;
3745        i = visiblePanels.length;
3746        while (i--) {
3747          if (visiblePanels[i] === panel) {
3748            visiblePanels.splice(i, 1);
3749          }
3750        }
3751        i = zOrder.length;
3752        while (i--) {
3753          if (zOrder[i] === panel) {
3754            zOrder.splice(i, 1);
3755          }
3756        }
3757      }
3758  
3759      var isFixed$1 = function (inlineToolbarContainer, editor) {
3760        return !!(inlineToolbarContainer && !editor.settings.ui_container);
3761      };
3762      var render$1 = function (editor, theme, args) {
3763        var panel, inlineToolbarContainer;
3764        var DOM = global$3.DOM;
3765        var fixedToolbarContainer = getFixedToolbarContainer(editor);
3766        if (fixedToolbarContainer) {
3767          inlineToolbarContainer = DOM.select(fixedToolbarContainer)[0];
3768        }
3769        var reposition = function () {
3770          if (panel && panel.moveRel && panel.visible() && !panel._fixed) {
3771            var scrollContainer = editor.selection.getScrollContainer(), body = editor.getBody();
3772            var deltaX = 0, deltaY = 0;
3773            if (scrollContainer) {
3774              var bodyPos = DOM.getPos(body), scrollContainerPos = DOM.getPos(scrollContainer);
3775              deltaX = Math.max(0, scrollContainerPos.x - bodyPos.x);
3776              deltaY = Math.max(0, scrollContainerPos.y - bodyPos.y);
3777            }
3778            panel.fixed(false).moveRel(body, editor.rtl ? [
3779              'tr-br',
3780              'br-tr'
3781            ] : [
3782              'tl-bl',
3783              'bl-tl',
3784              'tr-br'
3785            ]).moveBy(deltaX, deltaY);
3786          }
3787        };
3788        var show = function () {
3789          if (panel) {
3790            panel.show();
3791            reposition();
3792            DOM.addClass(editor.getBody(), 'mce-edit-focus');
3793          }
3794        };
3795        var hide = function () {
3796          if (panel) {
3797            panel.hide();
3798            FloatPanel.hideAll();
3799            DOM.removeClass(editor.getBody(), 'mce-edit-focus');
3800          }
3801        };
3802        var render = function () {
3803          if (panel) {
3804            if (!panel.visible()) {
3805              show();
3806            }
3807            return;
3808          }
3809          panel = theme.panel = global$4.create({
3810            type: inlineToolbarContainer ? 'panel' : 'floatpanel',
3811            role: 'application',
3812            classes: 'tinymce tinymce-inline',
3813            layout: 'flex',
3814            direction: 'column',
3815            align: 'stretch',
3816            autohide: false,
3817            autofix: true,
3818            fixed: isFixed$1(inlineToolbarContainer, editor),
3819            border: 1,
3820            items: [
3821              hasMenubar(editor) === false ? null : {
3822                type: 'menubar',
3823                border: '0 0 1 0',
3824                items: Menubar.createMenuButtons(editor)
3825              },
3826              Toolbar.createToolbars(editor, getToolbarSize(editor))
3827            ]
3828          });
3829          UiContainer.setUiContainer(editor, panel);
3830          Events.fireBeforeRenderUI(editor);
3831          if (inlineToolbarContainer) {
3832            panel.renderTo(inlineToolbarContainer).reflow();
3833          } else {
3834            panel.renderTo().reflow();
3835          }
3836          A11y.addKeys(editor, panel);
3837          show();
3838          ContextToolbars.addContextualToolbars(editor);
3839          editor.on('nodeChange', reposition);
3840          editor.on('ResizeWindow', reposition);
3841          editor.on('activate', show);
3842          editor.on('deactivate', hide);
3843          editor.nodeChanged();
3844        };
3845        editor.settings.content_editable = true;
3846        editor.on('focus', function () {
3847          if (isSkinDisabled(editor) === false && args.skinUiCss) {
3848            DOM.styleSheetLoader.load(args.skinUiCss, render, render);
3849          } else {
3850            render();
3851          }
3852        });
3853        editor.on('blur hide', hide);
3854        editor.on('remove', function () {
3855          if (panel) {
3856            panel.remove();
3857            panel = null;
3858          }
3859        });
3860        if (isSkinDisabled(editor) === false && args.skinUiCss) {
3861          DOM.styleSheetLoader.load(args.skinUiCss, SkinLoaded.fireSkinLoaded(editor));
3862        } else {
3863          SkinLoaded.fireSkinLoaded(editor)();
3864        }
3865        return {};
3866      };
3867      var Inline = { render: render$1 };
3868  
3869      function Throbber (elm, inline) {
3870        var self = this;
3871        var state;
3872        var classPrefix = Control$1.classPrefix;
3873        var timer;
3874        self.show = function (time, callback) {
3875          function render() {
3876            if (state) {
3877              global$9(elm).append('<div class="' + classPrefix + 'throbber' + (inline ? ' ' + classPrefix + 'throbber-inline' : '') + '"></div>');
3878              if (callback) {
3879                callback();
3880              }
3881            }
3882          }
3883          self.hide();
3884          state = true;
3885          if (time) {
3886            timer = global$7.setTimeout(render, time);
3887          } else {
3888            render();
3889          }
3890          return self;
3891        };
3892        self.hide = function () {
3893          var child = elm.lastChild;
3894          global$7.clearTimeout(timer);
3895          if (child && child.className.indexOf('throbber') !== -1) {
3896            child.parentNode.removeChild(child);
3897          }
3898          state = false;
3899          return self;
3900        };
3901      }
3902  
3903      var setup = function (editor, theme) {
3904        var throbber;
3905        editor.on('ProgressState', function (e) {
3906          throbber = throbber || new Throbber(theme.panel.getEl('body'));
3907          if (e.state) {
3908            throbber.show(e.time);
3909          } else {
3910            throbber.hide();
3911          }
3912        });
3913      };
3914      var ProgressState = { setup: setup };
3915  
3916      var renderUI = function (editor, theme, args) {
3917        var skinUrl = getSkinUrl(editor);
3918        if (skinUrl) {
3919          args.skinUiCss = skinUrl + '/skin.min.css';
3920          editor.contentCSS.push(skinUrl + '/content' + (editor.inline ? '.inline' : '') + '.min.css');
3921        }
3922        ProgressState.setup(editor, theme);
3923        return isInline(editor) ? Inline.render(editor, theme, args) : Iframe.render(editor, theme, args);
3924      };
3925      var Render = { renderUI: renderUI };
3926  
3927      var Tooltip = Control$1.extend({
3928        Mixins: [Movable],
3929        Defaults: { classes: 'widget tooltip tooltip-n' },
3930        renderHtml: function () {
3931          var self = this, prefix = self.classPrefix;
3932          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>';
3933        },
3934        bindStates: function () {
3935          var self = this;
3936          self.state.on('change:text', function (e) {
3937            self.getEl().lastChild.innerHTML = self.encode(e.value);
3938          });
3939          return self._super();
3940        },
3941        repaint: function () {
3942          var self = this;
3943          var style, rect;
3944          style = self.getEl().style;
3945          rect = self._layoutRect;
3946          style.left = rect.x + 'px';
3947          style.top = rect.y + 'px';
3948          style.zIndex = 65535 + 65535;
3949        }
3950      });
3951  
3952      var Widget = Control$1.extend({
3953        init: function (settings) {
3954          var self = this;
3955          self._super(settings);
3956          settings = self.settings;
3957          self.canFocus = true;
3958          if (settings.tooltip && Widget.tooltips !== false) {
3959            self.on('mouseenter', function (e) {
3960              var tooltip = self.tooltip().moveTo(-65535);
3961              if (e.control === self) {
3962                var rel = tooltip.text(settings.tooltip).show().testMoveRel(self.getEl(), [
3963                  'bc-tc',
3964                  'bc-tl',
3965                  'bc-tr'
3966                ]);
3967                tooltip.classes.toggle('tooltip-n', rel === 'bc-tc');
3968                tooltip.classes.toggle('tooltip-nw', rel === 'bc-tl');
3969                tooltip.classes.toggle('tooltip-ne', rel === 'bc-tr');
3970                tooltip.moveRel(self.getEl(), rel);
3971              } else {
3972                tooltip.hide();
3973              }
3974            });
3975            self.on('mouseleave mousedown click', function () {
3976              self.tooltip().remove();
3977              self._tooltip = null;
3978            });
3979          }
3980          self.aria('label', settings.ariaLabel || settings.tooltip);
3981        },
3982        tooltip: function () {
3983          if (!this._tooltip) {
3984            this._tooltip = new Tooltip({ type: 'tooltip' });
3985            UiContainer.inheritUiContainer(this, this._tooltip);
3986            this._tooltip.renderTo();
3987          }
3988          return this._tooltip;
3989        },
3990        postRender: function () {
3991          var self = this, settings = self.settings;
3992          self._super();
3993          if (!self.parent() && (settings.width || settings.height)) {
3994            self.initLayoutRect();
3995            self.repaint();
3996          }
3997          if (settings.autofocus) {
3998            self.focus();
3999          }
4000        },
4001        bindStates: function () {
4002          var self = this;
4003          function disable(state) {
4004            self.aria('disabled', state);
4005            self.classes.toggle('disabled', state);
4006          }
4007          function active(state) {
4008            self.aria('pressed', state);
4009            self.classes.toggle('active', state);
4010          }
4011          self.state.on('change:disabled', function (e) {
4012            disable(e.value);
4013          });
4014          self.state.on('change:active', function (e) {
4015            active(e.value);
4016          });
4017          if (self.state.get('disabled')) {
4018            disable(true);
4019          }
4020          if (self.state.get('active')) {
4021            active(true);
4022          }
4023          return self._super();
4024        },
4025        remove: function () {
4026          this._super();
4027          if (this._tooltip) {
4028            this._tooltip.remove();
4029            this._tooltip = null;
4030          }
4031        }
4032      });
4033  
4034      var Progress = Widget.extend({
4035        Defaults: { value: 0 },
4036        init: function (settings) {
4037          var self = this;
4038          self._super(settings);
4039          self.classes.add('progress');
4040          if (!self.settings.filter) {
4041            self.settings.filter = function (value) {
4042              return Math.round(value);
4043            };
4044          }
4045        },
4046        renderHtml: function () {
4047          var self = this, id = self._id, prefix = this.classPrefix;
4048          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>';
4049        },
4050        postRender: function () {
4051          var self = this;
4052          self._super();
4053          self.value(self.settings.value);
4054          return self;
4055        },
4056        bindStates: function () {
4057          var self = this;
4058          function setValue(value) {
4059            value = self.settings.filter(value);
4060            self.getEl().lastChild.innerHTML = value + '%';
4061            self.getEl().firstChild.firstChild.style.width = value + '%';
4062          }
4063          self.state.on('change:value', function (e) {
4064            setValue(e.value);
4065          });
4066          setValue(self.state.get('value'));
4067          return self._super();
4068        }
4069      });
4070  
4071      var updateLiveRegion = function (ctx, text) {
4072        ctx.getEl().lastChild.textContent = text + (ctx.progressBar ? ' ' + ctx.progressBar.value() + '%' : '');
4073      };
4074      var Notification = Control$1.extend({
4075        Mixins: [Movable],
4076        Defaults: { classes: 'widget notification' },
4077        init: function (settings) {
4078          var self = this;
4079          self._super(settings);
4080          self.maxWidth = settings.maxWidth;
4081          if (settings.text) {
4082            self.text(settings.text);
4083          }
4084          if (settings.icon) {
4085            self.icon = settings.icon;
4086          }
4087          if (settings.color) {
4088            self.color = settings.color;
4089          }
4090          if (settings.type) {
4091            self.classes.add('notification-' + settings.type);
4092          }
4093          if (settings.timeout && (settings.timeout < 0 || settings.timeout > 0) && !settings.closeButton) {
4094            self.closeButton = false;
4095          } else {
4096            self.classes.add('has-close');
4097            self.closeButton = true;
4098          }
4099          if (settings.progressBar) {
4100            self.progressBar = new Progress();
4101          }
4102          self.on('click', function (e) {
4103            if (e.target.className.indexOf(self.classPrefix + 'close') !== -1) {
4104              self.close();
4105            }
4106          });
4107        },
4108        renderHtml: function () {
4109          var self = this;
4110          var prefix = self.classPrefix;
4111          var icon = '', closeButton = '', progressBar = '', notificationStyle = '';
4112          if (self.icon) {
4113            icon = '<i class="' + prefix + 'ico' + ' ' + prefix + 'i-' + self.icon + '"></i>';
4114          }
4115          notificationStyle = ' style="max-width: ' + self.maxWidth + 'px;' + (self.color ? 'background-color: ' + self.color + ';"' : '"');
4116          if (self.closeButton) {
4117            closeButton = '<button type="button" class="' + prefix + 'close" aria-hidden="true">\xD7</button>';
4118          }
4119          if (self.progressBar) {
4120            progressBar = self.progressBar.renderHtml();
4121          }
4122          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>';
4123        },
4124        postRender: function () {
4125          var self = this;
4126          global$7.setTimeout(function () {
4127            self.$el.addClass(self.classPrefix + 'in');
4128            updateLiveRegion(self, self.state.get('text'));
4129          }, 100);
4130          return self._super();
4131        },
4132        bindStates: function () {
4133          var self = this;
4134          self.state.on('change:text', function (e) {
4135            self.getEl().firstChild.innerHTML = e.value;
4136            updateLiveRegion(self, e.value);
4137          });
4138          if (self.progressBar) {
4139            self.progressBar.bindStates();
4140            self.progressBar.state.on('change:value', function (e) {
4141              updateLiveRegion(self, self.state.get('text'));
4142            });
4143          }
4144          return self._super();
4145        },
4146        close: function () {
4147          var self = this;
4148          if (!self.fire('close').isDefaultPrevented()) {
4149            self.remove();
4150          }
4151          return self;
4152        },
4153        repaint: function () {
4154          var self = this;
4155          var style, rect;
4156          style = self.getEl().style;
4157          rect = self._layoutRect;
4158          style.left = rect.x + 'px';
4159          style.top = rect.y + 'px';
4160          style.zIndex = 65535 - 1;
4161        }
4162      });
4163  
4164      function NotificationManagerImpl (editor) {
4165        var getEditorContainer = function (editor) {
4166          return editor.inline ? editor.getElement() : editor.getContentAreaContainer();
4167        };
4168        var getContainerWidth = function () {
4169          var container = getEditorContainer(editor);
4170          return funcs.getSize(container).width;
4171        };
4172        var prePositionNotifications = function (notifications) {
4173          each(notifications, function (notification) {
4174            notification.moveTo(0, 0);
4175          });
4176        };
4177        var positionNotifications = function (notifications) {
4178          if (notifications.length > 0) {
4179            var firstItem = notifications.slice(0, 1)[0];
4180            var container = getEditorContainer(editor);
4181            firstItem.moveRel(container, 'tc-tc');
4182            each(notifications, function (notification, index) {
4183              if (index > 0) {
4184                notification.moveRel(notifications[index - 1].getEl(), 'bc-tc');
4185              }
4186            });
4187          }
4188        };
4189        var reposition = function (notifications) {
4190          prePositionNotifications(notifications);
4191          positionNotifications(notifications);
4192        };
4193        var open = function (args, closeCallback) {
4194          var extendedArgs = global$2.extend(args, { maxWidth: getContainerWidth() });
4195          var notif = new Notification(extendedArgs);
4196          notif.args = extendedArgs;
4197          if (extendedArgs.timeout > 0) {
4198            notif.timer = setTimeout(function () {
4199              notif.close();
4200              closeCallback();
4201            }, extendedArgs.timeout);
4202          }
4203          notif.on('close', function () {
4204            closeCallback();
4205          });
4206          notif.renderTo();
4207          return notif;
4208        };
4209        var close = function (notification) {
4210          notification.close();
4211        };
4212        var getArgs = function (notification) {
4213          return notification.args;
4214        };
4215        return {
4216          open: open,
4217          close: close,
4218          reposition: reposition,
4219          getArgs: getArgs
4220        };
4221      }
4222  
4223      var windows = [];
4224      var oldMetaValue = '';
4225      function toggleFullScreenState(state) {
4226        var noScaleMetaValue = 'width=device-width,initial-scale=1.0,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0';
4227        var viewport = global$9('meta[name=viewport]')[0], contentValue;
4228        if (global$8.overrideViewPort === false) {
4229          return;
4230        }
4231        if (!viewport) {
4232          viewport = domGlobals.document.createElement('meta');
4233          viewport.setAttribute('name', 'viewport');
4234          domGlobals.document.getElementsByTagName('head')[0].appendChild(viewport);
4235        }
4236        contentValue = viewport.getAttribute('content');
4237        if (contentValue && typeof oldMetaValue !== 'undefined') {
4238          oldMetaValue = contentValue;
4239        }
4240        viewport.setAttribute('content', state ? noScaleMetaValue : oldMetaValue);
4241      }
4242      function toggleBodyFullScreenClasses(classPrefix, state) {
4243        if (checkFullscreenWindows() && state === false) {
4244          global$9([
4245            domGlobals.document.documentElement,
4246            domGlobals.document.body
4247          ]).removeClass(classPrefix + 'fullscreen');
4248        }
4249      }
4250      function checkFullscreenWindows() {
4251        for (var i = 0; i < windows.length; i++) {
4252          if (windows[i]._fullscreen) {
4253            return true;
4254          }
4255        }
4256        return false;
4257      }
4258      function handleWindowResize() {
4259        if (!global$8.desktop) {
4260          var lastSize_1 = {
4261            w: domGlobals.window.innerWidth,
4262            h: domGlobals.window.innerHeight
4263          };
4264          global$7.setInterval(function () {
4265            var w = domGlobals.window.innerWidth, h = domGlobals.window.innerHeight;
4266            if (lastSize_1.w !== w || lastSize_1.h !== h) {
4267              lastSize_1 = {
4268                w: w,
4269                h: h
4270              };
4271              global$9(domGlobals.window).trigger('resize');
4272            }
4273          }, 100);
4274        }
4275        function reposition() {
4276          var i;
4277          var rect = funcs.getWindowSize();
4278          var layoutRect;
4279          for (i = 0; i < windows.length; i++) {
4280            layoutRect = windows[i].layoutRect();
4281            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));
4282          }
4283        }
4284        global$9(domGlobals.window).on('resize', reposition);
4285      }
4286      var Window = FloatPanel.extend({
4287        modal: true,
4288        Defaults: {
4289          border: 1,
4290          layout: 'flex',
4291          containerCls: 'panel',
4292          role: 'dialog',
4293          callbacks: {
4294            submit: function () {
4295              this.fire('submit', { data: this.toJSON() });
4296            },
4297            close: function () {
4298              this.close();
4299            }
4300          }
4301        },
4302        init: function (settings) {
4303          var self = this;
4304          self._super(settings);
4305          if (self.isRtl()) {
4306            self.classes.add('rtl');
4307          }
4308          self.classes.add('window');
4309          self.bodyClasses.add('window-body');
4310          self.state.set('fixed', true);
4311          if (settings.buttons) {
4312            self.statusbar = new Panel({
4313              layout: 'flex',
4314              border: '1 0 0 0',
4315              spacing: 3,
4316              padding: 10,
4317              align: 'center',
4318              pack: self.isRtl() ? 'start' : 'end',
4319              defaults: { type: 'button' },
4320              items: settings.buttons
4321            });
4322            self.statusbar.classes.add('foot');
4323            self.statusbar.parent(self);
4324          }
4325          self.on('click', function (e) {
4326            var closeClass = self.classPrefix + 'close';
4327            if (funcs.hasClass(e.target, closeClass) || funcs.hasClass(e.target.parentNode, closeClass)) {
4328              self.close();
4329            }
4330          });
4331          self.on('cancel', function () {
4332            self.close();
4333          });
4334          self.on('move', function (e) {
4335            if (e.control === self) {
4336              FloatPanel.hideAll();
4337            }
4338          });
4339          self.aria('describedby', self.describedBy || self._id + '-none');
4340          self.aria('label', settings.title);
4341          self._fullscreen = false;
4342        },
4343        recalc: function () {
4344          var self = this;
4345          var statusbar = self.statusbar;
4346          var layoutRect, width, x, needsRecalc;
4347          if (self._fullscreen) {
4348            self.layoutRect(funcs.getWindowSize());
4349            self.layoutRect().contentH = self.layoutRect().innerH;
4350          }
4351          self._super();
4352          layoutRect = self.layoutRect();
4353          if (self.settings.title && !self._fullscreen) {
4354            width = layoutRect.headerW;
4355            if (width > layoutRect.w) {
4356              x = layoutRect.x - Math.max(0, width / 2);
4357              self.layoutRect({
4358                w: width,
4359                x: x
4360              });
4361              needsRecalc = true;
4362            }
4363          }
4364          if (statusbar) {
4365            statusbar.layoutRect({ w: self.layoutRect().innerW }).recalc();
4366            width = statusbar.layoutRect().minW + layoutRect.deltaW;
4367            if (width > layoutRect.w) {
4368              x = layoutRect.x - Math.max(0, width - layoutRect.w);
4369              self.layoutRect({
4370                w: width,
4371                x: x
4372              });
4373              needsRecalc = true;
4374            }
4375          }
4376          if (needsRecalc) {
4377            self.recalc();
4378          }
4379        },
4380        initLayoutRect: function () {
4381          var self = this;
4382          var layoutRect = self._super();
4383          var deltaH = 0, headEl;
4384          if (self.settings.title && !self._fullscreen) {
4385            headEl = self.getEl('head');
4386            var size = funcs.getSize(headEl);
4387            layoutRect.headerW = size.width;
4388            layoutRect.headerH = size.height;
4389            deltaH += layoutRect.headerH;
4390          }
4391          if (self.statusbar) {
4392            deltaH += self.statusbar.layoutRect().h;
4393          }
4394          layoutRect.deltaH += deltaH;
4395          layoutRect.minH += deltaH;
4396          layoutRect.h += deltaH;
4397          var rect = funcs.getWindowSize();
4398          layoutRect.x = self.settings.x || Math.max(0, rect.w / 2 - layoutRect.w / 2);
4399          layoutRect.y = self.settings.y || Math.max(0, rect.h / 2 - layoutRect.h / 2);
4400          return layoutRect;
4401        },
4402        renderHtml: function () {
4403          var self = this, layout = self._layout, id = self._id, prefix = self.classPrefix;
4404          var settings = self.settings;
4405          var headerHtml = '', footerHtml = '', html = settings.html;
4406          self.preRender();
4407          layout.preRender(self);
4408          if (settings.title) {
4409            headerHtml = '<div id="' + id + '-head" class="' + prefix + 'window-head">' + '<div id="' + id + '-title" class="' + prefix + 'title">' + self.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>';
4410          }
4411          if (settings.url) {
4412            html = '<iframe src="' + settings.url + '" tabindex="-1"></iframe>';
4413          }
4414          if (typeof html === 'undefined') {
4415            html = layout.renderHtml(self);
4416          }
4417          if (self.statusbar) {
4418            footerHtml = self.statusbar.renderHtml();
4419          }
4420          return '<div id="' + id + '" class="' + self.classes + '" hidefocus="1">' + '<div class="' + self.classPrefix + 'reset" role="application">' + headerHtml + '<div id="' + id + '-body" class="' + self.bodyClasses + '">' + html + '</div>' + footerHtml + '</div>' + '</div>';
4421        },
4422        fullscreen: function (state) {
4423          var self = this;
4424          var documentElement = domGlobals.document.documentElement;
4425          var slowRendering;
4426          var prefix = self.classPrefix;
4427          var layoutRect;
4428          if (state !== self._fullscreen) {
4429            global$9(domGlobals.window).on('resize', function () {
4430              var time;
4431              if (self._fullscreen) {
4432                if (!slowRendering) {
4433                  time = new Date().getTime();
4434                  var rect = funcs.getWindowSize();
4435                  self.moveTo(0, 0).resizeTo(rect.w, rect.h);
4436                  if (new Date().getTime() - time > 50) {
4437                    slowRendering = true;
4438                  }
4439                } else {
4440                  if (!self._timer) {
4441                    self._timer = global$7.setTimeout(function () {
4442                      var rect = funcs.getWindowSize();
4443                      self.moveTo(0, 0).resizeTo(rect.w, rect.h);
4444                      self._timer = 0;
4445                    }, 50);
4446                  }
4447                }
4448              }
4449            });
4450            layoutRect = self.layoutRect();
4451            self._fullscreen = state;
4452            if (!state) {
4453              self.borderBox = BoxUtils.parseBox(self.settings.border);
4454              self.getEl('head').style.display = '';
4455              layoutRect.deltaH += layoutRect.headerH;
4456              global$9([
4457                documentElement,
4458                domGlobals.document.body
4459              ]).removeClass(prefix + 'fullscreen');
4460              self.classes.remove('fullscreen');
4461              self.moveTo(self._initial.x, self._initial.y).resizeTo(self._initial.w, self._initial.h);
4462            } else {
4463              self._initial = {
4464                x: layoutRect.x,
4465                y: layoutRect.y,
4466                w: layoutRect.w,
4467                h: layoutRect.h
4468              };
4469              self.borderBox = BoxUtils.parseBox('0');
4470              self.getEl('head').style.display = 'none';
4471              layoutRect.deltaH -= layoutRect.headerH + 2;
4472              global$9([
4473                documentElement,
4474                domGlobals.document.body
4475              ]).addClass(prefix + 'fullscreen');
4476              self.classes.add('fullscreen');
4477              var rect = funcs.getWindowSize();
4478              self.moveTo(0, 0).resizeTo(rect.w, rect.h);
4479            }
4480          }
4481          return self.reflow();
4482        },
4483        postRender: function () {
4484          var self = this;
4485          var startPos;
4486          setTimeout(function () {
4487            self.classes.add('in');
4488            self.fire('open');
4489          }, 0);
4490          self._super();
4491          if (self.statusbar) {
4492            self.statusbar.postRender();
4493          }
4494          self.focus();
4495          this.dragHelper = new DragHelper(self._id + '-dragh', {
4496            start: function () {
4497              startPos = {
4498                x: self.layoutRect().x,
4499                y: self.layoutRect().y
4500              };
4501            },
4502            drag: function (e) {
4503              self.moveTo(startPos.x + e.deltaX, startPos.y + e.deltaY);
4504            }
4505          });
4506          self.on('submit', function (e) {
4507            if (!e.isDefaultPrevented()) {
4508              self.close();
4509            }
4510          });
4511          windows.push(self);
4512          toggleFullScreenState(true);
4513        },
4514        submit: function () {
4515          return this.fire('submit', { data: this.toJSON() });
4516        },
4517        remove: function () {
4518          var self = this;
4519          var i;
4520          self.dragHelper.destroy();
4521          self._super();
4522          if (self.statusbar) {
4523            this.statusbar.remove();
4524          }
4525          toggleBodyFullScreenClasses(self.classPrefix, false);
4526          i = windows.length;
4527          while (i--) {
4528            if (windows[i] === self) {
4529              windows.splice(i, 1);
4530            }
4531          }
4532          toggleFullScreenState(windows.length > 0);
4533        },
4534        getContentWindow: function () {
4535          var ifr = this.getEl().getElementsByTagName('iframe')[0];
4536          return ifr ? ifr.contentWindow : null;
4537        }
4538      });
4539      handleWindowResize();
4540  
4541      var MessageBox = Window.extend({
4542        init: function (settings) {
4543          settings = {
4544            border: 1,
4545            padding: 20,
4546            layout: 'flex',
4547            pack: 'center',
4548            align: 'center',
4549            containerCls: 'panel',
4550            autoScroll: true,
4551            buttons: {
4552              type: 'button',
4553              text: 'Ok',
4554              action: 'ok'
4555            },
4556            items: {
4557              type: 'label',
4558              multiline: true,
4559              maxWidth: 500,
4560              maxHeight: 200
4561            }
4562          };
4563          this._super(settings);
4564        },
4565        Statics: {
4566          OK: 1,
4567          OK_CANCEL: 2,
4568          YES_NO: 3,
4569          YES_NO_CANCEL: 4,
4570          msgBox: function (settings) {
4571            var buttons;
4572            var callback = settings.callback || function () {
4573            };
4574            function createButton(text, status, primary) {
4575              return {
4576                type: 'button',
4577                text: text,
4578                subtype: primary ? 'primary' : '',
4579                onClick: function (e) {
4580                  e.control.parents()[1].close();
4581                  callback(status);
4582                }
4583              };
4584            }
4585            switch (settings.buttons) {
4586            case MessageBox.OK_CANCEL:
4587              buttons = [
4588                createButton('Ok', true, true),
4589                createButton('Cancel', false)
4590              ];
4591              break;
4592            case MessageBox.YES_NO:
4593            case MessageBox.YES_NO_CANCEL:
4594              buttons = [
4595                createButton('Yes', 1, true),
4596                createButton('No', 0)
4597              ];
4598              if (settings.buttons === MessageBox.YES_NO_CANCEL) {
4599                buttons.push(createButton('Cancel', -1));
4600              }
4601              break;
4602            default:
4603              buttons = [createButton('Ok', true, true)];
4604              break;
4605            }
4606            return new Window({
4607              padding: 20,
4608              x: settings.x,
4609              y: settings.y,
4610              minWidth: 300,
4611              minHeight: 100,
4612              layout: 'flex',
4613              pack: 'center',
4614              align: 'center',
4615              buttons: buttons,
4616              title: settings.title,
4617              role: 'alertdialog',
4618              items: {
4619                type: 'label',
4620                multiline: true,
4621                maxWidth: 500,
4622                maxHeight: 200,
4623                text: settings.text
4624              },
4625              onPostRender: function () {
4626                this.aria('describedby', this.items()[0]._id);
4627              },
4628              onClose: settings.onClose,
4629              onCancel: function () {
4630                callback(false);
4631              }
4632            }).renderTo(domGlobals.document.body).reflow();
4633          },
4634          alert: function (settings, callback) {
4635            if (typeof settings === 'string') {
4636              settings = { text: settings };
4637            }
4638            settings.callback = callback;
4639            return MessageBox.msgBox(settings);
4640          },
4641          confirm: function (settings, callback) {
4642            if (typeof settings === 'string') {
4643              settings = { text: settings };
4644            }
4645            settings.callback = callback;
4646            settings.buttons = MessageBox.OK_CANCEL;
4647            return MessageBox.msgBox(settings);
4648          }
4649        }
4650      });
4651  
4652      function WindowManagerImpl (editor) {
4653        var open = function (args, params, closeCallback) {
4654          var win;
4655          args.title = args.title || ' ';
4656          args.url = args.url || args.file;
4657          if (args.url) {
4658            args.width = parseInt(args.width || 320, 10);
4659            args.height = parseInt(args.height || 240, 10);
4660          }
4661          if (args.body) {
4662            args.items = {
4663              defaults: args.defaults,
4664              type: args.bodyType || 'form',
4665              items: args.body,
4666              data: args.data,
4667              callbacks: args.commands
4668            };
4669          }
4670          if (!args.url && !args.buttons) {
4671            args.buttons = [
4672              {
4673                text: 'Ok',
4674                subtype: 'primary',
4675                onclick: function () {
4676                  win.find('form')[0].submit();
4677                }
4678              },
4679              {
4680                text: 'Cancel',
4681                onclick: function () {
4682                  win.close();
4683                }
4684              }
4685            ];
4686          }
4687          win = new Window(args);
4688          win.on('close', function () {
4689            closeCallback(win);
4690          });
4691          if (args.data) {
4692            win.on('postRender', function () {
4693              this.find('*').each(function (ctrl) {
4694                var name = ctrl.name();
4695                if (name in args.data) {
4696                  ctrl.value(args.data[name]);
4697                }
4698              });
4699            });
4700          }
4701          win.features = args || {};
4702          win.params = params || {};
4703          win = win.renderTo(domGlobals.document.body).reflow();
4704          return win;
4705        };
4706        var alert = function (message, choiceCallback, closeCallback) {
4707          var win;
4708          win = MessageBox.alert(message, function () {
4709            choiceCallback();
4710          });
4711          win.on('close', function () {
4712            closeCallback(win);
4713          });
4714          return win;
4715        };
4716        var confirm = function (message, choiceCallback, closeCallback) {
4717          var win;
4718          win = MessageBox.confirm(message, function (state) {
4719            choiceCallback(state);
4720          });
4721          win.on('close', function () {
4722            closeCallback(win);
4723          });
4724          return win;
4725        };
4726        var close = function (window) {
4727          window.close();
4728        };
4729        var getParams = function (window) {
4730          return window.params;
4731        };
4732        var setParams = function (window, params) {
4733          window.params = params;
4734        };
4735        return {
4736          open: open,
4737          alert: alert,
4738          confirm: confirm,
4739          close: close,
4740          getParams: getParams,
4741          setParams: setParams
4742        };
4743      }
4744  
4745      var get = function (editor) {
4746        var renderUI = function (args) {
4747          return Render.renderUI(editor, this, args);
4748        };
4749        var resizeTo = function (w, h) {
4750          return Resize.resizeTo(editor, w, h);
4751        };
4752        var resizeBy = function (dw, dh) {
4753          return Resize.resizeBy(editor, dw, dh);
4754        };
4755        var getNotificationManagerImpl = function () {
4756          return NotificationManagerImpl(editor);
4757        };
4758        var getWindowManagerImpl = function () {
4759          return WindowManagerImpl();
4760        };
4761        return {
4762          renderUI: renderUI,
4763          resizeTo: resizeTo,
4764          resizeBy: resizeBy,
4765          getNotificationManagerImpl: getNotificationManagerImpl,
4766          getWindowManagerImpl: getWindowManagerImpl
4767        };
4768      };
4769      var ThemeApi = { get: get };
4770  
4771      var Layout = global$a.extend({
4772        Defaults: {
4773          firstControlClass: 'first',
4774          lastControlClass: 'last'
4775        },
4776        init: function (settings) {
4777          this.settings = global$2.extend({}, this.Defaults, settings);
4778        },
4779        preRender: function (container) {
4780          container.bodyClasses.add(this.settings.containerClass);
4781        },
4782        applyClasses: function (items) {
4783          var self = this;
4784          var settings = self.settings;
4785          var firstClass, lastClass, firstItem, lastItem;
4786          firstClass = settings.firstControlClass;
4787          lastClass = settings.lastControlClass;
4788          items.each(function (item) {
4789            item.classes.remove(firstClass).remove(lastClass).add(settings.controlClass);
4790            if (item.visible()) {
4791              if (!firstItem) {
4792                firstItem = item;
4793              }
4794              lastItem = item;
4795            }
4796          });
4797          if (firstItem) {
4798            firstItem.classes.add(firstClass);
4799          }
4800          if (lastItem) {
4801            lastItem.classes.add(lastClass);
4802          }
4803        },
4804        renderHtml: function (container) {
4805          var self = this;
4806          var html = '';
4807          self.applyClasses(container.items());
4808          container.items().each(function (item) {
4809            html += item.renderHtml();
4810          });
4811          return html;
4812        },
4813        recalc: function () {
4814        },
4815        postRender: function () {
4816        },
4817        isNative: function () {
4818          return false;
4819        }
4820      });
4821  
4822      var AbsoluteLayout = Layout.extend({
4823        Defaults: {
4824          containerClass: 'abs-layout',
4825          controlClass: 'abs-layout-item'
4826        },
4827        recalc: function (container) {
4828          container.items().filter(':visible').each(function (ctrl) {
4829            var settings = ctrl.settings;
4830            ctrl.layoutRect({
4831              x: settings.x,
4832              y: settings.y,
4833              w: settings.w,
4834              h: settings.h
4835            });
4836            if (ctrl.recalc) {
4837              ctrl.recalc();
4838            }
4839          });
4840        },
4841        renderHtml: function (container) {
4842          return '<div id="' + container._id + '-absend" class="' + container.classPrefix + 'abs-end"></div>' + this._super(container);
4843        }
4844      });
4845  
4846      var Button = Widget.extend({
4847        Defaults: {
4848          classes: 'widget btn',
4849          role: 'button'
4850        },
4851        init: function (settings) {
4852          var self = this;
4853          var size;
4854          self._super(settings);
4855          settings = self.settings;
4856          size = self.settings.size;
4857          self.on('click mousedown', function (e) {
4858            e.preventDefault();
4859          });
4860          self.on('touchstart', function (e) {
4861            self.fire('click', e);
4862            e.preventDefault();
4863          });
4864          if (settings.subtype) {
4865            self.classes.add(settings.subtype);
4866          }
4867          if (size) {
4868            self.classes.add('btn-' + size);
4869          }
4870          if (settings.icon) {
4871            self.icon(settings.icon);
4872          }
4873        },
4874        icon: function (icon) {
4875          if (!arguments.length) {
4876            return this.state.get('icon');
4877          }
4878          this.state.set('icon', icon);
4879          return this;
4880        },
4881        repaint: function () {
4882          var btnElm = this.getEl().firstChild;
4883          var btnStyle;
4884          if (btnElm) {
4885            btnStyle = btnElm.style;
4886            btnStyle.width = btnStyle.height = '100%';
4887          }
4888          this._super();
4889        },
4890        renderHtml: function () {
4891          var self = this, id = self._id, prefix = self.classPrefix;
4892          var icon = self.state.get('icon'), image;
4893          var text = self.state.get('text');
4894          var textHtml = '';
4895          var ariaPressed;
4896          var settings = self.settings;
4897          image = settings.image;
4898          if (image) {
4899            icon = 'none';
4900            if (typeof image !== 'string') {
4901              image = domGlobals.window.getSelection ? image[0] : image[1];
4902            }
4903            image = ' style="background-image: url(\'' + image + '\')"';
4904          } else {
4905            image = '';
4906          }
4907          if (text) {
4908            self.classes.add('btn-has-text');
4909            textHtml = '<span class="' + prefix + 'txt">' + self.encode(text) + '</span>';
4910          }
4911          icon = icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
4912          ariaPressed = typeof settings.active === 'boolean' ? ' aria-pressed="' + settings.active + '"' : '';
4913          return '<div id="' + id + '" class="' + self.classes + '" tabindex="-1"' + ariaPressed + '>' + '<button id="' + id + '-button" role="presentation" type="button" tabindex="-1">' + (icon ? '<i class="' + icon + '"' + image + '></i>' : '') + textHtml + '</button>' + '</div>';
4914        },
4915        bindStates: function () {
4916          var self = this, $ = self.$, textCls = self.classPrefix + 'txt';
4917          function setButtonText(text) {
4918            var $span = $('span.' + textCls, self.getEl());
4919            if (text) {
4920              if (!$span[0]) {
4921                $('button:first', self.getEl()).append('<span class="' + textCls + '"></span>');
4922                $span = $('span.' + textCls, self.getEl());
4923              }
4924              $span.html(self.encode(text));
4925            } else {
4926              $span.remove();
4927            }
4928            self.classes.toggle('btn-has-text', !!text);
4929          }
4930          self.state.on('change:text', function (e) {
4931            setButtonText(e.value);
4932          });
4933          self.state.on('change:icon', function (e) {
4934            var icon = e.value;
4935            var prefix = self.classPrefix;
4936            self.settings.icon = icon;
4937            icon = icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
4938            var btnElm = self.getEl().firstChild;
4939            var iconElm = btnElm.getElementsByTagName('i')[0];
4940            if (icon) {
4941              if (!iconElm || iconElm !== btnElm.firstChild) {
4942                iconElm = domGlobals.document.createElement('i');
4943                btnElm.insertBefore(iconElm, btnElm.firstChild);
4944              }
4945              iconElm.className = icon;
4946            } else if (iconElm) {
4947              btnElm.removeChild(iconElm);
4948            }
4949            setButtonText(self.state.get('text'));
4950          });
4951          return self._super();
4952        }
4953      });
4954  
4955      var BrowseButton = Button.extend({
4956        init: function (settings) {
4957          var self = this;
4958          settings = global$2.extend({
4959            text: 'Browse...',
4960            multiple: false,
4961            accept: null
4962          }, settings);
4963          self._super(settings);
4964          self.classes.add('browsebutton');
4965          if (settings.multiple) {
4966            self.classes.add('multiple');
4967          }
4968        },
4969        postRender: function () {
4970          var self = this;
4971          var input = funcs.create('input', {
4972            type: 'file',
4973            id: self._id + '-browse',
4974            accept: self.settings.accept
4975          });
4976          self._super();
4977          global$9(input).on('change', function (e) {
4978            var files = e.target.files;
4979            self.value = function () {
4980              if (!files.length) {
4981                return null;
4982              } else if (self.settings.multiple) {
4983                return files;
4984              } else {
4985                return files[0];
4986              }
4987            };
4988            e.preventDefault();
4989            if (files.length) {
4990              self.fire('change', e);
4991            }
4992          });
4993          global$9(input).on('click', function (e) {
4994            e.stopPropagation();
4995          });
4996          global$9(self.getEl('button')).on('click touchstart', function (e) {
4997            e.stopPropagation();
4998            input.click();
4999            e.preventDefault();
5000          });
5001          self.getEl().appendChild(input);
5002        },
5003        remove: function () {
5004          global$9(this.getEl('button')).off();
5005          global$9(this.getEl('input')).off();
5006          this._super();
5007        }
5008      });
5009  
5010      var ButtonGroup = Container.extend({
5011        Defaults: {
5012          defaultType: 'button',
5013          role: 'group'
5014        },
5015        renderHtml: function () {
5016          var self = this, layout = self._layout;
5017          self.classes.add('btn-group');
5018          self.preRender();
5019          layout.preRender(self);
5020          return '<div id="' + self._id + '" class="' + self.classes + '">' + '<div id="' + self._id + '-body">' + (self.settings.html || '') + layout.renderHtml(self) + '</div>' + '</div>';
5021        }
5022      });
5023  
5024      var Checkbox = Widget.extend({
5025        Defaults: {
5026          classes: 'checkbox',
5027          role: 'checkbox',
5028          checked: false
5029        },
5030        init: function (settings) {
5031          var self = this;
5032          self._super(settings);
5033          self.on('click mousedown', function (e) {
5034            e.preventDefault();
5035          });
5036          self.on('click', function (e) {
5037            e.preventDefault();
5038            if (!self.disabled()) {
5039              self.checked(!self.checked());
5040            }
5041          });
5042          self.checked(self.settings.checked);
5043        },
5044        checked: function (state) {
5045          if (!arguments.length) {
5046            return this.state.get('checked');
5047          }
5048          this.state.set('checked', state);
5049          return this;
5050        },
5051        value: function (state) {
5052          if (!arguments.length) {
5053            return this.checked();
5054          }
5055          return this.checked(state);
5056        },
5057        renderHtml: function () {
5058          var self = this, id = self._id, prefix = self.classPrefix;
5059          return '<div id="' + id + '" class="' + self.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.encode(self.state.get('text')) + '</span>' + '</div>';
5060        },
5061        bindStates: function () {
5062          var self = this;
5063          function checked(state) {
5064            self.classes.toggle('checked', state);
5065            self.aria('checked', state);
5066          }
5067          self.state.on('change:text', function (e) {
5068            self.getEl('al').firstChild.data = self.translate(e.value);
5069          });
5070          self.state.on('change:checked change:value', function (e) {
5071            self.fire('change');
5072            checked(e.value);
5073          });
5074          self.state.on('change:icon', function (e) {
5075            var icon = e.value;
5076            var prefix = self.classPrefix;
5077            if (typeof icon === 'undefined') {
5078              return self.settings.icon;
5079            }
5080            self.settings.icon = icon;
5081            icon = icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
5082            var btnElm = self.getEl().firstChild;
5083            var iconElm = btnElm.getElementsByTagName('i')[0];
5084            if (icon) {
5085              if (!iconElm || iconElm !== btnElm.firstChild) {
5086                iconElm = domGlobals.document.createElement('i');
5087                btnElm.insertBefore(iconElm, btnElm.firstChild);
5088              }
5089              iconElm.className = icon;
5090            } else if (iconElm) {
5091              btnElm.removeChild(iconElm);
5092            }
5093          });
5094          if (self.state.get('checked')) {
5095            checked(true);
5096          }
5097          return self._super();
5098        }
5099      });
5100  
5101      var global$d = tinymce.util.Tools.resolve('tinymce.util.VK');
5102  
5103      var ComboBox = Widget.extend({
5104        init: function (settings) {
5105          var self = this;
5106          self._super(settings);
5107          settings = self.settings;
5108          self.classes.add('combobox');
5109          self.subinput = true;
5110          self.ariaTarget = 'inp';
5111          settings.menu = settings.menu || settings.values;
5112          if (settings.menu) {
5113            settings.icon = 'caret';
5114          }
5115          self.on('click', function (e) {
5116            var elm = e.target;
5117            var root = self.getEl();
5118            if (!global$9.contains(root, elm) && elm !== root) {
5119              return;
5120            }
5121            while (elm && elm !== root) {
5122              if (elm.id && elm.id.indexOf('-open') !== -1) {
5123                self.fire('action');
5124                if (settings.menu) {
5125                  self.showMenu();
5126                  if (e.aria) {
5127                    self.menu.items()[0].focus();
5128                  }
5129                }
5130              }
5131              elm = elm.parentNode;
5132            }
5133          });
5134          self.on('keydown', function (e) {
5135            var rootControl;
5136            if (e.keyCode === 13 && e.target.nodeName === 'INPUT') {
5137              e.preventDefault();
5138              self.parents().reverse().each(function (ctrl) {
5139                if (ctrl.toJSON) {
5140                  rootControl = ctrl;
5141                  return false;
5142                }
5143              });
5144              self.fire('submit', { data: rootControl.toJSON() });
5145            }
5146          });
5147          self.on('keyup', function (e) {
5148            if (e.target.nodeName === 'INPUT') {
5149              var oldValue = self.state.get('value');
5150              var newValue = e.target.value;
5151              if (newValue !== oldValue) {
5152                self.state.set('value', newValue);
5153                self.fire('autocomplete', e);
5154              }
5155            }
5156          });
5157          self.on('mouseover', function (e) {
5158            var tooltip = self.tooltip().moveTo(-65535);
5159            if (self.statusLevel() && e.target.className.indexOf(self.classPrefix + 'status') !== -1) {
5160              var statusMessage = self.statusMessage() || 'Ok';
5161              var rel = tooltip.text(statusMessage).show().testMoveRel(e.target, [
5162                'bc-tc',
5163                'bc-tl',
5164                'bc-tr'
5165              ]);
5166              tooltip.classes.toggle('tooltip-n', rel === 'bc-tc');
5167              tooltip.classes.toggle('tooltip-nw', rel === 'bc-tl');
5168              tooltip.classes.toggle('tooltip-ne', rel === 'bc-tr');
5169              tooltip.moveRel(e.target, rel);
5170            }
5171          });
5172        },
5173        statusLevel: function (value) {
5174          if (arguments.length > 0) {
5175            this.state.set('statusLevel', value);
5176          }
5177          return this.state.get('statusLevel');
5178        },
5179        statusMessage: function (value) {
5180          if (arguments.length > 0) {
5181            this.state.set('statusMessage', value);
5182          }
5183          return this.state.get('statusMessage');
5184        },
5185        showMenu: function () {
5186          var self = this;
5187          var settings = self.settings;
5188          var menu;
5189          if (!self.menu) {
5190            menu = settings.menu || [];
5191            if (menu.length) {
5192              menu = {
5193                type: 'menu',
5194                items: menu
5195              };
5196            } else {
5197              menu.type = menu.type || 'menu';
5198            }
5199            self.menu = global$4.create(menu).parent(self).renderTo(self.getContainerElm());
5200            self.fire('createmenu');
5201            self.menu.reflow();
5202            self.menu.on('cancel', function (e) {
5203              if (e.control === self.menu) {
5204                self.focus();
5205              }
5206            });
5207            self.menu.on('show hide', function (e) {
5208              e.control.items().each(function (ctrl) {
5209                ctrl.active(ctrl.value() === self.value());
5210              });
5211            }).fire('show');
5212            self.menu.on('select', function (e) {
5213              self.value(e.control.value());
5214            });
5215            self.on('focusin', function (e) {
5216              if (e.target.tagName.toUpperCase() === 'INPUT') {
5217                self.menu.hide();
5218              }
5219            });
5220            self.aria('expanded', true);
5221          }
5222          self.menu.show();
5223          self.menu.layoutRect({ w: self.layoutRect().w });
5224          self.menu.moveRel(self.getEl(), self.isRtl() ? [
5225            'br-tr',
5226            'tr-br'
5227          ] : [
5228            'bl-tl',
5229            'tl-bl'
5230          ]);
5231        },
5232        focus: function () {
5233          this.getEl('inp').focus();
5234        },
5235        repaint: function () {
5236          var self = this, elm = self.getEl(), openElm = self.getEl('open'), rect = self.layoutRect();
5237          var width, lineHeight, innerPadding = 0;
5238          var inputElm = elm.firstChild;
5239          if (self.statusLevel() && self.statusLevel() !== 'none') {
5240            innerPadding = parseInt(funcs.getRuntimeStyle(inputElm, 'padding-right'), 10) - parseInt(funcs.getRuntimeStyle(inputElm, 'padding-left'), 10);
5241          }
5242          if (openElm) {
5243            width = rect.w - funcs.getSize(openElm).width - 10;
5244          } else {
5245            width = rect.w - 10;
5246          }
5247          var doc = domGlobals.document;
5248          if (doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
5249            lineHeight = self.layoutRect().h - 2 + 'px';
5250          }
5251          global$9(inputElm).css({
5252            width: width - innerPadding,
5253            lineHeight: lineHeight
5254          });
5255          self._super();
5256          return self;
5257        },
5258        postRender: function () {
5259          var self = this;
5260          global$9(this.getEl('inp')).on('change', function (e) {
5261            self.state.set('value', e.target.value);
5262            self.fire('change', e);
5263          });
5264          return self._super();
5265        },
5266        renderHtml: function () {
5267          var self = this, id = self._id, settings = self.settings, prefix = self.classPrefix;
5268          var value = self.state.get('value') || '';
5269          var icon, text, openBtnHtml = '', extraAttrs = '', statusHtml = '';
5270          if ('spellcheck' in settings) {
5271            extraAttrs += ' spellcheck="' + settings.spellcheck + '"';
5272          }
5273          if (settings.maxLength) {
5274            extraAttrs += ' maxlength="' + settings.maxLength + '"';
5275          }
5276          if (settings.size) {
5277            extraAttrs += ' size="' + settings.size + '"';
5278          }
5279          if (settings.subtype) {
5280            extraAttrs += ' type="' + settings.subtype + '"';
5281          }
5282          statusHtml = '<i id="' + id + '-status" class="mce-status mce-ico" style="display: none"></i>';
5283          if (self.disabled()) {
5284            extraAttrs += ' disabled="disabled"';
5285          }
5286          icon = settings.icon;
5287          if (icon && icon !== 'caret') {
5288            icon = prefix + 'ico ' + prefix + 'i-' + settings.icon;
5289          }
5290          text = self.state.get('text');
5291          if (icon || text) {
5292            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>';
5293            self.classes.add('has-open');
5294          }
5295          return '<div id="' + id + '" class="' + self.classes + '">' + '<input id="' + id + '-inp" class="' + prefix + 'textbox" value="' + self.encode(value, false) + '" hidefocus="1"' + extraAttrs + ' placeholder="' + self.encode(settings.placeholder) + '" />' + statusHtml + openBtnHtml + '</div>';
5296        },
5297        value: function (value) {
5298          if (arguments.length) {
5299            this.state.set('value', value);
5300            return this;
5301          }
5302          if (this.state.get('rendered')) {
5303            this.state.set('value', this.getEl('inp').value);
5304          }
5305          return this.state.get('value');
5306        },
5307        showAutoComplete: function (items, term) {
5308          var self = this;
5309          if (items.length === 0) {
5310            self.hideMenu();
5311            return;
5312          }
5313          var insert = function (value, title) {
5314            return function () {
5315              self.fire('selectitem', {
5316                title: title,
5317                value: value
5318              });
5319            };
5320          };
5321          if (self.menu) {
5322            self.menu.items().remove();
5323          } else {
5324            self.menu = global$4.create({
5325              type: 'menu',
5326              classes: 'combobox-menu',
5327              layout: 'flow'
5328            }).parent(self).renderTo();
5329          }
5330          global$2.each(items, function (item) {
5331            self.menu.add({
5332              text: item.title,
5333              url: item.previewUrl,
5334              match: term,
5335              classes: 'menu-item-ellipsis',
5336              onclick: insert(item.value, item.title)
5337            });
5338          });
5339          self.menu.renderNew();
5340          self.hideMenu();
5341          self.menu.on('cancel', function (e) {
5342            if (e.control.parent() === self.menu) {
5343              e.stopPropagation();
5344              self.focus();
5345              self.hideMenu();
5346            }
5347          });
5348          self.menu.on('select', function () {
5349            self.focus();
5350          });
5351          var maxW = self.layoutRect().w;
5352          self.menu.layoutRect({
5353            w: maxW,
5354            minW: 0,
5355            maxW: maxW
5356          });
5357          self.menu.repaint();
5358          self.menu.reflow();
5359          self.menu.show();
5360          self.menu.moveRel(self.getEl(), self.isRtl() ? [
5361            'br-tr',
5362            'tr-br'
5363          ] : [
5364            'bl-tl',
5365            'tl-bl'
5366          ]);
5367        },
5368        hideMenu: function () {
5369          if (this.menu) {
5370            this.menu.hide();
5371          }
5372        },
5373        bindStates: function () {
5374          var self = this;
5375          self.state.on('change:value', function (e) {
5376            if (self.getEl('inp').value !== e.value) {
5377              self.getEl('inp').value = e.value;
5378            }
5379          });
5380          self.state.on('change:disabled', function (e) {
5381            self.getEl('inp').disabled = e.value;
5382          });
5383          self.state.on('change:statusLevel', function (e) {
5384            var statusIconElm = self.getEl('status');
5385            var prefix = self.classPrefix, value = e.value;
5386            funcs.css(statusIconElm, 'display', value === 'none' ? 'none' : '');
5387            funcs.toggleClass(statusIconElm, prefix + 'i-checkmark', value === 'ok');
5388            funcs.toggleClass(statusIconElm, prefix + 'i-warning', value === 'warn');
5389            funcs.toggleClass(statusIconElm, prefix + 'i-error', value === 'error');
5390            self.classes.toggle('has-status', value !== 'none');
5391            self.repaint();
5392          });
5393          funcs.on(self.getEl('status'), 'mouseleave', function () {
5394            self.tooltip().hide();
5395          });
5396          self.on('cancel', function (e) {
5397            if (self.menu && self.menu.visible()) {
5398              e.stopPropagation();
5399              self.hideMenu();
5400            }
5401          });
5402          var focusIdx = function (idx, menu) {
5403            if (menu && menu.items().length > 0) {
5404              menu.items().eq(idx)[0].focus();
5405            }
5406          };
5407          self.on('keydown', function (e) {
5408            var keyCode = e.keyCode;
5409            if (e.target.nodeName === 'INPUT') {
5410              if (keyCode === global$d.DOWN) {
5411                e.preventDefault();
5412                self.fire('autocomplete');
5413                focusIdx(0, self.menu);
5414              } else if (keyCode === global$d.UP) {
5415                e.preventDefault();
5416                focusIdx(-1, self.menu);
5417              }
5418            }
5419          });
5420          return self._super();
5421        },
5422        remove: function () {
5423          global$9(this.getEl('inp')).off();
5424          if (this.menu) {
5425            this.menu.remove();
5426          }
5427          this._super();
5428        }
5429      });
5430  
5431      var ColorBox = ComboBox.extend({
5432        init: function (settings) {
5433          var self = this;
5434          settings.spellcheck = false;
5435          if (settings.onaction) {
5436            settings.icon = 'none';
5437          }
5438          self._super(settings);
5439          self.classes.add('colorbox');
5440          self.on('change keyup postrender', function () {
5441            self.repaintColor(self.value());
5442          });
5443        },
5444        repaintColor: function (value) {
5445          var openElm = this.getEl('open');
5446          var elm = openElm ? openElm.getElementsByTagName('i')[0] : null;
5447          if (elm) {
5448            try {
5449              elm.style.background = value;
5450            } catch (ex) {
5451            }
5452          }
5453        },
5454        bindStates: function () {
5455          var self = this;
5456          self.state.on('change:value', function (e) {
5457            if (self.state.get('rendered')) {
5458              self.repaintColor(e.value);
5459            }
5460          });
5461          return self._super();
5462        }
5463      });
5464  
5465      var PanelButton = Button.extend({
5466        showPanel: function () {
5467          var self = this, settings = self.settings;
5468          self.classes.add('opened');
5469          if (!self.panel) {
5470            var panelSettings = settings.panel;
5471            if (panelSettings.type) {
5472              panelSettings = {
5473                layout: 'grid',
5474                items: panelSettings
5475              };
5476            }
5477            panelSettings.role = panelSettings.role || 'dialog';
5478            panelSettings.popover = true;
5479            panelSettings.autohide = true;
5480            panelSettings.ariaRoot = true;
5481            self.panel = new FloatPanel(panelSettings).on('hide', function () {
5482              self.classes.remove('opened');
5483            }).on('cancel', function (e) {
5484              e.stopPropagation();
5485              self.focus();
5486              self.hidePanel();
5487            }).parent(self).renderTo(self.getContainerElm());
5488            self.panel.fire('show');
5489            self.panel.reflow();
5490          } else {
5491            self.panel.show();
5492          }
5493          var rtlRels = [
5494            'bc-tc',
5495            'bc-tl',
5496            'bc-tr'
5497          ];
5498          var ltrRels = [
5499            'bc-tc',
5500            'bc-tr',
5501            'bc-tl',
5502            'tc-bc',
5503            'tc-br',
5504            'tc-bl'
5505          ];
5506          var rel = self.panel.testMoveRel(self.getEl(), settings.popoverAlign || (self.isRtl() ? rtlRels : ltrRels));
5507          self.panel.classes.toggle('start', rel.substr(-1) === 'l');
5508          self.panel.classes.toggle('end', rel.substr(-1) === 'r');
5509          var isTop = rel.substr(0, 1) === 't';
5510          self.panel.classes.toggle('bottom', !isTop);
5511          self.panel.classes.toggle('top', isTop);
5512          self.panel.moveRel(self.getEl(), rel);
5513        },
5514        hidePanel: function () {
5515          var self = this;
5516          if (self.panel) {
5517            self.panel.hide();
5518          }
5519        },
5520        postRender: function () {
5521          var self = this;
5522          self.aria('haspopup', true);
5523          self.on('click', function (e) {
5524            if (e.control === self) {
5525              if (self.panel && self.panel.visible()) {
5526                self.hidePanel();
5527              } else {
5528                self.showPanel();
5529                self.panel.focus(!!e.aria);
5530              }
5531            }
5532          });
5533          return self._super();
5534        },
5535        remove: function () {
5536          if (this.panel) {
5537            this.panel.remove();
5538            this.panel = null;
5539          }
5540          return this._super();
5541        }
5542      });
5543  
5544      var DOM$3 = global$3.DOM;
5545      var ColorButton = PanelButton.extend({
5546        init: function (settings) {
5547          this._super(settings);
5548          this.classes.add('splitbtn');
5549          this.classes.add('colorbutton');
5550        },
5551        color: function (color) {
5552          if (color) {
5553            this._color = color;
5554            this.getEl('preview').style.backgroundColor = color;
5555            return this;
5556          }
5557          return this._color;
5558        },
5559        resetColor: function () {
5560          this._color = null;
5561          this.getEl('preview').style.backgroundColor = null;
5562          return this;
5563        },
5564        renderHtml: function () {
5565          var self = this, id = self._id, prefix = self.classPrefix, text = self.state.get('text');
5566          var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
5567          var image = self.settings.image ? ' style="background-image: url(\'' + self.settings.image + '\')"' : '';
5568          var textHtml = '';
5569          if (text) {
5570            self.classes.add('btn-has-text');
5571            textHtml = '<span class="' + prefix + 'txt">' + self.encode(text) + '</span>';
5572          }
5573          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>';
5574        },
5575        postRender: function () {
5576          var self = this, onClickHandler = self.settings.onclick;
5577          self.on('click', function (e) {
5578            if (e.aria && e.aria.key === 'down') {
5579              return;
5580            }
5581            if (e.control === self && !DOM$3.getParent(e.target, '.' + self.classPrefix + 'open')) {
5582              e.stopImmediatePropagation();
5583              onClickHandler.call(self, e);
5584            }
5585          });
5586          delete self.settings.onclick;
5587          return self._super();
5588        }
5589      });
5590  
5591      var global$e = tinymce.util.Tools.resolve('tinymce.util.Color');
5592  
5593      var ColorPicker = Widget.extend({
5594        Defaults: { classes: 'widget colorpicker' },
5595        init: function (settings) {
5596          this._super(settings);
5597        },
5598        postRender: function () {
5599          var self = this;
5600          var color = self.color();
5601          var hsv, hueRootElm, huePointElm, svRootElm, svPointElm;
5602          hueRootElm = self.getEl('h');
5603          huePointElm = self.getEl('hp');
5604          svRootElm = self.getEl('sv');
5605          svPointElm = self.getEl('svp');
5606          function getPos(elm, event) {
5607            var pos = funcs.getPos(elm);
5608            var x, y;
5609            x = event.pageX - pos.x;
5610            y = event.pageY - pos.y;
5611            x = Math.max(0, Math.min(x / elm.clientWidth, 1));
5612            y = Math.max(0, Math.min(y / elm.clientHeight, 1));
5613            return {
5614              x: x,
5615              y: y
5616            };
5617          }
5618          function updateColor(hsv, hueUpdate) {
5619            var hue = (360 - hsv.h) / 360;
5620            funcs.css(huePointElm, { top: hue * 100 + '%' });
5621            if (!hueUpdate) {
5622              funcs.css(svPointElm, {
5623                left: hsv.s + '%',
5624                top: 100 - hsv.v + '%'
5625              });
5626            }
5627            svRootElm.style.background = global$e({
5628              s: 100,
5629              v: 100,
5630              h: hsv.h
5631            }).toHex();
5632            self.color().parse({
5633              s: hsv.s,
5634              v: hsv.v,
5635              h: hsv.h
5636            });
5637          }
5638          function updateSaturationAndValue(e) {
5639            var pos;
5640            pos = getPos(svRootElm, e);
5641            hsv.s = pos.x * 100;
5642            hsv.v = (1 - pos.y) * 100;
5643            updateColor(hsv);
5644            self.fire('change');
5645          }
5646          function updateHue(e) {
5647            var pos;
5648            pos = getPos(hueRootElm, e);
5649            hsv = color.toHsv();
5650            hsv.h = (1 - pos.y) * 360;
5651            updateColor(hsv, true);
5652            self.fire('change');
5653          }
5654          self._repaint = function () {
5655            hsv = color.toHsv();
5656            updateColor(hsv);
5657          };
5658          self._super();
5659          self._svdraghelper = new DragHelper(self._id + '-sv', {
5660            start: updateSaturationAndValue,
5661            drag: updateSaturationAndValue
5662          });
5663          self._hdraghelper = new DragHelper(self._id + '-h', {
5664            start: updateHue,
5665            drag: updateHue
5666          });
5667          self._repaint();
5668        },
5669        rgb: function () {
5670          return this.color().toRgb();
5671        },
5672        value: function (value) {
5673          var self = this;
5674          if (arguments.length) {
5675            self.color().parse(value);
5676            if (self._rendered) {
5677              self._repaint();
5678            }
5679          } else {
5680            return self.color().toHex();
5681          }
5682        },
5683        color: function () {
5684          if (!this._color) {
5685            this._color = global$e();
5686          }
5687          return this._color;
5688        },
5689        renderHtml: function () {
5690          var self = this;
5691          var id = self._id;
5692          var prefix = self.classPrefix;
5693          var hueHtml;
5694          var stops = '#ff0000,#ff0080,#ff00ff,#8000ff,#0000ff,#0080ff,#00ffff,#00ff80,#00ff00,#80ff00,#ffff00,#ff8000,#ff0000';
5695          function getOldIeFallbackHtml() {
5696            var i, l, html = '', gradientPrefix, stopsList;
5697            gradientPrefix = 'filter:progid:DXImageTransform.Microsoft.gradient(GradientType=0,startColorstr=';
5698            stopsList = stops.split(',');
5699            for (i = 0, l = stopsList.length - 1; i < l; i++) {
5700              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>';
5701            }
5702            return html;
5703          }
5704          var gradientCssText = 'background: -ms-linear-gradient(top,' + stops + ');' + 'background: linear-gradient(to bottom,' + stops + ');';
5705          hueHtml = '<div id="' + id + '-h" class="' + prefix + 'colorpicker-h" style="' + gradientCssText + '">' + getOldIeFallbackHtml() + '<div id="' + id + '-hp" class="' + prefix + 'colorpicker-h-marker"></div>' + '</div>';
5706          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>';
5707        }
5708      });
5709  
5710      var DropZone = Widget.extend({
5711        init: function (settings) {
5712          var self = this;
5713          settings = global$2.extend({
5714            height: 100,
5715            text: 'Drop an image here',
5716            multiple: false,
5717            accept: null
5718          }, settings);
5719          self._super(settings);
5720          self.classes.add('dropzone');
5721          if (settings.multiple) {
5722            self.classes.add('multiple');
5723          }
5724        },
5725        renderHtml: function () {
5726          var self = this;
5727          var attrs, elm;
5728          var cfg = self.settings;
5729          attrs = {
5730            id: self._id,
5731            hidefocus: '1'
5732          };
5733          elm = funcs.create('div', attrs, '<span>' + this.translate(cfg.text) + '</span>');
5734          if (cfg.height) {
5735            funcs.css(elm, 'height', cfg.height + 'px');
5736          }
5737          if (cfg.width) {
5738            funcs.css(elm, 'width', cfg.width + 'px');
5739          }
5740          elm.className = self.classes;
5741          return elm.outerHTML;
5742        },
5743        postRender: function () {
5744          var self = this;
5745          var toggleDragClass = function (e) {
5746            e.preventDefault();
5747            self.classes.toggle('dragenter');
5748            self.getEl().className = self.classes;
5749          };
5750          var filter = function (files) {
5751            var accept = self.settings.accept;
5752            if (typeof accept !== 'string') {
5753              return files;
5754            }
5755            var re = new RegExp('(' + accept.split(/\s*,\s*/).join('|') + ')$', 'i');
5756            return global$2.grep(files, function (file) {
5757              return re.test(file.name);
5758            });
5759          };
5760          self._super();
5761          self.$el.on('dragover', function (e) {
5762            e.preventDefault();
5763          });
5764          self.$el.on('dragenter', toggleDragClass);
5765          self.$el.on('dragleave', toggleDragClass);
5766          self.$el.on('drop', function (e) {
5767            e.preventDefault();
5768            if (self.state.get('disabled')) {
5769              return;
5770            }
5771            var files = filter(e.dataTransfer.files);
5772            self.value = function () {
5773              if (!files.length) {
5774                return null;
5775              } else if (self.settings.multiple) {
5776                return files;
5777              } else {
5778                return files[0];
5779              }
5780            };
5781            if (files.length) {
5782              self.fire('change', e);
5783            }
5784          });
5785        },
5786        remove: function () {
5787          this.$el.off();
5788          this._super();
5789        }
5790      });
5791  
5792      var Path = Widget.extend({
5793        init: function (settings) {
5794          var self = this;
5795          if (!settings.delimiter) {
5796            settings.delimiter = '\xBB';
5797          }
5798          self._super(settings);
5799          self.classes.add('path');
5800          self.canFocus = true;
5801          self.on('click', function (e) {
5802            var index;
5803            var target = e.target;
5804            if (index = target.getAttribute('data-index')) {
5805              self.fire('select', {
5806                value: self.row()[index],
5807                index: index
5808              });
5809            }
5810          });
5811          self.row(self.settings.row);
5812        },
5813        focus: function () {
5814          var self = this;
5815          self.getEl().firstChild.focus();
5816          return self;
5817        },
5818        row: function (row) {
5819          if (!arguments.length) {
5820            return this.state.get('row');
5821          }
5822          this.state.set('row', row);
5823          return this;
5824        },
5825        renderHtml: function () {
5826          var self = this;
5827          return '<div id="' + self._id + '" class="' + self.classes + '">' + self._getDataPathHtml(self.state.get('row')) + '</div>';
5828        },
5829        bindStates: function () {
5830          var self = this;
5831          self.state.on('change:row', function (e) {
5832            self.innerHtml(self._getDataPathHtml(e.value));
5833          });
5834          return self._super();
5835        },
5836        _getDataPathHtml: function (data) {
5837          var self = this;
5838          var parts = data || [];
5839          var i, l, html = '';
5840          var prefix = self.classPrefix;
5841          for (i = 0, l = parts.length; i < l; i++) {
5842            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>';
5843          }
5844          if (!html) {
5845            html = '<div class="' + prefix + 'path-item">\xA0</div>';
5846          }
5847          return html;
5848        }
5849      });
5850  
5851      var ElementPath = Path.extend({
5852        postRender: function () {
5853          var self = this, editor = self.settings.editor;
5854          function isHidden(elm) {
5855            if (elm.nodeType === 1) {
5856              if (elm.nodeName === 'BR' || !!elm.getAttribute('data-mce-bogus')) {
5857                return true;
5858              }
5859              if (elm.getAttribute('data-mce-type') === 'bookmark') {
5860                return true;
5861              }
5862            }
5863            return false;
5864          }
5865          if (editor.settings.elementpath !== false) {
5866            self.on('select', function (e) {
5867              editor.focus();
5868              editor.selection.select(this.row()[e.index].element);
5869              editor.nodeChanged();
5870            });
5871            editor.on('nodeChange', function (e) {
5872              var outParents = [];
5873              var parents = e.parents;
5874              var i = parents.length;
5875              while (i--) {
5876                if (parents[i].nodeType === 1 && !isHidden(parents[i])) {
5877                  var args = editor.fire('ResolveName', {
5878                    name: parents[i].nodeName.toLowerCase(),
5879                    target: parents[i]
5880                  });
5881                  if (!args.isDefaultPrevented()) {
5882                    outParents.push({
5883                      name: args.name,
5884                      element: parents[i]
5885                    });
5886                  }
5887                  if (args.isPropagationStopped()) {
5888                    break;
5889                  }
5890                }
5891              }
5892              self.row(outParents);
5893            });
5894          }
5895          return self._super();
5896        }
5897      });
5898  
5899      var FormItem = Container.extend({
5900        Defaults: {
5901          layout: 'flex',
5902          align: 'center',
5903          defaults: { flex: 1 }
5904        },
5905        renderHtml: function () {
5906          var self = this, layout = self._layout, prefix = self.classPrefix;
5907          self.classes.add('formitem');
5908          layout.preRender(self);
5909          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>';
5910        }
5911      });
5912  
5913      var Form = Container.extend({
5914        Defaults: {
5915          containerCls: 'form',
5916          layout: 'flex',
5917          direction: 'column',
5918          align: 'stretch',
5919          flex: 1,
5920          padding: 15,
5921          labelGap: 30,
5922          spacing: 10,
5923          callbacks: {
5924            submit: function () {
5925              this.submit();
5926            }
5927          }
5928        },
5929        preRender: function () {
5930          var self = this, items = self.items();
5931          if (!self.settings.formItemDefaults) {
5932            self.settings.formItemDefaults = {
5933              layout: 'flex',
5934              autoResize: 'overflow',
5935              defaults: { flex: 1 }
5936            };
5937          }
5938          items.each(function (ctrl) {
5939            var formItem;
5940            var label = ctrl.settings.label;
5941            if (label) {
5942              formItem = new FormItem(global$2.extend({
5943                items: {
5944                  type: 'label',
5945                  id: ctrl._id + '-l',
5946                  text: label,
5947                  flex: 0,
5948                  forId: ctrl._id,
5949                  disabled: ctrl.disabled()
5950                }
5951              }, self.settings.formItemDefaults));
5952              formItem.type = 'formitem';
5953              ctrl.aria('labelledby', ctrl._id + '-l');
5954              if (typeof ctrl.settings.flex === 'undefined') {
5955                ctrl.settings.flex = 1;
5956              }
5957              self.replace(ctrl, formItem);
5958              formItem.add(ctrl);
5959            }
5960          });
5961        },
5962        submit: function () {
5963          return this.fire('submit', { data: this.toJSON() });
5964        },
5965        postRender: function () {
5966          var self = this;
5967          self._super();
5968          self.fromJSON(self.settings.data);
5969        },
5970        bindStates: function () {
5971          var self = this;
5972          self._super();
5973          function recalcLabels() {
5974            var maxLabelWidth = 0;
5975            var labels = [];
5976            var i, labelGap, items;
5977            if (self.settings.labelGapCalc === false) {
5978              return;
5979            }
5980            if (self.settings.labelGapCalc === 'children') {
5981              items = self.find('formitem');
5982            } else {
5983              items = self.items();
5984            }
5985            items.filter('formitem').each(function (item) {
5986              var labelCtrl = item.items()[0], labelWidth = labelCtrl.getEl().clientWidth;
5987              maxLabelWidth = labelWidth > maxLabelWidth ? labelWidth : maxLabelWidth;
5988              labels.push(labelCtrl);
5989            });
5990            labelGap = self.settings.labelGap || 0;
5991            i = labels.length;
5992            while (i--) {
5993              labels[i].settings.minWidth = maxLabelWidth + labelGap;
5994            }
5995          }
5996          self.on('show', recalcLabels);
5997          recalcLabels();
5998        }
5999      });
6000  
6001      var FieldSet = Form.extend({
6002        Defaults: {
6003          containerCls: 'fieldset',
6004          layout: 'flex',
6005          direction: 'column',
6006          align: 'stretch',
6007          flex: 1,
6008          padding: '25 15 5 15',
6009          labelGap: 30,
6010          spacing: 10,
6011          border: 1
6012        },
6013        renderHtml: function () {
6014          var self = this, layout = self._layout, prefix = self.classPrefix;
6015          self.preRender();
6016          layout.preRender(self);
6017          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>';
6018        }
6019      });
6020  
6021      var unique$1 = 0;
6022      var generate = function (prefix) {
6023        var date = new Date();
6024        var time = date.getTime();
6025        var random = Math.floor(Math.random() * 1000000000);
6026        unique$1++;
6027        return prefix + '_' + random + unique$1 + String(time);
6028      };
6029  
6030      var fromHtml = function (html, scope) {
6031        var doc = scope || domGlobals.document;
6032        var div = doc.createElement('div');
6033        div.innerHTML = html;
6034        if (!div.hasChildNodes() || div.childNodes.length > 1) {
6035          domGlobals.console.error('HTML does not have a single root node', html);
6036          throw new Error('HTML must have a single root node');
6037        }
6038        return fromDom(div.childNodes[0]);
6039      };
6040      var fromTag = function (tag, scope) {
6041        var doc = scope || domGlobals.document;
6042        var node = doc.createElement(tag);
6043        return fromDom(node);
6044      };
6045      var fromText = function (text, scope) {
6046        var doc = scope || domGlobals.document;
6047        var node = doc.createTextNode(text);
6048        return fromDom(node);
6049      };
6050      var fromDom = function (node) {
6051        if (node === null || node === undefined) {
6052          throw new Error('Node cannot be null or undefined');
6053        }
6054        return { dom: constant(node) };
6055      };
6056      var fromPoint = function (docElm, x, y) {
6057        var doc = docElm.dom();
6058        return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
6059      };
6060      var Element = {
6061        fromHtml: fromHtml,
6062        fromTag: fromTag,
6063        fromText: fromText,
6064        fromDom: fromDom,
6065        fromPoint: fromPoint
6066      };
6067  
6068      var cached = function (f) {
6069        var called = false;
6070        var r;
6071        return function () {
6072          var args = [];
6073          for (var _i = 0; _i < arguments.length; _i++) {
6074            args[_i] = arguments[_i];
6075          }
6076          if (!called) {
6077            called = true;
6078            r = f.apply(null, args);
6079          }
6080          return r;
6081        };
6082      };
6083  
6084      var ATTRIBUTE = domGlobals.Node.ATTRIBUTE_NODE;
6085      var CDATA_SECTION = domGlobals.Node.CDATA_SECTION_NODE;
6086      var COMMENT = domGlobals.Node.COMMENT_NODE;
6087      var DOCUMENT = domGlobals.Node.DOCUMENT_NODE;
6088      var DOCUMENT_TYPE = domGlobals.Node.DOCUMENT_TYPE_NODE;
6089      var DOCUMENT_FRAGMENT = domGlobals.Node.DOCUMENT_FRAGMENT_NODE;
6090      var ELEMENT = domGlobals.Node.ELEMENT_NODE;
6091      var TEXT = domGlobals.Node.TEXT_NODE;
6092      var PROCESSING_INSTRUCTION = domGlobals.Node.PROCESSING_INSTRUCTION_NODE;
6093      var ENTITY_REFERENCE = domGlobals.Node.ENTITY_REFERENCE_NODE;
6094      var ENTITY = domGlobals.Node.ENTITY_NODE;
6095      var NOTATION = domGlobals.Node.NOTATION_NODE;
6096  
6097      var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
6098  
6099      var path = function (parts, scope) {
6100        var o = scope !== undefined && scope !== null ? scope : Global;
6101        for (var i = 0; i < parts.length && o !== undefined && o !== null; ++i) {
6102          o = o[parts[i]];
6103        }
6104        return o;
6105      };
6106      var resolve = function (p, scope) {
6107        var parts = p.split('.');
6108        return path(parts, scope);
6109      };
6110  
6111      var unsafe = function (name, scope) {
6112        return resolve(name, scope);
6113      };
6114      var getOrDie = function (name, scope) {
6115        var actual = unsafe(name, scope);
6116        if (actual === undefined || actual === null) {
6117          throw new Error(name + ' not available on this browser');
6118        }
6119        return actual;
6120      };
6121      var Global$1 = { getOrDie: getOrDie };
6122  
6123      var Immutable = function () {
6124        var fields = [];
6125        for (var _i = 0; _i < arguments.length; _i++) {
6126          fields[_i] = arguments[_i];
6127        }
6128        return function () {
6129          var values = [];
6130          for (var _i = 0; _i < arguments.length; _i++) {
6131            values[_i] = arguments[_i];
6132          }
6133          if (fields.length !== values.length) {
6134            throw new Error('Wrong number of arguments to struct. Expected "[' + fields.length + ']", got ' + values.length + ' arguments');
6135          }
6136          var struct = {};
6137          each(fields, function (name, i) {
6138            struct[name] = constant(values[i]);
6139          });
6140          return struct;
6141        };
6142      };
6143  
6144      var node = function () {
6145        var f = Global$1.getOrDie('Node');
6146        return f;
6147      };
6148      var compareDocumentPosition = function (a, b, match) {
6149        return (a.compareDocumentPosition(b) & match) !== 0;
6150      };
6151      var documentPositionPreceding = function (a, b) {
6152        return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_PRECEDING);
6153      };
6154      var documentPositionContainedBy = function (a, b) {
6155        return compareDocumentPosition(a, b, node().DOCUMENT_POSITION_CONTAINED_BY);
6156      };
6157      var Node = {
6158        documentPositionPreceding: documentPositionPreceding,
6159        documentPositionContainedBy: documentPositionContainedBy
6160      };
6161  
6162      var firstMatch = function (regexes, s) {
6163        for (var i = 0; i < regexes.length; i++) {
6164          var x = regexes[i];
6165          if (x.test(s)) {
6166            return x;
6167          }
6168        }
6169        return undefined;
6170      };
6171      var find$1 = function (regexes, agent) {
6172        var r = firstMatch(regexes, agent);
6173        if (!r) {
6174          return {
6175            major: 0,
6176            minor: 0
6177          };
6178        }
6179        var group = function (i) {
6180          return Number(agent.replace(r, '$' + i));
6181        };
6182        return nu(group(1), group(2));
6183      };
6184      var detect = function (versionRegexes, agent) {
6185        var cleanedAgent = String(agent).toLowerCase();
6186        if (versionRegexes.length === 0) {
6187          return unknown();
6188        }
6189        return find$1(versionRegexes, cleanedAgent);
6190      };
6191      var unknown = function () {
6192        return nu(0, 0);
6193      };
6194      var nu = function (major, minor) {
6195        return {
6196          major: major,
6197          minor: minor
6198        };
6199      };
6200      var Version = {
6201        nu: nu,
6202        detect: detect,
6203        unknown: unknown
6204      };
6205  
6206      var edge = 'Edge';
6207      var chrome = 'Chrome';
6208      var ie = 'IE';
6209      var opera = 'Opera';
6210      var firefox = 'Firefox';
6211      var safari = 'Safari';
6212      var isBrowser = function (name, current) {
6213        return function () {
6214          return current === name;
6215        };
6216      };
6217      var unknown$1 = function () {
6218        return nu$1({
6219          current: undefined,
6220          version: Version.unknown()
6221        });
6222      };
6223      var nu$1 = function (info) {
6224        var current = info.current;
6225        var version = info.version;
6226        return {
6227          current: current,
6228          version: version,
6229          isEdge: isBrowser(edge, current),
6230          isChrome: isBrowser(chrome, current),
6231          isIE: isBrowser(ie, current),
6232          isOpera: isBrowser(opera, current),
6233          isFirefox: isBrowser(firefox, current),
6234          isSafari: isBrowser(safari, current)
6235        };
6236      };
6237      var Browser = {
6238        unknown: unknown$1,
6239        nu: nu$1,
6240        edge: constant(edge),
6241        chrome: constant(chrome),
6242        ie: constant(ie),
6243        opera: constant(opera),
6244        firefox: constant(firefox),
6245        safari: constant(safari)
6246      };
6247  
6248      var windows$1 = 'Windows';
6249      var ios = 'iOS';
6250      var android = 'Android';
6251      var linux = 'Linux';
6252      var osx = 'OSX';
6253      var solaris = 'Solaris';
6254      var freebsd = 'FreeBSD';
6255      var isOS = function (name, current) {
6256        return function () {
6257          return current === name;
6258        };
6259      };
6260      var unknown$2 = function () {
6261        return nu$2({
6262          current: undefined,
6263          version: Version.unknown()
6264        });
6265      };
6266      var nu$2 = function (info) {
6267        var current = info.current;
6268        var version = info.version;
6269        return {
6270          current: current,
6271          version: version,
6272          isWindows: isOS(windows$1, current),
6273          isiOS: isOS(ios, current),
6274          isAndroid: isOS(android, current),
6275          isOSX: isOS(osx, current),
6276          isLinux: isOS(linux, current),
6277          isSolaris: isOS(solaris, current),
6278          isFreeBSD: isOS(freebsd, current)
6279        };
6280      };
6281      var OperatingSystem = {
6282        unknown: unknown$2,
6283        nu: nu$2,
6284        windows: constant(windows$1),
6285        ios: constant(ios),
6286        android: constant(android),
6287        linux: constant(linux),
6288        osx: constant(osx),
6289        solaris: constant(solaris),
6290        freebsd: constant(freebsd)
6291      };
6292  
6293      var DeviceType = function (os, browser, userAgent) {
6294        var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
6295        var isiPhone = os.isiOS() && !isiPad;
6296        var isAndroid3 = os.isAndroid() && os.version.major === 3;
6297        var isAndroid4 = os.isAndroid() && os.version.major === 4;
6298        var isTablet = isiPad || isAndroid3 || isAndroid4 && /mobile/i.test(userAgent) === true;
6299        var isTouch = os.isiOS() || os.isAndroid();
6300        var isPhone = isTouch && !isTablet;
6301        var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
6302        return {
6303          isiPad: constant(isiPad),
6304          isiPhone: constant(isiPhone),
6305          isTablet: constant(isTablet),
6306          isPhone: constant(isPhone),
6307          isTouch: constant(isTouch),
6308          isAndroid: os.isAndroid,
6309          isiOS: os.isiOS,
6310          isWebView: constant(iOSwebview)
6311        };
6312      };
6313  
6314      var detect$1 = function (candidates, userAgent) {
6315        var agent = String(userAgent).toLowerCase();
6316        return find(candidates, function (candidate) {
6317          return candidate.search(agent);
6318        });
6319      };
6320      var detectBrowser = function (browsers, userAgent) {
6321        return detect$1(browsers, userAgent).map(function (browser) {
6322          var version = Version.detect(browser.versionRegexes, userAgent);
6323          return {
6324            current: browser.name,
6325            version: version
6326          };
6327        });
6328      };
6329      var detectOs = function (oses, userAgent) {
6330        return detect$1(oses, userAgent).map(function (os) {
6331          var version = Version.detect(os.versionRegexes, userAgent);
6332          return {
6333            current: os.name,
6334            version: version
6335          };
6336        });
6337      };
6338      var UaString = {
6339        detectBrowser: detectBrowser,
6340        detectOs: detectOs
6341      };
6342  
6343      var contains = function (str, substr) {
6344        return str.indexOf(substr) !== -1;
6345      };
6346  
6347      var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
6348      var checkContains = function (target) {
6349        return function (uastring) {
6350          return contains(uastring, target);
6351        };
6352      };
6353      var browsers = [
6354        {
6355          name: 'Edge',
6356          versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
6357          search: function (uastring) {
6358            return contains(uastring, 'edge/') && contains(uastring, 'chrome') && contains(uastring, 'safari') && contains(uastring, 'applewebkit');
6359          }
6360        },
6361        {
6362          name: 'Chrome',
6363          versionRegexes: [
6364            /.*?chrome\/([0-9]+)\.([0-9]+).*/,
6365            normalVersionRegex
6366          ],
6367          search: function (uastring) {
6368            return contains(uastring, 'chrome') && !contains(uastring, 'chromeframe');
6369          }
6370        },
6371        {
6372          name: 'IE',
6373          versionRegexes: [
6374            /.*?msie\ ?([0-9]+)\.([0-9]+).*/,
6375            /.*?rv:([0-9]+)\.([0-9]+).*/
6376          ],
6377          search: function (uastring) {
6378            return contains(uastring, 'msie') || contains(uastring, 'trident');
6379          }
6380        },
6381        {
6382          name: 'Opera',
6383          versionRegexes: [
6384            normalVersionRegex,
6385            /.*?opera\/([0-9]+)\.([0-9]+).*/
6386          ],
6387          search: checkContains('opera')
6388        },
6389        {
6390          name: 'Firefox',
6391          versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
6392          search: checkContains('firefox')
6393        },
6394        {
6395          name: 'Safari',
6396          versionRegexes: [
6397            normalVersionRegex,
6398            /.*?cpu os ([0-9]+)_([0-9]+).*/
6399          ],
6400          search: function (uastring) {
6401            return (contains(uastring, 'safari') || contains(uastring, 'mobile/')) && contains(uastring, 'applewebkit');
6402          }
6403        }
6404      ];
6405      var oses = [
6406        {
6407          name: 'Windows',
6408          search: checkContains('win'),
6409          versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
6410        },
6411        {
6412          name: 'iOS',
6413          search: function (uastring) {
6414            return contains(uastring, 'iphone') || contains(uastring, 'ipad');
6415          },
6416          versionRegexes: [
6417            /.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
6418            /.*cpu os ([0-9]+)_([0-9]+).*/,
6419            /.*cpu iphone os ([0-9]+)_([0-9]+).*/
6420          ]
6421        },
6422        {
6423          name: 'Android',
6424          search: checkContains('android'),
6425          versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
6426        },
6427        {
6428          name: 'OSX',
6429          search: checkContains('os x'),
6430          versionRegexes: [/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]
6431        },
6432        {
6433          name: 'Linux',
6434          search: checkContains('linux'),
6435          versionRegexes: []
6436        },
6437        {
6438          name: 'Solaris',
6439          search: checkContains('sunos'),
6440          versionRegexes: []
6441        },
6442        {
6443          name: 'FreeBSD',
6444          search: checkContains('freebsd'),
6445          versionRegexes: []
6446        }
6447      ];
6448      var PlatformInfo = {
6449        browsers: constant(browsers),
6450        oses: constant(oses)
6451      };
6452  
6453      var detect$2 = function (userAgent) {
6454        var browsers = PlatformInfo.browsers();
6455        var oses = PlatformInfo.oses();
6456        var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
6457        var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
6458        var deviceType = DeviceType(os, browser, userAgent);
6459        return {
6460          browser: browser,
6461          os: os,
6462          deviceType: deviceType
6463        };
6464      };
6465      var PlatformDetection = { detect: detect$2 };
6466  
6467      var detect$3 = cached(function () {
6468        var userAgent = domGlobals.navigator.userAgent;
6469        return PlatformDetection.detect(userAgent);
6470      });
6471      var PlatformDetection$1 = { detect: detect$3 };
6472  
6473      var ELEMENT$1 = ELEMENT;
6474      var DOCUMENT$1 = DOCUMENT;
6475      var bypassSelector = function (dom) {
6476        return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
6477      };
6478      var all = function (selector, scope) {
6479        var base = scope === undefined ? domGlobals.document : scope.dom();
6480        return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
6481      };
6482      var one = function (selector, scope) {
6483        var base = scope === undefined ? domGlobals.document : scope.dom();
6484        return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
6485      };
6486  
6487      var regularContains = function (e1, e2) {
6488        var d1 = e1.dom();
6489        var d2 = e2.dom();
6490        return d1 === d2 ? false : d1.contains(d2);
6491      };
6492      var ieContains = function (e1, e2) {
6493        return Node.documentPositionContainedBy(e1.dom(), e2.dom());
6494      };
6495      var browser = PlatformDetection$1.detect().browser;
6496      var contains$1 = browser.isIE() ? ieContains : regularContains;
6497  
6498      var spot = Immutable('element', 'offset');
6499  
6500      var descendants = function (scope, selector) {
6501        return all(selector, scope);
6502      };
6503  
6504      var trim = global$2.trim;
6505      var hasContentEditableState = function (value) {
6506        return function (node) {
6507          if (node && node.nodeType === 1) {
6508            if (node.contentEditable === value) {
6509              return true;
6510            }
6511            if (node.getAttribute('data-mce-contenteditable') === value) {
6512              return true;
6513            }
6514          }
6515          return false;
6516        };
6517      };
6518      var isContentEditableTrue = hasContentEditableState('true');
6519      var isContentEditableFalse = hasContentEditableState('false');
6520      var create = function (type, title, url, level, attach) {
6521        return {
6522          type: type,
6523          title: title,
6524          url: url,
6525          level: level,
6526          attach: attach
6527        };
6528      };
6529      var isChildOfContentEditableTrue = function (node) {
6530        while (node = node.parentNode) {
6531          var value = node.contentEditable;
6532          if (value && value !== 'inherit') {
6533            return isContentEditableTrue(node);
6534          }
6535        }
6536        return false;
6537      };
6538      var select = function (selector, root) {
6539        return map(descendants(Element.fromDom(root), selector), function (element) {
6540          return element.dom();
6541        });
6542      };
6543      var getElementText = function (elm) {
6544        return elm.innerText || elm.textContent;
6545      };
6546      var getOrGenerateId = function (elm) {
6547        return elm.id ? elm.id : generate('h');
6548      };
6549      var isAnchor = function (elm) {
6550        return elm && elm.nodeName === 'A' && (elm.id || elm.name);
6551      };
6552      var isValidAnchor = function (elm) {
6553        return isAnchor(elm) && isEditable(elm);
6554      };
6555      var isHeader = function (elm) {
6556        return elm && /^(H[1-6])$/.test(elm.nodeName);
6557      };
6558      var isEditable = function (elm) {
6559        return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
6560      };
6561      var isValidHeader = function (elm) {
6562        return isHeader(elm) && isEditable(elm);
6563      };
6564      var getLevel = function (elm) {
6565        return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
6566      };
6567      var headerTarget = function (elm) {
6568        var headerId = getOrGenerateId(elm);
6569        var attach = function () {
6570          elm.id = headerId;
6571        };
6572        return create('header', getElementText(elm), '#' + headerId, getLevel(elm), attach);
6573      };
6574      var anchorTarget = function (elm) {
6575        var anchorId = elm.id || elm.name;
6576        var anchorText = getElementText(elm);
6577        return create('anchor', anchorText ? anchorText : '#' + anchorId, '#' + anchorId, 0, noop);
6578      };
6579      var getHeaderTargets = function (elms) {
6580        return map(filter(elms, isValidHeader), headerTarget);
6581      };
6582      var getAnchorTargets = function (elms) {
6583        return map(filter(elms, isValidAnchor), anchorTarget);
6584      };
6585      var getTargetElements = function (elm) {
6586        var elms = select('h1,h2,h3,h4,h5,h6,a:not([href])', elm);
6587        return elms;
6588      };
6589      var hasTitle = function (target) {
6590        return trim(target.title).length > 0;
6591      };
6592      var find$2 = function (elm) {
6593        var elms = getTargetElements(elm);
6594        return filter(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
6595      };
6596      var LinkTargets = { find: find$2 };
6597  
6598      var getActiveEditor = function () {
6599        return window.tinymce ? window.tinymce.activeEditor : global$1.activeEditor;
6600      };
6601      var history = {};
6602      var HISTORY_LENGTH = 5;
6603      var clearHistory = function () {
6604        history = {};
6605      };
6606      var toMenuItem = function (target) {
6607        return {
6608          title: target.title,
6609          value: {
6610            title: { raw: target.title },
6611            url: target.url,
6612            attach: target.attach
6613          }
6614        };
6615      };
6616      var toMenuItems = function (targets) {
6617        return global$2.map(targets, toMenuItem);
6618      };
6619      var staticMenuItem = function (title, url) {
6620        return {
6621          title: title,
6622          value: {
6623            title: title,
6624            url: url,
6625            attach: noop
6626          }
6627        };
6628      };
6629      var isUniqueUrl = function (url, targets) {
6630        var foundTarget = exists(targets, function (target) {
6631          return target.url === url;
6632        });
6633        return !foundTarget;
6634      };
6635      var getSetting = function (editorSettings, name, defaultValue) {
6636        var value = name in editorSettings ? editorSettings[name] : defaultValue;
6637        return value === false ? null : value;
6638      };
6639      var createMenuItems = function (term, targets, fileType, editorSettings) {
6640        var separator = { title: '-' };
6641        var fromHistoryMenuItems = function (history) {
6642          var historyItems = history.hasOwnProperty(fileType) ? history[fileType] : [];
6643          var uniqueHistory = filter(historyItems, function (url) {
6644            return isUniqueUrl(url, targets);
6645          });
6646          return global$2.map(uniqueHistory, function (url) {
6647            return {
6648              title: url,
6649              value: {
6650                title: url,
6651                url: url,
6652                attach: noop
6653              }
6654            };
6655          });
6656        };
6657        var fromMenuItems = function (type) {
6658          var filteredTargets = filter(targets, function (target) {
6659            return target.type === type;
6660          });
6661          return toMenuItems(filteredTargets);
6662        };
6663        var anchorMenuItems = function () {
6664          var anchorMenuItems = fromMenuItems('anchor');
6665          var topAnchor = getSetting(editorSettings, 'anchor_top', '#top');
6666          var bottomAchor = getSetting(editorSettings, 'anchor_bottom', '#bottom');
6667          if (topAnchor !== null) {
6668            anchorMenuItems.unshift(staticMenuItem('<top>', topAnchor));
6669          }
6670          if (bottomAchor !== null) {
6671            anchorMenuItems.push(staticMenuItem('<bottom>', bottomAchor));
6672          }
6673          return anchorMenuItems;
6674        };
6675        var join = function (items) {
6676          return foldl(items, function (a, b) {
6677            var bothEmpty = a.length === 0 || b.length === 0;
6678            return bothEmpty ? a.concat(b) : a.concat(separator, b);
6679          }, []);
6680        };
6681        if (editorSettings.typeahead_urls === false) {
6682          return [];
6683        }
6684        return fileType === 'file' ? join([
6685          filterByQuery(term, fromHistoryMenuItems(history)),
6686          filterByQuery(term, fromMenuItems('header')),
6687          filterByQuery(term, anchorMenuItems())
6688        ]) : filterByQuery(term, fromHistoryMenuItems(history));
6689      };
6690      var addToHistory = function (url, fileType) {
6691        var items = history[fileType];
6692        if (!/^https?/.test(url)) {
6693          return;
6694        }
6695        if (items) {
6696          if (indexOf(items, url).isNone()) {
6697            history[fileType] = items.slice(0, HISTORY_LENGTH).concat(url);
6698          }
6699        } else {
6700          history[fileType] = [url];
6701        }
6702      };
6703      var filterByQuery = function (term, menuItems) {
6704        var lowerCaseTerm = term.toLowerCase();
6705        var result = global$2.grep(menuItems, function (item) {
6706          return item.title.toLowerCase().indexOf(lowerCaseTerm) !== -1;
6707        });
6708        return result.length === 1 && result[0].title === term ? [] : result;
6709      };
6710      var getTitle = function (linkDetails) {
6711        var title = linkDetails.title;
6712        return title.raw ? title.raw : title;
6713      };
6714      var setupAutoCompleteHandler = function (ctrl, editorSettings, bodyElm, fileType) {
6715        var autocomplete = function (term) {
6716          var linkTargets = LinkTargets.find(bodyElm);
6717          var menuItems = createMenuItems(term, linkTargets, fileType, editorSettings);
6718          ctrl.showAutoComplete(menuItems, term);
6719        };
6720        ctrl.on('autocomplete', function () {
6721          autocomplete(ctrl.value());
6722        });
6723        ctrl.on('selectitem', function (e) {
6724          var linkDetails = e.value;
6725          ctrl.value(linkDetails.url);
6726          var title = getTitle(linkDetails);
6727          if (fileType === 'image') {
6728            ctrl.fire('change', {
6729              meta: {
6730                alt: title,
6731                attach: linkDetails.attach
6732              }
6733            });
6734          } else {
6735            ctrl.fire('change', {
6736              meta: {
6737                text: title,
6738                attach: linkDetails.attach
6739              }
6740            });
6741          }
6742          ctrl.focus();
6743        });
6744        ctrl.on('click', function (e) {
6745          if (ctrl.value().length === 0 && e.target.nodeName === 'INPUT') {
6746            autocomplete('');
6747          }
6748        });
6749        ctrl.on('PostRender', function () {
6750          ctrl.getRoot().on('submit', function (e) {
6751            if (!e.isDefaultPrevented()) {
6752              addToHistory(ctrl.value(), fileType);
6753            }
6754          });
6755        });
6756      };
6757      var statusToUiState = function (result) {
6758        var status = result.status, message = result.message;
6759        if (status === 'valid') {
6760          return {
6761            status: 'ok',
6762            message: message
6763          };
6764        } else if (status === 'unknown') {
6765          return {
6766            status: 'warn',
6767            message: message
6768          };
6769        } else if (status === 'invalid') {
6770          return {
6771            status: 'warn',
6772            message: message
6773          };
6774        } else {
6775          return {
6776            status: 'none',
6777            message: ''
6778          };
6779        }
6780      };
6781      var setupLinkValidatorHandler = function (ctrl, editorSettings, fileType) {
6782        var validatorHandler = editorSettings.filepicker_validator_handler;
6783        if (validatorHandler) {
6784          var validateUrl_1 = function (url) {
6785            if (url.length === 0) {
6786              ctrl.statusLevel('none');
6787              return;
6788            }
6789            validatorHandler({
6790              url: url,
6791              type: fileType
6792            }, function (result) {
6793              var uiState = statusToUiState(result);
6794              ctrl.statusMessage(uiState.message);
6795              ctrl.statusLevel(uiState.status);
6796            });
6797          };
6798          ctrl.state.on('change:value', function (e) {
6799            validateUrl_1(e.value);
6800          });
6801        }
6802      };
6803      var FilePicker = ComboBox.extend({
6804        Statics: { clearHistory: clearHistory },
6805        init: function (settings) {
6806          var self = this, editor = getActiveEditor(), editorSettings = editor.settings;
6807          var actionCallback, fileBrowserCallback, fileBrowserCallbackTypes;
6808          var fileType = settings.filetype;
6809          settings.spellcheck = false;
6810          fileBrowserCallbackTypes = editorSettings.file_picker_types || editorSettings.file_browser_callback_types;
6811          if (fileBrowserCallbackTypes) {
6812            fileBrowserCallbackTypes = global$2.makeMap(fileBrowserCallbackTypes, /[, ]/);
6813          }
6814          if (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType]) {
6815            fileBrowserCallback = editorSettings.file_picker_callback;
6816            if (fileBrowserCallback && (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType])) {
6817              actionCallback = function () {
6818                var meta = self.fire('beforecall').meta;
6819                meta = global$2.extend({ filetype: fileType }, meta);
6820                fileBrowserCallback.call(editor, function (value, meta) {
6821                  self.value(value).fire('change', { meta: meta });
6822                }, self.value(), meta);
6823              };
6824            } else {
6825              fileBrowserCallback = editorSettings.file_browser_callback;
6826              if (fileBrowserCallback && (!fileBrowserCallbackTypes || fileBrowserCallbackTypes[fileType])) {
6827                actionCallback = function () {
6828                  fileBrowserCallback(self.getEl('inp').id, self.value(), fileType, window);
6829                };
6830              }
6831            }
6832          }
6833          if (actionCallback) {
6834            settings.icon = 'browse';
6835            settings.onaction = actionCallback;
6836          }
6837          self._super(settings);
6838          self.classes.add('filepicker');
6839          setupAutoCompleteHandler(self, editorSettings, editor.getBody(), fileType);
6840          setupLinkValidatorHandler(self, editorSettings, fileType);
6841        }
6842      });
6843  
6844      var FitLayout = AbsoluteLayout.extend({
6845        recalc: function (container) {
6846          var contLayoutRect = container.layoutRect(), paddingBox = container.paddingBox;
6847          container.items().filter(':visible').each(function (ctrl) {
6848            ctrl.layoutRect({
6849              x: paddingBox.left,
6850              y: paddingBox.top,
6851              w: contLayoutRect.innerW - paddingBox.right - paddingBox.left,
6852              h: contLayoutRect.innerH - paddingBox.top - paddingBox.bottom
6853            });
6854            if (ctrl.recalc) {
6855              ctrl.recalc();
6856            }
6857          });
6858        }
6859      });
6860  
6861      var FlexLayout = AbsoluteLayout.extend({
6862        recalc: function (container) {
6863          var i, l, items, contLayoutRect, contPaddingBox, contSettings, align, pack, spacing, totalFlex, availableSpace, direction;
6864          var ctrl, ctrlLayoutRect, ctrlSettings, flex;
6865          var maxSizeItems = [];
6866          var size, maxSize, ratio, rect, pos, maxAlignEndPos;
6867          var sizeName, minSizeName, posName, maxSizeName, beforeName, innerSizeName, deltaSizeName, contentSizeName;
6868          var alignAxisName, alignInnerSizeName, alignSizeName, alignMinSizeName, alignBeforeName, alignAfterName;
6869          var alignDeltaSizeName, alignContentSizeName;
6870          var max = Math.max, min = Math.min;
6871          items = container.items().filter(':visible');
6872          contLayoutRect = container.layoutRect();
6873          contPaddingBox = container.paddingBox;
6874          contSettings = container.settings;
6875          direction = container.isRtl() ? contSettings.direction || 'row-reversed' : contSettings.direction;
6876          align = contSettings.align;
6877          pack = container.isRtl() ? contSettings.pack || 'end' : contSettings.pack;
6878          spacing = contSettings.spacing || 0;
6879          if (direction === 'row-reversed' || direction === 'column-reverse') {
6880            items = items.set(items.toArray().reverse());
6881            direction = direction.split('-')[0];
6882          }
6883          if (direction === 'column') {
6884            posName = 'y';
6885            sizeName = 'h';
6886            minSizeName = 'minH';
6887            maxSizeName = 'maxH';
6888            innerSizeName = 'innerH';
6889            beforeName = 'top';
6890            deltaSizeName = 'deltaH';
6891            contentSizeName = 'contentH';
6892            alignBeforeName = 'left';
6893            alignSizeName = 'w';
6894            alignAxisName = 'x';
6895            alignInnerSizeName = 'innerW';
6896            alignMinSizeName = 'minW';
6897            alignAfterName = 'right';
6898            alignDeltaSizeName = 'deltaW';
6899            alignContentSizeName = 'contentW';
6900          } else {
6901            posName = 'x';
6902            sizeName = 'w';
6903            minSizeName = 'minW';
6904            maxSizeName = 'maxW';
6905            innerSizeName = 'innerW';
6906            beforeName = 'left';
6907            deltaSizeName = 'deltaW';
6908            contentSizeName = 'contentW';
6909            alignBeforeName = 'top';
6910            alignSizeName = 'h';
6911            alignAxisName = 'y';
6912            alignInnerSizeName = 'innerH';
6913            alignMinSizeName = 'minH';
6914            alignAfterName = 'bottom';
6915            alignDeltaSizeName = 'deltaH';
6916            alignContentSizeName = 'contentH';
6917          }
6918          availableSpace = contLayoutRect[innerSizeName] - contPaddingBox[beforeName] - contPaddingBox[beforeName];
6919          maxAlignEndPos = totalFlex = 0;
6920          for (i = 0, l = items.length; i < l; i++) {
6921            ctrl = items[i];
6922            ctrlLayoutRect = ctrl.layoutRect();
6923            ctrlSettings = ctrl.settings;
6924            flex = ctrlSettings.flex;
6925            availableSpace -= i < l - 1 ? spacing : 0;
6926            if (flex > 0) {
6927              totalFlex += flex;
6928              if (ctrlLayoutRect[maxSizeName]) {
6929                maxSizeItems.push(ctrl);
6930              }
6931              ctrlLayoutRect.flex = flex;
6932            }
6933            availableSpace -= ctrlLayoutRect[minSizeName];
6934            size = contPaddingBox[alignBeforeName] + ctrlLayoutRect[alignMinSizeName] + contPaddingBox[alignAfterName];
6935            if (size > maxAlignEndPos) {
6936              maxAlignEndPos = size;
6937            }
6938          }
6939          rect = {};
6940          if (availableSpace < 0) {
6941            rect[minSizeName] = contLayoutRect[minSizeName] - availableSpace + contLayoutRect[deltaSizeName];
6942          } else {
6943            rect[minSizeName] = contLayoutRect[innerSizeName] - availableSpace + contLayoutRect[deltaSizeName];
6944          }
6945          rect[alignMinSizeName] = maxAlignEndPos + contLayoutRect[alignDeltaSizeName];
6946          rect[contentSizeName] = contLayoutRect[innerSizeName] - availableSpace;
6947          rect[alignContentSizeName] = maxAlignEndPos;
6948          rect.minW = min(rect.minW, contLayoutRect.maxW);
6949          rect.minH = min(rect.minH, contLayoutRect.maxH);
6950          rect.minW = max(rect.minW, contLayoutRect.startMinWidth);
6951          rect.minH = max(rect.minH, contLayoutRect.startMinHeight);
6952          if (contLayoutRect.autoResize && (rect.minW !== contLayoutRect.minW || rect.minH !== contLayoutRect.minH)) {
6953            rect.w = rect.minW;
6954            rect.h = rect.minH;
6955            container.layoutRect(rect);
6956            this.recalc(container);
6957            if (container._lastRect === null) {
6958              var parentCtrl = container.parent();
6959              if (parentCtrl) {
6960                parentCtrl._lastRect = null;
6961                parentCtrl.recalc();
6962              }
6963            }
6964            return;
6965          }
6966          ratio = availableSpace / totalFlex;
6967          for (i = 0, l = maxSizeItems.length; i < l; i++) {
6968            ctrl = maxSizeItems[i];
6969            ctrlLayoutRect = ctrl.layoutRect();
6970            maxSize = ctrlLayoutRect[maxSizeName];
6971            size = ctrlLayoutRect[minSizeName] + ctrlLayoutRect.flex * ratio;
6972            if (size > maxSize) {
6973              availableSpace -= ctrlLayoutRect[maxSizeName] - ctrlLayoutRect[minSizeName];
6974              totalFlex -= ctrlLayoutRect.flex;
6975              ctrlLayoutRect.flex = 0;
6976              ctrlLayoutRect.maxFlexSize = maxSize;
6977            } else {
6978              ctrlLayoutRect.maxFlexSize = 0;
6979            }
6980          }
6981          ratio = availableSpace / totalFlex;
6982          pos = contPaddingBox[beforeName];
6983          rect = {};
6984          if (totalFlex === 0) {
6985            if (pack === 'end') {
6986              pos = availableSpace + contPaddingBox[beforeName];
6987            } else if (pack === 'center') {
6988              pos = Math.round(contLayoutRect[innerSizeName] / 2 - (contLayoutRect[innerSizeName] - availableSpace) / 2) + contPaddingBox[beforeName];
6989              if (pos < 0) {
6990                pos = contPaddingBox[beforeName];
6991              }
6992            } else if (pack === 'justify') {
6993              pos = contPaddingBox[beforeName];
6994              spacing = Math.floor(availableSpace / (items.length - 1));
6995            }
6996          }
6997          rect[alignAxisName] = contPaddingBox[alignBeforeName];
6998          for (i = 0, l = items.length; i < l; i++) {
6999            ctrl = items[i];
7000            ctrlLayoutRect = ctrl.layoutRect();
7001            size = ctrlLayoutRect.maxFlexSize || ctrlLayoutRect[minSizeName];
7002            if (align === 'center') {
7003              rect[alignAxisName] = Math.round(contLayoutRect[alignInnerSizeName] / 2 - ctrlLayoutRect[alignSizeName] / 2);
7004            } else if (align === 'stretch') {
7005              rect[alignSizeName] = max(ctrlLayoutRect[alignMinSizeName] || 0, contLayoutRect[alignInnerSizeName] - contPaddingBox[alignBeforeName] - contPaddingBox[alignAfterName]);
7006              rect[alignAxisName] = contPaddingBox[alignBeforeName];
7007            } else if (align === 'end') {
7008              rect[alignAxisName] = contLayoutRect[alignInnerSizeName] - ctrlLayoutRect[alignSizeName] - contPaddingBox.top;
7009            }
7010            if (ctrlLayoutRect.flex > 0) {
7011              size += ctrlLayoutRect.flex * ratio;
7012            }
7013            rect[sizeName] = size;
7014            rect[posName] = pos;
7015            ctrl.layoutRect(rect);
7016            if (ctrl.recalc) {
7017              ctrl.recalc();
7018            }
7019            pos += size + spacing;
7020          }
7021        }
7022      });
7023  
7024      var FlowLayout = Layout.extend({
7025        Defaults: {
7026          containerClass: 'flow-layout',
7027          controlClass: 'flow-layout-item',
7028          endClass: 'break'
7029        },
7030        recalc: function (container) {
7031          container.items().filter(':visible').each(function (ctrl) {
7032            if (ctrl.recalc) {
7033              ctrl.recalc();
7034            }
7035          });
7036        },
7037        isNative: function () {
7038          return true;
7039        }
7040      });
7041  
7042      var descendant = function (scope, selector) {
7043        return one(selector, scope);
7044      };
7045  
7046      var toggleFormat = function (editor, fmt) {
7047        return function () {
7048          editor.execCommand('mceToggleFormat', false, fmt);
7049        };
7050      };
7051      var addFormatChangedListener = function (editor, name, changed) {
7052        var handler = function (state) {
7053          changed(state, name);
7054        };
7055        if (editor.formatter) {
7056          editor.formatter.formatChanged(name, handler);
7057        } else {
7058          editor.on('init', function () {
7059            editor.formatter.formatChanged(name, handler);
7060          });
7061        }
7062      };
7063      var postRenderFormatToggle = function (editor, name) {
7064        return function (e) {
7065          addFormatChangedListener(editor, name, function (state) {
7066            e.control.active(state);
7067          });
7068        };
7069      };
7070  
7071      var register = function (editor) {
7072        var alignFormats = [
7073          'alignleft',
7074          'aligncenter',
7075          'alignright',
7076          'alignjustify'
7077        ];
7078        var defaultAlign = 'alignleft';
7079        var alignMenuItems = [
7080          {
7081            text: 'Left',
7082            icon: 'alignleft',
7083            onclick: toggleFormat(editor, 'alignleft')
7084          },
7085          {
7086            text: 'Center',
7087            icon: 'aligncenter',
7088            onclick: toggleFormat(editor, 'aligncenter')
7089          },
7090          {
7091            text: 'Right',
7092            icon: 'alignright',
7093            onclick: toggleFormat(editor, 'alignright')
7094          },
7095          {
7096            text: 'Justify',
7097            icon: 'alignjustify',
7098            onclick: toggleFormat(editor, 'alignjustify')
7099          }
7100        ];
7101        editor.addMenuItem('align', {
7102          text: 'Align',
7103          menu: alignMenuItems
7104        });
7105        editor.addButton('align', {
7106          type: 'menubutton',
7107          icon: defaultAlign,
7108          menu: alignMenuItems,
7109          onShowMenu: function (e) {
7110            var menu = e.control.menu;
7111            global$2.each(alignFormats, function (formatName, idx) {
7112              menu.items().eq(idx).each(function (item) {
7113                return item.active(editor.formatter.match(formatName));
7114              });
7115            });
7116          },
7117          onPostRender: function (e) {
7118            var ctrl = e.control;
7119            global$2.each(alignFormats, function (formatName, idx) {
7120              addFormatChangedListener(editor, formatName, function (state) {
7121                ctrl.icon(defaultAlign);
7122                if (state) {
7123                  ctrl.icon(formatName);
7124                }
7125              });
7126            });
7127          }
7128        });
7129        global$2.each({
7130          alignleft: [
7131            'Align left',
7132            'JustifyLeft'
7133          ],
7134          aligncenter: [
7135            'Align center',
7136            'JustifyCenter'
7137          ],
7138          alignright: [
7139            'Align right',
7140            'JustifyRight'
7141          ],
7142          alignjustify: [
7143            'Justify',
7144            'JustifyFull'
7145          ],
7146          alignnone: [
7147            'No alignment',
7148            'JustifyNone'
7149          ]
7150        }, function (item, name) {
7151          editor.addButton(name, {
7152            active: false,
7153            tooltip: item[0],
7154            cmd: item[1],
7155            onPostRender: postRenderFormatToggle(editor, name)
7156          });
7157        });
7158      };
7159      var Align = { register: register };
7160  
7161      var getFirstFont = function (fontFamily) {
7162        return fontFamily ? fontFamily.split(',')[0] : '';
7163      };
7164      var findMatchingValue = function (items, fontFamily) {
7165        var font = fontFamily ? fontFamily.toLowerCase() : '';
7166        var value;
7167        global$2.each(items, function (item) {
7168          if (item.value.toLowerCase() === font) {
7169            value = item.value;
7170          }
7171        });
7172        global$2.each(items, function (item) {
7173          if (!value && getFirstFont(item.value).toLowerCase() === getFirstFont(font).toLowerCase()) {
7174            value = item.value;
7175          }
7176        });
7177        return value;
7178      };
7179      var createFontNameListBoxChangeHandler = function (editor, items) {
7180        return function () {
7181          var self = this;
7182          self.state.set('value', null);
7183          editor.on('init nodeChange', function (e) {
7184            var fontFamily = editor.queryCommandValue('FontName');
7185            var match = findMatchingValue(items, fontFamily);
7186            self.value(match ? match : null);
7187            if (!match && fontFamily) {
7188              self.text(getFirstFont(fontFamily));
7189            }
7190          });
7191        };
7192      };
7193      var createFormats = function (formats) {
7194        formats = formats.replace(/;$/, '').split(';');
7195        var i = formats.length;
7196        while (i--) {
7197          formats[i] = formats[i].split('=');
7198        }
7199        return formats;
7200      };
7201      var getFontItems = function (editor) {
7202        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';
7203        var fonts = createFormats(editor.settings.font_formats || defaultFontsFormats);
7204        return global$2.map(fonts, function (font) {
7205          return {
7206            text: { raw: font[0] },
7207            value: font[1],
7208            textStyle: font[1].indexOf('dings') === -1 ? 'font-family:' + font[1] : ''
7209          };
7210        });
7211      };
7212      var registerButtons = function (editor) {
7213        editor.addButton('fontselect', function () {
7214          var items = getFontItems(editor);
7215          return {
7216            type: 'listbox',
7217            text: 'Font Family',
7218            tooltip: 'Font Family',
7219            values: items,
7220            fixedWidth: true,
7221            onPostRender: createFontNameListBoxChangeHandler(editor, items),
7222            onselect: function (e) {
7223              if (e.control.settings.value) {
7224                editor.execCommand('FontName', false, e.control.settings.value);
7225              }
7226            }
7227          };
7228        });
7229      };
7230      var register$1 = function (editor) {
7231        registerButtons(editor);
7232      };
7233      var FontSelect = { register: register$1 };
7234  
7235      var round = function (number, precision) {
7236        var factor = Math.pow(10, precision);
7237        return Math.round(number * factor) / factor;
7238      };
7239      var toPt = function (fontSize, precision) {
7240        if (/[0-9.]+px$/.test(fontSize)) {
7241          return round(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
7242        }
7243        return fontSize;
7244      };
7245      var findMatchingValue$1 = function (items, pt, px) {
7246        var value;
7247        global$2.each(items, function (item) {
7248          if (item.value === px) {
7249            value = px;
7250          } else if (item.value === pt) {
7251            value = pt;
7252          }
7253        });
7254        return value;
7255      };
7256      var createFontSizeListBoxChangeHandler = function (editor, items) {
7257        return function () {
7258          var self = this;
7259          editor.on('init nodeChange', function (e) {
7260            var px, pt, precision, match;
7261            px = editor.queryCommandValue('FontSize');
7262            if (px) {
7263              for (precision = 3; !match && precision >= 0; precision--) {
7264                pt = toPt(px, precision);
7265                match = findMatchingValue$1(items, pt, px);
7266              }
7267            }
7268            self.value(match ? match : null);
7269            if (!match) {
7270              self.text(pt);
7271            }
7272          });
7273        };
7274      };
7275      var getFontSizeItems = function (editor) {
7276        var defaultFontsizeFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
7277        var fontsizeFormats = editor.settings.fontsize_formats || defaultFontsizeFormats;
7278        return global$2.map(fontsizeFormats.split(' '), function (item) {
7279          var text = item, value = item;
7280          var values = item.split('=');
7281          if (values.length > 1) {
7282            text = values[0];
7283            value = values[1];
7284          }
7285          return {
7286            text: text,
7287            value: value
7288          };
7289        });
7290      };
7291      var registerButtons$1 = function (editor) {
7292        editor.addButton('fontsizeselect', function () {
7293          var items = getFontSizeItems(editor);
7294          return {
7295            type: 'listbox',
7296            text: 'Font Sizes',
7297            tooltip: 'Font Sizes',
7298            values: items,
7299            fixedWidth: true,
7300            onPostRender: createFontSizeListBoxChangeHandler(editor, items),
7301            onclick: function (e) {
7302              if (e.control.settings.value) {
7303                editor.execCommand('FontSize', false, e.control.settings.value);
7304              }
7305            }
7306          };
7307        });
7308      };
7309      var register$2 = function (editor) {
7310        registerButtons$1(editor);
7311      };
7312      var FontSizeSelect = { register: register$2 };
7313  
7314      var hideMenuObjects = function (editor, menu) {
7315        var count = menu.length;
7316        global$2.each(menu, function (item) {
7317          if (item.menu) {
7318            item.hidden = hideMenuObjects(editor, item.menu) === 0;
7319          }
7320          var formatName = item.format;
7321          if (formatName) {
7322            item.hidden = !editor.formatter.canApply(formatName);
7323          }
7324          if (item.hidden) {
7325            count--;
7326          }
7327        });
7328        return count;
7329      };
7330      var hideFormatMenuItems = function (editor, menu) {
7331        var count = menu.items().length;
7332        menu.items().each(function (item) {
7333          if (item.menu) {
7334            item.visible(hideFormatMenuItems(editor, item.menu) > 0);
7335          }
7336          if (!item.menu && item.settings.menu) {
7337            item.visible(hideMenuObjects(editor, item.settings.menu) > 0);
7338          }
7339          var formatName = item.settings.format;
7340          if (formatName) {
7341            item.visible(editor.formatter.canApply(formatName));
7342          }
7343          if (!item.visible()) {
7344            count--;
7345          }
7346        });
7347        return count;
7348      };
7349      var createFormatMenu = function (editor) {
7350        var count = 0;
7351        var newFormats = [];
7352        var defaultStyleFormats = [
7353          {
7354            title: 'Headings',
7355            items: [
7356              {
7357                title: 'Heading 1',
7358                format: 'h1'
7359              },
7360              {
7361                title: 'Heading 2',
7362                format: 'h2'
7363              },
7364              {
7365                title: 'Heading 3',
7366                format: 'h3'
7367              },
7368              {
7369                title: 'Heading 4',
7370                format: 'h4'
7371              },
7372              {
7373                title: 'Heading 5',
7374                format: 'h5'
7375              },
7376              {
7377                title: 'Heading 6',
7378                format: 'h6'
7379              }
7380            ]
7381          },
7382          {
7383            title: 'Inline',
7384            items: [
7385              {
7386                title: 'Bold',
7387                icon: 'bold',
7388                format: 'bold'
7389              },
7390              {
7391                title: 'Italic',
7392                icon: 'italic',
7393                format: 'italic'
7394              },
7395              {
7396                title: 'Underline',
7397                icon: 'underline',
7398                format: 'underline'
7399              },
7400              {
7401                title: 'Strikethrough',
7402                icon: 'strikethrough',
7403                format: 'strikethrough'
7404              },
7405              {
7406                title: 'Superscript',
7407                icon: 'superscript',
7408                format: 'superscript'
7409              },
7410              {
7411                title: 'Subscript',
7412                icon: 'subscript',
7413                format: 'subscript'
7414              },
7415              {
7416                title: 'Code',
7417                icon: 'code',
7418                format: 'code'
7419              }
7420            ]
7421          },
7422          {
7423            title: 'Blocks',
7424            items: [
7425              {
7426                title: 'Paragraph',
7427                format: 'p'
7428              },
7429              {
7430                title: 'Blockquote',
7431                format: 'blockquote'
7432              },
7433              {
7434                title: 'Div',
7435                format: 'div'
7436              },
7437              {
7438                title: 'Pre',
7439                format: 'pre'
7440              }
7441            ]
7442          },
7443          {
7444            title: 'Alignment',
7445            items: [
7446              {
7447                title: 'Left',
7448                icon: 'alignleft',
7449                format: 'alignleft'
7450              },
7451              {
7452                title: 'Center',
7453                icon: 'aligncenter',
7454                format: 'aligncenter'
7455              },
7456              {
7457                title: 'Right',
7458                icon: 'alignright',
7459                format: 'alignright'
7460              },
7461              {
7462                title: 'Justify',
7463                icon: 'alignjustify',
7464                format: 'alignjustify'
7465              }
7466            ]
7467          }
7468        ];
7469        var createMenu = function (formats) {
7470          var menu = [];
7471          if (!formats) {
7472            return;
7473          }
7474          global$2.each(formats, function (format) {
7475            var menuItem = {
7476              text: format.title,
7477              icon: format.icon
7478            };
7479            if (format.items) {
7480              menuItem.menu = createMenu(format.items);
7481            } else {
7482              var formatName = format.format || 'custom' + count++;
7483              if (!format.format) {
7484                format.name = formatName;
7485                newFormats.push(format);
7486              }
7487              menuItem.format = formatName;
7488              menuItem.cmd = format.cmd;
7489            }
7490            menu.push(menuItem);
7491          });
7492          return menu;
7493        };
7494        var createStylesMenu = function () {
7495          var menu;
7496          if (editor.settings.style_formats_merge) {
7497            if (editor.settings.style_formats) {
7498              menu = createMenu(defaultStyleFormats.concat(editor.settings.style_formats));
7499            } else {
7500              menu = createMenu(defaultStyleFormats);
7501            }
7502          } else {
7503            menu = createMenu(editor.settings.style_formats || defaultStyleFormats);
7504          }
7505          return menu;
7506        };
7507        editor.on('init', function () {
7508          global$2.each(newFormats, function (format) {
7509            editor.formatter.register(format.name, format);
7510          });
7511        });
7512        return {
7513          type: 'menu',
7514          items: createStylesMenu(),
7515          onPostRender: function (e) {
7516            editor.fire('renderFormatsMenu', { control: e.control });
7517          },
7518          itemDefaults: {
7519            preview: true,
7520            textStyle: function () {
7521              if (this.settings.format) {
7522                return editor.formatter.getCssText(this.settings.format);
7523              }
7524            },
7525            onPostRender: function () {
7526              var self = this;
7527              self.parent().on('show', function () {
7528                var formatName, command;
7529                formatName = self.settings.format;
7530                if (formatName) {
7531                  self.disabled(!editor.formatter.canApply(formatName));
7532                  self.active(editor.formatter.match(formatName));
7533                }
7534                command = self.settings.cmd;
7535                if (command) {
7536                  self.active(editor.queryCommandState(command));
7537                }
7538              });
7539            },
7540            onclick: function () {
7541              if (this.settings.format) {
7542                toggleFormat(editor, this.settings.format)();
7543              }
7544              if (this.settings.cmd) {
7545                editor.execCommand(this.settings.cmd);
7546              }
7547            }
7548          }
7549        };
7550      };
7551      var registerMenuItems = function (editor, formatMenu) {
7552        editor.addMenuItem('formats', {
7553          text: 'Formats',
7554          menu: formatMenu
7555        });
7556      };
7557      var registerButtons$2 = function (editor, formatMenu) {
7558        editor.addButton('styleselect', {
7559          type: 'menubutton',
7560          text: 'Formats',
7561          menu: formatMenu,
7562          onShowMenu: function () {
7563            if (editor.settings.style_formats_autohide) {
7564              hideFormatMenuItems(editor, this.menu);
7565            }
7566          }
7567        });
7568      };
7569      var register$3 = function (editor) {
7570        var formatMenu = createFormatMenu(editor);
7571        registerMenuItems(editor, formatMenu);
7572        registerButtons$2(editor, formatMenu);
7573      };
7574      var Formats = { register: register$3 };
7575  
7576      var defaultBlocks = 'Paragraph=p;' + 'Heading 1=h1;' + 'Heading 2=h2;' + 'Heading 3=h3;' + 'Heading 4=h4;' + 'Heading 5=h5;' + 'Heading 6=h6;' + 'Preformatted=pre';
7577      var createFormats$1 = function (formats) {
7578        formats = formats.replace(/;$/, '').split(';');
7579        var i = formats.length;
7580        while (i--) {
7581          formats[i] = formats[i].split('=');
7582        }
7583        return formats;
7584      };
7585      var createListBoxChangeHandler = function (editor, items, formatName) {
7586        return function () {
7587          var self = this;
7588          editor.on('nodeChange', function (e) {
7589            var formatter = editor.formatter;
7590            var value = null;
7591            global$2.each(e.parents, function (node) {
7592              global$2.each(items, function (item) {
7593                if (formatName) {
7594                  if (formatter.matchNode(node, formatName, { value: item.value })) {
7595                    value = item.value;
7596                  }
7597                } else {
7598                  if (formatter.matchNode(node, item.value)) {
7599                    value = item.value;
7600                  }
7601                }
7602                if (value) {
7603                  return false;
7604                }
7605              });
7606              if (value) {
7607                return false;
7608              }
7609            });
7610            self.value(value);
7611          });
7612        };
7613      };
7614      var lazyFormatSelectBoxItems = function (editor, blocks) {
7615        return function () {
7616          var items = [];
7617          global$2.each(blocks, function (block) {
7618            items.push({
7619              text: block[0],
7620              value: block[1],
7621              textStyle: function () {
7622                return editor.formatter.getCssText(block[1]);
7623              }
7624            });
7625          });
7626          return {
7627            type: 'listbox',
7628            text: blocks[0][0],
7629            values: items,
7630            fixedWidth: true,
7631            onselect: function (e) {
7632              if (e.control) {
7633                var fmt = e.control.value();
7634                toggleFormat(editor, fmt)();
7635              }
7636            },
7637            onPostRender: createListBoxChangeHandler(editor, items)
7638          };
7639        };
7640      };
7641      var buildMenuItems = function (editor, blocks) {
7642        return global$2.map(blocks, function (block) {
7643          return {
7644            text: block[0],
7645            onclick: toggleFormat(editor, block[1]),
7646            textStyle: function () {
7647              return editor.formatter.getCssText(block[1]);
7648            }
7649          };
7650        });
7651      };
7652      var register$4 = function (editor) {
7653        var blocks = createFormats$1(editor.settings.block_formats || defaultBlocks);
7654        editor.addMenuItem('blockformats', {
7655          text: 'Blocks',
7656          menu: buildMenuItems(editor, blocks)
7657        });
7658        editor.addButton('formatselect', lazyFormatSelectBoxItems(editor, blocks));
7659      };
7660      var FormatSelect = { register: register$4 };
7661  
7662      var createCustomMenuItems = function (editor, names) {
7663        var items, nameList;
7664        if (typeof names === 'string') {
7665          nameList = names.split(' ');
7666        } else if (global$2.isArray(names)) {
7667          return flatten(global$2.map(names, function (names) {
7668            return createCustomMenuItems(editor, names);
7669          }));
7670        }
7671        items = global$2.grep(nameList, function (name) {
7672          return name === '|' || name in editor.menuItems;
7673        });
7674        return global$2.map(items, function (name) {
7675          return name === '|' ? { text: '-' } : editor.menuItems[name];
7676        });
7677      };
7678      var isSeparator$1 = function (menuItem) {
7679        return menuItem && menuItem.text === '-';
7680      };
7681      var trimMenuItems = function (menuItems) {
7682        var menuItems2 = filter(menuItems, function (menuItem, i, menuItems) {
7683          return !isSeparator$1(menuItem) || !isSeparator$1(menuItems[i - 1]);
7684        });
7685        return filter(menuItems2, function (menuItem, i, menuItems) {
7686          return !isSeparator$1(menuItem) || i > 0 && i < menuItems.length - 1;
7687        });
7688      };
7689      var createContextMenuItems = function (editor, context) {
7690        var outputMenuItems = [{ text: '-' }];
7691        var menuItems = global$2.grep(editor.menuItems, function (menuItem) {
7692          return menuItem.context === context;
7693        });
7694        global$2.each(menuItems, function (menuItem) {
7695          if (menuItem.separator === 'before') {
7696            outputMenuItems.push({ text: '|' });
7697          }
7698          if (menuItem.prependToContext) {
7699            outputMenuItems.unshift(menuItem);
7700          } else {
7701            outputMenuItems.push(menuItem);
7702          }
7703          if (menuItem.separator === 'after') {
7704            outputMenuItems.push({ text: '|' });
7705          }
7706        });
7707        return outputMenuItems;
7708      };
7709      var createInsertMenu = function (editor) {
7710        var insertButtonItems = editor.settings.insert_button_items;
7711        if (insertButtonItems) {
7712          return trimMenuItems(createCustomMenuItems(editor, insertButtonItems));
7713        } else {
7714          return trimMenuItems(createContextMenuItems(editor, 'insert'));
7715        }
7716      };
7717      var registerButtons$3 = function (editor) {
7718        editor.addButton('insert', {
7719          type: 'menubutton',
7720          icon: 'insert',
7721          menu: [],
7722          oncreatemenu: function () {
7723            this.menu.add(createInsertMenu(editor));
7724            this.menu.renderNew();
7725          }
7726        });
7727      };
7728      var register$5 = function (editor) {
7729        registerButtons$3(editor);
7730      };
7731      var InsertButton = { register: register$5 };
7732  
7733      var registerFormatButtons = function (editor) {
7734        global$2.each({
7735          bold: 'Bold',
7736          italic: 'Italic',
7737          underline: 'Underline',
7738          strikethrough: 'Strikethrough',
7739          subscript: 'Subscript',
7740          superscript: 'Superscript'
7741        }, function (text, name) {
7742          editor.addButton(name, {
7743            active: false,
7744            tooltip: text,
7745            onPostRender: postRenderFormatToggle(editor, name),
7746            onclick: toggleFormat(editor, name)
7747          });
7748        });
7749      };
7750      var registerCommandButtons = function (editor) {
7751        global$2.each({
7752          outdent: [
7753            'Decrease indent',
7754            'Outdent'
7755          ],
7756          indent: [
7757            'Increase indent',
7758            'Indent'
7759          ],
7760          cut: [
7761            'Cut',
7762            'Cut'
7763          ],
7764          copy: [
7765            'Copy',
7766            'Copy'
7767          ],
7768          paste: [
7769            'Paste',
7770            'Paste'
7771          ],
7772          help: [
7773            'Help',
7774            'mceHelp'
7775          ],
7776          selectall: [
7777            'Select all',
7778            'SelectAll'
7779          ],
7780          visualaid: [
7781            'Visual aids',
7782            'mceToggleVisualAid'
7783          ],
7784          newdocument: [
7785            'New document',
7786            'mceNewDocument'
7787          ],
7788          removeformat: [
7789            'Clear formatting',
7790            'RemoveFormat'
7791          ],
7792          remove: [
7793            'Remove',
7794            'Delete'
7795          ]
7796        }, function (item, name) {
7797          editor.addButton(name, {
7798            tooltip: item[0],
7799            cmd: item[1]
7800          });
7801        });
7802      };
7803      var registerCommandToggleButtons = function (editor) {
7804        global$2.each({
7805          blockquote: [
7806            'Blockquote',
7807            'mceBlockQuote'
7808          ],
7809          subscript: [
7810            'Subscript',
7811            'Subscript'
7812          ],
7813          superscript: [
7814            'Superscript',
7815            'Superscript'
7816          ]
7817        }, function (item, name) {
7818          editor.addButton(name, {
7819            active: false,
7820            tooltip: item[0],
7821            cmd: item[1],
7822            onPostRender: postRenderFormatToggle(editor, name)
7823          });
7824        });
7825      };
7826      var registerButtons$4 = function (editor) {
7827        registerFormatButtons(editor);
7828        registerCommandButtons(editor);
7829        registerCommandToggleButtons(editor);
7830      };
7831      var registerMenuItems$1 = function (editor) {
7832        global$2.each({
7833          bold: [
7834            'Bold',
7835            'Bold',
7836            'Meta+B'
7837          ],
7838          italic: [
7839            'Italic',
7840            'Italic',
7841            'Meta+I'
7842          ],
7843          underline: [
7844            'Underline',
7845            'Underline',
7846            'Meta+U'
7847          ],
7848          strikethrough: [
7849            'Strikethrough',
7850            'Strikethrough'
7851          ],
7852          subscript: [
7853            'Subscript',
7854            'Subscript'
7855          ],
7856          superscript: [
7857            'Superscript',
7858            'Superscript'
7859          ],
7860          removeformat: [
7861            'Clear formatting',
7862            'RemoveFormat'
7863          ],
7864          newdocument: [
7865            'New document',
7866            'mceNewDocument'
7867          ],
7868          cut: [
7869            'Cut',
7870            'Cut',
7871            'Meta+X'
7872          ],
7873          copy: [
7874            'Copy',
7875            'Copy',
7876            'Meta+C'
7877          ],
7878          paste: [
7879            'Paste',
7880            'Paste',
7881            'Meta+V'
7882          ],
7883          selectall: [
7884            'Select all',
7885            'SelectAll',
7886            'Meta+A'
7887          ]
7888        }, function (item, name) {
7889          editor.addMenuItem(name, {
7890            text: item[0],
7891            icon: name,
7892            shortcut: item[2],
7893            cmd: item[1]
7894          });
7895        });
7896        editor.addMenuItem('codeformat', {
7897          text: 'Code',
7898          icon: 'code',
7899          onclick: toggleFormat(editor, 'code')
7900        });
7901      };
7902      var register$6 = function (editor) {
7903        registerButtons$4(editor);
7904        registerMenuItems$1(editor);
7905      };
7906      var SimpleControls = { register: register$6 };
7907  
7908      var toggleUndoRedoState = function (editor, type) {
7909        return function () {
7910          var self = this;
7911          var checkState = function () {
7912            var typeFn = type === 'redo' ? 'hasRedo' : 'hasUndo';
7913            return editor.undoManager ? editor.undoManager[typeFn]() : false;
7914          };
7915          self.disabled(!checkState());
7916          editor.on('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', function () {
7917            self.disabled(editor.readonly || !checkState());
7918          });
7919        };
7920      };
7921      var registerMenuItems$2 = function (editor) {
7922        editor.addMenuItem('undo', {
7923          text: 'Undo',
7924          icon: 'undo',
7925          shortcut: 'Meta+Z',
7926          onPostRender: toggleUndoRedoState(editor, 'undo'),
7927          cmd: 'undo'
7928        });
7929        editor.addMenuItem('redo', {
7930          text: 'Redo',
7931          icon: 'redo',
7932          shortcut: 'Meta+Y',
7933          onPostRender: toggleUndoRedoState(editor, 'redo'),
7934          cmd: 'redo'
7935        });
7936      };
7937      var registerButtons$5 = function (editor) {
7938        editor.addButton('undo', {
7939          tooltip: 'Undo',
7940          onPostRender: toggleUndoRedoState(editor, 'undo'),
7941          cmd: 'undo'
7942        });
7943        editor.addButton('redo', {
7944          tooltip: 'Redo',
7945          onPostRender: toggleUndoRedoState(editor, 'redo'),
7946          cmd: 'redo'
7947        });
7948      };
7949      var register$7 = function (editor) {
7950        registerMenuItems$2(editor);
7951        registerButtons$5(editor);
7952      };
7953      var UndoRedo = { register: register$7 };
7954  
7955      var toggleVisualAidState = function (editor) {
7956        return function () {
7957          var self = this;
7958          editor.on('VisualAid', function (e) {
7959            self.active(e.hasVisual);
7960          });
7961          self.active(editor.hasVisual);
7962        };
7963      };
7964      var registerMenuItems$3 = function (editor) {
7965        editor.addMenuItem('visualaid', {
7966          text: 'Visual aids',
7967          selectable: true,
7968          onPostRender: toggleVisualAidState(editor),
7969          cmd: 'mceToggleVisualAid'
7970        });
7971      };
7972      var register$8 = function (editor) {
7973        registerMenuItems$3(editor);
7974      };
7975      var VisualAid = { register: register$8 };
7976  
7977      var setupEnvironment = function () {
7978        Widget.tooltips = !global$8.iOS;
7979        Control$1.translate = function (text) {
7980          return global$1.translate(text);
7981        };
7982      };
7983      var setupUiContainer = function (editor) {
7984        if (editor.settings.ui_container) {
7985          global$8.container = descendant(Element.fromDom(domGlobals.document.body), editor.settings.ui_container).fold(constant(null), function (elm) {
7986            return elm.dom();
7987          });
7988        }
7989      };
7990      var setupRtlMode = function (editor) {
7991        if (editor.rtl) {
7992          Control$1.rtl = true;
7993        }
7994      };
7995      var setupHideFloatPanels = function (editor) {
7996        editor.on('mousedown progressstate', function () {
7997          FloatPanel.hideAll();
7998        });
7999      };
8000      var setup$1 = function (editor) {
8001        setupRtlMode(editor);
8002        setupHideFloatPanels(editor);
8003        setupUiContainer(editor);
8004        setupEnvironment();
8005        FormatSelect.register(editor);
8006        Align.register(editor);
8007        SimpleControls.register(editor);
8008        UndoRedo.register(editor);
8009        FontSizeSelect.register(editor);
8010        FontSelect.register(editor);
8011        Formats.register(editor);
8012        VisualAid.register(editor);
8013        InsertButton.register(editor);
8014      };
8015      var FormatControls = { setup: setup$1 };
8016  
8017      var GridLayout = AbsoluteLayout.extend({
8018        recalc: function (container) {
8019          var settings, rows, cols, items, contLayoutRect, width, height, rect, ctrlLayoutRect, ctrl, x, y, posX, posY, ctrlSettings, contPaddingBox, align, spacingH, spacingV, alignH, alignV, maxX, maxY;
8020          var colWidths = [];
8021          var rowHeights = [];
8022          var ctrlMinWidth, ctrlMinHeight, availableWidth, availableHeight, reverseRows, idx;
8023          settings = container.settings;
8024          items = container.items().filter(':visible');
8025          contLayoutRect = container.layoutRect();
8026          cols = settings.columns || Math.ceil(Math.sqrt(items.length));
8027          rows = Math.ceil(items.length / cols);
8028          spacingH = settings.spacingH || settings.spacing || 0;
8029          spacingV = settings.spacingV || settings.spacing || 0;
8030          alignH = settings.alignH || settings.align;
8031          alignV = settings.alignV || settings.align;
8032          contPaddingBox = container.paddingBox;
8033          reverseRows = 'reverseRows' in settings ? settings.reverseRows : container.isRtl();
8034          if (alignH && typeof alignH === 'string') {
8035            alignH = [alignH];
8036          }
8037          if (alignV && typeof alignV === 'string') {
8038            alignV = [alignV];
8039          }
8040          for (x = 0; x < cols; x++) {
8041            colWidths.push(0);
8042          }
8043          for (y = 0; y < rows; y++) {
8044            rowHeights.push(0);
8045          }
8046          for (y = 0; y < rows; y++) {
8047            for (x = 0; x < cols; x++) {
8048              ctrl = items[y * cols + x];
8049              if (!ctrl) {
8050                break;
8051              }
8052              ctrlLayoutRect = ctrl.layoutRect();
8053              ctrlMinWidth = ctrlLayoutRect.minW;
8054              ctrlMinHeight = ctrlLayoutRect.minH;
8055              colWidths[x] = ctrlMinWidth > colWidths[x] ? ctrlMinWidth : colWidths[x];
8056              rowHeights[y] = ctrlMinHeight > rowHeights[y] ? ctrlMinHeight : rowHeights[y];
8057            }
8058          }
8059          availableWidth = contLayoutRect.innerW - contPaddingBox.left - contPaddingBox.right;
8060          for (maxX = 0, x = 0; x < cols; x++) {
8061            maxX += colWidths[x] + (x > 0 ? spacingH : 0);
8062            availableWidth -= (x > 0 ? spacingH : 0) + colWidths[x];
8063          }
8064          availableHeight = contLayoutRect.innerH - contPaddingBox.top - contPaddingBox.bottom;
8065          for (maxY = 0, y = 0; y < rows; y++) {
8066            maxY += rowHeights[y] + (y > 0 ? spacingV : 0);
8067            availableHeight -= (y > 0 ? spacingV : 0) + rowHeights[y];
8068          }
8069          maxX += contPaddingBox.left + contPaddingBox.right;
8070          maxY += contPaddingBox.top + contPaddingBox.bottom;
8071          rect = {};
8072          rect.minW = maxX + (contLayoutRect.w - contLayoutRect.innerW);
8073          rect.minH = maxY + (contLayoutRect.h - contLayoutRect.innerH);
8074          rect.contentW = rect.minW - contLayoutRect.deltaW;
8075          rect.contentH = rect.minH - contLayoutRect.deltaH;
8076          rect.minW = Math.min(rect.minW, contLayoutRect.maxW);
8077          rect.minH = Math.min(rect.minH, contLayoutRect.maxH);
8078          rect.minW = Math.max(rect.minW, contLayoutRect.startMinWidth);
8079          rect.minH = Math.max(rect.minH, contLayoutRect.startMinHeight);
8080          if (contLayoutRect.autoResize && (rect.minW !== contLayoutRect.minW || rect.minH !== contLayoutRect.minH)) {
8081            rect.w = rect.minW;
8082            rect.h = rect.minH;
8083            container.layoutRect(rect);
8084            this.recalc(container);
8085            if (container._lastRect === null) {
8086              var parentCtrl = container.parent();
8087              if (parentCtrl) {
8088                parentCtrl._lastRect = null;
8089                parentCtrl.recalc();
8090              }
8091            }
8092            return;
8093          }
8094          if (contLayoutRect.autoResize) {
8095            rect = container.layoutRect(rect);
8096            rect.contentW = rect.minW - contLayoutRect.deltaW;
8097            rect.contentH = rect.minH - contLayoutRect.deltaH;
8098          }
8099          var flexV;
8100          if (settings.packV === 'start') {
8101            flexV = 0;
8102          } else {
8103            flexV = availableHeight > 0 ? Math.floor(availableHeight / rows) : 0;
8104          }
8105          var totalFlex = 0;
8106          var flexWidths = settings.flexWidths;
8107          if (flexWidths) {
8108            for (x = 0; x < flexWidths.length; x++) {
8109              totalFlex += flexWidths[x];
8110            }
8111          } else {
8112            totalFlex = cols;
8113          }
8114          var ratio = availableWidth / totalFlex;
8115          for (x = 0; x < cols; x++) {
8116            colWidths[x] += flexWidths ? flexWidths[x] * ratio : ratio;
8117          }
8118          posY = contPaddingBox.top;
8119          for (y = 0; y < rows; y++) {
8120            posX = contPaddingBox.left;
8121            height = rowHeights[y] + flexV;
8122            for (x = 0; x < cols; x++) {
8123              if (reverseRows) {
8124                idx = y * cols + cols - 1 - x;
8125              } else {
8126                idx = y * cols + x;
8127              }
8128              ctrl = items[idx];
8129              if (!ctrl) {
8130                break;
8131              }
8132              ctrlSettings = ctrl.settings;
8133              ctrlLayoutRect = ctrl.layoutRect();
8134              width = Math.max(colWidths[x], ctrlLayoutRect.startMinWidth);
8135              ctrlLayoutRect.x = posX;
8136              ctrlLayoutRect.y = posY;
8137              align = ctrlSettings.alignH || (alignH ? alignH[x] || alignH[0] : null);
8138              if (align === 'center') {
8139                ctrlLayoutRect.x = posX + width / 2 - ctrlLayoutRect.w / 2;
8140              } else if (align === 'right') {
8141                ctrlLayoutRect.x = posX + width - ctrlLayoutRect.w;
8142              } else if (align === 'stretch') {
8143                ctrlLayoutRect.w = width;
8144              }
8145              align = ctrlSettings.alignV || (alignV ? alignV[x] || alignV[0] : null);
8146              if (align === 'center') {
8147                ctrlLayoutRect.y = posY + height / 2 - ctrlLayoutRect.h / 2;
8148              } else if (align === 'bottom') {
8149                ctrlLayoutRect.y = posY + height - ctrlLayoutRect.h;
8150              } else if (align === 'stretch') {
8151                ctrlLayoutRect.h = height;
8152              }
8153              ctrl.layoutRect(ctrlLayoutRect);
8154              posX += width + spacingH;
8155              if (ctrl.recalc) {
8156                ctrl.recalc();
8157              }
8158            }
8159            posY += height + spacingV;
8160          }
8161        }
8162      });
8163  
8164      var Iframe$1 = Widget.extend({
8165        renderHtml: function () {
8166          var self = this;
8167          self.classes.add('iframe');
8168          self.canFocus = false;
8169          return '<iframe id="' + self._id + '" class="' + self.classes + '" tabindex="-1" src="' + (self.settings.url || 'javascript:\'\'') + '" frameborder="0"></iframe>';
8170        },
8171        src: function (src) {
8172          this.getEl().src = src;
8173        },
8174        html: function (html, callback) {
8175          var self = this, body = this.getEl().contentWindow.document.body;
8176          if (!body) {
8177            global$7.setTimeout(function () {
8178              self.html(html);
8179            });
8180          } else {
8181            body.innerHTML = html;
8182            if (callback) {
8183              callback();
8184            }
8185          }
8186          return this;
8187        }
8188      });
8189  
8190      var InfoBox = Widget.extend({
8191        init: function (settings) {
8192          var self = this;
8193          self._super(settings);
8194          self.classes.add('widget').add('infobox');
8195          self.canFocus = false;
8196        },
8197        severity: function (level) {
8198          this.classes.remove('error');
8199          this.classes.remove('warning');
8200          this.classes.remove('success');
8201          this.classes.add(level);
8202        },
8203        help: function (state) {
8204          this.state.set('help', state);
8205        },
8206        renderHtml: function () {
8207          var self = this, prefix = self.classPrefix;
8208          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>';
8209        },
8210        bindStates: function () {
8211          var self = this;
8212          self.state.on('change:text', function (e) {
8213            self.getEl('body').firstChild.data = self.encode(e.value);
8214            if (self.state.get('rendered')) {
8215              self.updateLayoutRect();
8216            }
8217          });
8218          self.state.on('change:help', function (e) {
8219            self.classes.toggle('has-help', e.value);
8220            if (self.state.get('rendered')) {
8221              self.updateLayoutRect();
8222            }
8223          });
8224          return self._super();
8225        }
8226      });
8227  
8228      var Label = Widget.extend({
8229        init: function (settings) {
8230          var self = this;
8231          self._super(settings);
8232          self.classes.add('widget').add('label');
8233          self.canFocus = false;
8234          if (settings.multiline) {
8235            self.classes.add('autoscroll');
8236          }
8237          if (settings.strong) {
8238            self.classes.add('strong');
8239          }
8240        },
8241        initLayoutRect: function () {
8242          var self = this, layoutRect = self._super();
8243          if (self.settings.multiline) {
8244            var size = funcs.getSize(self.getEl());
8245            if (size.width > layoutRect.maxW) {
8246              layoutRect.minW = layoutRect.maxW;
8247              self.classes.add('multiline');
8248            }
8249            self.getEl().style.width = layoutRect.minW + 'px';
8250            layoutRect.startMinH = layoutRect.h = layoutRect.minH = Math.min(layoutRect.maxH, funcs.getSize(self.getEl()).height);
8251          }
8252          return layoutRect;
8253        },
8254        repaint: function () {
8255          var self = this;
8256          if (!self.settings.multiline) {
8257            self.getEl().style.lineHeight = self.layoutRect().h + 'px';
8258          }
8259          return self._super();
8260        },
8261        severity: function (level) {
8262          this.classes.remove('error');
8263          this.classes.remove('warning');
8264          this.classes.remove('success');
8265          this.classes.add(level);
8266        },
8267        renderHtml: function () {
8268          var self = this;
8269          var targetCtrl, forName, forId = self.settings.forId;
8270          var text = self.settings.html ? self.settings.html : self.encode(self.state.get('text'));
8271          if (!forId && (forName = self.settings.forName)) {
8272            targetCtrl = self.getRoot().find('#' + forName)[0];
8273            if (targetCtrl) {
8274              forId = targetCtrl._id;
8275            }
8276          }
8277          if (forId) {
8278            return '<label id="' + self._id + '" class="' + self.classes + '"' + (forId ? ' for="' + forId + '"' : '') + '>' + text + '</label>';
8279          }
8280          return '<span id="' + self._id + '" class="' + self.classes + '">' + text + '</span>';
8281        },
8282        bindStates: function () {
8283          var self = this;
8284          self.state.on('change:text', function (e) {
8285            self.innerHtml(self.encode(e.value));
8286            if (self.state.get('rendered')) {
8287              self.updateLayoutRect();
8288            }
8289          });
8290          return self._super();
8291        }
8292      });
8293  
8294      var Toolbar$1 = Container.extend({
8295        Defaults: {
8296          role: 'toolbar',
8297          layout: 'flow'
8298        },
8299        init: function (settings) {
8300          var self = this;
8301          self._super(settings);
8302          self.classes.add('toolbar');
8303        },
8304        postRender: function () {
8305          var self = this;
8306          self.items().each(function (ctrl) {
8307            ctrl.classes.add('toolbar-item');
8308          });
8309          return self._super();
8310        }
8311      });
8312  
8313      var MenuBar = Toolbar$1.extend({
8314        Defaults: {
8315          role: 'menubar',
8316          containerCls: 'menubar',
8317          ariaRoot: true,
8318          defaults: { type: 'menubutton' }
8319        }
8320      });
8321  
8322      function isChildOf$1(node, parent) {
8323        while (node) {
8324          if (parent === node) {
8325            return true;
8326          }
8327          node = node.parentNode;
8328        }
8329        return false;
8330      }
8331      var MenuButton = Button.extend({
8332        init: function (settings) {
8333          var self = this;
8334          self._renderOpen = true;
8335          self._super(settings);
8336          settings = self.settings;
8337          self.classes.add('menubtn');
8338          if (settings.fixedWidth) {
8339            self.classes.add('fixed-width');
8340          }
8341          self.aria('haspopup', true);
8342          self.state.set('menu', settings.menu || self.render());
8343        },
8344        showMenu: function (toggle) {
8345          var self = this;
8346          var menu;
8347          if (self.menu && self.menu.visible() && toggle !== false) {
8348            return self.hideMenu();
8349          }
8350          if (!self.menu) {
8351            menu = self.state.get('menu') || [];
8352            self.classes.add('opened');
8353            if (menu.length) {
8354              menu = {
8355                type: 'menu',
8356                animate: true,
8357                items: menu
8358              };
8359            } else {
8360              menu.type = menu.type || 'menu';
8361              menu.animate = true;
8362            }
8363            if (!menu.renderTo) {
8364              self.menu = global$4.create(menu).parent(self).renderTo();
8365            } else {
8366              self.menu = menu.parent(self).show().renderTo();
8367            }
8368            self.fire('createmenu');
8369            self.menu.reflow();
8370            self.menu.on('cancel', function (e) {
8371              if (e.control.parent() === self.menu) {
8372                e.stopPropagation();
8373                self.focus();
8374                self.hideMenu();
8375              }
8376            });
8377            self.menu.on('select', function () {
8378              self.focus();
8379            });
8380            self.menu.on('show hide', function (e) {
8381              if (e.type === 'hide' && e.control.parent() === self) {
8382                self.classes.remove('opened-under');
8383              }
8384              if (e.control === self.menu) {
8385                self.activeMenu(e.type === 'show');
8386                self.classes.toggle('opened', e.type === 'show');
8387              }
8388              self.aria('expanded', e.type === 'show');
8389            }).fire('show');
8390          }
8391          self.menu.show();
8392          self.menu.layoutRect({ w: self.layoutRect().w });
8393          self.menu.repaint();
8394          self.menu.moveRel(self.getEl(), self.isRtl() ? [
8395            'br-tr',
8396            'tr-br'
8397          ] : [
8398            'bl-tl',
8399            'tl-bl'
8400          ]);
8401          var menuLayoutRect = self.menu.layoutRect();
8402          var selfBottom = self.$el.offset().top + self.layoutRect().h;
8403          if (selfBottom > menuLayoutRect.y && selfBottom < menuLayoutRect.y + menuLayoutRect.h) {
8404            self.classes.add('opened-under');
8405          }
8406          self.fire('showmenu');
8407        },
8408        hideMenu: function () {
8409          var self = this;
8410          if (self.menu) {
8411            self.menu.items().each(function (item) {
8412              if (item.hideMenu) {
8413                item.hideMenu();
8414              }
8415            });
8416            self.menu.hide();
8417          }
8418        },
8419        activeMenu: function (state) {
8420          this.classes.toggle('active', state);
8421        },
8422        renderHtml: function () {
8423          var self = this, id = self._id, prefix = self.classPrefix;
8424          var icon = self.settings.icon, image;
8425          var text = self.state.get('text');
8426          var textHtml = '';
8427          image = self.settings.image;
8428          if (image) {
8429            icon = 'none';
8430            if (typeof image !== 'string') {
8431              image = domGlobals.window.getSelection ? image[0] : image[1];
8432            }
8433            image = ' style="background-image: url(\'' + image + '\')"';
8434          } else {
8435            image = '';
8436          }
8437          if (text) {
8438            self.classes.add('btn-has-text');
8439            textHtml = '<span class="' + prefix + 'txt">' + self.encode(text) + '</span>';
8440          }
8441          icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
8442          self.aria('role', self.parent() instanceof MenuBar ? 'menuitem' : 'button');
8443          return '<div id="' + id + '" class="' + self.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>';
8444        },
8445        postRender: function () {
8446          var self = this;
8447          self.on('click', function (e) {
8448            if (e.control === self && isChildOf$1(e.target, self.getEl())) {
8449              self.focus();
8450              self.showMenu(!e.aria);
8451              if (e.aria) {
8452                self.menu.items().filter(':visible')[0].focus();
8453              }
8454            }
8455          });
8456          self.on('mouseenter', function (e) {
8457            var overCtrl = e.control;
8458            var parent = self.parent();
8459            var hasVisibleSiblingMenu;
8460            if (overCtrl && parent && overCtrl instanceof MenuButton && overCtrl.parent() === parent) {
8461              parent.items().filter('MenuButton').each(function (ctrl) {
8462                if (ctrl.hideMenu && ctrl !== overCtrl) {
8463                  if (ctrl.menu && ctrl.menu.visible()) {
8464                    hasVisibleSiblingMenu = true;
8465                  }
8466                  ctrl.hideMenu();
8467                }
8468              });
8469              if (hasVisibleSiblingMenu) {
8470                overCtrl.focus();
8471                overCtrl.showMenu();
8472              }
8473            }
8474          });
8475          return self._super();
8476        },
8477        bindStates: function () {
8478          var self = this;
8479          self.state.on('change:menu', function () {
8480            if (self.menu) {
8481              self.menu.remove();
8482            }
8483            self.menu = null;
8484          });
8485          return self._super();
8486        },
8487        remove: function () {
8488          this._super();
8489          if (this.menu) {
8490            this.menu.remove();
8491          }
8492        }
8493      });
8494  
8495      var Menu = FloatPanel.extend({
8496        Defaults: {
8497          defaultType: 'menuitem',
8498          border: 1,
8499          layout: 'stack',
8500          role: 'application',
8501          bodyRole: 'menu',
8502          ariaRoot: true
8503        },
8504        init: function (settings) {
8505          var self = this;
8506          settings.autohide = true;
8507          settings.constrainToViewport = true;
8508          if (typeof settings.items === 'function') {
8509            settings.itemsFactory = settings.items;
8510            settings.items = [];
8511          }
8512          if (settings.itemDefaults) {
8513            var items = settings.items;
8514            var i = items.length;
8515            while (i--) {
8516              items[i] = global$2.extend({}, settings.itemDefaults, items[i]);
8517            }
8518          }
8519          self._super(settings);
8520          self.classes.add('menu');
8521          if (settings.animate && global$8.ie !== 11) {
8522            self.classes.add('animate');
8523          }
8524        },
8525        repaint: function () {
8526          this.classes.toggle('menu-align', true);
8527          this._super();
8528          this.getEl().style.height = '';
8529          this.getEl('body').style.height = '';
8530          return this;
8531        },
8532        cancel: function () {
8533          var self = this;
8534          self.hideAll();
8535          self.fire('select');
8536        },
8537        load: function () {
8538          var self = this;
8539          var time, factory;
8540          function hideThrobber() {
8541            if (self.throbber) {
8542              self.throbber.hide();
8543              self.throbber = null;
8544            }
8545          }
8546          factory = self.settings.itemsFactory;
8547          if (!factory) {
8548            return;
8549          }
8550          if (!self.throbber) {
8551            self.throbber = new Throbber(self.getEl('body'), true);
8552            if (self.items().length === 0) {
8553              self.throbber.show();
8554              self.fire('loading');
8555            } else {
8556              self.throbber.show(100, function () {
8557                self.items().remove();
8558                self.fire('loading');
8559              });
8560            }
8561            self.on('hide close', hideThrobber);
8562          }
8563          self.requestTime = time = new Date().getTime();
8564          self.settings.itemsFactory(function (items) {
8565            if (items.length === 0) {
8566              self.hide();
8567              return;
8568            }
8569            if (self.requestTime !== time) {
8570              return;
8571            }
8572            self.getEl().style.width = '';
8573            self.getEl('body').style.width = '';
8574            hideThrobber();
8575            self.items().remove();
8576            self.getEl('body').innerHTML = '';
8577            self.add(items);
8578            self.renderNew();
8579            self.fire('loaded');
8580          });
8581        },
8582        hideAll: function () {
8583          var self = this;
8584          this.find('menuitem').exec('hideMenu');
8585          return self._super();
8586        },
8587        preRender: function () {
8588          var self = this;
8589          self.items().each(function (ctrl) {
8590            var settings = ctrl.settings;
8591            if (settings.icon || settings.image || settings.selectable) {
8592              self._hasIcons = true;
8593              return false;
8594            }
8595          });
8596          if (self.settings.itemsFactory) {
8597            self.on('postrender', function () {
8598              if (self.settings.itemsFactory) {
8599                self.load();
8600              }
8601            });
8602          }
8603          self.on('show hide', function (e) {
8604            if (e.control === self) {
8605              if (e.type === 'show') {
8606                global$7.setTimeout(function () {
8607                  self.classes.add('in');
8608                }, 0);
8609              } else {
8610                self.classes.remove('in');
8611              }
8612            }
8613          });
8614          return self._super();
8615        }
8616      });
8617  
8618      var ListBox = MenuButton.extend({
8619        init: function (settings) {
8620          var self = this;
8621          var values, selected, selectedText, lastItemCtrl;
8622          function setSelected(menuValues) {
8623            for (var i = 0; i < menuValues.length; i++) {
8624              selected = menuValues[i].selected || settings.value === menuValues[i].value;
8625              if (selected) {
8626                selectedText = selectedText || menuValues[i].text;
8627                self.state.set('value', menuValues[i].value);
8628                return true;
8629              }
8630              if (menuValues[i].menu) {
8631                if (setSelected(menuValues[i].menu)) {
8632                  return true;
8633                }
8634              }
8635            }
8636          }
8637          self._super(settings);
8638          settings = self.settings;
8639          self._values = values = settings.values;
8640          if (values) {
8641            if (typeof settings.value !== 'undefined') {
8642              setSelected(values);
8643            }
8644            if (!selected && values.length > 0) {
8645              selectedText = values[0].text;
8646              self.state.set('value', values[0].value);
8647            }
8648            self.state.set('menu', values);
864