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 $('input, select', 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 // ).siblings( 'fieldset:last' ).after( '<fieldset class="inline-edit-col-bottom"><div class="inline-edit-col"></div></fieldset>' );
40 // $('fieldset.inline-edit-col-bottom').prepend(
41 $('#inline-edit label.inline-edit-tags').clone()
44 // categories expandable?
45 $('span.catshow').click(function() {
46 $('.inline-editor ul.cat-checklist').addClass("cat-hover");
47 $('.inline-editor span.cathide').show();
51 $('span.cathide').click(function() {
52 $('.inline-editor ul.cat-checklist').removeClass("cat-hover");
53 $('.inline-editor span.catshow').show();
57 $('select[name="_status"] option[value="future"]', bulkRow).remove();
59 $('#doaction, #doaction2').click(function(e){
60 var n = $(this).attr('id').substr(2);
61 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
64 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
69 $('#post-query-submit').click(function(e){
70 if ( $('form#posts-filter tr.inline-editor').length > 0 )
76 toggle : function(el) {
79 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
82 addEvents : function(r) {
85 $('a.editinline', row).click(function() { inlineEditPost.edit(this); return false; });
89 setBulk : function() {
90 var te = '', c = '', type = this.type;
93 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
94 $('table.widefat tbody').prepend( $('#bulk-edit') );
95 $('#bulk-edit').addClass('inline-editor').show();
97 $('tbody th.check-column input[type="checkbox"]').each(function(i){
98 if ( $(this).attr('checked') ) {
99 var id = $(this).val();
100 var 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>';
105 $('#bulk-titles').html(te);
106 $('#bulk-titles a').click(function() {
107 var id = $(this).attr('id').substr(1), r = inlineEditPost.type+'-'+id;
109 $('table.widefat input[value="'+id+'"]').attr('checked', '');
110 $('#ttle'+id).remove();
113 // enable autocomplete for tags
114 if ( type == 'post' )
115 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
118 edit : function(id) {
122 if ( typeof(id) == 'object' )
125 var 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 var 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 var rowData = $('#inline_'+id);
139 for ( var 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");
152 if ( cats = $('.post_category', rowData).text() )
153 $('ul.cat-checklist :checkbox', editRow).val(cats.split(','));
155 // handle the post status
156 var status = $('._status', rowData).text();
157 if ( status != 'future' ) $('select[name="_status"] option[value="future"]', editRow).remove();
158 if ( status == 'private' ) {
159 $('input[name="keep_private"]', editRow).attr("checked", "checked");
160 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled');
163 // remove the current page and children from the parent dropdown
164 var pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow);
165 if ( pageOpt.length > 0 ) {
166 var pageLevel = pageOpt[0].className.split('-')[1], nextPage = pageOpt, pageLoop = true;
168 var nextPage = nextPage.next('option');
169 if (nextPage.length == 0) break;
170 var 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' )
186 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
191 save : function(id) {
192 if( typeof(id) == 'object' )
195 $('table.widefat .inline-edit-save .waiting').show();
198 action: 'inline-save',
199 post_type: this.type,
204 var fields = $('#edit-'+id+' :input').fieldSerialize();
205 params = fields + '&' + $.param(params);
208 $.post('admin-ajax.php', params,
210 $('table.widefat .inline-edit-save .waiting').hide();
213 if ( -1 != r.indexOf('<tr') ) {
214 $(inlineEditPost.what+id).remove();
215 $('#edit-'+id).before(r).remove();
217 var row = $(inlineEditPost.what+id);
220 if ( 'draft' == $('input[name="post_status"]').val() )
221 row.find('td.column-comments').hide();
223 row.find('.hide-if-no-js').removeClass('hide-if-no-js');
224 inlineEditPost.addEvents(row);
227 r = r.replace( /<.[^<>]*?>/g, '' );
228 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
231 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
238 revert : function() {
241 if ( id = $('table.widefat tr.inline-editor').attr('id') ) {
242 $('table.widefat .inline-edit-save .waiting').hide();
244 if ( 'bulk-edit' == id ) {
245 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
246 $('#bulk-titles').html('');
247 $('#inlineedit').append( $('#bulk-edit') );
250 id = id.substr( id.lastIndexOf('-') + 1 );
251 $(this.what+id).show();
258 getId : function(o) {
259 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id');
260 var parts = id.split('-');
261 return parts[parts.length - 1];
265 $(document).ready(function(){inlineEditPost.init();});