[ Index ]

PHP Cross Reference of Wordpress 2.7.1

title

Body

[close]

/wp-admin/js/ -> inline-edit-tax.js (source)

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


Generated: Mon Mar 23 16:23:02 2009 Cross-referenced by PHPXref 0.7