2018-06-28 04:30:15 +02:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/comment.js
|
|
|
|
*/
|
|
|
|
|
2015-07-21 01:39:24 +02:00
|
|
|
/* global postboxes, commentL10n */
|
2017-06-15 15:02:40 +02:00
|
|
|
|
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Binds to the document ready event.
|
2017-06-15 15:02:40 +02:00
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param {jQuery} $ The jQuery object.
|
|
|
|
*/
|
2012-08-23 02:04:18 +02:00
|
|
|
jQuery(document).ready( function($) {
|
|
|
|
|
2012-09-03 17:39:06 +02:00
|
|
|
postboxes.add_postbox_toggles('comment');
|
|
|
|
|
2015-07-22 00:09:25 +02:00
|
|
|
var $timestampdiv = $('#timestampdiv'),
|
2015-07-26 04:26:24 +02:00
|
|
|
$timestamp = $( '#timestamp' ),
|
|
|
|
stamp = $timestamp.html(),
|
|
|
|
$timestampwrap = $timestampdiv.find( '.timestamp-wrap' ),
|
|
|
|
$edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' );
|
2015-07-22 00:09:25 +02:00
|
|
|
|
2017-06-15 15:02:40 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Adds event that opens the time stamp form if the form is hidden.
|
2017-06-15 15:02:40 +02:00
|
|
|
*
|
|
|
|
* @listens $edittimestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-07-26 04:26:24 +02:00
|
|
|
$edittimestamp.click( function( event ) {
|
2015-07-22 00:09:25 +02:00
|
|
|
if ( $timestampdiv.is( ':hidden' ) ) {
|
2017-06-15 15:02:40 +02:00
|
|
|
// Slide down the form and set focus on the first field.
|
2015-07-22 00:46:24 +02:00
|
|
|
$timestampdiv.slideDown( 'fast', function() {
|
2015-07-26 04:26:24 +02:00
|
|
|
$( 'input, select', $timestampwrap ).first().focus();
|
2015-07-22 00:46:24 +02:00
|
|
|
} );
|
2015-07-22 00:09:25 +02:00
|
|
|
$(this).hide();
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
2015-07-22 00:09:25 +02:00
|
|
|
event.preventDefault();
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2017-06-15 15:02:40 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Resets the time stamp values when the cancel button is clicked.
|
2017-06-15 15:02:40 +02:00
|
|
|
*
|
|
|
|
* @listens .cancel-timestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
|
2015-07-22 00:09:25 +02:00
|
|
|
$timestampdiv.find('.cancel-timestamp').click( function( event ) {
|
2015-07-26 04:26:24 +02:00
|
|
|
// Move focus back to the Edit link.
|
|
|
|
$edittimestamp.show().focus();
|
|
|
|
$timestampdiv.slideUp( 'fast' );
|
2012-08-23 02:04:18 +02:00
|
|
|
$('#mm').val($('#hidden_mm').val());
|
|
|
|
$('#jj').val($('#hidden_jj').val());
|
|
|
|
$('#aa').val($('#hidden_aa').val());
|
|
|
|
$('#hh').val($('#hidden_hh').val());
|
|
|
|
$('#mn').val($('#hidden_mn').val());
|
2015-07-26 04:26:24 +02:00
|
|
|
$timestamp.html( stamp );
|
2015-07-22 00:09:25 +02:00
|
|
|
event.preventDefault();
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
|
2017-06-15 15:02:40 +02:00
|
|
|
/**
|
2017-12-18 15:14:53 +01:00
|
|
|
* Sets the time stamp values when the ok button is clicked.
|
2017-06-15 15:02:40 +02:00
|
|
|
*
|
|
|
|
* @listens .save-timestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-07-22 00:09:25 +02:00
|
|
|
$timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
|
2012-08-23 02:04:18 +02:00
|
|
|
var aa = $('#aa').val(), mm = $('#mm').val(), jj = $('#jj').val(), hh = $('#hh').val(), mn = $('#mn').val(),
|
|
|
|
newD = new Date( aa, mm - 1, jj, hh, mn );
|
|
|
|
|
2015-07-22 00:09:25 +02:00
|
|
|
event.preventDefault();
|
|
|
|
|
2012-08-23 02:04:18 +02:00
|
|
|
if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
|
2015-07-26 04:26:24 +02:00
|
|
|
$timestampwrap.addClass( 'form-invalid' );
|
2015-07-22 00:09:25 +02:00
|
|
|
return;
|
2012-08-23 02:04:18 +02:00
|
|
|
} else {
|
2015-07-26 04:26:24 +02:00
|
|
|
$timestampwrap.removeClass( 'form-invalid' );
|
2012-08-23 02:04:18 +02:00
|
|
|
}
|
|
|
|
|
2015-07-26 04:26:24 +02:00
|
|
|
$timestamp.html(
|
2012-08-23 02:04:18 +02:00
|
|
|
commentL10n.submittedOn + ' <b>' +
|
2015-07-22 00:09:25 +02:00
|
|
|
commentL10n.dateFormat
|
|
|
|
.replace( '%1$s', $( 'option[value="' + mm + '"]', '#mm' ).attr( 'data-text' ) )
|
|
|
|
.replace( '%2$s', parseInt( jj, 10 ) )
|
|
|
|
.replace( '%3$s', aa )
|
|
|
|
.replace( '%4$s', ( '00' + hh ).slice( -2 ) )
|
|
|
|
.replace( '%5$s', ( '00' + mn ).slice( -2 ) ) +
|
|
|
|
'</b> '
|
2012-08-23 02:04:18 +02:00
|
|
|
);
|
2015-07-22 00:09:25 +02:00
|
|
|
|
2015-07-26 04:26:24 +02:00
|
|
|
// Move focus back to the Edit link.
|
|
|
|
$edittimestamp.show().focus();
|
|
|
|
$timestampdiv.slideUp( 'fast' );
|
2012-08-23 02:04:18 +02:00
|
|
|
});
|
|
|
|
});
|