raw
mp-wp_genesis           1 
mp-wp_genesis 2 (function($) {
mp-wp_genesis 3 inlineEditPost = {
mp-wp_genesis 4
mp-wp_genesis 5 init : function() {
mp-wp_genesis 6 var t = this, qeRow = $('#inline-edit'), bulkRow = $('#bulk-edit');
mp-wp_genesis 7
mp-wp_genesis 8 t.type = $('table.widefat').hasClass('page') ? 'page' : 'post';
mp-wp_genesis 9 t.what = '#'+t.type+'-';
mp-wp_genesis 10
mp-wp_genesis 11 // get all editable rows
mp-wp_genesis 12 t.rows = $('tr.iedit');
mp-wp_genesis 13
mp-wp_genesis 14 // prepare the edit rows
mp-wp_genesis 15 qeRow.keyup(function(e) { if(e.which == 27) return inlineEditPost.revert(); });
mp-wp_genesis 16 bulkRow.keyup(function(e) { if (e.which == 27) return inlineEditPost.revert(); });
mp-wp_genesis 17
mp-wp_genesis 18 $('a.cancel', qeRow).click(function() { return inlineEditPost.revert(); });
mp-wp_genesis 19 $('a.save', qeRow).click(function() { return inlineEditPost.save(this); });
mp-wp_genesis 20 $('input, select', qeRow).keydown(function(e) { if(e.which == 13) return inlineEditPost.save(this); });
mp-wp_genesis 21
mp-wp_genesis 22 $('a.cancel', bulkRow).click(function() { return inlineEditPost.revert(); });
mp-wp_genesis 23
mp-wp_genesis 24 $('#inline-edit .inline-edit-private input[value=private]').click( function(){
mp-wp_genesis 25 var pw = $('input.inline-edit-password-input');
mp-wp_genesis 26 if ( $(this).attr('checked') ) {
mp-wp_genesis 27 pw.val('').attr('disabled', 'disabled');
mp-wp_genesis 28 } else {
mp-wp_genesis 29 pw.attr('disabled', '');
mp-wp_genesis 30 }
mp-wp_genesis 31 });
mp-wp_genesis 32
mp-wp_genesis 33 // add events
mp-wp_genesis 34 t.addEvents(t.rows);
mp-wp_genesis 35
mp-wp_genesis 36 $('#bulk-title-div').parents('fieldset').after(
mp-wp_genesis 37 $('#inline-edit fieldset.inline-edit-categories').clone()
mp-wp_genesis 38 ).siblings( 'fieldset:last' ).prepend(
mp-wp_genesis 39 // ).siblings( 'fieldset:last' ).after( '<fieldset class="inline-edit-col-bottom"><div class="inline-edit-col"></div></fieldset>' );
mp-wp_genesis 40 // $('fieldset.inline-edit-col-bottom').prepend(
mp-wp_genesis 41 $('#inline-edit label.inline-edit-tags').clone()
mp-wp_genesis 42 );
mp-wp_genesis 43
mp-wp_genesis 44 // categories expandable?
mp-wp_genesis 45 $('span.catshow').click(function() {
mp-wp_genesis 46 $('.inline-editor ul.cat-checklist').addClass("cat-hover");
mp-wp_genesis 47 $('.inline-editor span.cathide').show();
mp-wp_genesis 48 $(this).hide();
mp-wp_genesis 49 });
mp-wp_genesis 50
mp-wp_genesis 51 $('span.cathide').click(function() {
mp-wp_genesis 52 $('.inline-editor ul.cat-checklist').removeClass("cat-hover");
mp-wp_genesis 53 $('.inline-editor span.catshow').show();
mp-wp_genesis 54 $(this).hide();
mp-wp_genesis 55 });
mp-wp_genesis 56
mp-wp_genesis 57 $('select[name="_status"] option[value="future"]', bulkRow).remove();
mp-wp_genesis 58
mp-wp_genesis 59 $('#doaction, #doaction2').click(function(e){
mp-wp_genesis 60 var n = $(this).attr('id').substr(2);
mp-wp_genesis 61 if ( $('select[name="'+n+'"]').val() == 'edit' ) {
mp-wp_genesis 62 e.preventDefault();
mp-wp_genesis 63 t.setBulk();
mp-wp_genesis 64 } else if ( $('form#posts-filter tr.inline-editor').length > 0 ) {
mp-wp_genesis 65 t.revert();
mp-wp_genesis 66 }
mp-wp_genesis 67 });
mp-wp_genesis 68
mp-wp_genesis 69 $('#post-query-submit').click(function(e){
mp-wp_genesis 70 if ( $('form#posts-filter tr.inline-editor').length > 0 )
mp-wp_genesis 71 t.revert();
mp-wp_genesis 72 });
mp-wp_genesis 73
mp-wp_genesis 74 },
mp-wp_genesis 75
mp-wp_genesis 76 toggle : function(el) {
mp-wp_genesis 77 var t = this;
mp-wp_genesis 78
mp-wp_genesis 79 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
mp-wp_genesis 80 },
mp-wp_genesis 81
mp-wp_genesis 82 addEvents : function(r) {
mp-wp_genesis 83 r.each(function() {
mp-wp_genesis 84 var row = $(this);
mp-wp_genesis 85 $('a.editinline', row).click(function() { inlineEditPost.edit(this); return false; });
mp-wp_genesis 86 });
mp-wp_genesis 87 },
mp-wp_genesis 88
mp-wp_genesis 89 setBulk : function() {
mp-wp_genesis 90 var te = '', c = '', type = this.type;
mp-wp_genesis 91 this.revert();
mp-wp_genesis 92
mp-wp_genesis 93 $('#bulk-edit td').attr('colspan', $('.widefat:first thead th:visible').length);
mp-wp_genesis 94 $('table.widefat tbody').prepend( $('#bulk-edit') );
mp-wp_genesis 95 $('#bulk-edit').addClass('inline-editor').show();
mp-wp_genesis 96
mp-wp_genesis 97 $('tbody th.check-column input[type="checkbox"]').each(function(i){
mp-wp_genesis 98 if ( $(this).attr('checked') ) {
mp-wp_genesis 99 var id = $(this).val();
mp-wp_genesis 100 var theTitle = $('#inline_'+id+' .post_title').text() || inlineEditL10n.notitle;
mp-wp_genesis 101 te += '<div id="ttle'+id+'"><a id="_'+id+'" class="ntdelbutton" title="'+inlineEditL10n.ntdeltitle+'">X</a>'+theTitle+'</div>';
mp-wp_genesis 102 }
mp-wp_genesis 103 });
mp-wp_genesis 104
mp-wp_genesis 105 $('#bulk-titles').html(te);
mp-wp_genesis 106 $('#bulk-titles a').click(function() {
mp-wp_genesis 107 var id = $(this).attr('id').substr(1), r = inlineEditPost.type+'-'+id;
mp-wp_genesis 108
mp-wp_genesis 109 $('table.widefat input[value="'+id+'"]').attr('checked', '');
mp-wp_genesis 110 $('#ttle'+id).remove();
mp-wp_genesis 111 });
mp-wp_genesis 112
mp-wp_genesis 113 // enable autocomplete for tags
mp-wp_genesis 114 if ( type == 'post' )
mp-wp_genesis 115 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
mp-wp_genesis 116 },
mp-wp_genesis 117
mp-wp_genesis 118 edit : function(id) {
mp-wp_genesis 119 var t = this;
mp-wp_genesis 120 t.revert();
mp-wp_genesis 121
mp-wp_genesis 122 if ( typeof(id) == 'object' )
mp-wp_genesis 123 id = t.getId(id);
mp-wp_genesis 124
mp-wp_genesis 125 var fields = ['post_title', 'post_name', 'post_author', '_status', 'jj', 'mm', 'aa', 'hh', 'mn', 'ss', 'post_password'];
mp-wp_genesis 126 if ( t.type == 'page' ) fields.push('post_parent', 'menu_order', 'page_template');
mp-wp_genesis 127 if ( t.type == 'post' ) fields.push('tags_input');
mp-wp_genesis 128
mp-wp_genesis 129 // add the new blank row
mp-wp_genesis 130 var editRow = $('#inline-edit').clone(true);
mp-wp_genesis 131 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
mp-wp_genesis 132
mp-wp_genesis 133 if ( $(t.what+id).hasClass('alternate') )
mp-wp_genesis 134 $(editRow).addClass('alternate');
mp-wp_genesis 135 $(t.what+id).hide().after(editRow);
mp-wp_genesis 136
mp-wp_genesis 137 // populate the data
mp-wp_genesis 138 var rowData = $('#inline_'+id);
mp-wp_genesis 139 for ( var f = 0; f < fields.length; f++ ) {
mp-wp_genesis 140 $(':input[name="'+fields[f]+'"]', editRow).val( $('.'+fields[f], rowData).text() );
mp-wp_genesis 141 }
mp-wp_genesis 142
mp-wp_genesis 143 if ( $('.comment_status', rowData).text() == 'open' )
mp-wp_genesis 144 $('input[name="comment_status"]', editRow).attr("checked", "checked");
mp-wp_genesis 145 if ( $('.ping_status', rowData).text() == 'open' )
mp-wp_genesis 146 $('input[name="ping_status"]', editRow).attr("checked", "checked");
mp-wp_genesis 147 if ( $('.sticky', rowData).text() == 'sticky' )
mp-wp_genesis 148 $('input[name="sticky"]', editRow).attr("checked", "checked");
mp-wp_genesis 149
mp-wp_genesis 150 // categories
mp-wp_genesis 151 var cats;
mp-wp_genesis 152 if ( cats = $('.post_category', rowData).text() )
mp-wp_genesis 153 $('ul.cat-checklist :checkbox', editRow).val(cats.split(','));
mp-wp_genesis 154
mp-wp_genesis 155 // handle the post status
mp-wp_genesis 156 var status = $('._status', rowData).text();
mp-wp_genesis 157 if ( status != 'future' ) $('select[name="_status"] option[value="future"]', editRow).remove();
mp-wp_genesis 158 if ( status == 'private' ) {
mp-wp_genesis 159 $('input[name="keep_private"]', editRow).attr("checked", "checked");
mp-wp_genesis 160 $('input.inline-edit-password-input').val('').attr('disabled', 'disabled');
mp-wp_genesis 161 }
mp-wp_genesis 162
mp-wp_genesis 163 // remove the current page and children from the parent dropdown
mp-wp_genesis 164 var pageOpt = $('select[name="post_parent"] option[value="'+id+'"]', editRow);
mp-wp_genesis 165 if ( pageOpt.length > 0 ) {
mp-wp_genesis 166 var pageLevel = pageOpt[0].className.split('-')[1], nextPage = pageOpt, pageLoop = true;
mp-wp_genesis 167 while ( pageLoop ) {
mp-wp_genesis 168 var nextPage = nextPage.next('option');
mp-wp_genesis 169 if (nextPage.length == 0) break;
mp-wp_genesis 170 var nextLevel = nextPage[0].className.split('-')[1];
mp-wp_genesis 171 if ( nextLevel <= pageLevel ) {
mp-wp_genesis 172 pageLoop = false;
mp-wp_genesis 173 } else {
mp-wp_genesis 174 nextPage.remove();
mp-wp_genesis 175 nextPage = pageOpt;
mp-wp_genesis 176 }
mp-wp_genesis 177 }
mp-wp_genesis 178 pageOpt.remove();
mp-wp_genesis 179 }
mp-wp_genesis 180
mp-wp_genesis 181 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
mp-wp_genesis 182 $('.ptitle', editRow).focus();
mp-wp_genesis 183
mp-wp_genesis 184 // enable autocomplete for tags
mp-wp_genesis 185 if ( t.type == 'post' )
mp-wp_genesis 186 $('tr.inline-editor textarea[name="tags_input"]').suggest( 'admin-ajax.php?action=ajax-tag-search', { delay: 500, minchars: 2, multiple: true, multipleSep: ", " } );
mp-wp_genesis 187
mp-wp_genesis 188 return false;
mp-wp_genesis 189 },
mp-wp_genesis 190
mp-wp_genesis 191 save : function(id) {
mp-wp_genesis 192 if( typeof(id) == 'object' )
mp-wp_genesis 193 id = this.getId(id);
mp-wp_genesis 194
mp-wp_genesis 195 $('table.widefat .inline-edit-save .waiting').show();
mp-wp_genesis 196
mp-wp_genesis 197 var params = {
mp-wp_genesis 198 action: 'inline-save',
mp-wp_genesis 199 post_type: this.type,
mp-wp_genesis 200 post_ID: id,
mp-wp_genesis 201 edit_date: 'true'
mp-wp_genesis 202 };
mp-wp_genesis 203
mp-wp_genesis 204 var fields = $('#edit-'+id+' :input').fieldSerialize();
mp-wp_genesis 205 params = fields + '&' + $.param(params);
mp-wp_genesis 206
mp-wp_genesis 207 // make ajax request
mp-wp_genesis 208 $.post('admin-ajax.php', params,
mp-wp_genesis 209 function(r) {
mp-wp_genesis 210 $('table.widefat .inline-edit-save .waiting').hide();
mp-wp_genesis 211
mp-wp_genesis 212 if (r) {
mp-wp_genesis 213 if ( -1 != r.indexOf('<tr') ) {
mp-wp_genesis 214 $(inlineEditPost.what+id).remove();
mp-wp_genesis 215 $('#edit-'+id).before(r).remove();
mp-wp_genesis 216
mp-wp_genesis 217 var row = $(inlineEditPost.what+id);
mp-wp_genesis 218 row.hide();
mp-wp_genesis 219
mp-wp_genesis 220 if ( 'draft' == $('input[name="post_status"]').val() )
mp-wp_genesis 221 row.find('td.column-comments').hide();
mp-wp_genesis 222
mp-wp_genesis 223 row.find('.hide-if-no-js').removeClass('hide-if-no-js');
mp-wp_genesis 224 inlineEditPost.addEvents(row);
mp-wp_genesis 225 row.fadeIn();
mp-wp_genesis 226 } else {
mp-wp_genesis 227 r = r.replace( /<.[^<>]*?>/g, '' );
mp-wp_genesis 228 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+r+'</span>');
mp-wp_genesis 229 }
mp-wp_genesis 230 } else {
mp-wp_genesis 231 $('#edit-'+id+' .inline-edit-save').append('<span class="error">'+inlineEditL10n.error+'</span>');
mp-wp_genesis 232 }
mp-wp_genesis 233 }
mp-wp_genesis 234 , 'html');
mp-wp_genesis 235 return false;
mp-wp_genesis 236 },
mp-wp_genesis 237
mp-wp_genesis 238 revert : function() {
mp-wp_genesis 239 var id;
mp-wp_genesis 240
mp-wp_genesis 241 if ( id = $('table.widefat tr.inline-editor').attr('id') ) {
mp-wp_genesis 242 $('table.widefat .inline-edit-save .waiting').hide();
mp-wp_genesis 243
mp-wp_genesis 244 if ( 'bulk-edit' == id ) {
mp-wp_genesis 245 $('table.widefat #bulk-edit').removeClass('inline-editor').hide();
mp-wp_genesis 246 $('#bulk-titles').html('');
mp-wp_genesis 247 $('#inlineedit').append( $('#bulk-edit') );
mp-wp_genesis 248 } else {
mp-wp_genesis 249 $('#'+id).remove();
mp-wp_genesis 250 id = id.substr( id.lastIndexOf('-') + 1 );
mp-wp_genesis 251 $(this.what+id).show();
mp-wp_genesis 252 }
mp-wp_genesis 253 }
mp-wp_genesis 254
mp-wp_genesis 255 return false;
mp-wp_genesis 256 },
mp-wp_genesis 257
mp-wp_genesis 258 getId : function(o) {
mp-wp_genesis 259 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id');
mp-wp_genesis 260 var parts = id.split('-');
mp-wp_genesis 261 return parts[parts.length - 1];
mp-wp_genesis 262 }
mp-wp_genesis 263 };
mp-wp_genesis 264
mp-wp_genesis 265 $(document).ready(function(){inlineEditPost.init();});
mp-wp_genesis 266 })(jQuery);