author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 18:28:13 +0200 | |
changeset 9 | 177826044cd9 |
parent 7 | cf61fcea0001 |
child 16 | a86126ab1dd4 |
permissions | -rw-r--r-- |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
1 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
2 |
* This file contains the functions needed for the inline editing of posts. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
4 |
* @since 2.7.0 |
9 | 5 |
* @output wp-admin/js/inline-edit-post.js |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
6 |
*/ |
5 | 7 |
|
9 | 8 |
/* global inlineEditL10n, ajaxurl, typenow, inlineEditPost */ |
9 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
10 |
window.wp = window.wp || {}; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
11 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
12 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
* Manages the quick edit and bulk edit windows for editing posts or pages. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
* |
9 | 15 |
* @namespace inlineEditPost |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
* @type {Object} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
20 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
21 |
* @property {string} type The type of inline editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
22 |
* @property {string} what The prefix before the post id. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
23 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
24 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
25 |
( function( $, wp ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
26 |
|
9 | 27 |
window.inlineEditPost = { |
0 | 28 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
29 |
/** |
9 | 30 |
* Initializes the inline and bulk post editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
31 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
32 |
* Binds event handlers to the escape key to close the inline editor |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
33 |
* and to the save and close buttons. Changes DOM to be ready for inline |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
34 |
* editing. Adds event handler to bulk edit. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
35 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
36 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
39 |
* @returns {void} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
40 |
*/ |
0 | 41 |
init : function(){ |
42 |
var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); |
|
43 |
||
44 |
t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
45 |
// Post id prefix. |
0 | 46 |
t.what = '#post-'; |
47 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
48 |
/** |
9 | 49 |
* Binds the escape key to revert the changes and close the quick editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
50 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
51 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
*/ |
0 | 53 |
qeRow.keyup(function(e){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
// Revert changes if escape key is pressed. |
5 | 55 |
if ( e.which === 27 ) { |
0 | 56 |
return inlineEditPost.revert(); |
5 | 57 |
} |
0 | 58 |
}); |
59 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
/** |
9 | 61 |
* Binds the escape key to revert the changes and close the bulk editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
62 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
63 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
64 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
65 |
bulkRow.keyup(function(e){ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
66 |
// Revert changes if escape key is pressed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
if ( e.which === 27 ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
return inlineEditPost.revert(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
70 |
}); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
71 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
/** |
9 | 73 |
* Reverts changes and close the quick editor if the cancel button is clicked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
$( '.cancel', qeRow ).click( function() { |
0 | 78 |
return inlineEditPost.revert(); |
79 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
80 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
81 |
/** |
9 | 82 |
* Saves changes in the quick editor if the save(named: update) button is clicked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
83 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
84 |
* @returns {boolean} The result of save. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
85 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
86 |
$( '.save', qeRow ).click( function() { |
0 | 87 |
return inlineEditPost.save(this); |
88 |
}); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
89 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
90 |
/** |
9 | 91 |
* If enter is pressed, and the target is not the cancel button, save the post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
92 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
93 |
* @returns {boolean} The result of save. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
94 |
*/ |
0 | 95 |
$('td', qeRow).keydown(function(e){ |
5 | 96 |
if ( e.which === 13 && ! $( e.target ).hasClass( 'cancel' ) ) { |
0 | 97 |
return inlineEditPost.save(this); |
5 | 98 |
} |
0 | 99 |
}); |
100 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
101 |
/** |
9 | 102 |
* Reverts changes and close the bulk editor if the cancel button is clicked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
103 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
104 |
* @returns {boolean} The result of revert. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
$( '.cancel', bulkRow ).click( function() { |
0 | 107 |
return inlineEditPost.revert(); |
108 |
}); |
|
109 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
/** |
9 | 111 |
* Disables the password input field when the private post checkbox is checked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
*/ |
0 | 113 |
$('#inline-edit .inline-edit-private input[value="private"]').click( function(){ |
114 |
var pw = $('input.inline-edit-password-input'); |
|
115 |
if ( $(this).prop('checked') ) { |
|
116 |
pw.val('').prop('disabled', true); |
|
117 |
} else { |
|
118 |
pw.prop('disabled', false); |
|
119 |
} |
|
120 |
}); |
|
121 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
/** |
9 | 123 |
* Binds click event to the .editinline button which opens the quick editor. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
*/ |
9 | 125 |
$( '#the-list' ).on( 'click', '.editinline', function() { |
126 |
$( this ).attr( 'aria-expanded', 'true' ); |
|
127 |
inlineEditPost.edit( this ); |
|
0 | 128 |
}); |
129 |
||
5 | 130 |
$('#bulk-edit').find('fieldset:first').after( |
0 | 131 |
$('#inline-edit fieldset.inline-edit-categories').clone() |
132 |
).siblings( 'fieldset:last' ).prepend( |
|
133 |
$('#inline-edit label.inline-edit-tags').clone() |
|
134 |
); |
|
135 |
||
136 |
$('select[name="_status"] option[value="future"]', bulkRow).remove(); |
|
137 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
138 |
/** |
9 | 139 |
* Adds onclick events to the apply buttons. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
*/ |
0 | 141 |
$('#doaction, #doaction2').click(function(e){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
142 |
var n; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
143 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
144 |
t.whichBulkButtonId = $( this ).attr( 'id' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
145 |
n = t.whichBulkButtonId.substr( 2 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
146 |
|
5 | 147 |
if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) { |
0 | 148 |
e.preventDefault(); |
149 |
t.setBulk(); |
|
150 |
} else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { |
|
151 |
t.revert(); |
|
152 |
} |
|
153 |
}); |
|
154 |
}, |
|
155 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
156 |
/** |
9 | 157 |
* Toggles the quick edit window, hiding it when it's active and showing it when |
158 |
* inactive. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
159 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
160 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
161 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
162 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
163 |
* @param {Object} el Element within a post table row. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
164 |
*/ |
0 | 165 |
toggle : function(el){ |
166 |
var t = this; |
|
5 | 167 |
$( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el ); |
0 | 168 |
}, |
169 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
170 |
/** |
9 | 171 |
* Creates the bulk editor row to edit multiple posts at once. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
172 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
173 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
175 |
*/ |
0 | 176 |
setBulk : function(){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
177 |
var te = '', type = this.type, c = true; |
0 | 178 |
this.revert(); |
179 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
180 |
$( '#bulk-edit td' ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
181 |
|
5 | 182 |
// Insert the editor at the top of the table with an empty row above to maintain zebra striping. |
183 |
$('table.widefat tbody').prepend( $('#bulk-edit') ).prepend('<tr class="hidden"></tr>'); |
|
0 | 184 |
$('#bulk-edit').addClass('inline-editor').show(); |
185 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
186 |
/** |
9 | 187 |
* Create a HTML div with the title and a link(delete-icon) for each selected |
188 |
* post. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
189 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
190 |
* Get the selected posts based on the checked checkboxes in the post table. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
191 |
*/ |
5 | 192 |
$( 'tbody th.check-column input[type="checkbox"]' ).each( function() { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
193 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
194 |
// If the checkbox for a post is selected, add the post to the edit list. |
0 | 195 |
if ( $(this).prop('checked') ) { |
196 |
c = false; |
|
197 |
var id = $(this).val(), theTitle; |
|
198 |
theTitle = $('#inline_'+id+' .post_title').html() || inlineEditL10n.notitle; |
|
199 |
te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>'; |
|
200 |
} |
|
201 |
}); |
|
202 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
203 |
// If no checkboxes where checked, just hide the quick/bulk edit rows. |
5 | 204 |
if ( c ) { |
0 | 205 |
return this.revert(); |
5 | 206 |
} |
0 | 207 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
208 |
// Add onclick events to the delete-icons in the bulk editors the post title list. |
0 | 209 |
$('#bulk-titles').html(te); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
210 |
/** |
9 | 211 |
* Binds on click events to the checkboxes before the posts in the table. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
212 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
213 |
* @listens click |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
*/ |
0 | 215 |
$('#bulk-titles a').click(function(){ |
216 |
var id = $(this).attr('id').substr(1); |
|
217 |
||
218 |
$('table.widefat input[value="' + id + '"]').prop('checked', false); |
|
219 |
$('#ttle'+id).remove(); |
|
220 |
}); |
|
221 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
// Enable auto-complete for tags when editing posts. |
5 | 223 |
if ( 'post' === type ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
224 |
$( 'tr.inline-editor textarea[data-wp-taxonomy]' ).each( function ( i, element ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
225 |
/* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
226 |
* While Quick Edit clones the form each time, Bulk Edit always re-uses |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
227 |
* the same form. Let's check if an autocomplete instance already exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
228 |
*/ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
229 |
if ( $( element ).autocomplete( 'instance' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
230 |
// jQuery equivalent of `continue` within an `each()` loop. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
231 |
return; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
233 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
234 |
$( element ).wpTagsSuggest(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
235 |
} ); |
0 | 236 |
} |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
237 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
238 |
// Scrolls to the top of the table where the editor is rendered. |
0 | 239 |
$('html, body').animate( { scrollTop: 0 }, 'fast' ); |
240 |
}, |
|
241 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
242 |
/** |
9 | 243 |
* Creates a quick edit window for the post that has been clicked. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
244 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
245 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
246 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
247 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
248 |
* @param {number|Object} id The id of the clicked post or an element within a post |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
249 |
* table row. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
250 |
* @returns {boolean} Always returns false at the end of execution. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
*/ |
0 | 252 |
edit : function(id) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
253 |
var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, f, val, pw; |
0 | 254 |
t.revert(); |
255 |
||
5 | 256 |
if ( typeof(id) === 'object' ) { |
0 | 257 |
id = t.getId(id); |
5 | 258 |
} |
0 | 259 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
260 |
fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order', 'page_template']; |
5 | 261 |
if ( t.type === 'page' ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
fields.push('post_parent'); |
5 | 263 |
} |
0 | 264 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
// Add the new edit row with an extra blank row underneath to maintain zebra striping. |
0 | 266 |
editRow = $('#inline-edit').clone(true); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
$( 'td', editRow ).attr( 'colspan', $( 'th:visible, td:visible', '.widefat:first thead' ).length ); |
0 | 268 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
$(t.what+id).removeClass('is-expanded').hide().after(editRow).after('<tr class="hidden"></tr>'); |
0 | 270 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
// Populate fields in the quick edit window. |
0 | 272 |
rowData = $('#inline_'+id); |
273 |
if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
// The post author no longer has edit capabilities, so we need to add them to the list of authors. |
0 | 276 |
$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>'); |
277 |
} |
|
5 | 278 |
if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) { |
0 | 279 |
$('label.inline-edit-author', editRow).hide(); |
280 |
} |
|
281 |
||
282 |
for ( f = 0; f < fields.length; f++ ) { |
|
5 | 283 |
val = $('.'+fields[f], rowData); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
284 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
285 |
/** |
9 | 286 |
* Replaces the image for a Twemoji(Twitter emoji) with it's alternate text. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
288 |
* @returns Alternate text from the image. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
*/ |
5 | 290 |
val.find( 'img' ).replaceWith( function() { return this.alt; } ); |
291 |
val = val.text(); |
|
292 |
$(':input[name="' + fields[f] + '"]', editRow).val( val ); |
|
0 | 293 |
} |
294 |
||
5 | 295 |
if ( $( '.comment_status', rowData ).text() === 'open' ) { |
296 |
$( 'input[name="comment_status"]', editRow ).prop( 'checked', true ); |
|
297 |
} |
|
298 |
if ( $( '.ping_status', rowData ).text() === 'open' ) { |
|
299 |
$( 'input[name="ping_status"]', editRow ).prop( 'checked', true ); |
|
300 |
} |
|
301 |
if ( $( '.sticky', rowData ).text() === 'sticky' ) { |
|
302 |
$( 'input[name="sticky"]', editRow ).prop( 'checked', true ); |
|
303 |
} |
|
0 | 304 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
305 |
/** |
9 | 306 |
* Creates the select boxes for the categories. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
307 |
*/ |
0 | 308 |
$('.post_category', rowData).each(function(){ |
5 | 309 |
var taxname, |
310 |
term_ids = $(this).text(); |
|
0 | 311 |
|
312 |
if ( term_ids ) { |
|
313 |
taxname = $(this).attr('id').replace('_'+id, ''); |
|
314 |
$('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); |
|
315 |
} |
|
316 |
}); |
|
317 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
318 |
/** |
9 | 319 |
* Gets all the taxonomies for live auto-fill suggestions when typing the name |
320 |
* of a tag. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
321 |
*/ |
0 | 322 |
$('.tags_input', rowData).each(function(){ |
5 | 323 |
var terms = $(this), |
0 | 324 |
taxname = $(this).attr('id').replace('_' + id, ''), |
325 |
textarea = $('textarea.tax_input_' + taxname, editRow), |
|
326 |
comma = inlineEditL10n.comma; |
|
327 |
||
5 | 328 |
terms.find( 'img' ).replaceWith( function() { return this.alt; } ); |
329 |
terms = terms.text(); |
|
330 |
||
0 | 331 |
if ( terms ) { |
5 | 332 |
if ( ',' !== comma ) { |
0 | 333 |
terms = terms.replace(/,/g, comma); |
5 | 334 |
} |
0 | 335 |
textarea.val(terms); |
336 |
} |
|
337 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
338 |
textarea.wpTagsSuggest(); |
0 | 339 |
}); |
340 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
341 |
// Handle the post status. |
0 | 342 |
status = $('._status', rowData).text(); |
5 | 343 |
if ( 'future' !== status ) { |
0 | 344 |
$('select[name="_status"] option[value="future"]', editRow).remove(); |
5 | 345 |
} |
0 | 346 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
347 |
pw = $( '.inline-edit-password-input' ).prop( 'disabled', false ); |
5 | 348 |
if ( 'private' === status ) { |
349 |
$('input[name="keep_private"]', editRow).prop('checked', true); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
350 |
pw.val( '' ).prop( 'disabled', true ); |
0 | 351 |
} |
352 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
353 |
// Remove the current page and children from the parent dropdown. |
0 | 354 |
pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow); |
355 |
if ( pageOpt.length > 0 ) { |
|
356 |
pageLevel = pageOpt[0].className.split('-')[1]; |
|
357 |
nextPage = pageOpt; |
|
358 |
while ( pageLoop ) { |
|
359 |
nextPage = nextPage.next('option'); |
|
5 | 360 |
if ( nextPage.length === 0 ) { |
361 |
break; |
|
362 |
} |
|
363 |
||
0 | 364 |
nextLevel = nextPage[0].className.split('-')[1]; |
5 | 365 |
|
0 | 366 |
if ( nextLevel <= pageLevel ) { |
367 |
pageLoop = false; |
|
368 |
} else { |
|
369 |
nextPage.remove(); |
|
370 |
nextPage = pageOpt; |
|
371 |
} |
|
372 |
} |
|
373 |
pageOpt.remove(); |
|
374 |
} |
|
375 |
||
376 |
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
|
377 |
$('.ptitle', editRow).focus(); |
|
378 |
||
379 |
return false; |
|
380 |
}, |
|
381 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
382 |
/** |
9 | 383 |
* Saves the changes made in the quick edit window to the post. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
384 |
* AJAX saving is only for Quick Edit and not for bulk edit. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
385 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
386 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
387 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
388 |
* @param {int} id The id for the post that has been changed. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
* @returns {boolean} false, so the form does not submit when pressing |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
390 |
* Enter on a focused field. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
391 |
*/ |
0 | 392 |
save : function(id) { |
393 |
var params, fields, page = $('.post_status_page').val() || ''; |
|
394 |
||
5 | 395 |
if ( typeof(id) === 'object' ) { |
0 | 396 |
id = this.getId(id); |
5 | 397 |
} |
0 | 398 |
|
5 | 399 |
$( 'table.widefat .spinner' ).addClass( 'is-active' ); |
0 | 400 |
|
401 |
params = { |
|
402 |
action: 'inline-save', |
|
403 |
post_type: typenow, |
|
404 |
post_ID: id, |
|
405 |
edit_date: 'true', |
|
406 |
post_status: page |
|
407 |
}; |
|
408 |
||
5 | 409 |
fields = $('#edit-'+id).find(':input').serialize(); |
0 | 410 |
params = fields + '&' + $.param(params); |
411 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
// Make ajax request. |
0 | 413 |
$.post( ajaxurl, params, |
414 |
function(r) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
var $errorNotice = $( '#edit-' + id + ' .inline-edit-save .notice-error' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
$error = $errorNotice.find( '.error' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
417 |
|
5 | 418 |
$( 'table.widefat .spinner' ).removeClass( 'is-active' ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
419 |
$( '.ac_results' ).hide(); |
0 | 420 |
|
421 |
if (r) { |
|
5 | 422 |
if ( -1 !== r.indexOf( '<tr' ) ) { |
423 |
$(inlineEditPost.what+id).siblings('tr.hidden').addBack().remove(); |
|
0 | 424 |
$('#edit-'+id).before(r).remove(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
425 |
$( inlineEditPost.what + id ).hide().fadeIn( 400, function() { |
9 | 426 |
// Move focus back to the Quick Edit button. $( this ) is the row being animated. |
427 |
$( this ).find( '.editinline' ) |
|
428 |
.attr( 'aria-expanded', 'false' ) |
|
429 |
.focus(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
430 |
wp.a11y.speak( inlineEditL10n.saved ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
}); |
0 | 432 |
} else { |
433 |
r = r.replace( /<.[^<>]*?>/g, '' ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
$errorNotice.removeClass( 'hidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
435 |
$error.html( r ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
436 |
wp.a11y.speak( $error.text() ); |
0 | 437 |
} |
438 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
439 |
$errorNotice.removeClass( 'hidden' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
440 |
$error.html( inlineEditL10n.error ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
wp.a11y.speak( inlineEditL10n.error ); |
0 | 442 |
} |
5 | 443 |
}, |
444 |
'html'); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
445 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
446 |
// Prevent submitting the form when pressing Enter on a focused field. |
0 | 447 |
return false; |
448 |
}, |
|
449 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
450 |
/** |
9 | 451 |
* Hides and empties the Quick Edit and/or Bulk Edit windows. |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
452 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
453 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
454 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
455 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
456 |
* @returns {boolean} Always returns false. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
457 |
*/ |
0 | 458 |
revert : function(){ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
459 |
var $tableWideFat = $( '.widefat' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
460 |
id = $( '.inline-editor', $tableWideFat ).attr( 'id' ); |
0 | 461 |
|
462 |
if ( id ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
463 |
$( '.spinner', $tableWideFat ).removeClass( 'is-active' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
464 |
$( '.ac_results' ).hide(); |
0 | 465 |
|
5 | 466 |
if ( 'bulk-edit' === id ) { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
467 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
468 |
// Hide the bulk editor. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
469 |
$( '#bulk-edit', $tableWideFat ).removeClass( 'inline-editor' ).hide().siblings( '.hidden' ).remove(); |
5 | 470 |
$('#bulk-titles').empty(); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
471 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
472 |
// Store the empty bulk editor in a hidden element. |
0 | 473 |
$('#inlineedit').append( $('#bulk-edit') ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
474 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
475 |
// Move focus back to the Bulk Action button that was activated. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
476 |
$( '#' + inlineEditPost.whichBulkButtonId ).focus(); |
0 | 477 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
478 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
479 |
// Remove both the inline-editor and its hidden tr siblings. |
5 | 480 |
$('#'+id).siblings('tr.hidden').addBack().remove(); |
0 | 481 |
id = id.substr( id.lastIndexOf('-') + 1 ); |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
482 |
|
9 | 483 |
// Show the post row and move focus back to the Quick Edit button. |
484 |
$( this.what + id ).show().find( '.editinline' ) |
|
485 |
.attr( 'aria-expanded', 'false' ) |
|
486 |
.focus(); |
|
0 | 487 |
} |
488 |
} |
|
489 |
||
490 |
return false; |
|
491 |
}, |
|
492 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
/** |
9 | 494 |
* Gets the id for a the post that you want to quick edit from the row in the quick |
495 |
* edit table. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
496 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
497 |
* @memberof inlineEditPost |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
* @since 2.7.0 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
* @param {Object} o DOM row object to get the id for. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
* @returns {string} The post id extracted from the table row in the object. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
*/ |
0 | 503 |
getId : function(o) { |
504 |
var id = $(o).closest('tr').attr('id'), |
|
505 |
parts = id.split('-'); |
|
506 |
return parts[parts.length - 1]; |
|
507 |
} |
|
508 |
}; |
|
509 |
||
510 |
$( document ).ready( function(){ inlineEditPost.init(); } ); |
|
511 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
// Show/hide locks on posts. |
0 | 513 |
$( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) { |
514 |
var locked = data['wp-check-locked-posts'] || {}; |
|
515 |
||
516 |
$('#the-list tr').each( function(i, el) { |
|
517 |
var key = el.id, row = $(el), lock_data, avatar; |
|
518 |
||
519 |
if ( locked.hasOwnProperty( key ) ) { |
|
520 |
if ( ! row.hasClass('wp-locked') ) { |
|
521 |
lock_data = locked[key]; |
|
522 |
row.find('.column-title .locked-text').text( lock_data.text ); |
|
523 |
row.find('.check-column checkbox').prop('checked', false); |
|
524 |
||
525 |
if ( lock_data.avatar_src ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
526 |
avatar = $( '<img class="avatar avatar-18 photo" width="18" height="18" alt="" />' ).attr( 'src', lock_data.avatar_src.replace( /&/g, '&' ) ); |
0 | 527 |
row.find('.column-title .locked-avatar').empty().append( avatar ); |
528 |
} |
|
529 |
row.addClass('wp-locked'); |
|
530 |
} |
|
531 |
} else if ( row.hasClass('wp-locked') ) { |
|
532 |
// Make room for the CSS animation |
|
533 |
row.removeClass('wp-locked').delay(1000).find('.locked-info span').empty(); |
|
534 |
} |
|
535 |
}); |
|
536 |
}).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) { |
|
537 |
var check = []; |
|
538 |
||
539 |
$('#the-list tr').each( function(i, el) { |
|
5 | 540 |
if ( el.id ) { |
0 | 541 |
check.push( el.id ); |
5 | 542 |
} |
0 | 543 |
}); |
544 |
||
5 | 545 |
if ( check.length ) { |
0 | 546 |
data['wp-check-locked-posts'] = check; |
5 | 547 |
} |
548 |
}).ready( function() { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
549 |
|
5 | 550 |
// Set the heartbeat interval to 15 sec. |
551 |
if ( typeof wp !== 'undefined' && wp.heartbeat ) { |
|
552 |
wp.heartbeat.interval( 15 ); |
|
553 |
} |
|
0 | 554 |
}); |
555 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
556 |
})( jQuery, window.wp ); |