home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-admin / js / comment.js < prev    next >
Encoding:
Text File  |  2017-06-15  |  2.7 KB  |  98 lines

  1. /* global postboxes, commentL10n */
  2.  
  3. /**
  4.  * @summary Binds to the document ready event.
  5.  *
  6.  * @since 2.5.0
  7.  *
  8.  * @param {jQuery} $ The jQuery object.
  9.  */
  10. jQuery(document).ready( function($) {
  11.  
  12.     postboxes.add_postbox_toggles('comment');
  13.  
  14.     var $timestampdiv = $('#timestampdiv'),
  15.         $timestamp = $( '#timestamp' ),
  16.         stamp = $timestamp.html(),
  17.         $timestampwrap = $timestampdiv.find( '.timestamp-wrap' ),
  18.         $edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' );
  19.  
  20.     /**
  21.      * @summary Adds event that opens the time stamp form if the form is hidden.
  22.      *
  23.      * @listens $edittimestamp:click
  24.      *
  25.      * @param {Event} event The event object.
  26.      * @returns {void}
  27.      */
  28.     $edittimestamp.click( function( event ) {
  29.         if ( $timestampdiv.is( ':hidden' ) ) {
  30.             // Slide down the form and set focus on the first field.
  31.             $timestampdiv.slideDown( 'fast', function() {
  32.                 $( 'input, select', $timestampwrap ).first().focus();
  33.             } );
  34.             $(this).hide();
  35.         }
  36.         event.preventDefault();
  37.     });
  38.  
  39.     /**
  40.      * @summary Resets the time stamp values when the cancel button is clicked.
  41.      *
  42.      * @listens .cancel-timestamp:click
  43.      *
  44.      * @param {Event} event The event object.
  45.      * @returns {void}
  46.      */
  47.  
  48.     $timestampdiv.find('.cancel-timestamp').click( function( event ) {
  49.         // Move focus back to the Edit link.
  50.         $edittimestamp.show().focus();
  51.         $timestampdiv.slideUp( 'fast' );
  52.         $('#mm').val($('#hidden_mm').val());
  53.         $('#jj').val($('#hidden_jj').val());
  54.         $('#aa').val($('#hidden_aa').val());
  55.         $('#hh').val($('#hidden_hh').val());
  56.         $('#mn').val($('#hidden_mn').val());
  57.         $timestamp.html( stamp );
  58.         event.preventDefault();
  59.     });
  60.  
  61.     /**
  62.      * @summary Sets the time stamp values when the ok button is clicked.
  63.      *
  64.      * @listens .save-timestamp:click
  65.      *
  66.      * @param {Event} event The event object.
  67.      * @returns {void}
  68.      */
  69.     $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
  70.         var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(),
  71.             newD = new Date( aa, mm - 1, jj, hh, mn );
  72.  
  73.         event.preventDefault();
  74.  
  75.         if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
  76.             $timestampwrap.addClass( 'form-invalid' );
  77.             return;
  78.         } else {
  79.             $timestampwrap.removeClass( 'form-invalid' );
  80.         }
  81.  
  82.         $timestamp.html(
  83.             commentL10n.submittedOn + ' <b>' +
  84.             commentL10n.dateFormat
  85.                 .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
  86.                 .replace( '%2$s', parseInt( jj, 10 ) )
  87.                 .replace( '%3$s', aa )
  88.                 .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
  89.                 .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
  90.                 '</b> '
  91.         );
  92.  
  93.         // Move focus back to the Edit link.
  94.         $edittimestamp.show().focus();
  95.         $timestampdiv.slideUp( 'fast' );
  96.     });
  97. });
  98.