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 ) {
68 $('#post-query-submit').mousedown(function(e){
70 $('select[name^="action"]').val('-1');
74 toggle : function(el){
76 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
80 var te = '', type = this.type, tax, c = true;
83 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
84 $('table.widefat tbody').prepend( $('#bulk-edit') );
85 $('#bulk-edit').addClass('inline-editor').show();
87 $('tbody th.check-column input[type="checkbox"]').each(function(i){
88 if ( $(this).prop('checked') ) {
90 var id = $(this).val(), theTitle;
91 theTitle = $('#inline_'+id+' .post_title').html() || inlineEditL10n.notitle;
92 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
99 $('#bulk-titles').html(te);
100 $('#bulk-titles a').click(function(){
101 var id = $(this).attr('id').substr(1);
103 $('table.widefat input[value="' + id + '"]').prop('checked', false);
104 $('#ttle'+id).remove();
107 // enable autocomplete for tags
108 if ( 'post' == type ) {
109 // support multi taxonomies?
111 $('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 + ' ' } );
113 $('html, body').animate( { scrollTop: 0 }, 'fast' );
116 edit : function(id) {
117 var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f;
120 if ( typeof(id) == 'object' )
123 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order'];
124 if ( t.type == 'page' )
125 fields.push('post_parent', 'page_template');
127 // add the new blank row
128 editRow = $('#inline-edit').clone(true);
129 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
131 if ( $(t.what+id).hasClass('alternate') )
132 $(editRow).addClass('alternate');
133 $(t.what+id).hide().after(editRow);
136 rowData = $('#inline_'+id);
137 if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
138 // author no longer has edit caps, so we need to add them to the list of authors
139 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
141 if ( $(':input[name="post_author"] option', editRow).length == 1 ) {
142 $('label.inline-edit-author', editRow).hide();
145 // hide unsupported formats, but leave the current format alone
146 cur_format = $('.post_format', rowData).text();
147 $('option.unsupported', editRow).each(function() {
149 if ( $this.val() != cur_format )
153 for ( f = 0; f < fields.length; f++ ) {
154 $(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() );
157 if ( $('.comment_status', rowData).text() == 'open' )
158 $('input[name="comment_status"]', editRow).prop("checked", true);
159 if ( $('.ping_status', rowData).text() == 'open' )
160 $('input[name="ping_status"]', editRow).prop("checked", true);
161 if ( $('.sticky', rowData).text() == 'sticky' )
162 $('input[name="sticky"]', editRow).prop("checked", true);
164 // hierarchical taxonomies
165 $('.post_category', rowData).each(function(){
166 var term_ids = $(this).text();
169 taxname = $(this).attr('id').replace('_'+id, '');
170 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
175 $('.tags_input', rowData).each(function(){
176 var terms = $(this).text(),
177 taxname = $(this).attr('id').replace('_' + id, ''),
178 textarea = $('textarea.tax_input_' + taxname, editRow),
179 comma = inlineEditL10n.comma;
183 terms = terms.replace(/,/g, comma);
187 textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } );
190 // handle the post status
191 status = $('._status', rowData).text();
192 if ( 'future' != status )
193 $('select[name="_status"] option[value="future"]', editRow).remove();
195 if ( 'private' == status ) {
196 $('input[name="keep_private"]', editRow).prop("checked", true);
197 $('input.inline-edit-password-input').val('').prop('disabled', true);
200 // remove the current page and children from the parent dropdown
201 pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow);
202 if ( pageOpt.length > 0 ) {
203 pageLevel = pageOpt[0].className.split('-')[1];
206 nextPage = nextPage.next('option');
207 if (nextPage.length == 0) break;
208 nextLevel = nextPage[0].className.split('-')[1];
209 if ( nextLevel <= pageLevel ) {
219 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
220 $('.ptitle', editRow).focus();
225 save : function(id) {
226 var params, fields, page = $('.post_status_page').val() || '';
228 if ( typeof(id) == 'object' )
231 $('table.widefat .spinner').show();
234 action: 'inline-save',
241 fields = $('#edit-'+id+' :input').serialize();
242 params = fields + '&' + $.param(params);
245 $.post( ajaxurl, params,
247 $('table.widefat .spinner').hide();
250 if ( -1 != r.indexOf('<tr') ) {
251 $(inlineEditPost.what+id).remove();
252 $('#edit-'+id).before(r).remove();
253 $(inlineEditPost.what+id).hide().fadeIn();
255 r = r.replace( /<.[^<>]*?>/g, '' );
256 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
259 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
267 var id = $('table.widefat tr.inline-editor').attr('id');
270 $('table.widefat .spinner').hide();
272 if ( 'bulk-edit' == id ) {
273 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
274 $('#bulk-titles').html('');
275 $('#inlineedit').append( $('#bulk-edit') );
278 id = id.substr( id.lastIndexOf('-') + 1 );
279 $(this.what+id).show();
286 getId : function(o) {
287 var id = $(o).closest('tr').attr('id'),
288 parts = id.split('-');
289 return parts[parts.length - 1];
293 $( document ).ready( function(){ inlineEditPost.init(); } );
295 // Show/hide locks on posts
296 $( document ).on( 'heartbeat-tick.wp-check-locked-posts', function( e, data ) {
297 var locked = data['wp-check-locked-posts'] || {};
299 $('#the-list tr').each( function(i, el) {
300 var key = el.id, row = $(el), lock_data, avatar;
302 if ( locked.hasOwnProperty( key ) ) {
303 if ( ! row.hasClass('wp-locked') ) {
304 lock_data = locked[key];
305 row.find('.column-title .locked-text').text( lock_data.text );
306 row.find('.check-column checkbox').prop('checked', false);
308 if ( lock_data.avatar_src ) {
309 avatar = $('<img class="avatar avatar-18 photo" width="18" height="18" />').attr( 'src', lock_data.avatar_src.replace(/&/g, '&') );
310 row.find('.column-title .locked-avatar').empty().append( avatar );
312 row.addClass('wp-locked');
314 } else if ( row.hasClass('wp-locked') ) {
315 // Make room for the CSS animation
316 row.removeClass('wp-locked').delay(1000).find('.locked-info span').empty();
319 }).on( 'heartbeat-send.wp-check-locked-posts', function( e, data ) {
322 $('#the-list tr').each( function(i, el) {
328 data['wp-check-locked-posts'] = check;