[ Index ]

PHP Cross Reference of WordPress

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