2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/link.js
|
|
|
|
*/
|
|
|
|
|
2013-11-15 00:16:09 -05:00
|
|
|
/* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
jQuery(document).ready( function($) {
|
|
|
|
|
|
|
|
var newCat, noSyncChecks = false, syncChecks, catAddAfter;
|
|
|
|
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#link_name').trigger( 'focus' );
|
2020-01-28 19:45:18 -05:00
|
|
|
// Postboxes.
|
2012-08-22 20:04:18 -04:00
|
|
|
postboxes.add_postbox_toggles('link');
|
|
|
|
|
2018-06-27 22:32:22 -04:00
|
|
|
/**
|
|
|
|
* Adds event that opens a particular category tab.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @return {boolean} Always returns false to prevent the default behavior.
|
|
|
|
*/
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#category-tabs a').on( 'click', function(){
|
2012-08-22 20:04:18 -04:00
|
|
|
var t = $(this).attr('href');
|
|
|
|
$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
|
|
|
|
$('.tabs-panel').hide();
|
|
|
|
$(t).show();
|
|
|
|
if ( '#categories-all' == t )
|
|
|
|
deleteUserSetting('cats');
|
|
|
|
else
|
|
|
|
setUserSetting('cats','pop');
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
if ( getUserSetting('cats') )
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#category-tabs a[href="#categories-pop"]').trigger( 'click' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2020-01-28 19:45:18 -05:00
|
|
|
// Ajax Cat.
|
2013-11-15 00:16:09 -05:00
|
|
|
newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* After adding a new category, focus on the category add input field.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#link-category-add-submit').on( 'click', function() { newCat.focus(); } );
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Synchronize category checkboxes.
|
|
|
|
*
|
|
|
|
* This function makes sure that the checkboxes are synced between the all
|
|
|
|
* categories tab and the most used categories tab.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
syncChecks = function() {
|
|
|
|
if ( noSyncChecks )
|
|
|
|
return;
|
|
|
|
noSyncChecks = true;
|
|
|
|
var th = $(this), c = th.is(':checked'), id = th.val().toString();
|
2013-03-02 18:58:34 -05:00
|
|
|
$('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c );
|
2012-08-22 20:04:18 -04:00
|
|
|
noSyncChecks = false;
|
|
|
|
};
|
|
|
|
|
2018-06-27 22:32:22 -04:00
|
|
|
/**
|
|
|
|
* Adds event listeners to an added category.
|
|
|
|
*
|
|
|
|
* This is run on the addAfter event to make sure the correct event listeners
|
|
|
|
* are bound to the DOM elements.
|
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param {string} r Raw XML response returned from the server after adding a
|
|
|
|
* category.
|
|
|
|
* @param {Object} s List manager configuration object; settings for the Ajax
|
|
|
|
* request.
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
catAddAfter = function( r, s ) {
|
|
|
|
$(s.what + ' response_data', r).each( function() {
|
|
|
|
var t = $($(this).text());
|
|
|
|
t.find( 'label' ).each( function() {
|
|
|
|
var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o;
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#' + id).on( 'change', syncChecks );
|
2012-08-22 20:04:18 -04:00
|
|
|
o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
2018-06-27 22:32:22 -04:00
|
|
|
/*
|
|
|
|
* Instantiates the list manager.
|
|
|
|
*
|
|
|
|
* @see js/_enqueues/lib/lists.js
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
$('#categorychecklist').wpList( {
|
2018-06-27 22:32:22 -04:00
|
|
|
// CSS class name for alternate styling.
|
2012-08-22 20:04:18 -04:00
|
|
|
alt: '',
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
// The type of list.
|
2012-08-22 20:04:18 -04:00
|
|
|
what: 'link-category',
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
// ID of the element the parsed Ajax response will be stored in.
|
2012-08-22 20:04:18 -04:00
|
|
|
response: 'category-ajax-response',
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
// Callback that's run after an item got added to the list.
|
2012-08-22 20:04:18 -04:00
|
|
|
addAfter: catAddAfter
|
|
|
|
} );
|
|
|
|
|
2018-06-27 22:32:22 -04:00
|
|
|
// All categories is the default tab, so we delete the user setting.
|
2021-02-23 14:45:04 -05:00
|
|
|
$('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');});
|
2018-06-27 22:32:22 -04:00
|
|
|
|
|
|
|
// Set a preference for the popular categories to cookies.
|
2021-02-23 14:45:04 -05:00
|
|
|
$('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');});
|
2018-06-27 22:32:22 -04:00
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( 'pop' == getUserSetting('cats') )
|
2021-02-23 14:45:04 -05:00
|
|
|
$('a[href="#categories-pop"]').trigger( 'click' );
|
2012-08-22 20:04:18 -04:00
|
|
|
|
2018-06-27 22:32:22 -04:00
|
|
|
/**
|
|
|
|
* Adds event handler that shows the interface controls to add a new category.
|
|
|
|
*
|
|
|
|
* @ignore
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
2019-11-29 13:01:03 -05:00
|
|
|
* @return {boolean} Always returns false to prevent regular link
|
|
|
|
* functionality.
|
2018-06-27 22:32:22 -04:00
|
|
|
*/
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#category-add-toggle').on( 'click', function() {
|
2012-08-22 20:04:18 -04:00
|
|
|
$(this).parents('div:first').toggleClass( 'wp-hidden-children' );
|
2021-02-23 14:45:04 -05:00
|
|
|
$('#category-tabs a[href="#categories-all"]').trigger( 'click' );
|
|
|
|
$('#newcategory').trigger( 'focus' );
|
2012-08-22 20:04:18 -04:00
|
|
|
return false;
|
|
|
|
} );
|
|
|
|
|
2021-02-23 14:45:04 -05:00
|
|
|
$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|