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 // get all editable rows
12 t.rows = $('tr.iedit');
14 // prepare the edit rows
15 qeRow.keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); });
16 bulkRow.keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); });
18 $('a.cancel', qeRow).click(function() { return inlineEditPost.revert(); });
19 $('a.save', qeRow).click(function() { return inlineEditPost.save(this); });
20 $('td', qeRow).keydown(function(e) { if ( e.which == 13 ) return inlineEditPost.save(this); });
22 $('a.cancel', bulkRow).click(function() { return inlineEditPost.revert(); });
24 $('#inline-edit .inline-edit-private input[value=private]').click( function(){
25 var pw = $('input.inline-edit-password-input');
26 if ( $(this).attr('checked') ) {
27 pw.val('').attr('disabled', 'disabled');
29 pw.attr('disabled', '');
36 $('#bulk-title-div').parents('fieldset').after(
37 $('#inline-edit fieldset.inline-edit-categories').clone()
38 ).siblings( 'fieldset:last' ).prepend(
39 $('#inline-edit label.inline-edit-tags').clone()
42 // categories expandable?
43 $('span.catshow').click(function() {
44 $('.inline-editor ul.cat-checklist').addClass("cat-hover");
45 $('.inline-editor span.cathide').show();
49 $('span.cathide').click(function() {
50 $('.inline-editor ul.cat-checklist').removeClass("cat-hover");
51 $('.inline-editor span.catshow').show();
55 $('select[name="_status"] option[value="future"]', bulkRow).remove();
57 $('#doaction, #doaction2').click(function(e){
58 var n = $(this).attr('id').substr(2);
59 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
62 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
67 $('#post-query-submit').click(function(e){
68 if ( $('form#posts-filter tr.inline-editor').length > 0 )
74 toggle : function(el) {
76 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
79 addEvents : function(r) {
82 $('a.editinline', row).click(function() { inlineEditPost.edit(this); return false; });
86 setBulk : function() {
87 var te = '', type = this.type, tax;
90 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
91 $('table.widefat tbody').prepend( $('#bulk-edit') );
92 $('#bulk-edit').addClass('inline-editor').show();
94 $('tbody th.check-column input[type="checkbox"]').each(function(i){
95 if ( $(this).attr('checked') ) {
96 var id = $(this).val(), theTitle;
97 theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
98 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
102 $('#bulk-titles').html(te);
103 $('#bulk-titles a').click(function() {
104 var id = $(this).attr('id').substr(1);
106 $('table.widefat input[value="'+id+'"]').attr('checked', '');
107 $('#ttle'+id).remove();
110 // enable autocomplete for tags
111 if ( type == 'post' ) {
112 // support multi taxonomies?
114 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
118 edit : function(id) {
119 var t = this, fields, editRow, rowData, cats, status, pageOpt, f, pageLevel, nextPage, pageLoop = true, nextLevel, tax;
122 if ( typeof(id) == 'object' )
125 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password'];
126 if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template');
127 if ( t.type == 'post' ) fields.push('tags_input');
129 // add the new blank row
130 editRow = $('#inline-edit').clone(true);
131 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
133 if ( $(t.what+id).hasClass('alternate') )
134 $(editRow).addClass('alternate');
135 $(t.what+id).hide().after(editRow);
138 rowData = $('#inline_'+id);
139 for ( f = 0; f < fields.length; f++ ) {
140 $(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() );
143 if ( $('.comment_status', rowData).text() == 'open' )
144 $('input[name="comment_status"]', editRow).attr("checked", "checked");
145 if ( $('.ping_status', rowData).text() == 'open' )
146 $('input[name="ping_status"]', editRow).attr("checked", "checked");
147 if ( $('.sticky', rowData).text() == 'sticky' )
148 $('input[name="sticky"]', editRow).attr("checked", "checked");
151 if ( cats = $('.post_category', rowData).text() )
152 $('ul.cat-checklist :checkbox', editRow).val(cats.split(','));
154 // handle the post status
155 status = $('._status', rowData).text();
156 if ( status != 'future' ) $('select[name="_status"] option[value="future"]', editRow).remove();
157 if ( status == 'private' ) {
158 $('input[name="keep_private"]', editRow).attr("checked", "checked");
159 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled');
162 // remove the current page and children from the parent dropdown
163 pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow);
164 if ( pageOpt.length > 0 ) {
165 pageLevel = pageOpt[0].className.split('-')[1];
168 nextPage = nextPage.next('option');
169 if (nextPage.length == 0) break;
170 nextLevel = nextPage[0].className.split('-')[1];
171 if ( nextLevel <= pageLevel ) {
181 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
182 $('.ptitle', editRow).focus();
184 // enable autocomplete for tags
185 if ( t.type == 'post' ) {
187 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
193 save : function(id) {
196 if( typeof(id) == 'object' )
199 $('table.widefat .inline-edit-save .waiting').show();
202 action: 'inline-save',
203 post_type: this.type,
208 fields = $('#edit-'+id+' :input').fieldSerialize();
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();
221 var row = $(inlineEditPost.what+id);
224 if ( 'draft' == $('input[name="post_status"]').val() )
225 row.find('td.column-comments').hide();
227 inlineEditPost.addEvents(row);
230 r = r.replace( /<.[^<>]*?>/g, '' );
231 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
234 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
241 revert : function() {
244 if ( id = $('table.widefat tr.inline-editor').attr('id') ) {
245 $('table.widefat .inline-edit-save .waiting').hide();
247 if ( 'bulk-edit' == id ) {
248 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
249 $('#bulk-titles').html('');
250 $('#inlineedit').append( $('#bulk-edit') );
253 id = id.substr( id.lastIndexOf('-') + 1 );
254 $(this.what+id).show();
261 getId : function(o) {
262 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-');
263 return parts[parts.length - 1];
267 $(document).ready(function(){inlineEditPost.init();});