[ Index ]

WordPress Cross Reference

title

Body

[close]

/wp-admin/js/ -> tags.js (source)

   1  /* global ajaxurl, wpAjax, tagsl10n, showNotice, validateForm */
   2  
   3  jQuery(document).ready(function($) {
   4  
   5      $( '#the-list' ).on( 'click', '.delete-tag', function() {
   6          var t = $(this), tr = t.parents('tr'), r = true, data;
   7          if ( 'undefined' != showNotice )
   8              r = showNotice.warn();
   9          if ( r ) {
  10              data = t.attr('href').replace(/[^?]*\?/, '').replace(/action=delete/, 'action=delete-tag');
  11              $.post(ajaxurl, data, function(r){
  12                  if ( '1' == r ) {
  13                      $('#ajax-response').empty();
  14                      tr.fadeOut('normal', function(){ tr.remove(); });
  15                      // Remove the term from the parent box and tag cloud
  16                      $('select#parent option[value="' + data.match(/tag_ID=(\d+)/)[1] + '"]').remove();
  17                      $('a.tag-link-' + data.match(/tag_ID=(\d+)/)[1]).remove();
  18                  } else if ( '-1' == r ) {
  19                      $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.noPerm + '</p></div>');
  20                      tr.children().css('backgroundColor', '');
  21                  } else {
  22                      $('#ajax-response').empty().append('<div class="error"><p>' + tagsl10n.broken + '</p></div>');
  23                      tr.children().css('backgroundColor', '');
  24                  }
  25              });
  26              tr.children().css('backgroundColor', '#f33');
  27          }
  28          return false;
  29      });
  30  
  31      $('#submit').click(function(){
  32          var form = $(this).parents('form');
  33  
  34          if ( ! validateForm( form ) )
  35              return false;
  36  
  37          $.post(ajaxurl, $('#addtag').serialize(), function(r){
  38              var res, parent, term, indent, i;
  39  
  40              $('#ajax-response').empty();
  41              res = wpAjax.parseAjaxResponse( r, 'ajax-response' );
  42              if ( ! res || res.errors )
  43                  return;
  44  
  45              parent = form.find( 'select#parent' ).val();
  46  
  47              if ( parent > 0 && $('#tag-' + parent ).length > 0 ) // If the parent exists on this page, insert it below. Else insert it at the top of the list.
  48                  $( '.tags #tag-' + parent ).after( res.responses[0].supplemental.noparents ); // As the parent exists, Insert the version with - - - prefixed
  49              else
  50                  $( '.tags' ).prepend( res.responses[0].supplemental.parents ); // As the parent is not visible, Insert the version with Parent - Child - ThisTerm
  51  
  52              $('.tags .no-items').remove();
  53  
  54              if ( form.find('select#parent') ) {
  55                  // Parents field exists, Add new term to the list.
  56                  term = res.responses[1].supplemental;
  57  
  58                  // Create an indent for the Parent field
  59                  indent = '';
  60                  for ( i = 0; i < res.responses[1].position; i++ )
  61                      indent += '&nbsp;&nbsp;&nbsp;';
  62  
  63                  form.find( 'select#parent option:selected' ).after( '<option value="' + term.term_id + '">' + indent + term.name + '</option>' );
  64              }
  65  
  66              $('input[type="text"]:visible, textarea:visible', form).val('');
  67          });
  68  
  69          return false;
  70      });
  71  
  72  });


Generated: Tue Mar 25 01:41:18 2014 WordPress honlapkészítés: online1.hu