| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of WordPress 3.0.1Provided by Yoast |
[Summary view] [Print] [Text view]
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 // hiearchical taxonomies expandable? 40 $('span.catshow').click(function() { 41 $(this).hide().next().show().parent().next().addClass("cat-hover"); 42 }); 43 44 $('span.cathide').click(function() { 45 $(this).hide().prev().show().parent().next().removeClass("cat-hover"); 46 }); 47 48 $('select[name="_status"] option[value="future"]', bulkRow).remove(); 49 50 $('#doaction, #doaction2').click(function(e){ 51 var n = $(this).attr('id').substr(2); 52 if ( $('select[name="'+n+'"]').val() == 'edit' ) { 53 e.preventDefault(); 54 t.setBulk(); 55 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) { 56 t.revert(); 57 } 58 }); 59 60 $('#post-query-submit').click(function(e){ 61 if ( $('form#posts-filter tr.inline-editor').length > 0 ) 62 t.revert(); 63 }); 64 65 }, 66 67 toggle : function(el) { 68 var t = this; 69 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el); 70 }, 71 72 setBulk : function() { 73 var te = '', type = this.type, tax, c = true; 74 this.revert(); 75 76 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length); 77 $('table.widefat tbody').prepend( $('#bulk-edit') ); 78 $('#bulk-edit').addClass('inline-editor').show(); 79 80 $('tbody th.check-column input[type="checkbox"]').each(function(i){ 81 if ( $(this).attr('checked') ) { 82 c = false; 83 var id = $(this).val(), theTitle; 84 theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle; 85 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>'; 86 } 87 }); 88 89 if ( c ) 90 return this.revert(); 91 92 $('#bulk-titles').html(te); 93 $('#bulk-titles a').click(function() { 94 var id = $(this).attr('id').substr(1); 95 96 $('table.widefat input[value="'+id+'"]').attr('checked', ''); 97 $('#ttle'+id).remove(); 98 }); 99 100 // enable autocomplete for tags 101 if ( type == 'post' ) { 102 // support multi taxonomies? 103 tax = 'post_tag'; 104 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+tax, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); 105 } 106 }, 107 108 edit : function(id) { 109 var t = this, fields, editRow, rowData, cats, status, pageOpt, f, pageLevel, nextPage, pageLoop = true, nextLevel, tax; 110 t.revert(); 111 112 if ( typeof(id) == 'object' ) 113 id = t.getId(id); 114 115 fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password']; 116 if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template'); 117 118 // add the new blank row 119 editRow = $('#inline-edit').clone(true); 120 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length); 121 122 if ( $(t.what+id).hasClass('alternate') ) 123 $(editRow).addClass('alternate'); 124 $(t.what+id).hide().after(editRow); 125 126 // populate the data 127 rowData = $('#inline_'+id); 128 if ( !$(':input[name="post_author"] option[value=' + $('.post_author', rowData).text() + ']', editRow).val() ) { 129 // author no longer has edit caps, so we need to add them to the list of authors 130 $(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#' + t.type + '-' + id + ' .author').text() + '</option>'); 131 } 132 133 for ( f = 0; f < fields.length; f++ ) { 134 $(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() ); 135 } 136 137 if ( $('.comment_status', rowData).text() == 'open' ) 138 $('input[name="comment_status"]', editRow).attr("checked", "checked"); 139 if ( $('.ping_status', rowData).text() == 'open' ) 140 $('input[name="ping_status"]', editRow).attr("checked", "checked"); 141 if ( $('.sticky', rowData).text() == 'sticky' ) 142 $('input[name="sticky"]', editRow).attr("checked", "checked"); 143 144 // hierarchical taxonomies 145 $('.post_category', rowData).each(function(){ 146 if( term_ids = $(this).text() ) 147 { 148 taxname = $(this).attr('id').replace('_'+id, ''); 149 $('ul.'+taxname+'-checklist :checkbox', editRow).val(term_ids.split(',')); 150 } 151 }); 152 //flat taxonomies 153 $('.tags_input', rowData).each(function(){ 154 if( terms = $(this).text() ) 155 { 156 taxname = $(this).attr('id').replace('_'+id, ''); 157 $('textarea.tax_input_'+taxname, editRow).val(terms); 158 $('textarea.tax_input_'+taxname, editRow).suggest( 'admin-ajax.php?action=ajax-tag-search&tax='+taxname, { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } ); 159 } 160 }); 161 162 163 // handle the post status 164 status = $('._status', rowData).text(); 165 if ( status != 'future' ) $('select[name="_status"] option[value="future"]', editRow).remove(); 166 if ( status == 'private' ) { 167 $('input[name="keep_private"]', editRow).attr("checked", "checked"); 168 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled'); 169 } 170 171 // remove the current page and children from the parent dropdown 172 pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow); 173 if ( pageOpt.length > 0 ) { 174 pageLevel = pageOpt[0].className.split('-')[1]; 175 nextPage = pageOpt; 176 while ( pageLoop ) { 177 nextPage = nextPage.next('option'); 178 if (nextPage.length == 0) break; 179 nextLevel = nextPage[0].className.split('-')[1]; 180 if ( nextLevel <= pageLevel ) { 181 pageLoop = false; 182 } else { 183 nextPage.remove(); 184 nextPage = pageOpt; 185 } 186 } 187 pageOpt.remove(); 188 } 189 190 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show(); 191 $('.ptitle', editRow).focus(); 192 193 return false; 194 }, 195 196 save : function(id) { 197 var params, fields, page = $('.post_status_page').val() || ''; 198 199 if( typeof(id) == 'object' ) 200 id = this.getId(id); 201 202 $('table.widefat .inline-edit-save .waiting').show(); 203 204 params = { 205 action: 'inline-save', 206 post_type: typenow, 207 post_ID: id, 208 edit_date: 'true', 209 post_status: page 210 }; 211 212 fields = $('#edit-'+id+' :input').serialize(); 213 params = fields + '&' + $.param(params); 214 215 // make ajax request 216 $.post('admin-ajax.php', params, 217 function(r) { 218 $('table.widefat .inline-edit-save .waiting').hide(); 219 220 if (r) { 221 if ( -1 != r.indexOf('<tr') ) { 222 $(inlineEditPost.what+id).remove(); 223 $('#edit-'+id).before(r).remove(); 224 $(inlineEditPost.what+id).hide().fadeIn(); 225 } else { 226 r = r.replace( /<.[^<>]*?>/g, '' ); 227 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>'); 228 } 229 } else { 230 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>'); 231 } 232 } 233 , 'html'); 234 return false; 235 }, 236 237 revert : function() { 238 var id; 239 240 if ( id = $('table.widefat tr.inline-editor').attr('id') ) { 241 $('table.widefat .inline-edit-save .waiting').hide(); 242 243 if ( 'bulk-edit' == id ) { 244 $('table.widefat #bulk-edit').removeClass('inline-editor').hide(); 245 $('#bulk-titles').html(''); 246 $('#inlineedit').append( $('#bulk-edit') ); 247 } else { 248 $('#'+id).remove(); 249 id = id.substr( id.lastIndexOf('-') + 1 ); 250 $(this.what+id).show(); 251 } 252 } 253 254 return false; 255 }, 256 257 getId : function(o) { 258 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id'), parts = id.split('-'); 259 return parts[parts.length - 1]; 260 } 261 }; 262 263 $(document).ready(function(){inlineEditPost.init();}); 264 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Oct 14 05:12:05 2010 | Cross-referenced by PHPXref 0.7 |