Make WordPress Core

Changeset 41311


Ignore:
Timestamp:
08/24/2017 05:51:19 PM (8 years ago)
Author:
wonderboymusic
Message:

Docs: improve JS docs for tags.js

Props atimmer, jipmoors.
Fixes #41069.

File:
1 edited

Legend:

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

    r40655 r41311  
    11/* global ajaxurl, wpAjax, tagsl10n, showNotice, validateForm */
     2/**
     3 * Contains logic for both adding and deleting tags. For deleting tags it makes a request
     4 * to the server to delete the tag. For adding tags it makes a request to the server to
     5 * add the tag.
     6 *
     7 * @summary Contains logic for deleting and adding tags
     8 */
    29
    310jQuery(document).ready(function($) {
    411
     12    /**
     13     * @summary Adds an event handler to the delete term link on the term overview page.
     14     *
     15     * Adds an event handler to the delete term link on the term overview page.
     16     * Cancels default event handling and event bubbling.
     17     *
     18     * @since 2.8.0
     19     *
     20     * @returns boolean Always returns false to cancel the default event handling.
     21     */
    522    $( '#the-list' ).on( 'click', '.delete-tag', function() {
    623        var t = $(this), tr = t.parents('tr'), r = true, data;
     24
    725        if ( 'undefined' != showNotice )
    826            r = showNotice.warn();
     27
    928        if ( r ) {
    1029            data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag');
     30
     31            /**
     32             * @summary Makes a request to the server to delete the term that
     33             * corresponds to the delete term button.
     34             *
     35             * @param {string} r The response from the server.
     36             *
     37             * @returns {void}
     38             */
    1139            $.post(ajaxurl, data, function(r){
    1240                if ( '1' == r ) {
    1341                    $('#ajax-response').empty();
    1442                    tr.fadeOut('normal', function(){ tr.remove(); });
    15                     // Remove the term from the parent box and tag cloud
     43
     44                    /**
     45                     * @summary Remove the term from the parent box and the tag cloud
     46                     *
     47                     * `data.match(/tag_ID=(\d+)/)[1]` matches the term id from the data variable.
     48                     * This term id is then used to select the relevant HTML elements:
     49                     * The parent box and the tag cloud.
     50                     */
    1651                    $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove();
    1752                    $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove();
     53
    1854                } else if ( '-1' == r ) {
    1955                    $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>');
    2056                    tr.children().css('backgroundColor', '');
     57
    2158                } else {
    2259                    $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.broken + '</p></div>');
     
    2461                }
    2562            });
     63
    2664            tr.children().css('backgroundColor', '#f33');
    2765        }
     66
    2867        return false;
    2968    });
    3069
     70    /**
     71     * Adds a deletion confirmation when removing a tag.
     72     *
     73     * @since 4.8.0
     74     *
     75     * @returns {void}
     76     */
    3177    $( '#edittag' ).on( 'click', '.delete', function( e ) {
    3278        if ( 'undefined' === typeof showNotice ) {
     
    3480        }
    3581
     82        // Confirms the deletion, a negative response means the deletion must not be executed.
    3683        var response = showNotice.warn();
    3784        if ( ! response ) {
     
    4087    });
    4188
     89    /**
     90     * @summary Adds an event handler tot he form submit on the term overview page.
     91     *
     92     * Cancels default event handling and event bubbling.
     93     *
     94     * @since 2.8.0
     95     *
     96     * @returns boolean Always returns false to cancel the default event handling.
     97     */
    4298    $('#submit').click(function(){
    4399        var form = $(this).parents('form');
     
    46102            return false;
    47103
     104        /**
     105         * Does a request to the server to add a new term to the database
     106         *
     107         * @param {string} r The response from the server.
     108         *
     109         * @returns {void}
     110         */
    48111        $.post(ajaxurl, $('#addtag').serialize(), function(r){
    49112            var res, parent, term, indent, i;
Note: See TracChangeset for help on using the changeset viewer.