1
/* global inlineEditL10n, ajaxurl, typenow */
8
var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
10
t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post';
13
// prepare the edit rows
14
qeRow.keyup(function(e){
15
if ( e.which === 27 ) {
16
return inlineEditPost.revert();
19
bulkRow.keyup(function(e){
20
if ( e.which === 27 ) {
21
return inlineEditPost.revert();
25
$('a.cancel', qeRow).click(function(){
26
return inlineEditPost.revert();
28
$('a.save', qeRow).click(function(){
29
return inlineEditPost.save(this);
31
$('td', qeRow).keydown(function(e){
32
if ( e.which === 13 ) {
33
return inlineEditPost.save(this);
37
$('a.cancel', bulkRow).click(function(){
38
return inlineEditPost.revert();
41
$('#inline-edit .inline-edit-private input[value="private"]').click( function(){
42
var pw = $('input.inline-edit-password-input');
43
if ( $(this).prop('checked') ) {
44
pw.val('').prop('disabled', true);
46
pw.prop('disabled', false);
51
$('#the-list').on('click', 'a.editinline', function(){
52
inlineEditPost.edit(this);
56
$('#bulk-edit').find('fieldset:first').after(
57
$('#inline-edit fieldset.inline-edit-categories').clone()
58
).siblings( 'fieldset:last' ).prepend(
59
$('#inline-edit label.inline-edit-tags').clone()
62
$('select[name="_status"] option[value="future"]', bulkRow).remove();
64
$('#doaction, #doaction2').click(function(e){
65
var n = $(this).attr('id').substr(2);
66
if ( 'edit' === $( 'select[name="' + n + '"]' ).val() ) {
69
} else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
75
toggle : function(el){
77
$( t.what + t.getId( el ) ).css( 'display' ) === 'none' ? t.revert() : t.edit( el );
81
var te = '', type = this.type, tax, c = true;
84
$('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
85
$('table.widefat tbody').prepend( $('#bulk-edit') );
86
$('#bulk-edit').addClass('inline-editor').show();
88
$( 'tbody th.check-column input[type="checkbox"]' ).each( function() {
89
if ( $(this).prop('checked') ) {
91
var id = $(this).val(), theTitle;
92
theTitle = $('#inline_'+id+' .post_title').html() || inlineEditL10n.notitle;
93
te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
101
$('#bulk-titles').html(te);
102
$('#bulk-titles a').click(function(){
103
var id = $(this).attr('id').substr(1);
105
$('table.widefat input[value="' + id + '"]').prop('checked', false);
106
$('#ttle'+id).remove();
109
// enable autocomplete for tags
110
if ( 'post' === type ) {
111
// support multi taxonomies?
113
$('tr.inline-editor textarea[name="tax_input['+tax+']"]').suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } );
115
$('html, body').animate( { scrollTop: 0 }, 'fast' );
118
edit : function(id) {
119
var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f;
122
if ( typeof(id) === 'object' ) {
126
fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order'];
127
if ( t.type === 'page' ) {
128
fields.push('post_parent', 'page_template');
131
// add the new blank row
132
editRow = $('#inline-edit').clone(true);
133
$('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
135
if ( $( t.what + id ).hasClass( 'alternate' ) ) {
136
$(editRow).addClass('alternate');
138
$(t.what+id).hide().after(editRow);
141
rowData = $('#inline_'+id);
142
if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
143
// author no longer has edit caps, so we need to add them to the list of authors
144
$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
146
if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) {
147
$('label.inline-edit-author', editRow).hide();
150
// hide unsupported formats, but leave the current format alone
151
cur_format = $('.post_format', rowData).text();
152
$('option.unsupported', editRow).each(function() {
154
if ( $this.val() !== cur_format ) {
159
for ( f = 0; f < fields.length; f++ ) {
160
$(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() );
163
if ( $( '.comment_status', rowData ).text() === 'open' ) {
164
$( 'input[name="comment_status"]', editRow ).prop( 'checked', true );
166
if ( $( '.ping_status', rowData ).text() === 'open' ) {
167
$( 'input[name="ping_status"]', editRow ).prop( 'checked', true );
169
if ( $( '.sticky', rowData ).text() === 'sticky' ) {
170
$( 'input[name="sticky"]', editRow ).prop( 'checked', true );
173
// hierarchical taxonomies
174
$('.post_category', rowData).each(function(){
176
term_ids = $(this).text();
179
taxname = $(this).attr('id').replace('_'+id, '');
180
$('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
185
$('.tags_input', rowData).each(function(){
186
var terms = $(this).text(),
187
taxname = $(this).attr('id').replace('_' + id, ''),
188
textarea = $('textarea.tax_input_' + taxname, editRow),
189
comma = inlineEditL10n.comma;
192
if ( ',' !== comma ) {
193
terms = terms.replace(/,/g, comma);
198
textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma } );
201
// handle the post status
202
status = $('._status', rowData).text();
203
if ( 'future' !== status ) {
204
$('select[name="_status"] option[value="future"]', editRow).remove();
207
if ( 'private' === status ) {
208
$('input[name="keep_private"]', editRow).prop('checked', true);
209
$('input.inline-edit-password-input').val('').prop('disabled', true);
212
// remove the current page and children from the parent dropdown
213
pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow);
214
if ( pageOpt.length > 0 ) {
215
pageLevel = pageOpt[0].className.split('-')[1];
218
nextPage = nextPage.next('option');
219
if ( nextPage.length === 0 ) {
223
nextLevel = nextPage[0].className.split('-')[1];
225
if ( nextLevel <= pageLevel ) {
235
$(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
236
$('.ptitle', editRow).focus();
241
save : function(id) {
242
var params, fields, page = $('.post_status_page').val() || '';
244
if ( typeof(id) === 'object' ) {
248
$('table.widefat .spinner').show();
251
action: 'inline-save',
258
fields = $('#edit-'+id).find(':input').serialize();
259
params = fields + '&' + $.param(params);
262
$.post( ajaxurl, params,
264
$('table.widefat .spinner').hide();
267
if ( -1 !== r.indexOf( '<tr' ) ) {
268
$(inlineEditPost.what+id).remove();
269
$('#edit-'+id).before(r).remove();
270
$(inlineEditPost.what+id).hide().fadeIn();
272
r = r.replace( /<.[^<>]*?>/g, '' );
273
$('#edit-'+id+' .inline-edit-save .error').html(r).show();
276
$('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
279
if ( $('#post-'+id).prev().hasClass('alternate') ) {
280
$('#post-'+id).removeClass('alternate');
288
var id = $('table.widefat tr.inline-editor').attr('id');
291
$('table.widefat .spinner').hide();
293
if ( 'bulk-edit' === id ) {
294
$('table.widefat #bulk-edit').removeClass('inline-editor').hide();
295
$('#bulk-titles').html('');
296
$('#inlineedit').append( $('#bulk-edit') );
299
id = id.substr( id.lastIndexOf('-') + 1 );
300
$(this.what+id).show();
307
getId : function(o) {
308
var id = $(o).closest('tr').attr('id'),
309
parts = id.split('-');
310
return parts[parts.length - 1];
314
$( document ).ready( function(){ inlineEditPost.init(); } );
316
// Show/hide locks on posts
317
$( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
318
var locked = data['wp-check-locked-posts'] || {};
320
$('#the-list tr').each( function(i, el) {
321
var key = el.id, row = $(el), lock_data, avatar;
323
if ( locked.hasOwnProperty( key ) ) {
324
if ( ! row.hasClass('wp-locked') ) {
325
lock_data = locked[key];
326
row.find('.column-title .locked-text').text( lock_data.text );
327
row.find('.check-column checkbox').prop('checked', false);
329
if ( lock_data.avatar_src ) {
330
avatar = $('<img class="avatar avatar-18 photo" width="18" height="18" />').attr( 'src', lock_data.avatar_src.replace(/&/g, '&') );
331
row.find('.column-title .locked-avatar').empty().append( avatar );
333
row.addClass('wp-locked');
335
} else if ( row.hasClass('wp-locked') ) {
336
// Make room for the CSS animation
337
row.removeClass('wp-locked').delay(1000).find('.locked-info span').empty();
340
}).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) {
343
$('#the-list tr').each( function(i, el) {
349
if ( check.length ) {
350
data['wp-check-locked-posts'] = check;
352
}).ready( function() {
353
// Set the heartbeat interval to 15 sec.
354
if ( typeof wp !== 'undefined' && wp.heartbeat ) {
355
wp.heartbeat.interval( 15 );