6 var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
8 t.type = $('table.widefat').hasClass('page') ? 'page' : 'post';
9 t.what = '#'+t.type+'-';
11 // prepare the edit rows
12 qeRow.keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); });
13 bulkRow.keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); });
15 $('a.cancel', qeRow).click(function() { return inlineEditPost.revert(); });
16 $('a.save', qeRow).click(function() { return inlineEditPost.save(this); });
17 $('td', qeRow).keydown(function(e) { if ( e.which == 13 ) return inlineEditPost.save(this); });
19 $('a.cancel', bulkRow).click(function() { return inlineEditPost.revert(); });
21 $('#inline-edit .inline-edit-private input[value=private]').click( function(){
22 var pw = $('input.inline-edit-password-input');
23 if ( $(this).attr('checked') ) {
24 pw.val('').attr('disabled', 'disabled');
26 pw.attr('disabled', '');
31 $('a.editinline').live('click', function() { inlineEditPost.edit(this); return false; });
33 $('#bulk-title-div').parents('fieldset').after(
34 $('#inline-edit fieldset.inline-edit-categories').clone()
35 ).siblings( 'fieldset:last' ).prepend(
36 $('#inline-edit label.inline-edit-tags').clone()
39 // categories expandable?
40 $('span.catshow').click(function() {
41 $('.inline-editor ul.cat-checklist').addClass("cat-hover");
42 $('.inline-editor span.cathide').show();
46 $('span.cathide').click(function() {
47 $('.inline-editor ul.cat-checklist').removeClass("cat-hover");
48 $('.inline-editor span.catshow').show();
52 $('select[name="_status"] option[value="future"]', bulkRow).remove();
54 $('#doaction, #doaction2').click(function(e){
55 var n = $(this).attr('id').substr(2);
56 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
59 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
64 $('#post-query-submit').click(function(e){
65 if ( $('form#posts-filter tr.inline-editor').length > 0 )
71 toggle : function(el) {
73 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
76 setBulk : function() {
77 var te = '', type = this.type, tax, c = true;
80 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
81 $('table.widefat tbody').prepend( $('#bulk-edit') );
82 $('#bulk-edit').addClass('inline-editor').show();
84 $('tbody th.check-column input[type="checkbox"]').each(function(i){
85 if ( $(this).attr('checked') ) {
87 var id = $(this).val(), theTitle;
88 theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
89 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
96 $('#bulk-titles').html(te);
97 $('#bulk-titles a').click(function() {
98 var id = $(this).attr('id').substr(1);
100 $('table.widefat input[value="'+id+'"]').attr('checked', '');
101 $('#ttle'+id).remove();
104 // enable autocomplete for tags
105 if ( type == 'post' ) {
106 // support multi taxonomies?
108 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
112 edit : function(id) {
113 var t = this, fields, editRow, rowData, cats, status, pageOpt, f, pageLevel, nextPage, pageLoop = true, nextLevel, tax;
116 if ( typeof(id) == 'object' )
119 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password'];
120 if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template');
121 if ( t.type == 'post' ) fields.push('tags_input');
123 // add the new blank row
124 editRow = $('#inline-edit').clone(true);
125 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
127 if ( $(t.what+id).hasClass('alternate') )
128 $(editRow).addClass('alternate');
129 $(t.what+id).hide().after(editRow);
132 rowData = $('#inline_'+id);
133 if ( !$(':input[name="post_author"] option[value=' + $('.post_author', rowData).text() + ']', editRow).val() ) {
134 // author no longer has edit caps, so we need to add them to the list of authors
135 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
138 for ( f = 0; f < fields.length; f++ ) {
139 $(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() );
142 if ( $('.comment_status', rowData).text() == 'open' )
143 $('input[name="comment_status"]', editRow).attr("checked", "checked");
144 if ( $('.ping_status', rowData).text() == 'open' )
145 $('input[name="ping_status"]', editRow).attr("checked", "checked");
146 if ( $('.sticky', rowData).text() == 'sticky' )
147 $('input[name="sticky"]', editRow).attr("checked", "checked");
150 if ( cats = $('.post_category', rowData).text() )
151 $('ul.cat-checklist :checkbox', editRow).val(cats.split(','));
153 // handle the post status
154 status = $('._status', rowData).text();
155 if ( status != 'future' ) $('select[name="_status"] option[value="future"]', editRow).remove();
156 if ( status == 'private' ) {
157 $('input[name="keep_private"]', editRow).attr("checked", "checked");
158 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled');
161 // remove the current page and children from the parent dropdown
162 pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow);
163 if ( pageOpt.length > 0 ) {
164 pageLevel = pageOpt[0].className.split('-')[1];
167 nextPage = nextPage.next('option');
168 if (nextPage.length == 0) break;
169 nextLevel = nextPage[0].className.split('-')[1];
170 if ( nextLevel <= pageLevel ) {
180 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
181 $('.ptitle', editRow).focus();
183 // enable autocomplete for tags
184 if ( t.type == 'post' ) {
186 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
192 save : function(id) {
193 var params, fields, page = $('.post_status_page').val() || '';
195 if( typeof(id) == 'object' )
198 $('table.widefat .inline-edit-save .waiting').show();
201 action: 'inline-save',
202 post_type: this.type,
208 fields = $('#edit-'+id+' :input').serialize();
209 params = fields + '&' + $.param(params);
212 $.post('admin-ajax.php', params,
214 $('table.widefat .inline-edit-save .waiting').hide();
217 if ( -1 != r.indexOf('<tr') ) {
218 $(inlineEditPost.what+id).remove();
219 $('#edit-'+id).before(r).remove();
220 $(inlineEditPost.what+id).hide().fadeIn();
222 r = r.replace( /<.[^<>]*?>/g, '' );
223 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
226 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
233 revert : function() {
236 if ( id = $('table.widefat tr.inline-editor').attr('id') ) {
237 $('table.widefat .inline-edit-save .waiting').hide();
239 if ( 'bulk-edit' == id ) {
240 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
241 $('#bulk-titles').html('');
242 $('#inlineedit').append( $('#bulk-edit') );
245 id = id.substr( id.lastIndexOf('-') + 1 );
246 $(this.what+id).show();
253 getId : function(o) {
254 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
255 return parts[parts.length - 1];
259 $(document).ready(function(){inlineEditPost.init();});