Make WordPress Core

Changeset 22774


Ignore:
Timestamp:
11/21/2012 05:01:40 PM (12 years ago)
Author:
koopersmith
Message:

Media: Move send_to_editor to wp.media.editor.insert to prevent redeclaration.

Maintains backwards compatibility by delegating to window.send_to_editor and window.tb_remove if they exist.

see #21390.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/js/media-editor.js

    r22773 r22774  
    1 // send html to the post editor
    2 
    3 var wpActiveEditor;
    4 
    5 function send_to_editor(h) {
    6     var ed, mce = typeof(tinymce) != 'undefined', qt = typeof(QTags) != 'undefined';
    7 
    8     if ( !wpActiveEditor ) {
    9         if ( mce && tinymce.activeEditor ) {
    10             ed = tinymce.activeEditor;
    11             wpActiveEditor = ed.id;
    12         } else if ( !qt ) {
    13             return false;
    14         }
    15     } else if ( mce ) {
    16         if ( tinymce.activeEditor && (tinymce.activeEditor.id == 'mce_fullscreen' || tinymce.activeEditor.id == 'wp_mce_fullscreen') )
    17             ed = tinymce.activeEditor;
    18         else
    19             ed = tinymce.get(wpActiveEditor);
    20     }
    21 
    22     if ( ed && !ed.isHidden() ) {
    23         // restore caret position on IE
    24         if ( tinymce.isIE && ed.windowManager.insertimagebookmark )
    25             ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
    26 
    27         if ( h.indexOf('[caption') === 0 ) {
    28             if ( ed.wpSetImgCaption )
    29                 h = ed.wpSetImgCaption(h);
    30         } else if ( h.indexOf('[gallery') === 0 ) {
    31             if ( ed.plugins.wpgallery )
    32                 h = ed.plugins.wpgallery._do_gallery(h);
    33         } else if ( h.indexOf('[embed') === 0 ) {
    34             if ( ed.plugins.wordpress )
    35                 h = ed.plugins.wordpress._setEmbed(h);
    36         }
    37 
    38         ed.execCommand('mceInsertContent', false, h);
    39     } else if ( qt ) {
    40         QTags.insertContent(h);
    41     } else {
    42         document.getElementById(wpActiveEditor).value += h;
    43     }
    44 
    45     try{tb_remove();}catch(e){};
    46 }
    47 
    481// WordPress, TinyMCE, and Media
    492// -----------------------------
     
    333286
    334287    wp.media.editor = {
    335         insert: send_to_editor,
     288        insert: function( h ) {
     289            var mce = typeof(tinymce) != 'undefined',
     290                qt = typeof(QTags) != 'undefined',
     291                wpActiveEditor = window.wpActiveEditor,
     292                ed;
     293
     294            // Delegate to the global `send_to_editor` if it exists.
     295            // This attempts to play nice with any themes/plugins that have
     296            // overridden the insert functionality.
     297            if ( window.send_to_editor )
     298                return window.send_to_editor.apply( this, arguments );
     299
     300            if ( ! wpActiveEditor ) {
     301                if ( mce && tinymce.activeEditor ) {
     302                    ed = tinymce.activeEditor;
     303                    wpActiveEditor = window.wpActiveEditor = ed.id;
     304                } else if ( !qt ) {
     305                    return false;
     306                }
     307            } else if ( mce ) {
     308                if ( tinymce.activeEditor && (tinymce.activeEditor.id == 'mce_fullscreen' || tinymce.activeEditor.id == 'wp_mce_fullscreen') )
     309                    ed = tinymce.activeEditor;
     310                else
     311                    ed = tinymce.get(wpActiveEditor);
     312            }
     313
     314            if ( ed && !ed.isHidden() ) {
     315                // restore caret position on IE
     316                if ( tinymce.isIE && ed.windowManager.insertimagebookmark )
     317                    ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
     318
     319                if ( h.indexOf('[caption') === 0 ) {
     320                    if ( ed.wpSetImgCaption )
     321                        h = ed.wpSetImgCaption(h);
     322                } else if ( h.indexOf('[gallery') === 0 ) {
     323                    if ( ed.plugins.wpgallery )
     324                        h = ed.plugins.wpgallery._do_gallery(h);
     325                } else if ( h.indexOf('[embed') === 0 ) {
     326                    if ( ed.plugins.wordpress )
     327                        h = ed.plugins.wordpress._setEmbed(h);
     328                }
     329
     330                ed.execCommand('mceInsertContent', false, h);
     331            } else if ( qt ) {
     332                QTags.insertContent(h);
     333            } else {
     334                document.getElementById(wpActiveEditor).value += h;
     335            }
     336
     337            // If the old thickbox remove function exists, call it in case
     338            // a theme/plugin overloaded it.
     339            if ( window.tb_remove )
     340                try { window.tb_remove(); } catch( e ) {}
     341        },
    336342
    337343        add: function( id, options ) {
Note: See TracChangeset for help on using the changeset viewer.