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