Make WordPress Core

Ticket #42956: media-uploads-documentation.diff

File media-uploads-documentation.diff, 3.1 KB (added by ireneyoast, 7 years ago)
  • src/wp-admin/js/media-upload.js

    diff --git src/wp-admin/js/media-upload.js src/wp-admin/js/media-upload.js
    index cd969b9b3a..3fbda74d55 100644
     
    1 /* global tinymce, QTags */
    2 // send html to the post editor
     1/* global wpActiveEditor, tinymce, QTags */
     2
     3/**
     4 * Makes sure the ThickBox dimensions are properly set and adds functionality to pass HTML to the editor.
     5 *
     6 * Updates the ThickBox anchor href and the ThickBox's own properties in order
     7 * to set the size and position on every resize event. Also adds a function to
     8 * send HTML or text to the currently active editor.
     9 *
     10 * @since 2.3.3
     11 *
     12 * @requires jQuery
     13 */
     14
    315
    416var wpActiveEditor, send_to_editor;
    517
     18/**
     19 * Sends the HTML passed in the parameters to TinyMCE.
     20 *
     21 * @since 2.3.3
     22 *
     23 * @global {tinymce} tinymce An instance of the TinyMCE editor.
     24 * @global {QTags} QTags An instance of QTags.
     25 *
     26 * @param {string} html The HTML to be sent to the editor.
     27 * @returns {boolean} Returns false when both TinyMCE and QTags instances are unavailable. This means that the HTML was not sent to the editor.
     28 */
    629send_to_editor = function( html ) {
    730        var editor,
    831                hasTinymce = typeof tinymce !== 'undefined',
    932                hasQuicktags = typeof QTags !== 'undefined';
    1033
     34        // If no active editor is set, try to set it.
    1135        if ( ! wpActiveEditor ) {
    1236                if ( hasTinymce && tinymce.activeEditor ) {
    1337                        editor = tinymce.activeEditor;
    send_to_editor = function( html ) { 
    1943                editor = tinymce.get( wpActiveEditor );
    2044        }
    2145
     46        // If the editor is set and not hidden, insert the HTML into the content of the editor.
    2247        if ( editor && ! editor.isHidden() ) {
    2348                editor.execCommand( 'mceInsertContent', false, html );
    2449        } else if ( hasQuicktags ) {
     50                // If quick tags are available, insert the HTML into its content.
    2551                QTags.insertContent( html );
    2652        } else {
     53                // If neither the TinyMCE editor and the quick tags are available, add the HTML to the current active editor.
    2754                document.getElementById( wpActiveEditor ).value += html;
    2855        }
    2956
    30         // If the old thickbox remove function exists, call it
     57        // If the old thickbox remove function exists, call it.
    3158        if ( window.tb_remove ) {
    3259                try { window.tb_remove(); } catch( e ) {}
    3360        }
    3461};
    3562
    36 // thickbox settings
     63// ThickBox positioning.
    3764var tb_position;
    3865(function($) {
     66        /**
     67         * Recalculates and applies the new ThickBox position based on the current window size.
     68         *
     69         * @since 2.6.0
     70         *
     71         * @returns {HTMLElements[]} Array containing all the found ThickBox anchors.
     72         */
    3973        tb_position = function() {
    4074                var tbWindow = $('#TB_window'),
    4175                        width = $(window).width(),
    var tb_position; 
    5589                                tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'});
    5690                }
    5791
     92                /**
     93                 * Recalculates the new height and width for all links with a ThickBox class.
     94                 *
     95                 * @since 2.6.0
     96                 */
    5897                return $('a.thickbox').each( function() {
    5998                        var href = $(this).attr('href');
    6099                        if ( ! href ) return;
    var tb_position; 
    64103                });
    65104        };
    66105
     106        /**
     107         * Recalculates the ThickBox position when the window is resized.
     108         */
    67109        $(window).resize(function(){ tb_position(); });
    68110
    69111})(jQuery);