]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/editor-expand.js
Wordpress 4.6-scripts
[autoinstalls/wordpress.git] / wp-admin / js / editor-expand.js
index 75496c26ce096a1bfa6e69eebc913a068b000350..bf67c64e04f7c4c88360cacc0b5e9e139a3c2ffd 100644 (file)
@@ -15,7 +15,8 @@
                        $visualEditor = $(),
                        $textTop = $( '#ed_toolbar' ),
                        $textEditor = $( '#content' ),
-                       $textEditorClone = $( '<div id="content-textarea-clone"></div>' ),
+                       textEditor = $textEditor[0],
+                       oldTextLength = 0,
                        $bottom = $( '#post-status-info' ),
                        $menuBar = $(),
                        $statusBar = $(),
                                sideSortablesHeight: 0
                        };
 
-               $textEditorClone.insertAfter( $textEditor );
-
-               $textEditorClone.css( {
-                       'font-family': $textEditor.css( 'font-family' ),
-                       'font-size': $textEditor.css( 'font-size' ),
-                       'line-height': $textEditor.css( 'line-height' ),
-                       'white-space': 'pre-wrap',
-                       'word-wrap': 'break-word'
-               } );
-
                function getHeights() {
                        var windowWidth = $window.width();
 
                        }
                }
 
-               function textEditorKeyup( event ) {
-                       var VK = jQuery.ui.keyCode,
-                               key = event.keyCode,
-                               range = document.createRange(),
-                               selStart = $textEditor[0].selectionStart,
-                               selEnd = $textEditor[0].selectionEnd,
-                               textNode = $textEditorClone[0].firstChild,
-                               buffer = 10,
-                               offset, cursorTop, cursorBottom, editorTop, editorBottom;
-
-                       if ( selStart && selEnd && selStart !== selEnd ) {
+               function textEditorResize() {
+                       if ( mceEditor && ! mceEditor.isHidden() ) {
                                return;
                        }
 
-                       // These are not TinyMCE ranges.
-                       try {
-                               range.setStart( textNode, selStart );
-                               range.setEnd( textNode, selEnd + 1 );
-                       } catch ( ex ) {}
-
-                       offset = range.getBoundingClientRect();
-
-                       if ( ! offset.height ) {
+                       if ( ! mceEditor && initialMode === 'tinymce' ) {
                                return;
                        }
 
-                       cursorTop = offset.top - buffer;
-                       cursorBottom = cursorTop + offset.height + buffer;
-                       editorTop = heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight;
-                       editorBottom = heights.windowHeight - heights.bottomHeight;
+                       var length = textEditor.value.length;
+                       var height = parseInt( textEditor.style.height, 10 );
+                       var top = window.scrollTop;
 
-                       if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
-                               window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop );
-                       } else if ( cursorBottom > editorBottom ) {
-                               window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
-                       }
-               }
+                       if ( length < oldTextLength ) {
+                               // textEditor.scrollHeight is not adjusted until the next line.
+                               textEditor.style.height = 'auto';
 
-               function textEditorResize() {
-                       if ( ( mceEditor && ! mceEditor.isHidden() ) || ( ! mceEditor && initialMode === 'tinymce' ) ) {
-                               return;
-                       }
-
-                       var textEditorHeight = $textEditor.height(),
-                               hiddenHeight;
-
-                       $textEditorClone.width( $textEditor.width() - 22 );
-                       $textEditorClone.text( $textEditor.val() + '&nbsp;' );
-
-                       hiddenHeight = $textEditorClone.height();
+                               if ( textEditor.scrollHeight > autoresizeMinHeight ) {
+                                       textEditor.style.height = textEditor.scrollHeight + 'px';
+                               } else {
+                                       textEditor.style.height = autoresizeMinHeight + 'px';
+                               }
 
-                       if ( hiddenHeight < autoresizeMinHeight ) {
-                               hiddenHeight = autoresizeMinHeight;
-                       }
+                               // Prevent scroll-jumping in Firefox and IE.
+                               window.scrollTop = top;
 
-                       if ( hiddenHeight === textEditorHeight ) {
-                               return;
+                               if ( textEditor.scrollHeight < height ) {
+                                       adjust();
+                               }
+                       } else if ( height < textEditor.scrollHeight ) {
+                               textEditor.style.height = textEditor.scrollHeight + 'px';
+                               adjust();
                        }
 
-                       $textEditor.height( hiddenHeight );
-
-                       adjust();
+                       oldTextLength = length;
                }
 
                // We need to wait for TinyMCE to initialize.
                                var node = editor.selection.getNode(),
                                        range, view, offset;
 
-                               if ( editor.plugins.wpview && ( view = editor.plugins.wpview.getView( node ) ) ) {
+                               if ( editor.wp && editor.wp.getView && ( view = editor.wp.getView( node ) ) ) {
                                        offset = view.getBoundingClientRect();
                                } else {
                                        range = editor.selection.getRng();
                        var windowPos = $window.scrollTop(),
                                type = event && event.type,
                                resize = type !== 'scroll',
-                               visual = ( mceEditor && ! mceEditor.isHidden() ),
+                               visual = mceEditor && ! mceEditor.isHidden(),
                                buffer = autoresizeMinHeight,
                                postBodyTop = $postBody.offset().top,
                                borderWidth = 1,
                                topHeight = heights.textTopHeight;
                        }
 
+                       // TinyMCE still intializing.
+                       if ( ! visual && ! $top.length ) {
+                               return;
+                       }
+
                        topPos = $top.parent().offset().top;
                        editorPos = $editor.offset().top;
                        editorHeight = $editor.outerHeight();
                                                width: contentWrapWidth - ( borderWidth * 2 ) - ( visual ? 0 : ( $top.outerWidth() - $top.width() ) )
                                        } );
 
-                                       $statusBar.add( $bottom ).attr( 'style', '' );
+                                       $statusBar.attr( 'style', advanced ? '' : 'visibility: hidden;' );
+                                       $bottom.attr( 'style', '' );
                                }
                        } else {
                                // Maybe pin the top.
 
                                        if ( event && event.deltaHeight > 0 && event.deltaHeight < 100 ) {
                                                window.scrollBy( 0, event.deltaHeight );
-                                       } else if ( advanced ) {
+                                       } else if ( visual && advanced ) {
                                                fixedBottom = true;
 
                                                $statusBar.css( {
                                                ( windowPos + heights.windowHeight ) > ( editorPos + editorHeight + heights.bottomHeight + heights.statusBarHeight - borderWidth ) ) ) {
                                        fixedBottom = false;
 
-                                       $statusBar.add( $bottom ).attr( 'style', '' );
-
-                                       if ( ! advanced ) {
-                                               $statusBar.css( 'visibility', 'hidden' );
-                                       }
+                                       $statusBar.attr( 'style', advanced ? '' : 'visibility: hidden;' );
+                                       $bottom.attr( 'style', '' );
                                }
                        }
 
                                        $textEditor.css( {
                                                marginTop: heights.textTopHeight
                                        } );
-
-                                       $textEditorClone.width( contentWrapWidth - 20 - ( borderWidth * 2 ) );
                                }
                        }
                }
 
                        // Adjust when collapsing the menu, changing the columns, changing the body class.
                        $document.on( 'wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand', adjust )
-                               .on( 'postbox-toggled.editor-expand', function() {
+                               .on( 'postbox-toggled.editor-expand postbox-moved.editor-expand', function() {
                                        if ( ! fixedSideTop && ! fixedSideBottom && window.pageYOffset > pinnedToolsTop ) {
                                                fixedSideBottom = true;
                                                window.scrollBy( 0, -1 );
                                });
 
                        $textEditor.on( 'focus.editor-expand input.editor-expand propertychange.editor-expand', textEditorResize );
-                       $textEditor.on( 'keyup.editor-expand', textEditorKeyup );
                        mceBind();
 
                        // Adjust when entering/exiting fullscreen mode.
                }
 
                function off() {
-                       var height = window.getUserSetting('ed_size');
+                       var height = parseInt( window.getUserSetting( 'ed_size', 300 ), 10 );
+
+                       if ( height < 50 ) {
+                               height = 50;
+                       } else if ( height > 5000 ) {
+                               height = 5000;
+                       }
 
                        // Scroll to the top when triggering this from JS.
                        // Ensures toolbars are reset properly.
                }
 
                function fadeOut( event ) {
-                       var key = event && event.keyCode;
+                       var isMac,
+                               key = event && event.keyCode;
+
+                       if ( window.navigator.platform ) {
+                               isMac = ( window.navigator.platform.indexOf( 'Mac' ) > -1 );
+                       }
 
-                       // fadeIn and return on Escape and keyboard shortcut Alt+Shift+W.
-                       if ( key === 27 || ( key === 87 && event.altKey && event.shiftKey ) ) {
+                       // fadeIn and return on Escape and keyboard shortcut Alt+Shift+W and Ctrl+Opt+W.
+                       if ( key === 27 || ( key === 87 && event.altKey && ( ( ! isMac && event.shiftKey ) || ( isMac && event.ctrlKey ) ) ) ) {
                                fadeIn( event );
                                return;
                        }
                        } );
 
                        editor.addCommand( 'wpToggleDFW', toggle );
-                       editor.addShortcut( 'alt+shift+w', '', 'wpToggleDFW' );
+                       editor.addShortcut( 'access+w', '', 'wpToggleDFW' );
                } );
 
                $document.on( 'tinymce-editor-init.focus', function( event, editor ) {
                                $document.on( 'dfw-on.focus', mceBind ).on( 'dfw-off.focus', mceUnbind );
 
                                // Make sure the body focuses when clicking outside it.
-                               editor.on( 'click', function( event ) {
+                               editor.on( 'click', function( event ) {
                                        if ( event.target === editor.getDoc().documentElement ) {
                                                editor.focus();
                                        }