link.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */
  2. jQuery(document).ready( function($) {
  3. var newCat, noSyncChecks = false, syncChecks, catAddAfter;
  4. $('#link_name').focus();
  5. // postboxes
  6. postboxes.add_postbox_toggles('link');
  7. // category tabs
  8. $('#category-tabs a').click(function(){
  9. var t = $(this).attr('href');
  10. $(this).parent().addClass('tabs').siblings('li').removeClass('tabs');
  11. $('.tabs-panel').hide();
  12. $(t).show();
  13. if ( '#categories-all' == t )
  14. deleteUserSetting('cats');
  15. else
  16. setUserSetting('cats','pop');
  17. return false;
  18. });
  19. if ( getUserSetting('cats') )
  20. $('#category-tabs a[href="#categories-pop"]').click();
  21. // Ajax Cat
  22. newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } );
  23. $('#link-category-add-submit').click( function() { newCat.focus(); } );
  24. syncChecks = function() {
  25. if ( noSyncChecks )
  26. return;
  27. noSyncChecks = true;
  28. var th = $(this), c = th.is(':checked'), id = th.val().toString();
  29. $('#in-link-category-' + id + ', #in-popular-link_category-' + id).prop( 'checked', c );
  30. noSyncChecks = false;
  31. };
  32. catAddAfter = function( r, s ) {
  33. $(s.what + ' response_data', r).each( function() {
  34. var t = $($(this).text());
  35. t.find( 'label' ).each( function() {
  36. var th = $(this), val = th.find('input').val(), id = th.find('input')[0].id, name = $.trim( th.text() ), o;
  37. $('#' + id).change( syncChecks );
  38. o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name );
  39. } );
  40. } );
  41. };
  42. $('#categorychecklist').wpList( {
  43. alt: '',
  44. what: 'link-category',
  45. response: 'category-ajax-response',
  46. addAfter: catAddAfter
  47. } );
  48. $('a[href="#categories-all"]').click(function(){deleteUserSetting('cats');});
  49. $('a[href="#categories-pop"]').click(function(){setUserSetting('cats','pop');});
  50. if ( 'pop' == getUserSetting('cats') )
  51. $('a[href="#categories-pop"]').click();
  52. $('#category-add-toggle').click( function() {
  53. $(this).parents('div:first').toggleClass( 'wp-hidden-children' );
  54. $('#category-tabs a[href="#categories-all"]').click();
  55. $('#newcategory').focus();
  56. return false;
  57. } );
  58. $('.categorychecklist :checkbox').change( syncChecks ).filter( ':checked' ).change();
  59. });