| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 /** 2 * @output wp-admin/js/link.js 3 */ 4 5 /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */ 6 7 jQuery( function($) { 8 9 var newCat, noSyncChecks = false, syncChecks, catAddAfter; 10 11 $('#link_name').trigger( 'focus' ); 12 // Postboxes. 13 postboxes.add_postbox_toggles('link'); 14 15 /** 16 * Adds event that opens a particular category tab. 17 * 18 * @ignore 19 * 20 * @return {boolean} Always returns false to prevent the default behavior. 21 */ 22 $('#category-tabs a').on( 'click keyup keydown', function( event ){ 23 var t = $(this).attr('href'); 24 if ( event.type === 'keydown' && event.key === ' ' ) { 25 event.preventDefault(); 26 } 27 if ( ( event.type === 'keyup' && event.key === ' ' ) || ( event.type === 'keydown' && event.key === 'Enter' ) || event.type === 'click' ) { 28 event.preventDefault(); 29 $('#category-tabs a').removeAttr( 'aria-selected' ).attr( 'tabindex', '-1' ); 30 $(this).attr( 'aria-selected', 'true' ).removeAttr( 'tabindex' ); 31 $(this).parent().addClass('tabs').siblings('li').removeClass('tabs'); 32 $('.tabs-panel').hide(); 33 $(t).show(); 34 if ( '#categories-all' == t ) { 35 deleteUserSetting('cats'); 36 } else { 37 setUserSetting('cats','pop'); 38 } 39 return false; 40 } 41 if ( event.type === 'keyup' && ( event.key === 'ArrowRight' || event.key === 'ArrowLeft' ) ) { 42 $(this).attr( 'tabindex', '-1' ); 43 let next = $(this).parent('li').next(); 44 let prev = $(this).parent('li').prev(); 45 if ( next.length > 0 ) { 46 next.find('a').removeAttr( 'tabindex'); 47 next.find('a').trigger( 'focus' ); 48 } else { 49 prev.find('a').removeAttr( 'tabindex'); 50 prev.find('a').trigger( 'focus' ); 51 } 52 } 53 }); 54 if ( getUserSetting('cats') ) 55 $('#category-tabs a[href="#categories-pop"]').trigger( 'click' ); 56 57 // Ajax Cat. 58 newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } ); 59 60 /** 61 * After adding a new category, focus on the category add input field. 62 * 63 * @return {void} 64 */ 65 $('#link-category-add-submit').on( 'click', function() { newCat.focus(); } ); 66 67 /** 68 * Synchronize category checkboxes. 69 * 70 * This function makes sure that the checkboxes are synced between the all 71 * categories tab and the most used categories tab. 72 * 73 * @since 2.5.0 74 * 75 * @return {void} 76 */ 77 syncChecks = function() { 78 if ( noSyncChecks ) 79 return; 80 noSyncChecks = true; 81 var th = $(this), c = th.is(':checked'), id = th.val().toString(); 82 $('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c ); 83 noSyncChecks = false; 84 }; 85 86 /** 87 * Adds event listeners to an added category. 88 * 89 * This is run on the addAfter event to make sure the correct event listeners 90 * are bound to the DOM elements. 91 * 92 * @since 2.5.0 93 * 94 * @param {string} r Raw XML response returned from the server after adding a 95 * category. 96 * @param {Object} s List manager configuration object; settings for the Ajax 97 * request. 98 * 99 * @return {void} 100 */ 101 catAddAfter = function( r, s ) { 102 $(s.what + ' response_data', r).each( function() { 103 var t = $($(this).text()); 104 t.find( 'label' ).each( function() { 105 var th = $(this), 106 val = th.find('input').val(), 107 id = th.find('input')[0].id, 108 name = th.text().trim(), 109 o; 110 $('#' + id).on( 'change', syncChecks ); 111 o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name ); 112 } ); 113 } ); 114 }; 115 116 /* 117 * Instantiates the list manager. 118 * 119 * @see js/_enqueues/lib/lists.js 120 */ 121 $('#categorychecklist').wpList( { 122 // CSS class name for alternate styling. 123 alt: '', 124 125 // The type of list. 126 what: 'link-category', 127 128 // ID of the element the parsed Ajax response will be stored in. 129 response: 'category-ajax-response', 130 131 // Callback that's run after an item got added to the list. 132 addAfter: catAddAfter 133 } ); 134 135 // All categories is the default tab, so we delete the user setting. 136 $('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');}); 137 138 // Set a preference for the popular categories to cookies. 139 $('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');}); 140 141 if ( 'pop' == getUserSetting('cats') ) 142 $('a[href="#categories-pop"]').trigger( 'click' ); 143 144 /** 145 * Adds event handler that shows the interface controls to add a new category. 146 * 147 * @ignore 148 * 149 * @param {Event} event The event object. 150 * @return {boolean} Always returns false to prevent regular link 151 * functionality. 152 */ 153 $('#category-add-toggle').on( 'click', function() { 154 $(this).parents('div:first').toggleClass( 'wp-hidden-children' ); 155 $('#category-tabs a[href="#categories-all"]').trigger( 'click' ); 156 $('#newcategory').trigger( 'focus' ); 157 return false; 158 } ); 159 160 $('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' ); 161 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Thu Apr 23 08:20:11 2026 | Cross-referenced by PHPXref |