2015-07-20 19:39:24 -04:00
|
|
|
/* global postboxes, commentL10n */
|
2017-06-15 09:02:40 -04:00
|
|
|
|
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Binds to the document ready event.
|
2017-06-15 09:02:40 -04:00
|
|
|
*
|
|
|
|
* @since 2.5.0
|
|
|
|
*
|
|
|
|
* @param {jQuery} $ The jQuery object.
|
|
|
|
*/
|
2012-08-22 20:04:18 -04:00
|
|
|
jQuery(document).ready( function($) {
|
|
|
|
|
2012-09-03 11:39:06 -04:00
|
|
|
postboxes.add_postbox_toggles('comment');
|
|
|
|
|
2015-07-21 18:09:25 -04:00
|
|
|
var $timestampdiv = $('#timestampdiv'),
|
2015-07-25 22:26:24 -04:00
|
|
|
$timestamp = $( '#timestamp' ),
|
|
|
|
stamp = $timestamp.html(),
|
|
|
|
$timestampwrap = $timestampdiv.find( '.timestamp-wrap' ),
|
|
|
|
$edittimestamp = $timestampdiv.siblings( 'a.edit-timestamp' );
|
2015-07-21 18:09:25 -04:00
|
|
|
|
2017-06-15 09:02:40 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Adds event that opens the time stamp form if the form is hidden.
|
2017-06-15 09:02:40 -04:00
|
|
|
*
|
|
|
|
* @listens $edittimestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-07-25 22:26:24 -04:00
|
|
|
$edittimestamp.click( function( event ) {
|
2015-07-21 18:09:25 -04:00
|
|
|
if ( $timestampdiv.is( ':hidden' ) ) {
|
2017-06-15 09:02:40 -04:00
|
|
|
// Slide down the form and set focus on the first field.
|
2015-07-21 18:46:24 -04:00
|
|
|
$timestampdiv.slideDown( 'fast', function() {
|
2015-07-25 22:26:24 -04:00
|
|
|
$( 'input, select', $timestampwrap ).first().focus();
|
2015-07-21 18:46:24 -04:00
|
|
|
} );
|
2015-07-21 18:09:25 -04:00
|
|
|
$(this).hide();
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
2015-07-21 18:09:25 -04:00
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-06-15 09:02:40 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Resets the time stamp values when the cancel button is clicked.
|
2017-06-15 09:02:40 -04:00
|
|
|
*
|
|
|
|
* @listens .cancel-timestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
|
2015-07-21 18:09:25 -04:00
|
|
|
$timestampdiv.find('.cancel-timestamp').click( function( event ) {
|
2015-07-25 22:26:24 -04:00
|
|
|
// Move focus back to the Edit link.
|
|
|
|
$edittimestamp.show().focus();
|
|
|
|
$timestampdiv.slideUp( 'fast' );
|
2012-08-22 20:04:18 -04: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-25 22:26:24 -04:00
|
|
|
$timestamp.html( stamp );
|
2015-07-21 18:09:25 -04:00
|
|
|
event.preventDefault();
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
|
2017-06-15 09:02:40 -04:00
|
|
|
/**
|
2017-12-18 09:14:53 -05:00
|
|
|
* Sets the time stamp values when the ok button is clicked.
|
2017-06-15 09:02:40 -04:00
|
|
|
*
|
|
|
|
* @listens .save-timestamp:click
|
|
|
|
*
|
|
|
|
* @param {Event} event The event object.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2015-07-21 18:09:25 -04:00
|
|
|
$timestampdiv.find('.save-timestamp').click( function( event ) { // crazyhorse - multiple ok cancels
|
2012-08-22 20:04:18 -04: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-21 18:09:25 -04:00
|
|
|
event.preventDefault();
|
|
|
|
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( newD.getFullYear() != aa || (1 + newD.getMonth()) != mm || newD.getDate() != jj || newD.getMinutes() != mn ) {
|
2015-07-25 22:26:24 -04:00
|
|
|
$timestampwrap.addClass( 'form-invalid' );
|
2015-07-21 18:09:25 -04:00
|
|
|
return;
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
2015-07-25 22:26:24 -04:00
|
|
|
$timestampwrap.removeClass( 'form-invalid' );
|
2012-08-22 20:04:18 -04:00
|
|
|
}
|
|
|
|
|
2015-07-25 22:26:24 -04:00
|
|
|
$timestamp.html(
|
2012-08-22 20:04:18 -04:00
|
|
|
commentL10n.submittedOn + ' <b>' +
|
2015-07-21 18:09:25 -04: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-22 20:04:18 -04:00
|
|
|
);
|
2015-07-21 18:09:25 -04:00
|
|
|
|
2015-07-25 22:26:24 -04:00
|
|
|
// Move focus back to the Edit link.
|
|
|
|
$edittimestamp.show().focus();
|
|
|
|
$timestampdiv.slideUp( 'fast' );
|
2012-08-22 20:04:18 -04:00
|
|
|
});
|
|
|
|
});
|