raw
mp-wp_genesis           1 
mp-wp_genesis 2 (function($) {
mp-wp_genesis 3 inlineEditTax = {
mp-wp_genesis 4
mp-wp_genesis 5 init : function() {
mp-wp_genesis 6 var t = this, row = $('#inline-edit');
mp-wp_genesis 7
mp-wp_genesis 8 t.type = $('#the-list').attr('className').substr(5);
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 row
mp-wp_genesis 15 row.keyup(function(e) { if(e.which == 27) return inlineEditTax.revert(); });
mp-wp_genesis 16
mp-wp_genesis 17 $('a.cancel', row).click(function() { return inlineEditTax.revert(); });
mp-wp_genesis 18 $('a.save', row).click(function() { return inlineEditTax.save(this); });
mp-wp_genesis 19 $('input, select', row).keydown(function(e) { if(e.which == 13) return inlineEditTax.save(this); });
mp-wp_genesis 20
mp-wp_genesis 21 // add events
mp-wp_genesis 22 t.addEvents(t.rows);
mp-wp_genesis 23
mp-wp_genesis 24 $('#posts-filter input[type="submit"]').click(function(e){
mp-wp_genesis 25 if ( $('form#posts-filter tr.inline-editor').length > 0 )
mp-wp_genesis 26 t.revert();
mp-wp_genesis 27 });
mp-wp_genesis 28 },
mp-wp_genesis 29
mp-wp_genesis 30 toggle : function(el) {
mp-wp_genesis 31 var t = this;
mp-wp_genesis 32
mp-wp_genesis 33 $(t.what+t.getId(el)).css('display') == 'none' ? t.revert() : t.edit(el);
mp-wp_genesis 34 },
mp-wp_genesis 35
mp-wp_genesis 36 addEvents : function(r) {
mp-wp_genesis 37 r.each(function() {
mp-wp_genesis 38 $(this).find('a.editinline').click(function() { inlineEditTax.edit(this); return false; });
mp-wp_genesis 39 $(this).find('.hide-if-no-js').removeClass('hide-if-no-js');
mp-wp_genesis 40 });
mp-wp_genesis 41 },
mp-wp_genesis 42
mp-wp_genesis 43 edit : function(id) {
mp-wp_genesis 44 var t = this;
mp-wp_genesis 45 t.revert();
mp-wp_genesis 46
mp-wp_genesis 47 if ( typeof(id) == 'object' )
mp-wp_genesis 48 id = t.getId(id);
mp-wp_genesis 49
mp-wp_genesis 50 var editRow = $('#inline-edit').clone(true), rowData = $('#inline_'+id);
mp-wp_genesis 51 $('td', editRow).attr('colspan', $('.widefat:first thead th:visible').length);
mp-wp_genesis 52
mp-wp_genesis 53 if ( $(t.what+id).hasClass('alternate') )
mp-wp_genesis 54 $(editRow).addClass('alternate');
mp-wp_genesis 55
mp-wp_genesis 56 $(t.what+id).hide().after(editRow);
mp-wp_genesis 57
mp-wp_genesis 58 $(':input[name="name"]', editRow).val( $('.name', rowData).text() );
mp-wp_genesis 59 $(':input[name="slug"]', editRow).val( $('.slug', rowData).text() );
mp-wp_genesis 60
mp-wp_genesis 61 // cat parents
mp-wp_genesis 62 var cat_parent = $('.cat_parent', rowData).text();
mp-wp_genesis 63 if ( cat_parent != '0' )
mp-wp_genesis 64 $('select[name="parent"]', editRow).val(cat_parent);
mp-wp_genesis 65
mp-wp_genesis 66 // remove the current parent and children from the parent dropdown
mp-wp_genesis 67 var pageOpt = $('select[name="parent"] option[value="'+id+'"]', editRow);
mp-wp_genesis 68 if ( pageOpt.length > 0 ) {
mp-wp_genesis 69 var pageLevel = pageOpt[0].className.split('-')[1], nextPage = pageOpt, pageLoop = true;
mp-wp_genesis 70 while ( pageLoop ) {
mp-wp_genesis 71 var nextPage = nextPage.next('option');
mp-wp_genesis 72 if (nextPage.length == 0) break;
mp-wp_genesis 73 var nextLevel = nextPage[0].className.split('-')[1];
mp-wp_genesis 74 if ( nextLevel <= pageLevel ) {
mp-wp_genesis 75 pageLoop = false;
mp-wp_genesis 76 } else {
mp-wp_genesis 77 nextPage.remove();
mp-wp_genesis 78 nextPage = pageOpt;
mp-wp_genesis 79 }
mp-wp_genesis 80 }
mp-wp_genesis 81 pageOpt.remove();
mp-wp_genesis 82 }
mp-wp_genesis 83
mp-wp_genesis 84 $(editRow).attr('id', 'edit-'+id).addClass('inline-editor').show();
mp-wp_genesis 85 $('.ptitle', editRow).eq(0).focus();
mp-wp_genesis 86
mp-wp_genesis 87 return false;
mp-wp_genesis 88 },
mp-wp_genesis 89
mp-wp_genesis 90 save : function(id) {
mp-wp_genesis 91 if( typeof(id) == 'object' )
mp-wp_genesis 92 id = this.getId(id);
mp-wp_genesis 93
mp-wp_genesis 94 $('table.widefat .inline-edit-save .waiting').show();
mp-wp_genesis 95
mp-wp_genesis 96 var params = {
mp-wp_genesis 97 action: 'inline-save-tax',
mp-wp_genesis 98 tax_type: this.type,
mp-wp_genesis 99 tax_ID: id
mp-wp_genesis 100 };
mp-wp_genesis 101
mp-wp_genesis 102 var fields = $('#edit-'+id+' :input').fieldSerialize();
mp-wp_genesis 103 params = fields + '&' + $.param(params);
mp-wp_genesis 104
mp-wp_genesis 105 // make ajax request
mp-wp_genesis 106 $.post('admin-ajax.php', params,
mp-wp_genesis 107 function(r) {
mp-wp_genesis 108
mp-wp_genesis 109 $('table.widefat .inline-edit-save .waiting').hide();
mp-wp_genesis 110
mp-wp_genesis 111 if (r) {
mp-wp_genesis 112 if ( -1 != r.indexOf('<tr') ) {
mp-wp_genesis 113 $(inlineEditTax.what+id).remove();
mp-wp_genesis 114 $('#edit-'+id).before(r).remove();
mp-wp_genesis 115
mp-wp_genesis 116 var row = $(inlineEditTax.what+id);
mp-wp_genesis 117 row.hide();
mp-wp_genesis 118
mp-wp_genesis 119 row.find('.hide-if-no-js').removeClass('hide-if-no-js');
mp-wp_genesis 120 inlineEditTax.addEvents(row);
mp-wp_genesis 121 row.fadeIn();
mp-wp_genesis 122 } else
mp-wp_genesis 123 $('#edit-'+id+' .inline-edit-save .error').html(r).show();
mp-wp_genesis 124 } else
mp-wp_genesis 125 $('#edit-'+id+' .inline-edit-save .error').html(inlineEditL10n.error).show();
mp-wp_genesis 126 }
mp-wp_genesis 127 );
mp-wp_genesis 128 return false;
mp-wp_genesis 129 },
mp-wp_genesis 130
mp-wp_genesis 131 revert : function() {
mp-wp_genesis 132 var id = $('table.widefat tr.inline-editor').attr('id');
mp-wp_genesis 133
mp-wp_genesis 134 if ( id ) {
mp-wp_genesis 135 $('table.widefat .inline-edit-save .waiting').hide();
mp-wp_genesis 136 $('#'+id).remove();
mp-wp_genesis 137 id = id.substr( id.lastIndexOf('-') + 1 );
mp-wp_genesis 138 $(this.what+id).show();
mp-wp_genesis 139 }
mp-wp_genesis 140
mp-wp_genesis 141 return false;
mp-wp_genesis 142 },
mp-wp_genesis 143
mp-wp_genesis 144 getId : function(o) {
mp-wp_genesis 145 var id = o.tagName == 'TR' ? o.id : $(o).parents('tr').attr('id');
mp-wp_genesis 146 var parts = id.split('-');
mp-wp_genesis 147 return parts[parts.length - 1];
mp-wp_genesis 148 }
mp-wp_genesis 149 };
mp-wp_genesis 150
mp-wp_genesis 151 $(document).ready(function(){inlineEditTax.init();});
mp-wp_genesis 152 })(jQuery);