comment.js 2.0 KB

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