[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  /**
   2   * @output wp-admin/js/comment.js
   3   */
   4  
   5  /* global postboxes, commentL10n */
   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(document).ready( 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       * @returns {void}
  31       */
  32      $edittimestamp.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().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       * @returns {void}
  50       */
  51  
  52      $timestampdiv.find('.cancel-timestamp').click( function( event ) {
  53          // Move focus back to the Edit link.
  54          $edittimestamp.show().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       * @returns {void}
  72       */
  73      $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - 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              commentL10n.submittedOn + ' <b>' +
  88              commentL10n.dateFormat
  89                  .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
  90                  .replace( '%2$s', parseInt( jj, 10 ) )
  91                  .replace( '%3$s', aa )
  92                  .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
  93                  .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
  94                  '</b> '
  95          );
  96  
  97          // Move focus back to the Edit link.
  98          $edittimestamp.show().focus();
  99          $timestampdiv.slideUp( 'fast' );
 100      });
 101  });


Generated: Sat Sep 21 01:00:03 2019 Cross-referenced by PHPXref 0.7.1