|
1 |
|
2 (function($) { |
|
3 inlineEditPost = { |
|
4 |
|
5 init : function() { |
|
6 var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); |
|
7 |
|
8 t.type = $('table.widefat').hasClass('page') ? 'page' : 'post'; |
|
9 t.what = '#'+t.type+'-'; |
|
10 |
|
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(); }); |
|
14 |
|
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); }); |
|
18 |
|
19 $('a.cancel', bulkRow).click(function() { return inlineEditPost.revert(); }); |
|
20 |
|
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'); |
|
25 } else { |
|
26 pw.attr('disabled', ''); |
|
27 } |
|
28 }); |
|
29 |
|
30 // add events |
|
31 $('a.editinline').live('click', function() { inlineEditPost.edit(this); return false; }); |
|
32 |
|
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() |
|
37 ); |
|
38 |
|
39 // categories expandable? |
|
40 $('span.catshow').click(function() { |
|
41 $('.inline-editor ul.cat-checklist').addClass("cat-hover"); |
|
42 $('.inline-editor span.cathide').show(); |
|
43 $(this).hide(); |
|
44 }); |
|
45 |
|
46 $('span.cathide').click(function() { |
|
47 $('.inline-editor ul.cat-checklist').removeClass("cat-hover"); |
|
48 $('.inline-editor span.catshow').show(); |
|
49 $(this).hide(); |
|
50 }); |
|
51 |
|
52 $('select[name="_status"] option[value="future"]', bulkRow).remove(); |
|
53 |
|
54 $('#doaction, #doaction2').click(function(e){ |
|
55 var n = $(this).attr('id').substr(2); |
|
56 if ( $('select[name="'+n+'"]').val() == 'edit' ) { |
|
57 e.preventDefault(); |
|
58 t.setBulk(); |
|
59 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { |
|
60 t.revert(); |
|
61 } |
|
62 }); |
|
63 |
|
64 $('#post-query-submit').click(function(e){ |
|
65 if ( $('form#posts-filter tr.inline-editor').length > 0 ) |
|
66 t.revert(); |
|
67 }); |
|
68 |
|
69 }, |
|
70 |
|
71 toggle : function(el) { |
|
72 var t = this; |
|
73 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); |
|
74 }, |
|
75 |
|
76 setBulk : function() { |
|
77 var te = '', type = this.type, tax, c = true; |
|
78 this.revert(); |
|
79 |
|
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(); |
|
83 |
|
84 $('tbody th.check-column input[type="checkbox"]').each(function(i){ |
|
85 if ( $(this).attr('checked') ) { |
|
86 c = false; |
|
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>'; |
|
90 } |
|
91 }); |
|
92 |
|
93 if ( c ) |
|
94 return this.revert(); |
|
95 |
|
96 $('#bulk-titles').html(te); |
|
97 $('#bulk-titles a').click(function() { |
|
98 var id = $(this).attr('id').substr(1); |
|
99 |
|
100 $('table.widefat input[value="'+id+'"]').attr('checked', ''); |
|
101 $('#ttle'+id).remove(); |
|
102 }); |
|
103 |
|
104 // enable autocomplete for tags |
|
105 if ( type == 'post' ) { |
|
106 // support multi taxonomies? |
|
107 tax = 'post_tag'; |
|
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: ", " } ); |
|
109 } |
|
110 }, |
|
111 |
|
112 edit : function(id) { |
|
113 var t = this, fields, editRow, rowData, cats, status, pageOpt, f, pageLevel, nextPage, pageLoop = true, nextLevel, tax; |
|
114 t.revert(); |
|
115 |
|
116 if ( typeof(id) == 'object' ) |
|
117 id = t.getId(id); |
|
118 |
|
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'); |
|
122 |
|
123 // add the new blank row |
|
124 editRow = $('#inline-edit').clone(true); |
|
125 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length); |
|
126 |
|
127 if ( $(t.what+id).hasClass('alternate') ) |
|
128 $(editRow).addClass('alternate'); |
|
129 $(t.what+id).hide().after(editRow); |
|
130 |
|
131 // populate the data |
|
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>'); |
|
136 } |
|
137 |
|
138 for ( f = 0; f < fields.length; f++ ) { |
|
139 $(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() ); |
|
140 } |
|
141 |
|
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"); |
|
148 |
|
149 // categories |
|
150 if ( cats = $('.post_category', rowData).text() ) |
|
151 $('ul.cat-checklist :checkbox', editRow).val(cats.split(',')); |
|
152 |
|
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'); |
|
159 } |
|
160 |
|
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]; |
|
165 nextPage = pageOpt; |
|
166 while ( pageLoop ) { |
|
167 nextPage = nextPage.next('option'); |
|
168 if (nextPage.length == 0) break; |
|
169 nextLevel = nextPage[0].className.split('-')[1]; |
|
170 if ( nextLevel <= pageLevel ) { |
|
171 pageLoop = false; |
|
172 } else { |
|
173 nextPage.remove(); |
|
174 nextPage = pageOpt; |
|
175 } |
|
176 } |
|
177 pageOpt.remove(); |
|
178 } |
|
179 |
|
180 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); |
|
181 $('.ptitle', editRow).focus(); |
|
182 |
|
183 // enable autocomplete for tags |
|
184 if ( t.type == 'post' ) { |
|
185 tax = 'post_tag'; |
|
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: ", " } ); |
|
187 } |
|
188 |
|
189 return false; |
|
190 }, |
|
191 |
|
192 save : function(id) { |
|
193 var params, fields, page = $('.post_status_page').val() || ''; |
|
194 |
|
195 if( typeof(id) == 'object' ) |
|
196 id = this.getId(id); |
|
197 |
|
198 $('table.widefat .inline-edit-save .waiting').show(); |
|
199 |
|
200 params = { |
|
201 action: 'inline-save', |
|
202 post_type: this.type, |
|
203 post_ID: id, |
|
204 edit_date: 'true', |
|
205 post_status: page |
|
206 }; |
|
207 |
|
208 fields = $('#edit-'+id+' :input').serialize(); |
|
209 params = fields + '&' + $.param(params); |
|
210 |
|
211 // make ajax request |
|
212 $.post('admin-ajax.php', params, |
|
213 function(r) { |
|
214 $('table.widefat .inline-edit-save .waiting').hide(); |
|
215 |
|
216 if (r) { |
|
217 if ( -1 != r.indexOf('<tr') ) { |
|
218 $(inlineEditPost.what+id).remove(); |
|
219 $('#edit-'+id).before(r).remove(); |
|
220 $(inlineEditPost.what+id).hide().fadeIn(); |
|
221 } else { |
|
222 r = r.replace( /<.[^<>]*?>/g, '' ); |
|
223 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>'); |
|
224 } |
|
225 } else { |
|
226 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>'); |
|
227 } |
|
228 } |
|
229 , 'html'); |
|
230 return false; |
|
231 }, |
|
232 |
|
233 revert : function() { |
|
234 var id; |
|
235 |
|
236 if ( id = $('table.widefat tr.inline-editor').attr('id') ) { |
|
237 $('table.widefat .inline-edit-save .waiting').hide(); |
|
238 |
|
239 if ( 'bulk-edit' == id ) { |
|
240 $('table.widefat #bulk-edit').removeClass('inline-editor').hide(); |
|
241 $('#bulk-titles').html(''); |
|
242 $('#inlineedit').append( $('#bulk-edit') ); |
|
243 } else { |
|
244 $('#'+id).remove(); |
|
245 id = id.substr( id.lastIndexOf('-') + 1 ); |
|
246 $(this.what+id).show(); |
|
247 } |
|
248 } |
|
249 |
|
250 return false; |
|
251 }, |
|
252 |
|
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]; |
|
256 } |
|
257 }; |
|
258 |
|
259 $(document).ready(function(){inlineEditPost.init();}); |
|
260 })(jQuery); |