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).attr('checked') ) {
38 pw.val('').attr('disabled', 'disabled');
40 pw.attr('disabled', '');
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').click(function(e){
78 if ( $('form#posts-filter tr.inline-editor').length > 0 )
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).attr('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+'"]').attr('checked', '');
113 $('#ttle'+id).remove();
116 // enable autocomplete for tags
117 if ( 'post' == type ) {
118 // support multi taxonomies?
120 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
124 edit : function(id) {
125 var t = this, fields, editRow, rowData, cats, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, tax;
128 if ( typeof(id) == 'object' )
131 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password'];
132 if ( t.type == 'page' )
133 fields.push('post_parent', 'menu_order', 'page_template');
135 // add the new blank row
136 editRow = $('#inline-edit').clone(true);
137 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
139 if ( $(t.what+id).hasClass('alternate') )
140 $(editRow).addClass('alternate');
141 $(t.what+id).hide().after(editRow);
144 rowData = $('#inline_'+id);
145 if ( !$(':input[name="post_author"] option[value=' + $('.post_author', rowData).text() + ']', editRow).val() ) {
146 // author no longer has edit caps, so we need to add them to the list of authors
147 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>');
149 if ( $(':input[name="post_author"] option', editRow).length == 1 ) {
150 $('label.inline-edit-author', editRow).hide();
153 for ( var 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).attr("checked", "checked");
159 if ( $('.ping_status', rowData).text() == 'open' )
160 $('input[name="ping_status"]', editRow).attr("checked", "checked");
161 if ( $('.sticky', rowData).text() == 'sticky' )
162 $('input[name="sticky"]', editRow).attr("checked", "checked");
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(','));
174 $('.tags_input', rowData).each(function(){
175 var terms = $(this).text();
178 taxname = $(this).attr('id').replace('_'+id, '');
179 $('textarea.tax_input_'+taxname, editRow).val(terms);
180 $('textarea.tax_input_'+taxname, editRow).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
185 // handle the post status
186 status = $('._status', rowData).text();
187 if ( 'future' != status )
188 $('select[name="_status"] option[value="future"]', editRow).remove();
190 if ( 'private' == status ) {
191 $('input[name="keep_private"]', editRow).attr("checked", "checked");
192 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled');
195 // remove the current page and children from the parent dropdown
196 pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow);
197 if ( pageOpt.length > 0 ) {
198 pageLevel = pageOpt[0].className.split('-')[1];
201 nextPage = nextPage.next('option');
202 if (nextPage.length == 0) break;
203 nextLevel = nextPage[0].className.split('-')[1];
204 if ( nextLevel <= pageLevel ) {
214 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
215 $('.ptitle', editRow).focus();
220 save : function(id) {
221 var params, fields, page = $('.post_status_page').val() || '';
223 if ( typeof(id) == 'object' )
226 $('table.widefat .inline-edit-save .waiting').show();
229 action: 'inline-save',
236 fields = $('#edit-'+id+' :input').serialize();
237 params = fields + '&' + $.param(params);
240 $.post('admin-ajax.php', params,
242 $('table.widefat .inline-edit-save .waiting').hide();
245 if ( -1 != r.indexOf('<tr') ) {
246 $(inlineEditPost.what+id).remove();
247 $('#edit-'+id).before(r).remove();
248 $(inlineEditPost.what+id).hide().fadeIn();
250 r = r.replace( /<.[^<>]*?>/g, '' );
251 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
254 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
262 var id = $('table.widefat tr.inline-editor').attr('id');
265 $('table.widefat .inline-edit-save .waiting').hide();
267 if ( 'bulk-edit' == id ) {
268 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
269 $('#bulk-titles').html('');
270 $('#inlineedit').append( $('#bulk-edit') );
273 id = id.substr( id.lastIndexOf('-') + 1 );
274 $(this.what+id).show();
281 getId : function(o) {
282 var id = $(o).closest('tr').attr('id'),
283 parts = id.split('-');
284 return parts[parts.length - 1];
288 $(document).ready(function(){inlineEditPost.init();});