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