wp/wp-admin/js/link.js
changeset 18 be944660c56a
parent 16 a86126ab1dd4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
     2  * @output wp-admin/js/link.js
     2  * @output wp-admin/js/link.js
     3  */
     3  */
     4 
     4 
     5 /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
     5 /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
     6 
     6 
     7 jQuery(document).ready( function($) {
     7 jQuery( function($) {
     8 
     8 
     9 	var newCat, noSyncChecks = false, syncChecks, catAddAfter;
     9 	var newCat, noSyncChecks = false, syncChecks, catAddAfter;
    10 
    10 
    11 	$('#link_name').focus();
    11 	$('#link_name').trigger( 'focus' );
    12 	// Postboxes.
    12 	// Postboxes.
    13 	postboxes.add_postbox_toggles('link');
    13 	postboxes.add_postbox_toggles('link');
    14 
    14 
    15 	/**
    15 	/**
    16 	 * Adds event that opens a particular category tab.
    16 	 * Adds event that opens a particular category tab.
    17 	 *
    17 	 *
    18 	 * @ignore
    18 	 * @ignore
    19 	 *
    19 	 *
    20 	 * @return {boolean} Always returns false to prevent the default behavior.
    20 	 * @return {boolean} Always returns false to prevent the default behavior.
    21 	 */
    21 	 */
    22 	$('#category-tabs a').click(function(){
    22 	$('#category-tabs a').on( 'click', function(){
    23 		var t = $(this).attr('href');
    23 		var t = $(this).attr('href');
    24 		$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
    24 		$(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
    25 		$('.tabs-panel').hide();
    25 		$('.tabs-panel').hide();
    26 		$(t).show();
    26 		$(t).show();
    27 		if ( '#categories-all' == t )
    27 		if ( '#categories-all' == t )
    29 		else
    29 		else
    30 			setUserSetting('cats','pop');
    30 			setUserSetting('cats','pop');
    31 		return false;
    31 		return false;
    32 	});
    32 	});
    33 	if ( getUserSetting('cats') )
    33 	if ( getUserSetting('cats') )
    34 		$('#category-tabs a[href="#categories-pop"]').click();
    34 		$('#category-tabs a[href="#categories-pop"]').trigger( 'click' );
    35 
    35 
    36 	// Ajax Cat.
    36 	// Ajax Cat.
    37 	newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
    37 	newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
    38 
    38 
    39 	/**
    39 	/**
    40 	 * After adding a new category, focus on the category add input field.
    40 	 * After adding a new category, focus on the category add input field.
    41 	 *
    41 	 *
    42 	 * @return {void}
    42 	 * @return {void}
    43 	 */
    43 	 */
    44 	$('#link-category-add-submit').click( function() { newCat.focus(); } );
    44 	$('#link-category-add-submit').on( 'click', function() { newCat.focus(); } );
    45 
    45 
    46 	/**
    46 	/**
    47 	 * Synchronize category checkboxes.
    47 	 * Synchronize category checkboxes.
    48 	 *
    48 	 *
    49 	 * This function makes sure that the checkboxes are synced between the all
    49 	 * This function makes sure that the checkboxes are synced between the all
    79 	 */
    79 	 */
    80 	catAddAfter = function( r, s ) {
    80 	catAddAfter = function( r, s ) {
    81 		$(s.what + ' response_data', r).each( function() {
    81 		$(s.what + ' response_data', r).each( function() {
    82 			var t = $($(this).text());
    82 			var t = $($(this).text());
    83 			t.find( 'label' ).each( function() {
    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;
    84 				var th = $(this),
    85 				$('#' + id).change( syncChecks );
    85 					val = th.find('input').val(),
       
    86 					id = th.find('input')[0].id,
       
    87 					name = th.text().trim(),
       
    88 					o;
       
    89 				$('#' + id).on( 'change', syncChecks );
    86 				o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
    90 				o = $( '<option value="' +  parseInt( val, 10 ) + '"></option>' ).text( name );
    87 			} );
    91 			} );
    88 		} );
    92 		} );
    89 	};
    93 	};
    90 
    94 
   106 		// Callback that's run after an item got added to the list.
   110 		// Callback that's run after an item got added to the list.
   107 		addAfter: catAddAfter
   111 		addAfter: catAddAfter
   108 	} );
   112 	} );
   109 
   113 
   110 	// All categories is the default tab, so we delete the user setting.
   114 	// All categories is the default tab, so we delete the user setting.
   111 	$('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
   115 	$('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');});
   112 
   116 
   113 	// Set a preference for the popular categories to cookies.
   117 	// Set a preference for the popular categories to cookies.
   114 	$('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
   118 	$('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');});
   115 
   119 
   116 	if ( 'pop' == getUserSetting('cats') )
   120 	if ( 'pop' == getUserSetting('cats') )
   117 		$('a[href="#categories-pop"]').click();
   121 		$('a[href="#categories-pop"]').trigger( 'click' );
   118 
   122 
   119 	/**
   123 	/**
   120 	 * Adds event handler that shows the interface controls to add a new category.
   124 	 * Adds event handler that shows the interface controls to add a new category.
   121 	 *
   125 	 *
   122 	 * @ignore
   126 	 * @ignore
   123 	 *
   127 	 *
   124 	 * @param {Event} event The event object.
   128 	 * @param {Event} event The event object.
   125 	 * @return {boolean} Always returns false to prevent regular link
   129 	 * @return {boolean} Always returns false to prevent regular link
   126 	 *                   functionality.
   130 	 *                   functionality.
   127 	 */
   131 	 */
   128 	$('#category-add-toggle').click( function() {
   132 	$('#category-add-toggle').on( 'click', function() {
   129 		$(this).parents('div:first').toggleClass( 'wp-hidden-children' );
   133 		$(this).parents('div:first').toggleClass( 'wp-hidden-children' );
   130 		$('#category-tabs a[href="#categories-all"]').click();
   134 		$('#category-tabs a[href="#categories-all"]').trigger( 'click' );
   131 		$('#newcategory').focus();
   135 		$('#newcategory').trigger( 'focus' );
   132 		return false;
   136 		return false;
   133 	} );
   137 	} );
   134 
   138 
   135 	$('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
   139 	$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' );
   136 });
   140 });