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 $('a.editinline').live('click', 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 // hiearchical taxonomies expandable?
57 $('span.catshow').click(function(){
58 $(this).hide().next().show().parent().next().addClass("cat-hover");
61 $('span.cathide').click(function(){
62 $(this).hide().prev().show().parent().next().removeClass("cat-hover");
65 $('select[name="_status"] option[value="future"]', bulkRow).remove();
67 $('#doaction, #doaction2').click(function(e){
68 var n = $(this).attr('id').substr(2);
69 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
72 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
77 $('#post-query-submit').mousedown(function(e){
79 $('select[name^="action"]').val('-1');
83 toggle : function(el){
85 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
89 var te = '', type = this.type, tax, c = true;
92 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
93 $('table.widefat tbody').prepend( $('#bulk-edit') );
94 $('#bulk-edit').addClass('inline-editor').show();
96 $('tbody th.check-column input[type="checkbox"]').each(function(i){
97 if ( $(this).prop('checked') ) {
99 var id = $(this).val(), theTitle;
100 theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
101 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
106 return this.revert();
108 $('#bulk-titles').html(te);
109 $('#bulk-titles a').click(function(){
110 var id = $(this).attr('id').substr(1);
112 $('table.widefat input[value="' + id + '"]').prop('checked', false);
113 $('#ttle'+id).remove();
116 // enable autocomplete for tags
117 if ( 'post' == type ) {
118 // support multi taxonomies?
120 $('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 + ' ' } );
122 $('html, body').animate( { scrollTop: 0 }, 'fast' );
125 edit : function(id) {
126 var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f;
129 if ( typeof(id) == 'object' )
132 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order'];
133 if ( t.type == 'page' )
134 fields.push('post_parent', 'page_template');
136 // add the new blank row
137 editRow = $('#inline-edit').clone(true);
138 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
140 if ( $(t.what+id).hasClass('alternate') )
141 $(editRow).addClass('alternate');
142 $(t.what+id).hide().after(editRow);
145 rowData = $('#inline_'+id);
146 if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
147 // author no longer has edit caps, so we need to add them to the list of authors
148 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
150 if ( $(':input[name="post_author"] option', editRow).length == 1 ) {
151 $('label.inline-edit-author', editRow).hide();
154 // hide unsupported formats, but leave the current format alone
155 cur_format = $('.post_format', rowData).text();
156 $('option.unsupported', editRow).each(function() {
158 if ( $this.val() != cur_format )
162 for ( f = 0; f < fields.length; f++ ) {
163 $(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() );
166 if ( $('.comment_status', rowData).text() == 'open' )
167 $('input[name="comment_status"]', editRow).prop("checked", true);
168 if ( $('.ping_status', rowData).text() == 'open' )
169 $('input[name="ping_status"]', editRow).prop("checked", true);
170 if ( $('.sticky', rowData).text() == 'sticky' )
171 $('input[name="sticky"]', editRow).prop("checked", true);
173 // hierarchical taxonomies
174 $('.post_category', rowData).each(function(){
175 var term_ids = $(this).text();
178 taxname = $(this).attr('id').replace('_'+id, '');
179 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(','));
184 $('.tags_input', rowData).each(function(){
185 var terms = $(this).text(),
186 taxname = $(this).attr('id').replace('_' + id, ''),
187 textarea = $('textarea.tax_input_' + taxname, editRow),
188 comma = inlineEditL10n.comma;
192 terms = terms.replace(/,/g, comma);
196 textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } );
199 // handle the post status
200 status = $('._status', rowData).text();
201 if ( 'future' != status )
202 $('select[name="_status"] option[value="future"]', editRow).remove();
204 if ( 'private' == status ) {
205 $('input[name="keep_private"]', editRow).prop("checked", true);
206 $('input.inline-edit-password-input').val('').prop('disabled', true);
209 // remove the current page and children from the parent dropdown
210 pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow);
211 if ( pageOpt.length > 0 ) {
212 pageLevel = pageOpt[0].className.split('-')[1];
215 nextPage = nextPage.next('option');
216 if (nextPage.length == 0) break;
217 nextLevel = nextPage[0].className.split('-')[1];
218 if ( nextLevel <= pageLevel ) {
228 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
229 $('.ptitle', editRow).focus();
234 save : function(id) {
235 var params, fields, page = $('.post_status_page').val() || '';
237 if ( typeof(id) == 'object' )
240 $('table.widefat .inline-edit-save .waiting').show();
243 action: 'inline-save',
250 fields = $('#edit-'+id+' :input').serialize();
251 params = fields + '&' + $.param(params);
254 $.post( ajaxurl, params,
256 $('table.widefat .inline-edit-save .waiting').hide();
259 if ( -1 != r.indexOf('<tr') ) {
260 $(inlineEditPost.what+id).remove();
261 $('#edit-'+id).before(r).remove();
262 $(inlineEditPost.what+id).hide().fadeIn();
264 r = r.replace( /<.[^<>]*?>/g, '' );
265 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
268 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
276 var id = $('table.widefat tr.inline-editor').attr('id');
279 $('table.widefat .inline-edit-save .waiting').hide();
281 if ( 'bulk-edit' == id ) {
282 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
283 $('#bulk-titles').html('');
284 $('#inlineedit').append( $('#bulk-edit') );
287 id = id.substr( id.lastIndexOf('-') + 1 );
288 $(this.what+id).show();
295 getId : function(o) {
296 var id = $(o).closest('tr').attr('id'),
297 parts = id.split('-');
298 return parts[parts.length - 1];
302 $(document).ready(function(){inlineEditPost.init();});