| [ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 (function($) { 2 inlineEditPost = { 3 4 init : function(){ 5 var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit'); 6 7 t.type = $('table.widefat').hasClass('pages') ? 'page' : 'post'; 8 t.what = '#post-'; 9 10 // prepare the edit rows 11 qeRow.keyup(function(e){ 12 if (e.which == 27) 13 return inlineEditPost.revert(); 14 }); 15 bulkRow.keyup(function(e){ 16 if (e.which == 27) 17 return inlineEditPost.revert(); 18 }); 19 20 $('a.cancel', qeRow).click(function(){ 21 return inlineEditPost.revert(); 22 }); 23 $('a.save', qeRow).click(function(){ 24 return inlineEditPost.save(this); 25 }); 26 $('td', qeRow).keydown(function(e){ 27 if ( e.which == 13 ) 28 return inlineEditPost.save(this); 29 }); 30 31 $('a.cancel', bulkRow).click(function(){ 32 return inlineEditPost.revert(); 33 }); 34 35 $('#inline-edit .inline-edit-private input[value="private"]').click( function(){ 36 var pw = $('input.inline-edit-password-input'); 37 if ( $(this).prop('checked') ) { 38 pw.val('').prop('disabled', true); 39 } else { 40 pw.prop('disabled', false); 41 } 42 }); 43 44 // add events 45 $('a.editinline').live('click', function(){ 46 inlineEditPost.edit(this); 47 return false; 48 }); 49 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() 54 ); 55 56 // hiearchical taxonomies expandable? 57 $('span.catshow').click(function(){ 58 $(this).hide().next().show().parent().next().addClass("cat-hover"); 59 }); 60 61 $('span.cathide').click(function(){ 62 $(this).hide().prev().show().parent().next().removeClass("cat-hover"); 63 }); 64 65 $('select[name="_status"] option[value="future"]', bulkRow).remove(); 66 67 $('#doaction, #doaction2').click(function(e){ 68 var n = $(this).attr('id').substr(2); 69 if ( $('select[name="'+n+'"]').val() == 'edit' ) { 70 e.preventDefault(); 71 t.setBulk(); 72 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { 73 t.revert(); 74 } 75 }); 76 77 $('#post-query-submit').mousedown(function(e){ 78 t.revert(); 79 $('select[name^="action"]').val('-1'); 80 }); 81 }, 82 83 toggle : function(el){ 84 var t = this; 85 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); 86 }, 87 88 setBulk : function(){ 89 var te = '', type = this.type, tax, c = true; 90 this.revert(); 91 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(); 95 96 $('tbody th.check-column input[type="checkbox"]').each(function(i){ 97 if ( $(this).prop('checked') ) { 98 c = false; 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>'; 102 } 103 }); 104 105 if ( c ) 106 return this.revert(); 107 108 $('#bulk-titles').html(te); 109 $('#bulk-titles a').click(function(){ 110 var id = $(this).attr('id').substr(1); 111 112 $('table.widefat input[value="' + id + '"]').prop('checked', false); 113 $('#ttle'+id).remove(); 114 }); 115 116 // enable autocomplete for tags 117 if ( 'post' == type ) { 118 // support multi taxonomies? 119 tax = 'post_tag'; 120 $('tr.inline-editor textarea[name="tax_input['+tax+']"]').suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } ); 121 } 122 $('html, body').animate( { scrollTop: 0 }, 'fast' ); 123 }, 124 125 edit : function(id) { 126 var t = this, fields, editRow, rowData, status, pageOpt, pageLevel, nextPage, pageLoop = true, nextLevel, cur_format, f; 127 t.revert(); 128 129 if ( typeof(id) == 'object' ) 130 id = t.getId(id); 131 132 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password', 'post_format', 'menu_order']; 133 if ( t.type == 'page' ) 134 fields.push('post_parent', 'page_template'); 135 136 // add the new blank row 137 editRow = $('#inline-edit').clone(true); 138 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length); 139 140 if ( $(t.what+id).hasClass('alternate') ) 141 $(editRow).addClass('alternate'); 142 $(t.what+id).hide().after(editRow); 143 144 // populate the data 145 rowData = $('#inline_'+id); 146 if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) { 147 // author no longer has edit caps, so we need to add them to the list of authors 148 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>'); 149 } 150 if ( $(':input[name="post_author"] option', editRow).length == 1 ) { 151 $('label.inline-edit-author', editRow).hide(); 152 } 153 154 // hide unsupported formats, but leave the current format alone 155 cur_format = $('.post_format', rowData).text(); 156 $('option.unsupported', editRow).each(function() { 157 var $this = $(this); 158 if ( $this.val() != cur_format ) 159 $this.remove(); 160 }); 161 162 for ( f = 0; f < fields.length; f++ ) { 163 $(':input[name="' + fields[f] + '"]', editRow).val( $('.'+fields[f], rowData).text() ); 164 } 165 166 if ( $('.comment_status', rowData).text() == 'open' ) 167 $('input[name="comment_status"]', editRow).prop("checked", true); 168 if ( $('.ping_status', rowData).text() == 'open' ) 169 $('input[name="ping_status"]', editRow).prop("checked", true); 170 if ( $('.sticky', rowData).text() == 'sticky' ) 171 $('input[name="sticky"]', editRow).prop("checked", true); 172 173 // hierarchical taxonomies 174 $('.post_category', rowData).each(function(){ 175 var term_ids = $(this).text(); 176 177 if ( term_ids ) { 178 taxname = $(this).attr('id').replace('_'+id, ''); 179 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); 180 } 181 }); 182 183 //flat taxonomies 184 $('.tags_input', rowData).each(function(){ 185 var terms = $(this).text(), 186 taxname = $(this).attr('id').replace('_' + id, ''), 187 textarea = $('textarea.tax_input_' + taxname, editRow), 188 comma = inlineEditL10n.comma; 189 190 if ( terms ) { 191 if ( ',' !== comma ) 192 terms = terms.replace(/,/g, comma); 193 textarea.val(terms); 194 } 195 196 textarea.suggest( ajaxurl + '?action=ajax-tag-search&tax=' + taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: inlineEditL10n.comma + ' ' } ); 197 }); 198 199 // handle the post status 200 status = $('._status', rowData).text(); 201 if ( 'future' != status ) 202 $('select[name="_status"] option[value="future"]', editRow).remove(); 203 204 if ( 'private' == status ) { 205 $('input[name="keep_private"]', editRow).prop("checked", true); 206 $('input.inline-edit-password-input').val('').prop('disabled', true); 207 } 208 209 // remove the current page and children from the parent dropdown 210 pageOpt = $('select[name="post_parent"] option[value="' + id + '"]', editRow); 211 if ( pageOpt.length > 0 ) { 212 pageLevel = pageOpt[0].className.split('-')[1]; 213 nextPage = pageOpt; 214 while ( pageLoop ) { 215 nextPage = nextPage.next('option'); 216 if (nextPage.length == 0) break; 217 nextLevel = nextPage[0].className.split('-')[1]; 218 if ( nextLevel <= pageLevel ) { 219 pageLoop = false; 220 } else { 221 nextPage.remove(); 222 nextPage = pageOpt; 223 } 224 } 225 pageOpt.remove(); 226 } 227 228 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); 229 $('.ptitle', editRow).focus(); 230 231 return false; 232 }, 233 234 save : function(id) { 235 var params, fields, page = $('.post_status_page').val() || ''; 236 237 if ( typeof(id) == 'object' ) 238 id = this.getId(id); 239 240 $('table.widefat .inline-edit-save .waiting').show(); 241 242 params = { 243 action: 'inline-save', 244 post_type: typenow, 245 post_ID: id, 246 edit_date: 'true', 247 post_status: page 248 }; 249 250 fields = $('#edit-'+id+' :input').serialize(); 251 params = fields + '&' + $.param(params); 252 253 // make ajax request 254 $.post( ajaxurl, params, 255 function(r) { 256 $('table.widefat .inline-edit-save .waiting').hide(); 257 258 if (r) { 259 if ( -1 != r.indexOf('<tr') ) { 260 $(inlineEditPost.what+id).remove(); 261 $('#edit-'+id).before(r).remove(); 262 $(inlineEditPost.what+id).hide().fadeIn(); 263 } else { 264 r = r.replace( /<.[^<>]*?>/g, '' ); 265 $('#edit-'+id+' .inline-edit-save .error').html(r).show(); 266 } 267 } else { 268 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show(); 269 } 270 } 271 , 'html'); 272 return false; 273 }, 274 275 revert : function(){ 276 var id = $('table.widefat tr.inline-editor').attr('id'); 277 278 if ( id ) { 279 $('table.widefat .inline-edit-save .waiting').hide(); 280 281 if ( 'bulk-edit' == id ) { 282 $('table.widefat #bulk-edit').removeClass('inline-editor').hide(); 283 $('#bulk-titles').html(''); 284 $('#inlineedit').append( $('#bulk-edit') ); 285 } else { 286 $('#'+id).remove(); 287 id = id.substr( id.lastIndexOf('-') + 1 ); 288 $(this.what+id).show(); 289 } 290 } 291 292 return false; 293 }, 294 295 getId : function(o) { 296 var id = $(o).closest('tr').attr('id'), 297 parts = id.split('-'); 298 return parts[parts.length - 1]; 299 } 300 }; 301 302 $(document).ready(function(){inlineEditPost.init();}); 303 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri May 25 03:56:23 2012 | Hosted by follow the white rabbit. |