You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

97 lines
2.6 KiB

  1. var addComment = {
  2. moveForm: function( commId, parentId, respondId, postId ) {
  3. var div, element, style, cssHidden,
  4. t = this,
  5. comm = t.I( commId ),
  6. respond = t.I( respondId ),
  7. cancel = t.I( 'cancel-comment-reply-link' ),
  8. parent = t.I( 'comment_parent' ),
  9. post = t.I( 'comment_post_ID' ),
  10. commentForm = respond.getElementsByTagName( 'form' )[0];
  11. if ( ! comm || ! respond || ! cancel || ! parent || ! commentForm ) {
  12. return;
  13. }
  14. t.respondId = respondId;
  15. postId = postId || false;
  16. if ( ! t.I( 'wp-temp-form-div' ) ) {
  17. div = document.createElement( 'div' );
  18. div.id = 'wp-temp-form-div';
  19. div.style.display = 'none';
  20. respond.parentNode.insertBefore( div, respond );
  21. }
  22. comm.parentNode.insertBefore( respond, comm.nextSibling );
  23. if ( post && postId ) {
  24. post.value = postId;
  25. }
  26. parent.value = parentId;
  27. cancel.style.display = '';
  28. cancel.onclick = function() {
  29. var t = addComment,
  30. temp = t.I( 'wp-temp-form-div' ),
  31. respond = t.I( t.respondId );
  32. if ( ! temp || ! respond ) {
  33. return;
  34. }
  35. t.I( 'comment_parent' ).value = '0';
  36. temp.parentNode.insertBefore( respond, temp );
  37. temp.parentNode.removeChild( temp );
  38. this.style.display = 'none';
  39. this.onclick = null;
  40. return false;
  41. };
  42. /*
  43. * Set initial focus to the first form focusable element.
  44. * Try/catch used just to avoid errors in IE 7- which return visibility
  45. * 'inherit' when the visibility value is inherited from an ancestor.
  46. */
  47. try {
  48. for ( var i = 0; i < commentForm.elements.length; i++ ) {
  49. element = commentForm.elements[i];
  50. cssHidden = false;
  51. // Modern browsers.
  52. if ( 'getComputedStyle' in window ) {
  53. style = window.getComputedStyle( element );
  54. // IE 8.
  55. } else if ( document.documentElement.currentStyle ) {
  56. style = element.currentStyle;
  57. }
  58. /*
  59. * For display none, do the same thing jQuery does. For visibility,
  60. * check the element computed style since browsers are already doing
  61. * the job for us. In fact, the visibility computed style is the actual
  62. * computed value and already takes into account the element ancestors.
  63. */
  64. if ( ( element.offsetWidth <= 0 && element.offsetHeight <= 0 ) || style.visibility === 'hidden' ) {
  65. cssHidden = true;
  66. }
  67. // Skip form elements that are hidden or disabled.
  68. if ( 'hidden' === element.type || element.disabled || cssHidden ) {
  69. continue;
  70. }
  71. element.focus();
  72. // Stop after the first focusable element.
  73. break;
  74. }
  75. } catch( er ) {}
  76. return false;
  77. },
  78. I: function( id ) {
  79. return document.getElementById( id );
  80. }
  81. };