[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   1  /**
   2   * @output wp-admin/js/comment.js
   3   */
   4  
   5  /* global postboxes */
   6  
   7  /**
   8   * Binds to the document ready event.
   9   *
  10   * @since 2.5.0
  11   *
  12   * @param {jQuery} $ The jQuery object.
  13   */
  14  jQuery( function($) {
  15  
  16      postboxes.add_postbox_toggles('comment');
  17  
  18      var $timestampdiv = $('#timestampdiv'),
  19          $timestamp = $( '#timestamp' ),
  20          stamp = $timestamp.html(),
  21          $timestampwrap = $timestampdiv.find( '.timestamp-wrap' ),
  22          $edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' );
  23  
  24      /**
  25       * Adds event that opens the time stamp form if the form is hidden.
  26       *
  27       * @listens $edittimestamp:click
  28       *
  29       * @param {Event} event The event object.
  30       * @return {void}
  31       */
  32      $edittimestamp.on( 'click', function( event ) {
  33          if ( $timestampdiv.is( ':hidden' ) ) {
  34              // Slide down the form and set focus on the first field.
  35              $timestampdiv.slideDown( 'fast', function() {
  36                  $( 'input, select', $timestampwrap ).first().trigger( 'focus' );
  37              } );
  38              $(this).hide();
  39          }
  40          event.preventDefault();
  41      });
  42  
  43      /**
  44       * Resets the time stamp values when the cancel button is clicked.
  45       *
  46       * @listens .cancel-timestamp:click
  47       *
  48       * @param {Event} event The event object.
  49       * @return {void}
  50       */
  51  
  52      $timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) {
  53          // Move focus back to the Edit link.
  54          $edittimestamp.show().trigger( 'focus' );
  55          $timestampdiv.slideUp( 'fast' );
  56          $('#mm').val($('#hidden_mm').val());
  57          $('#jj').val($('#hidden_jj').val());
  58          $('#aa').val($('#hidden_aa').val());
  59          $('#hh').val($('#hidden_hh').val());
  60          $('#mn').val($('#hidden_mn').val());
  61          $timestamp.html( stamp );
  62          event.preventDefault();
  63      });
  64  
  65      /**
  66       * Sets the time stamp values when the ok button is clicked.
  67       *
  68       * @listens .save-timestamp:click
  69       *
  70       * @param {Event} event The event object.
  71       * @return {void}
  72       */
  73      $timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels.
  74          var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(),
  75              newD = new Date( aa, mm - 1, jj, hh, mn );
  76  
  77          event.preventDefault();
  78  
  79          if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
  80              $timestampwrap.addClass( 'form-invalid' );
  81              return;
  82          } else {
  83              $timestampwrap.removeClass( 'form-invalid' );
  84          }
  85  
  86          $timestamp.html(
  87              wp.i18n.__( 'Submitted on:' ) + ' <b>' +
  88              /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */
  89              wp.i18n.__( '%1$s %2$s, %3$s at %4$s:%5$s' )
  90                  .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
  91                  .replace( '%2$s', parseInt( jj, 10 ) )
  92                  .replace( '%3$s', aa )
  93                  .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
  94                  .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
  95                  '</b> '
  96          );
  97  
  98          // Move focus back to the Edit link.
  99          $edittimestamp.show().trigger( 'focus' );
 100          $timestampdiv.slideUp( 'fast' );
 101      });
 102  
 103      var $commentparentdiv = $( '#comment-parent-div' ),
 104          $commentparentdisplay = $( '#comment-parent-display' ),
 105          originalcommentparentdisplay = $commentparentdisplay.html(),
 106          $editcommentparent = $commentparentdiv.siblings( 'a.edit-comment-parent' );
 107  
 108      /**
 109       * Adds event that opens the parent comment form if the form is hidden.
 110       *
 111       * @since 7.1.0
 112       *
 113       * @listens $editcommentparent:click
 114       *
 115       * @param {Event} event The event object.
 116       * @return {void}
 117       */
 118      $editcommentparent.on( 'click', function( event ) {
 119          if ( $commentparentdiv.is( ':hidden' ) ) {
 120              // Slide down the form and set focus on the parent field.
 121              $commentparentdiv.slideDown( 'fast', function() {
 122                  $( '#comment_parent' ).trigger( 'focus' );
 123              } );
 124              $(this).hide();
 125          }
 126          event.preventDefault();
 127      });
 128  
 129      /**
 130       * Resets the parent comment value when the cancel button is clicked.
 131       *
 132       * @since 7.1.0
 133       *
 134       * @listens .cancel-comment-parent:click
 135       *
 136       * @param {Event} event The event object.
 137       * @return {void}
 138       */
 139      $commentparentdiv.find( '.cancel-comment-parent' ).on( 'click', function( event ) {
 140          // Move focus back to the Edit link.
 141          $editcommentparent.show().trigger( 'focus' );
 142          $commentparentdiv.slideUp( 'fast' );
 143          $( '#comment_parent' ).val( $( '#hidden_comment_parent' ).val() );
 144          $commentparentdisplay.html( originalcommentparentdisplay );
 145          event.preventDefault();
 146      });
 147  
 148      /**
 149       * Updates the parent comment display when the ok button is clicked.
 150       *
 151       * @since 7.1.0
 152       *
 153       * @listens .save-comment-parent:click
 154       *
 155       * @param {Event} event The event object.
 156       * @return {void}
 157       */
 158      $commentparentdiv.find( '.save-comment-parent' ).on( 'click', function( event ) {
 159          var $selected = $( '#comment_parent option:selected' ),
 160              parentLabel = '0' === $selected.val() ?
 161                  /* translators: Displayed when a comment has no parent. */
 162                  wp.i18n.__( 'None' ) :
 163                  $selected.data( 'author' ) || $selected.text();
 164  
 165          event.preventDefault();
 166  
 167          $commentparentdisplay.html(
 168              wp.i18n.sprintf(
 169                  /* translators: %s: Parent comment link, or 'None'. */
 170                  wp.i18n.__( 'In reply to: %s' ),
 171                  $( '<b />' ).text( parentLabel ).prop( 'outerHTML' )
 172              )
 173          );
 174  
 175          // Move focus back to the Edit link.
 176          $editcommentparent.show().trigger( 'focus' );
 177          $commentparentdiv.slideUp( 'fast' );
 178      });
 179  });


Generated : Sun Jul 12 08:20:14 2026 Cross-referenced by PHPXref