5 var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
7 t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post';
10 // prepare the edit rows
11 qeRow.keyup(function(e){
13 return inlineEditPost.revert();
15 bulkRow.keyup(function(e){
17 return inlineEditPost.revert();
20 $('a.cancel', qeRow).click(function(){
21 return inlineEditPost.revert();
23 $('a.save', qeRow).click(function(){
24 return inlineEditPost.save(this);
26 $('td', qeRow).keydown(function(e){
28 return inlineEditPost.save(this);
31 $('a.cancel', bulkRow).click(function(){
32 return inlineEditPost.revert();
35 $('#inline-edit .inline-edit-private input[value="private"]').click( function(){
36 var pw = $('input.inline-edit-password-input');
37 if ( $(this).prop('checked') ) {
38 pw.val('').prop('disabled', true);
40 pw.prop('disabled', false);
45 $('#the-list').on('click', 'a.editinline', function(){
46 inlineEditPost.edit(this);
50 $('#bulk-title-div').parents('fieldset').after(
51 $('#inline-edit fieldset.inline-edit-categories').clone()
52 ).siblings( 'fieldset:last' ).prepend(
53 $('#inline-edit label.inline-edit-tags').clone()
56 $('select[name="_status"] option[value="future"]', bulkRow).remove();
58 $('#doaction, #doaction2').click(function(e){
59 var n = $(this).attr('id').substr(2);
60 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
63 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
69 toggle : function(el){
71 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
75 var te = '', type = this.type, tax, c = true;
78 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
79 $('table.widefat tbody').prepend( $('#bulk-edit') );
80 $('#bulk-edit').addClass('inline-editor').show();
82 $('tbody th.check-column input[type="checkbox"]').each(function(i){
83 if ( $(this).prop('checked') ) {
85 var id = $(this).val(), theTitle;
86 theTitle = $('#inline_'+id+' .post_title').html() || inlineEditL10n.notitle;
87 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
94 $('#bulk-titles').html(te);
95 $('#bulk-titles a').click(function(){
96 var id = $(this).attr('id').substr(1);
98 $('table.widefat input[value="' + id + '"]').prop('checked', false);
99 $('#ttle'+id).remove();
102 // enable autocomplete for tags
103 if ( 'post' == type ) {
104 // support multi taxonomies?
106 $('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 + ' ' } );
108 $('html, body').animate( { scrollTop: 0 }, 'fast' );
111 edit : function(id) {
112 var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f;
115 if ( typeof(id) == 'object' )
118 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order'];
119 if ( t.type == 'page' )
120 fields.push('post_parent', 'page_template');
122 // add the new blank row
123 editRow = $('#inline-edit').clone(true);
124 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
126 if ( $(t.what+id).hasClass('alternate') )
127 $(editRow).addClass('alternate');
128 $(t.what+id).hide().after(editRow);
131 rowData = $('#inline_'+id);
132 if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
133 // author no longer has edit caps, so we need to add them to the list of authors
134 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
136 if ( $(':input[name="post_author"] option', editRow).length == 1 ) {
137 $('label.inline-edit-author', editRow).hide();
140 // hide unsupported formats, but leave the current format alone
141 cur_format = $('.post_format', rowData).text();
142 $('option.unsupported', editRow).each(function() {
144 if ( $this.val() != cur_format )
148 for ( f = 0; f < fields.length; f++ ) {
149 $(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() );
152 if ( $('.comment_status', rowData).text() == 'open' )
153 $('input[name="comment_status"]', editRow).prop("checked", true);
154 if ( $('.ping_status', rowData).text() == 'open' )
155 $('input[name="ping_status"]', editRow).prop("checked", true);
156 if ( $('.sticky', rowData).text() == 'sticky' )
157 $('input[name="sticky"]', editRow).prop("checked", true);
159 // hierarchical taxonomies
160 $('.post_category', rowData).each(function(){
161 var term_ids = $(this).text();
164 taxname = $(this).attr('id').replace('_'+id, '');
165 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
170 $('.tags_input', rowData).each(function(){
171 var terms = $(this).text(),
172 taxname = $(this).attr('id').replace('_' + id, ''),
173 textarea = $('textarea.tax_input_' + taxname, editRow),
174 comma = inlineEditL10n.comma;
178 terms = terms.replace(/,/g, comma);
182 textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } );
185 // handle the post status
186 status = $('._status', rowData).text();
187 if ( 'future' != status )
188 $('select[name="_status"] option[value="future"]', editRow).remove();
190 if ( 'private' == status ) {
191 $('input[name="keep_private"]', editRow).prop("checked", true);
192 $('input.inline-edit-password-input').val('').prop('disabled', true);
195 // remove the current page and children from the parent dropdown
196 pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow);
197 if ( pageOpt.length > 0 ) {
198 pageLevel = pageOpt[0].className.split('-')[1];
201 nextPage = nextPage.next('option');
202 if (nextPage.length == 0) break;
203 nextLevel = nextPage[0].className.split('-')[1];
204 if ( nextLevel <= pageLevel ) {
214 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
215 $('.ptitle', editRow).focus();
220 save : function(id) {
221 var params, fields, page = $('.post_status_page').val() || '';
223 if ( typeof(id) == 'object' )
226 $('table.widefat .spinner').show();
229 action: 'inline-save',
236 fields = $('#edit-'+id+' :input').serialize();
237 params = fields + '&' + $.param(params);
240 $.post( ajaxurl, params,
242 $('table.widefat .spinner').hide();
245 if ( -1 != r.indexOf('<tr') ) {
246 $(inlineEditPost.what+id).remove();
247 $('#edit-'+id).before(r).remove();
248 $(inlineEditPost.what+id).hide().fadeIn();
250 r = r.replace( /<.[^<>]*?>/g, '' );
251 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
254 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
257 if ( $('#post-'+id).prev().hasClass('alternate') ) {
258 $('#post-'+id).removeClass('alternate');
266 var id = $('table.widefat tr.inline-editor').attr('id');
269 $('table.widefat .spinner').hide();
271 if ( 'bulk-edit' == id ) {
272 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
273 $('#bulk-titles').html('');
274 $('#inlineedit').append( $('#bulk-edit') );
277 id = id.substr( id.lastIndexOf('-') + 1 );
278 $(this.what+id).show();
285 getId : function(o) {
286 var id = $(o).closest('tr').attr('id'),
287 parts = id.split('-');
288 return parts[parts.length - 1];
292 $( document ).ready( function(){ inlineEditPost.init(); } );
294 // Show/hide locks on posts
295 $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
296 var locked = data['wp-check-locked-posts'] || {};
298 $('#the-list tr').each( function(i, el) {
299 var key = el.id, row = $(el), lock_data, avatar;
301 if ( locked.hasOwnProperty( key ) ) {
302 if ( ! row.hasClass('wp-locked') ) {
303 lock_data = locked[key];
304 row.find('.column-title .locked-text').text( lock_data.text );
305 row.find('.check-column checkbox').prop('checked', false);
307 if ( lock_data.avatar_src ) {
308 avatar = $('<img class="avatar avatar-18 photo" width="18" height="18" />').attr( 'src', lock_data.avatar_src.replace(/&/g, '&') );
309 row.find('.column-title .locked-avatar').empty().append( avatar );
311 row.addClass('wp-locked');
313 } else if ( row.hasClass('wp-locked') ) {
314 // Make room for the CSS animation
315 row.removeClass('wp-locked').delay(1000).find('.locked-info span').empty();
318 }).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) {
321 $('#the-list tr').each( function(i, el) {
327 data['wp-check-locked-posts'] = check;