~canonical-sysadmins/wordpress/4.8.1

« back to all changes in this revision

Viewing changes to wp-admin/js/editor-expand.js

  • Committer: Barry Price
  • Date: 2016-08-17 04:49:28 UTC
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: barry.price@canonical.com-20160817044928-viijiwb4tl8jwzmp
new upstream release 4.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
                        $visualEditor = $(),
16
16
                        $textTop = $( '#ed_toolbar' ),
17
17
                        $textEditor = $( '#content' ),
18
 
                        $textEditorClone = $( '<div id="content-textarea-clone" class="wp-exclude-emoji"></div>' ),
 
18
                        textEditor = $textEditor[0],
 
19
                        oldTextLength = 0,
19
20
                        $bottom = $( '#post-status-info' ),
20
21
                        $menuBar = $(),
21
22
                        $statusBar = $(),
52
53
                                sideSortablesHeight: 0
53
54
                        };
54
55
 
55
 
                $textEditorClone.insertAfter( $textEditor );
56
 
 
57
 
                $textEditorClone.css( {
58
 
                        'font-family': $textEditor.css( 'font-family' ),
59
 
                        'font-size': $textEditor.css( 'font-size' ),
60
 
                        'line-height': $textEditor.css( 'line-height' ),
61
 
                        'white-space': 'pre-wrap',
62
 
                        'word-wrap': 'break-word'
63
 
                } );
64
 
 
65
56
                function getHeights() {
66
57
                        var windowWidth = $window.width();
67
58
 
84
75
                        }
85
76
                }
86
77
 
87
 
                function textEditorKeyup( event ) {
88
 
                        var VK = jQuery.ui.keyCode,
89
 
                                key = event.keyCode,
90
 
                                range = document.createRange(),
91
 
                                selStart = $textEditor[0].selectionStart,
92
 
                                selEnd = $textEditor[0].selectionEnd,
93
 
                                textNode = $textEditorClone[0].firstChild,
94
 
                                buffer = 10,
95
 
                                offset, cursorTop, cursorBottom, editorTop, editorBottom;
96
 
 
97
 
                        if ( selStart && selEnd && selStart !== selEnd ) {
98
 
                                return;
99
 
                        }
100
 
 
101
 
                        // These are not TinyMCE ranges.
102
 
                        try {
103
 
                                range.setStart( textNode, selStart );
104
 
                                range.setEnd( textNode, selEnd + 1 );
105
 
                        } catch ( ex ) {}
106
 
 
107
 
                        offset = range.getBoundingClientRect();
108
 
 
109
 
                        if ( ! offset.height ) {
110
 
                                return;
111
 
                        }
112
 
 
113
 
                        cursorTop = offset.top - buffer;
114
 
                        cursorBottom = cursorTop + offset.height + buffer;
115
 
                        editorTop = heights.adminBarHeight + heights.toolsHeight + heights.textTopHeight;
116
 
                        editorBottom = heights.windowHeight - heights.bottomHeight;
117
 
 
118
 
                        if ( cursorTop < editorTop && ( key === VK.UP || key === VK.LEFT || key === VK.BACKSPACE ) ) {
119
 
                                window.scrollTo( window.pageXOffset, cursorTop + window.pageYOffset - editorTop );
120
 
                        } else if ( cursorBottom > editorBottom ) {
121
 
                                window.scrollTo( window.pageXOffset, cursorBottom + window.pageYOffset - editorBottom );
122
 
                        }
123
 
                }
124
 
 
125
78
                function textEditorResize() {
126
 
                        if ( ( mceEditor && ! mceEditor.isHidden() ) || ( ! mceEditor && initialMode === 'tinymce' ) ) {
127
 
                                return;
128
 
                        }
129
 
 
130
 
                        var textEditorHeight = $textEditor.height(),
131
 
                                hiddenHeight;
132
 
 
133
 
                        $textEditorClone.width( $textEditor.width() - 22 );
134
 
                        $textEditorClone.text( $textEditor.val() + '&nbsp;' );
135
 
 
136
 
                        hiddenHeight = $textEditorClone.height();
137
 
 
138
 
                        if ( hiddenHeight < autoresizeMinHeight ) {
139
 
                                hiddenHeight = autoresizeMinHeight;
140
 
                        }
141
 
 
142
 
                        if ( hiddenHeight === textEditorHeight ) {
143
 
                                return;
144
 
                        }
145
 
 
146
 
                        $textEditor.height( hiddenHeight );
147
 
 
148
 
                        adjust();
 
79
                        if ( mceEditor && ! mceEditor.isHidden() ) {
 
80
                                return;
 
81
                        }
 
82
 
 
83
                        if ( ! mceEditor && initialMode === 'tinymce' ) {
 
84
                                return;
 
85
                        }
 
86
 
 
87
                        var length = textEditor.value.length;
 
88
                        var height = parseInt( textEditor.style.height, 10 );
 
89
                        var top = window.scrollTop;
 
90
 
 
91
                        if ( length < oldTextLength ) {
 
92
                                // textEditor.scrollHeight is not adjusted until the next line.
 
93
                                textEditor.style.height = 'auto';
 
94
 
 
95
                                if ( textEditor.scrollHeight > autoresizeMinHeight ) {
 
96
                                        textEditor.style.height = textEditor.scrollHeight + 'px';
 
97
                                } else {
 
98
                                        textEditor.style.height = autoresizeMinHeight + 'px';
 
99
                                }
 
100
 
 
101
                                // Prevent scroll-jumping in Firefox and IE.
 
102
                                window.scrollTop = top;
 
103
 
 
104
                                if ( textEditor.scrollHeight < height ) {
 
105
                                        adjust();
 
106
                                }
 
107
                        } else if ( height < textEditor.scrollHeight ) {
 
108
                                textEditor.style.height = textEditor.scrollHeight + 'px';
 
109
                                adjust();
 
110
                        }
 
111
 
 
112
                        oldTextLength = length;
149
113
                }
150
114
 
151
115
                // We need to wait for TinyMCE to initialize.
474
438
 
475
439
                                        if ( event && event.deltaHeight > 0 && event.deltaHeight < 100 ) {
476
440
                                                window.scrollBy( 0, event.deltaHeight );
477
 
                                        } else if ( advanced ) {
 
441
                                        } else if ( visual && advanced ) {
478
442
                                                fixedBottom = true;
479
443
 
480
444
                                                $statusBar.css( {
603
567
                                        $textEditor.css( {
604
568
                                                marginTop: heights.textTopHeight
605
569
                                        } );
606
 
 
607
 
                                        $textEditorClone.width( contentWrapWidth - 20 - ( borderWidth * 2 ) );
608
570
                                }
609
571
                        }
610
572
                }
642
604
 
643
605
                        // Adjust when collapsing the menu, changing the columns, changing the body class.
644
606
                        $document.on( 'wp-collapse-menu.editor-expand postboxes-columnchange.editor-expand editor-classchange.editor-expand', adjust )
645
 
                                .on( 'postbox-toggled.editor-expand', function() {
 
607
                                .on( 'postbox-toggled.editor-expand postbox-moved.editor-expand', function() {
646
608
                                        if ( ! fixedSideTop && ! fixedSideBottom && window.pageYOffset > pinnedToolsTop ) {
647
609
                                                fixedSideBottom = true;
648
610
                                                window.scrollBy( 0, -1 );
660
622
                                });
661
623
 
662
624
                        $textEditor.on( 'focus.editor-expand input.editor-expand propertychange.editor-expand', textEditorResize );
663
 
                        $textEditor.on( 'keyup.editor-expand', textEditorKeyup );
664
625
                        mceBind();
665
626
 
666
627
                        // Adjust when entering/exiting fullscreen mode.