9
|
1 |
/** |
|
2 |
* @output wp-admin/js/link.js |
|
3 |
*/ |
|
4 |
|
5
|
5 |
/* global postboxes, deleteUserSetting, setUserSetting, getUserSetting */ |
|
6 |
|
18
|
7 |
jQuery( function($) { |
0
|
8 |
|
|
9 |
var newCat, noSyncChecks = false, syncChecks, catAddAfter; |
|
10 |
|
18
|
11 |
$('#link_name').trigger( 'focus' ); |
16
|
12 |
// Postboxes. |
0
|
13 |
postboxes.add_postbox_toggles('link'); |
|
14 |
|
9
|
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 |
*/ |
18
|
22 |
$('#category-tabs a').on( 'click', function(){ |
0
|
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') ) |
18
|
34 |
$('#category-tabs a[href="#categories-pop"]').trigger( 'click' ); |
0
|
35 |
|
16
|
36 |
// Ajax Cat. |
5
|
37 |
newCat = $('#newcat').one( 'focus', function() { $(this).val( '' ).removeClass( 'form-input-tip' ); } ); |
9
|
38 |
|
|
39 |
/** |
|
40 |
* After adding a new category, focus on the category add input field. |
|
41 |
* |
|
42 |
* @return {void} |
|
43 |
*/ |
18
|
44 |
$('#link-category-add-submit').on( 'click', function() { newCat.focus(); } ); |
9
|
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 |
*/ |
0
|
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 |
|
9
|
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 |
*/ |
0
|
80 |
catAddAfter = function( r, s ) { |
|
81 |
$(s.what + ' response_data', r).each( function() { |
|
82 |
var t = $($(this).text()); |
|
83 |
t.find( 'label' ).each( function() { |
18
|
84 |
var th = $(this), |
|
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 ); |
0
|
90 |
o = $( '<option value="' + parseInt( val, 10 ) + '"></option>' ).text( name ); |
|
91 |
} ); |
|
92 |
} ); |
|
93 |
}; |
|
94 |
|
9
|
95 |
/* |
|
96 |
* Instantiates the list manager. |
|
97 |
* |
|
98 |
* @see js/_enqueues/lib/lists.js |
|
99 |
*/ |
0
|
100 |
$('#categorychecklist').wpList( { |
9
|
101 |
// CSS class name for alternate styling. |
0
|
102 |
alt: '', |
9
|
103 |
|
|
104 |
// The type of list. |
0
|
105 |
what: 'link-category', |
9
|
106 |
|
|
107 |
// ID of the element the parsed Ajax response will be stored in. |
0
|
108 |
response: 'category-ajax-response', |
9
|
109 |
|
|
110 |
// Callback that's run after an item got added to the list. |
0
|
111 |
addAfter: catAddAfter |
|
112 |
} ); |
|
113 |
|
9
|
114 |
// All categories is the default tab, so we delete the user setting. |
18
|
115 |
$('a[href="#categories-all"]').on( 'click', function(){deleteUserSetting('cats');}); |
9
|
116 |
|
|
117 |
// Set a preference for the popular categories to cookies. |
18
|
118 |
$('a[href="#categories-pop"]').on( 'click', function(){setUserSetting('cats','pop');}); |
9
|
119 |
|
0
|
120 |
if ( 'pop' == getUserSetting('cats') ) |
18
|
121 |
$('a[href="#categories-pop"]').trigger( 'click' ); |
0
|
122 |
|
9
|
123 |
/** |
|
124 |
* Adds event handler that shows the interface controls to add a new category. |
|
125 |
* |
|
126 |
* @ignore |
|
127 |
* |
|
128 |
* @param {Event} event The event object. |
16
|
129 |
* @return {boolean} Always returns false to prevent regular link |
|
130 |
* functionality. |
9
|
131 |
*/ |
18
|
132 |
$('#category-add-toggle').on( 'click', function() { |
0
|
133 |
$(this).parents('div:first').toggleClass( 'wp-hidden-children' ); |
18
|
134 |
$('#category-tabs a[href="#categories-all"]').trigger( 'click' ); |
|
135 |
$('#newcategory').trigger( 'focus' ); |
0
|
136 |
return false; |
|
137 |
} ); |
|
138 |
|
18
|
139 |
$('.categorychecklist :checkbox').on( 'change', syncChecks ).filter( ':checked' ).trigger( 'change' ); |
0
|
140 |
}); |