]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/js/editor.js
WordPress 4.2.2-scripts
[autoinstalls/wordpress.git] / wp-admin / js / editor.js
index fff8b61bc1b96db4f9b85f9727e1a5cda9e59cee..4ff70df848846acce2a696cb11a7cbe6465ee1bb 100644 (file)
@@ -13,15 +13,15 @@ window.switchEditors = {
 
        // mode can be 'html', 'tmce', or 'toggle'; 'html' is used for the 'Text' editor tab.
        go: function( id, mode ) {
-               var t = this, ed, wrap_id, txtarea_el,
-                       dom = tinymce.DOM;
+               var t = this, ed, wrap_id, txtarea_el, iframe, editorHeight, toolbarHeight,
+                       DOM = tinymce.DOM; //DOMUtils outside the editor iframe
 
                id = id || 'content';
                mode = mode || 'toggle';
 
                ed = tinymce.get( id );
                wrap_id = 'wp-' + id + '-wrap';
-               txtarea_el = dom.get( id );
+               txtarea_el = DOM.get( id );
 
                if ( 'toggle' === mode ) {
                        if ( ed && ! ed.isHidden() ) {
@@ -31,6 +31,17 @@ window.switchEditors = {
                        }
                }
 
+               function getToolbarHeight() {
+                       var node = DOM.select( '.mce-toolbar-grp', ed.getContainer() )[0],
+                               height = node && node.clientHeight;
+
+                       if ( height && height > 10 && height < 200 ) {
+                               return parseInt( height, 10 );
+                       }
+
+                       return 30;
+               }
+
                if ( 'tmce' === mode || 'tinymce' === mode ) {
                        if ( ed && ! ed.isHidden() ) {
                                return false;
@@ -40,19 +51,32 @@ window.switchEditors = {
                                QTags.closeAllTags( id );
                        }
 
+                       editorHeight = txtarea_el ? parseInt( txtarea_el.style.height, 10 ) : 0;
+
                        if ( tinyMCEPreInit.mceInit[ id ] && tinyMCEPreInit.mceInit[ id ].wpautop ) {
                                txtarea_el.value = t.wpautop( txtarea_el.value );
                        }
 
                        if ( ed ) {
                                ed.show();
+
+                               // No point resizing the iframe in iOS
+                               if ( ! tinymce.Env.iOS && editorHeight ) {
+                                       toolbarHeight = getToolbarHeight();
+                                       editorHeight = editorHeight - toolbarHeight + 14;
+
+                                       // height cannot be under 50 or over 5000
+                                       if ( editorHeight > 50 && editorHeight < 5000 ) {
+                                               ed.theme.resizeTo( null, editorHeight );
+                                       }
+                               }
                        } else {
-                               ed = new tinymce.Editor( id, tinyMCEPreInit.mceInit[ id ] );
-                               ed.render();
+                               tinymce.init( tinyMCEPreInit.mceInit[id] );
                        }
 
-                       dom.removeClass( wrap_id, 'html-active' );
-                       dom.addClass( wrap_id, 'tmce-active' );
+                       DOM.removeClass( wrap_id, 'html-active' );
+                       DOM.addClass( wrap_id, 'tmce-active' );
+                       DOM.setAttrib( txtarea_el, 'aria-hidden', true );
                        setUserSetting( 'editor', 'tinymce' );
 
                } else if ( 'html' === mode ) {
@@ -62,6 +86,21 @@ window.switchEditors = {
                        }
 
                        if ( ed ) {
+                               if ( ! tinymce.Env.iOS ) {
+                                       iframe = DOM.get( id + '_ifr' );
+                                       editorHeight = iframe ? parseInt( iframe.style.height, 10 ) : 0;
+
+                                       if ( editorHeight ) {
+                                               toolbarHeight = getToolbarHeight();
+                                               editorHeight = editorHeight + toolbarHeight - 14;
+
+                                               // height cannot be under 50 or over 5000
+                                               if ( editorHeight > 50 && editorHeight < 5000 ) {
+                                                       txtarea_el.style.height = editorHeight + 'px';
+                                               }
+                                       }
+                               }
+
                                ed.hide();
                        } else {
                                // The TinyMCE instance doesn't exist, run the content through 'pre_wpautop()' and show the textarea
@@ -69,11 +108,12 @@ window.switchEditors = {
                                        txtarea_el.value = t.pre_wpautop( txtarea_el.value );
                                }
 
-                               dom.setStyles( txtarea_el, {'display': '', 'visibility': ''} );
+                               DOM.setStyles( txtarea_el, {'display': '', 'visibility': ''} );
                        }
 
-                       dom.removeClass( wrap_id, 'tmce-active' );
-                       dom.addClass( wrap_id, 'html-active' );
+                       DOM.removeClass( wrap_id, 'tmce-active' );
+                       DOM.addClass( wrap_id, 'html-active' );
+                       DOM.setAttrib( txtarea_el, 'aria-hidden', false );
                        setUserSetting( 'editor', 'html' );
                }
                return false;
@@ -88,8 +128,9 @@ window.switchEditors = {
                if ( content.indexOf( '<pre' ) !== -1 || content.indexOf( '<script' ) !== -1 ) {
                        preserve_linebreaks = true;
                        content = content.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) {
-                               a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-temp-lb>' );
-                               return a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-temp-lb>' );
+                               a = a.replace( /<br ?\/?>(\r\n|\n)?/g, '<wp-line-break>' );
+                               a = a.replace( /<\/?p( [^>]*)?>(\r\n|\n)?/g, '<wp-line-break>' );
+                               return a.replace( /\r?\n/g, '<wp-line-break>' );
                        });
                }
 
@@ -129,6 +170,11 @@ window.switchEditors = {
                content = content.replace( new RegExp('\\s*</(' + blocklist2 + ')>\\s*', 'g' ), '</$1>\n' );
                content = content.replace( /<li([^>]*)>/g, '\t<li$1>' );
 
+               if ( content.indexOf( '<option' ) !== -1 ) {
+                       content = content.replace( /\s*<option/g, '\n<option' );
+                       content = content.replace( /\s*<\/select>/g, '\n</select>' );
+               }
+
                if ( content.indexOf( '<hr' ) !== -1 ) {
                        content = content.replace( /\s*<hr( [^>]*)?>\s*/g, '\n\n<hr$1>\n\n' );
                }
@@ -149,7 +195,7 @@ window.switchEditors = {
 
                // put back the line breaks in pre|script
                if ( preserve_linebreaks ) {
-                       content = content.replace( /<wp-temp-lb>/g, '\n' );
+                       content = content.replace( /<wp-line-break>/g, '\n' );
                }
 
                // and the <br> tags in captions
@@ -163,8 +209,8 @@ window.switchEditors = {
        _wp_Autop: function(pee) {
                var preserve_linebreaks = false,
                        preserve_br = false,
-                       blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select' +
-                               '|option|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|noscript|legend|section' +
+                       blocklist = 'table|thead|tfoot|caption|col|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre' +
+                               '|form|map|area|blockquote|address|math|style|p|h[1-6]|hr|fieldset|legend|section' +
                                '|article|aside|hgroup|header|footer|nav|figure|figcaption|details|menu|summary';
 
                if ( pee.indexOf( '<object' ) !== -1 ) {
@@ -181,7 +227,7 @@ window.switchEditors = {
                if ( pee.indexOf( '<pre' ) !== -1 || pee.indexOf( '<script' ) !== -1 ) {
                        preserve_linebreaks = true;
                        pee = pee.replace( /<(pre|script)[^>]*>[\s\S]+?<\/\1>/g, function( a ) {
-                               return a.replace( /(\r\n|\n)/g, '<wp-temp-lb>' );
+                               return a.replace( /(\r\n|\n)/g, '<wp-line-break>' );
                        });
                }
 
@@ -205,6 +251,8 @@ window.switchEditors = {
                pee = pee.replace( new RegExp( '(<(?:' + blocklist + ')(?: [^>]*)?>)', 'gi' ), '\n$1' );
                pee = pee.replace( new RegExp( '(</(?:' + blocklist + ')>)', 'gi' ), '$1\n\n' );
                pee = pee.replace( /<hr( [^>]*)?>/gi, '<hr$1>\n\n' ); // hr is self closing block element
+               pee = pee.replace( /\s*<option/gi, '<option' ); // No <p> or <br> around <option>
+               pee = pee.replace( /<\/option>\s*/gi, '</option>' );
                pee = pee.replace( /\r\n|\r/g, '\n' );
                pee = pee.replace( /\n\s*\n+/g, '\n\n' );
                pee = pee.replace( /([\s\S]+?)\n\n/g, '<p>$1</p>\n' );
@@ -230,7 +278,7 @@ window.switchEditors = {
 
                // put back the line breaks in pre|script
                if ( preserve_linebreaks ) {
-                       pee = pee.replace( /<wp-temp-lb>/g, '\n' );
+                       pee = pee.replace( /<wp-line-break>/g, '\n' );
                }
 
                if ( preserve_br ) {