Make WordPress Core

Changeset 42426


Ignore:
Timestamp:
01/04/2018 02:36:13 PM (9 years ago)
Author:
atimmer
Message:

Docs: Improve JSDoc for js/media-upload.js.

Props terwdan, diedeexterkate, andizer, ireneyoast.
Fixes #42956.

File:
1 edited

Legend:

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

    r36286 r42426  
    11/* global tinymce, QTags */
    2 // send html to the post editor
     2
     3/**
     4 * Contains global functions for the media upload within the post edit screen.
     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 * @file
     11 * @since 2.5.0
     12 *
     13 * @requires jQuery
     14 */
    315
    416var wpActiveEditor, send_to_editor;
    517
     18/**
     19 * Sends the HTML passed in the parameters to TinyMCE.
     20 *
     21 * @since 2.5.0
     22 *
     23 * @global
     24 *
     25 * @param {string} html The HTML to be sent to the editor.
     26 * @returns {void|boolean} Returns false when both TinyMCE and QTags instances
     27 *                         are unavailable. This means that the HTML was not
     28 *                         sent to the editor.
     29 */
    630send_to_editor = function( html ) {
    731        var editor,
    … …  
    933                hasQuicktags = typeof QTags !== 'undefined';
    1034
     35        // If no active editor is set, try to set it.
    1136        if ( ! wpActiveEditor ) {
    1237                if ( hasTinymce && tinymce.activeEditor ) {
    … …  
    2045        }
    2146
     47        // If the editor is set and not hidden, insert the HTML into the content of the
     48        // editor.
    2249        if ( editor && ! editor.isHidden() ) {
    2350                editor.execCommand( 'mceInsertContent', false, html );
    2451        } else if ( hasQuicktags ) {
     52                // If quick tags are available, insert the HTML into its content.
    2553                QTags.insertContent( html );
    2654        } else {
     55                // If neither the TinyMCE editor and the quick tags are available, add the HTML
     56                // to the current active editor.
    2757                document.getElementById( wpActiveEditor ).value += html;
    2858        }
    2959
    30         // If the old thickbox remove function exists, call it
     60        // If the old thickbox remove function exists, call it.
    3161        if ( window.tb_remove ) {
    3262                try { window.tb_remove(); } catch( e ) {}
    … …  
    3464};
    3565
    36 // thickbox settings
    3766var tb_position;
    3867(function($) {
     68        /**
     69         * Recalculates and applies the new ThickBox position based on the current
     70         * window size.
     71         *
     72         * @since 2.6.0
     73         *
     74         * @global
     75         *
     76         * @returns {Object[]} Array containing jQuery objects for all the found
     77         *                     ThickBox anchors.
     78         */
    3979        tb_position = function() {
    4080                var tbWindow = $('#TB_window'),
    … …  
    5696                }
    5797
     98                /**
     99                 * Recalculates the new height and width for all links with a ThickBox class.
     100                 *
     101                 * @since 2.6.0
     102                 */
    58103                return $('a.thickbox').each( function() {
    59104                        var href = $(this).attr('href');
    … …  
    65110        };
    66111
     112        // Add handler to recalculates the ThickBox position when the window is resized.
    67113        $(window).resize(function(){ tb_position(); });
    68114
Note: See TracChangeset for help on using the changeset viewer.