Make WordPress Core

Changeset 26945


Ignore:
Timestamp:
01/14/2014 11:34:23 PM (13 years ago)
Author:
azaozz
Message:

TinyMCE: fix send_to_editor(). It no longer needs to replace shortcode strings with html placeholers before inserting them in the editor. This is handled properly by the editor's 'BeforeSetContent' event callbacks. See #24067.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/media-upload.js

    r26876 r26945  
    44var wpActiveEditor, send_to_editor;
    55
    6 send_to_editor = function(h) {
    7         var ed, mce = typeof(tinymce) != 'undefined', qt = typeof(QTags) != 'undefined';
     6send_to_editor = function( html ) {
     7        var editor,
     8                hasTinymce = typeof tinymce !== 'undefined',
     9                hasQuicktags = typeof QTags !== 'undefined';
    810
    911        if ( ! wpActiveEditor ) {
    10                 if ( mce && tinymce.activeEditor ) {
    11                         ed = tinymce.activeEditor;
    12                         wpActiveEditor = ed.id;
    13                 } else if ( ! qt ) {
     12                if ( hasTinymce && tinymce.activeEditor ) {
     13                        editor = tinymce.activeEditor;
     14                        wpActiveEditor = editor.id;
     15                } else if ( ! hasQuicktags ) {
    1416                        return false;
    1517                }
    16         } else if ( mce ) {
    17                 ed = tinymce.get( wpActiveEditor );
     18        } else if ( hasTinymce ) {
     19                editor = tinymce.get( wpActiveEditor );
    1820        }
    1921
    20         if ( ed && ! ed.isHidden() ) {
    21                 // restore caret position on IE
    22         //      if ( tinymce.isIE && ed.windowManager.insertimagebookmark )
    23         //              ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
    24 
    25                 if ( h.indexOf('[caption') !== -1 ) {
    26                         if ( ed.wpSetImgCaption )
    27                                 h = ed.wpSetImgCaption(h);
    28                 } else if ( h.indexOf('[gallery') !== -1 ) {
    29                         if ( ed.plugins.wpgallery )
    30                                 h = ed.plugins.wpgallery._do_gallery(h);
    31                 } else if ( h.indexOf('[embed') === 0 ) {
    32                         if ( ed.plugins.wordpress )
    33                                 h = ed.plugins.wordpress._setEmbed(h);
    34                 }
    35 
    36                 ed.execCommand('mceInsertContent', false, h);
    37         } else if ( qt ) {
    38                 QTags.insertContent(h);
     22        if ( editor && ! editor.isHidden() ) {
     23                editor.execCommand( 'mceInsertContent', false, html );
     24        } else if ( hasQuicktags ) {
     25                QTags.insertContent( html );
    3926        } else {
    40                 document.getElementById(wpActiveEditor).value += h;
     27                document.getElementById( wpActiveEditor ).value += html;
    4128        }
    4229
    43         try{tb_remove();}catch(e){}
     30        // If the old thickbox remove function exists, call it
     31        if ( window.tb_remove ) {
     32                try { window.tb_remove(); } catch( e ) {}
     33        }
    4434};
    4535
     
    7666
    7767        $(window).resize(function(){ tb_position(); });
    78 /*
    79         // store caret position in IE
    80         $(document).ready(function($){
    81                 $('a.thickbox').click(function(){
    82                         var ed;
    8368
    84                         if ( typeof(tinymce) != 'undefined' && tinymce.isIE && ( ed = tinymce.get(wpActiveEditor) ) && !ed.isHidden() ) {
    85                                 ed.focus();
    86                                 ed.windowManager.insertimagebookmark = ed.selection.getBookmark();
    87                         }
    88                 });
    89         });
    90 */
    9169})(jQuery);
  • trunk/src/wp-includes/js/media-editor.js

    r26876 r26945  
    447447
    448448        wp.media.editor = {
    449                 insert: function( h ) {
    450                         var mce = typeof(tinymce) != 'undefined',
    451                                 qt = typeof(QTags) != 'undefined',
    452                                 wpActiveEditor = window.wpActiveEditor,
    453                                 ed;
     449                insert: function( html ) {
     450                        var editor,
     451                                hasTinymce = typeof tinymce !== 'undefined',
     452                                hasQuicktags = typeof QTags !== 'undefined',
     453                                wpActiveEditor = window.wpActiveEditor;
    454454
    455455                        // Delegate to the global `send_to_editor` if it exists.
    456456                        // This attempts to play nice with any themes/plugins that have
    457457                        // overridden the insert functionality.
    458                         if ( window.send_to_editor )
     458                        if ( window.send_to_editor ) {
    459459                                return window.send_to_editor.apply( this, arguments );
     460                        }
    460461
    461462                        if ( ! wpActiveEditor ) {
    462                                 if ( mce && tinymce.activeEditor ) {
    463                                         ed = tinymce.activeEditor;
    464                                         wpActiveEditor = window.wpActiveEditor = ed.id;
    465                                 } else if ( !qt ) {
     463                                if ( hasTinymce && tinymce.activeEditor ) {
     464                                        editor = tinymce.activeEditor;
     465                                        wpActiveEditor = window.wpActiveEditor = editor.id;
     466                                } else if ( ! hasQuicktags ) {
    466467                                        return false;
    467468                                }
    468                         } else if ( mce ) {
    469                                 ed = tinymce.get( wpActiveEditor );
    470                         }
    471 
    472                         if ( ed && ! ed.isHidden() ) {
    473                                 // restore caret position on IE
    474         //                      if ( tinymce.isIE && ed.windowManager.insertimagebookmark )
    475         //                              ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
    476 
    477                                 if ( h.indexOf('[caption') !== -1 ) {
    478                                         if ( ed.wpSetImgCaption )
    479                                                 h = ed.wpSetImgCaption(h);
    480                                 } else if ( h.indexOf('[gallery') !== -1 ) {
    481                                         if ( ed.plugins.wpgallery )
    482                                                 h = ed.plugins.wpgallery._do_gallery(h);
    483                                 } else if ( h.indexOf('[embed') === 0 ) {
    484                                         if ( ed.plugins.wordpress )
    485                                                 h = ed.plugins.wordpress._setEmbed(h);
    486                                 }
    487 
    488                                 ed.execCommand('mceInsertContent', false, h);
    489                         } else if ( qt ) {
    490                                 QTags.insertContent(h);
     469                        } else if ( hasTinymce ) {
     470                                editor = tinymce.get( wpActiveEditor );
     471                        }
     472
     473                        if ( editor && ! editor.isHidden() ) {
     474                                editor.execCommand( 'mceInsertContent', false, html );
     475                        } else if ( hasQuicktags ) {
     476                                QTags.insertContent( html );
    491477                        } else {
    492                                 document.getElementById(wpActiveEditor).value += h;
     478                                document.getElementById( wpActiveEditor ).value += html;
    493479                        }
    494480
    495481                        // If the old thickbox remove function exists, call it in case
    496482                        // a theme/plugin overloaded it.
    497                         if ( window.tb_remove )
     483                        if ( window.tb_remove ) {
    498484                                try { window.tb_remove(); } catch( e ) {}
     485                        }
    499486                },
    500487
Note: See TracChangeset for help on using the changeset viewer.