]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/comment.js
WordPress 4.7.1-scripts
[autoinstalls/wordpress.git] / wp-admin / js / comment.js
1 /* global postboxes, commentL10n */
2 jQuery(document).ready( function($) {
3
4         postboxes.add_postbox_toggles('comment');
5
6         var $timestampdiv = $('#timestampdiv'),
7                 $timestamp = $( '#timestamp' ),
8                 stamp = $timestamp.html(),
9                 $timestampwrap = $timestampdiv.find( '.timestamp-wrap' ),
10                 $edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' );
11
12         $edittimestamp.click( function( event ) {
13                 if ( $timestampdiv.is( ':hidden' ) ) {
14                         $timestampdiv.slideDown( 'fast', function() {
15                                 $( 'input, select', $timestampwrap ).first().focus();
16                         } );
17                         $(this).hide();
18                 }
19                 event.preventDefault();
20         });
21
22         $timestampdiv.find('.cancel-timestamp').click( function( event ) {
23                 // Move focus back to the Edit link.
24                 $edittimestamp.show().focus();
25                 $timestampdiv.slideUp( 'fast' );
26                 $('#mm').val($('#hidden_mm').val());
27                 $('#jj').val($('#hidden_jj').val());
28                 $('#aa').val($('#hidden_aa').val());
29                 $('#hh').val($('#hidden_hh').val());
30                 $('#mn').val($('#hidden_mn').val());
31                 $timestamp.html( stamp );
32                 event.preventDefault();
33         });
34
35         $timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
36                 var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(),
37                         newD = new Date( aa, mm - 1, jj, hh, mn );
38
39                 event.preventDefault();
40
41                 if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
42                         $timestampwrap.addClass( 'form-invalid' );
43                         return;
44                 } else {
45                         $timestampwrap.removeClass( 'form-invalid' );
46                 }
47
48                 $timestamp.html(
49                         commentL10n.submittedOn + ' <b>' +
50                         commentL10n.dateFormat
51                                 .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
52                                 .replace( '%2$s', parseInt( jj, 10 ) )
53                                 .replace( '%3$s', aa )
54                                 .replace( '%4$s', ( '00' + hh ).slice( -2 ) )
55                                 .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
56                                 '</b> '
57                 );
58
59                 // Move focus back to the Edit link.
60                 $edittimestamp.show().focus();
61                 $timestampdiv.slideUp( 'fast' );
62         });
63 });