wp/wp-admin/js/link.js
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:52:52 +0200
changeset 22 8c2e4d02f4ef
parent 18 be944660c56a
permissions -rw-r--r--
Update WordPress to latest version (6.7) - Sync WordPress core files from latest release - Updated admin interface, blocks, and core functionality - Enhanced block editor features and performance - Security updates and bug fixes - Preserved custom wp-content directory and configuration 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     1
/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     2
 * @output wp-admin/js/link.js
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 */
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     4
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     5
/* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
     7
jQuery( function($) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
	var newCat, noSyncChecks = false, syncChecks, catAddAfter;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    11
	$('#link_name').trigger( 'focus' );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    12
	// Postboxes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	postboxes.add_postbox_toggles('link');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
	 * Adds event that opens a particular category tab.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    17
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    18
	 * @ignore
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    19
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    20
	 * @return {boolean} Always returns false to prevent the default behavior.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    21
	 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    22
	$('#category-tabs a').on( 'click', function(){
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
		var t = $(this).attr('href');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
		$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
		$('.tabs-panel').hide();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
		$(t).show();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		if ( '#categories-all' == t )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
			deleteUserSetting('cats');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
			setUserSetting('cats','pop');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	if ( getUserSetting('cats') )
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    34
		$('#category-tabs a[href="#categories-pop"]').trigger( 'click' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    36
	// Ajax Cat.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
	newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    38
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    39
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    40
	 * After adding a new category, focus on the category add input field.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    41
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    42
	 * @return {void}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    43
	 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    44
	$('#link-category-add-submit').on( 'click', function() { newCat.focus(); } );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    45
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    46
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    47
	 * Synchronize category checkboxes.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    48
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    49
	 * This function makes sure that the checkboxes are synced between the all
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    50
	 * categories tab and the most used categories tab.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    51
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    52
	 * @since 2.5.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    53
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    54
	 * @return {void}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    55
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	syncChecks = function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		if ( noSyncChecks )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		noSyncChecks = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
		var th = $(this), c = th.is(':checked'), id = th.val().toString();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
		$('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
		noSyncChecks = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    65
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    66
	 * Adds event listeners to an added category.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    67
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    68
	 * This is run on the addAfter event to make sure the correct event listeners
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    69
	 * are bound to the DOM elements.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    70
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    71
	 * @since 2.5.0
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    72
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    73
	 * @param {string} r Raw XML response returned from the server after adding a
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    74
	 *                   category.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    75
	 * @param {Object} s List manager configuration object; settings for the Ajax
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    76
	 *                   request.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    77
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    78
	 * @return {void}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    79
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	catAddAfter = function( r, s ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
		$(s.what + ' response_data', r).each( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
			var t = $($(this).text());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
			t.find( 'label' ).each( function() {
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    84
				var th = $(this),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    85
					val = th.find('input').val(),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    86
					id = th.find('input')[0].id,
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    87
					name = th.text().trim(),
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    88
					o;
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    89
				$('#' + id).on( 'change', syncChecks );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
				o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
			} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    95
	/*
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    96
	 * Instantiates the list manager.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    97
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    98
	 * @see js/_enqueues/lib/lists.js
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    99
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	$('#categorychecklist').wpList( {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   101
		// CSS class name for alternate styling.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		alt: '',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   103
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   104
		// The type of list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		what: 'link-category',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   107
		// ID of the element the parsed Ajax response will be stored in.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
		response: 'category-ajax-response',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   110
		// Callback that's run after an item got added to the list.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		addAfter: catAddAfter
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   114
	// All categories is the default tab, so we delete the user setting.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   115
	$('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');});
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   117
	// Set a preference for the popular categories to cookies.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   118
	$('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');});
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   119
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	if ( 'pop' == getUserSetting('cats') )
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   121
		$('a[href="#categories-pop"]').trigger( 'click' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   123
	/**
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   124
	 * Adds event handler that shows the interface controls to add a new category.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   125
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   126
	 * @ignore
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   127
	 *
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   128
	 * @param {Event} event The event object.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   129
	 * @return {boolean} Always returns false to prevent regular link
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   130
	 *                   functionality.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   131
	 */
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   132
	$('#category-add-toggle').on( 'click', function() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
		$(this).parents('div:first').toggleClass( 'wp-hidden-children' );
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   134
		$('#category-tabs a[href="#categories-all"]').trigger( 'click' );
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   135
		$('#newcategory').trigger( 'focus' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
	} );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   139
	$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
});