| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 {JQueryStatic} $ 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 * @param {Event} event The event object. 28 * @return {void} 29 */ 30 $edittimestamp.on( 'click', function( event ) { 31 if ( $timestampdiv.is( ':hidden' ) ) { 32 // Slide down the form and set focus on the first field. 33 $timestampdiv.slideDown( 'fast', function() { 34 $( 'input, select', $timestampwrap ).first().trigger( 'focus' ); 35 } ); 36 $(this).hide(); 37 } 38 event.preventDefault(); 39 }); 40 41 /** 42 * Resets the time stamp values when the cancel button is clicked. 43 * 44 * @param {Event} event The event object. 45 * @return {void} 46 */ 47 48 $timestampdiv.find('.cancel-timestamp').on( 'click', function( event ) { 49 // Move focus back to the Edit link. 50 $edittimestamp.show().trigger( '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 * Sets the time stamp values when the ok button is clicked. 63 * 64 * @param {Event} event The event object. 65 * @return {void} 66 */ 67 $timestampdiv.find('.save-timestamp').on( 'click', function( event ) { // Crazyhorse branch - multiple OK cancels. 68 var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(), 69 newD = new Date( aa, mm - 1, jj, hh, mn ); 70 71 event.preventDefault(); 72 73 if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) { 74 $timestampwrap.addClass( 'form-invalid' ); 75 return; 76 } else { 77 $timestampwrap.removeClass( 'form-invalid' ); 78 } 79 80 $timestamp.html( 81 wp.i18n.__( 'Submitted on:' ) + ' <b>' + 82 /* translators: 1: Month, 2: Day, 3: Year, 4: Hour, 5: Minute. */ 83 wp.i18n.__( '%1$s %2$s, %3$s at %4$s:%5$s' ) 84 .replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) ) 85 .replace( '%2$s', parseInt( jj, 10 ) ) 86 .replace( '%3$s', aa ) 87 .replace( '%4$s', ( '00' + hh ).slice( -2 ) ) 88 .replace( '%5$s', ( '00' + mn ).slice( -2 ) ) + 89 '</b> ' 90 ); 91 92 // Move focus back to the Edit link. 93 $edittimestamp.show().trigger( 'focus' ); 94 $timestampdiv.slideUp( 'fast' ); 95 }); 96 97 var $commentparentdiv = $( '#comment-parent-div' ), 98 $commentparentdisplay = $( '#comment-parent-display' ), 99 originalcommentparentdisplay = $commentparentdisplay.html(), 100 $editcommentparent = $commentparentdiv.siblings( 'a.edit-comment-parent' ); 101 102 /** 103 * Adds event that opens the parent comment form if the form is hidden. 104 * 105 * @since 7.1.0 106 * 107 * @param {Event} event The event object. 108 * @return {void} 109 */ 110 $editcommentparent.on( 'click', function( event ) { 111 if ( $commentparentdiv.is( ':hidden' ) ) { 112 // Slide down the form and set focus on the parent field. 113 $commentparentdiv.slideDown( 'fast', function() { 114 $( '#comment_parent' ).trigger( 'focus' ); 115 } ); 116 $(this).hide(); 117 } 118 event.preventDefault(); 119 }); 120 121 /** 122 * Resets the parent comment value when the cancel button is clicked. 123 * 124 * @since 7.1.0 125 * 126 * @param {Event} event The event object. 127 * @return {void} 128 */ 129 $commentparentdiv.find( '.cancel-comment-parent' ).on( 'click', function( event ) { 130 // Move focus back to the Edit link. 131 $editcommentparent.show().trigger( 'focus' ); 132 $commentparentdiv.slideUp( 'fast' ); 133 $( '#comment_parent' ).val( $( '#hidden_comment_parent' ).val() ); 134 $commentparentdisplay.html( originalcommentparentdisplay ); 135 event.preventDefault(); 136 }); 137 138 /** 139 * Updates the parent comment display when the ok button is clicked. 140 * 141 * @since 7.1.0 142 * 143 * @param {Event} event The event object. 144 * @return {void} 145 */ 146 $commentparentdiv.find( '.save-comment-parent' ).on( 'click', function( event ) { 147 var $selected = $( '#comment_parent option:selected' ), 148 parentLabel = '0' === $selected.val() ? 149 /* translators: Displayed when a comment has no parent. */ 150 wp.i18n.__( 'None' ) : 151 $selected.data( 'author' ) || $selected.text(); 152 153 event.preventDefault(); 154 155 $commentparentdisplay.html( 156 wp.i18n.sprintf( 157 /* translators: %s: Parent comment link, or 'None'. */ 158 wp.i18n.__( 'In reply to: %s' ), 159 $( '<b />' ).text( parentLabel ).prop( 'outerHTML' ) 160 ) 161 ); 162 163 // Move focus back to the Edit link. 164 $editcommentparent.show().trigger( 'focus' ); 165 $commentparentdiv.slideUp( 'fast' ); 166 }); 167 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Sat Oct 10 08:20:33 2026 | Cross-referenced by PHPXref |