]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/js/tinymce/themes/modern/theme.js
WordPress 4.5-scripts
[autoinstalls/wordpress.git] / wp-includes / js / tinymce / themes / modern / theme.js
index 774f01226d1db0db0cd6505456aa1ee16f9907da..adfeb271e360ccc6feb3dbae1a17965db1d8fe2c 100644 (file)
@@ -12,7 +12,7 @@
 
 tinymce.ThemeManager.add('modern', function(editor) {
        var self = this, settings = editor.settings, Factory = tinymce.ui.Factory,
-               each = tinymce.each, DOM = tinymce.DOM, Rect = tinymce.ui.Rect, FloatPanel = tinymce.ui.FloatPanel;
+               each = tinymce.each, DOM = tinymce.DOM, Rect = tinymce.geom.Rect, FloatPanel = tinymce.ui.FloatPanel;
 
        // Default menus
        var defaultMenus = {
@@ -416,13 +416,18 @@ tinymce.ThemeManager.add('modern', function(editor) {
                        panelRect = tinymce.DOM.getRect(panel.getEl());
                        contentAreaRect = tinymce.DOM.getRect(editor.getContentAreaContainer() || editor.getBody());
 
+                       // We need to use these instead of the rect values since the style
+                       // size properites might not be the same as the real size for a table
+                       elementRect.w = match.element.clientWidth;
+                       elementRect.h = match.element.clientHeight;
+
                        if (!editor.inline) {
                                contentAreaRect.w = editor.getDoc().documentElement.offsetWidth;
                        }
 
                        // Inflate the elementRect so it doesn't get placed above resize handles
                        if (editor.selection.controlSelection.isResizable(match.element)) {
-                               elementRect = Rect.inflate(elementRect, 0, 7);
+                               elementRect = Rect.inflate(elementRect, 0, 8);
                        }
 
                        relPos = Rect.findBestRelativePosition(panelRect, elementRect, contentAreaRect, testPositions);
@@ -471,11 +476,7 @@ tinymce.ThemeManager.add('modern', function(editor) {
                                }
                        }
 
-                       if (window.requestAnimationFrame) {
-                               window.requestAnimationFrame(execute);
-                       } else {
-                               execute();
-                       }
+                       tinymce.util.Delay.requestAnimationFrame(execute);
                }
 
                function bindScrollEvent() {
@@ -545,22 +546,24 @@ tinymce.ThemeManager.add('modern', function(editor) {
                        return null;
                }
 
-               editor.on('click keyup', function() {
+               editor.on('click keyup setContent', function(e) {
+                       // Only act on partial inserts
+                       if (e.type == 'setcontent' && !e.selection) {
+                               return;
+                       }
+
                        // Needs to be delayed to avoid Chrome img focus out bug
-                       window.setTimeout(function() {
+                       tinymce.util.Delay.setEditorTimeout(editor, function() {
                                var match;
 
-                               if (editor.removed) {
-                                       return;
-                               }
-
                                match = findFrontMostMatch(editor.selection.getNode());
                                if (match) {
+                                       hideAllContextToolbars();
                                        showContextToolbar(match);
                                } else {
                                        hideAllContextToolbars();
                                }
-                       }, 0);
+                       });
                });
 
                editor.on('blur hide', hideAllContextToolbars);
@@ -586,6 +589,18 @@ tinymce.ThemeManager.add('modern', function(editor) {
                });
        }
 
+       function fireSkinLoaded(editor) {
+               return function() {
+                       if (editor.initialized) {
+                               editor.fire('SkinLoaded');
+                       } else {
+                               editor.on('init', function() {
+                                       editor.fire('SkinLoaded');
+                               });
+                       }
+               };
+       }
+
        /**
         * Renders the inline editor UI.
         *
@@ -706,7 +721,7 @@ tinymce.ThemeManager.add('modern', function(editor) {
 
                // Preload skin css
                if (args.skinUiCss) {
-                       tinymce.DOM.styleSheetLoader.load(args.skinUiCss);
+                       tinymce.DOM.styleSheetLoader.load(args.skinUiCss, fireSkinLoaded(editor));
                }
 
                return {};
@@ -721,8 +736,18 @@ tinymce.ThemeManager.add('modern', function(editor) {
        function renderIframeUI(args) {
                var panel, resizeHandleCtrl, startSize;
 
+               function switchMode() {
+                       return function(e) {
+                               if (e.mode == 'readonly') {
+                                       panel.find('*').disabled(true);
+                               } else {
+                                       panel.find('*').disabled(false);
+                               }
+                       };
+               }
+
                if (args.skinUiCss) {
-                       tinymce.DOM.loadCSS(args.skinUiCss);
+                       tinymce.DOM.styleSheetLoader.load(args.skinUiCss, fireSkinLoaded(editor));
                }
 
                // Basic UI layout
@@ -772,13 +797,14 @@ tinymce.ThemeManager.add('modern', function(editor) {
                        ]});
                }
 
-               if (settings.readonly) {
-                       panel.find('*').disabled(true);
-               }
-
                editor.fire('BeforeRenderUI');
+               editor.on('SwitchMode', switchMode());
                panel.renderBefore(args.targetNode).reflow();
 
+               if (settings.readonly) {
+                       editor.setMode('readonly');
+               }
+
                if (settings.width) {
                        tinymce.DOM.setStyle(panel.getEl(), 'width', settings.width);
                }