PageSourceSearch

https://cdn.prohockeyrumors.com/wp-content/plugins/fv-view-comments-button/move-comment-form.js?ver=1765798926

js prohockeyrumors.com collected 2026-09-24 18:29:25 UTC 4,861 bytes, 171 lines download raw bytes

1document.addEventListener('DOMContentLoaded', function() {
2
3	jQuery(function( $ ){
4	
5		/**
6		 * Move the comment form to the bottom of the comments if the comments are longer than the window and you scroll down
7		 */
8		let comments_wrap = $( '#comments-wrap' ),
9			comments_list = $('.commentlist'), // .commentlist has to be checked first as it's used in Touch Three where #commments wraps #respond
10			last_scroll_position = false,
11			respond_position = false,
12			respond_wrap = false,
13			respond_placeholder = false,
14			cancel_reply = false,
15			comments_list_offset,
16			comments_list_height,
17			window_height;
18
19		// If Touch Three .commentlist is not found, use #comments
20		if ( ! comments_list.length ) {
21			comments_list = $('#comments');
22		}
23
24		// Touch Three does not have #comments_wrap but uses #comments
25		if ( ! comments_wrap.length ) {
26			comments_wrap = $('#comments');
27		}
28
29		function measure_comments() {
30			comments_list_offset = comments_list.offset(),
31
32			comments_list_height = comments_list.height(),
33			window_height = $( window ).height();
34
35			respond_position = false;
36
37			// Load elements, as on DCL they might be there yet if users are getting cached pages
38			if ( ! respond_wrap ) {
39				respond_wrap = $('#respond');
40			}
41
42			if ( ! cancel_reply ) {
43				cancel_reply = respond_wrap.find( '#cancel-comment-reply-link' );
44				if ( ! cancel_reply.length ) {
45					cancel_reply = false;
46				}
47			}
48
49			// Is the form still loading? Then try to get it on next run again
50			if ( typeof respond_wrap.data('fv-ajax-comment-form') != "undefined" ) {
51				respond_wrap = false;
52
53				jQuery( document ).trigger( 'fv_measure_comments_on_scroll' );
54				return;
55			}
56
57			if ( respond_placeholder && respond_wrap ) {
58				respond_placeholder.height( respond_wrap.outerHeight( true ) );
59			}
60
61			//console.log( 'DEBUG: measure_comments: comments_list_offset.top: ' + ( comments_list_offset ? comments_list_offset.top : 'none' ) + ' comments_list_height: ' + comments_list_height + ' cancel_reply: ' + cancel_reply );
62		}
63
64		function calculate_placeholder() {
65			if ( respond_placeholder ) {
66				respond_placeholder.remove();
67			}
68
69			return $( '<div id="respond-placeholder"></div>' ).height( respond_wrap.outerHeight(true) );
70		}
71
72		measure_comments();
73
74		var decounced_measure_comments = debounce( measure_comments, 100 );
75		$( window ).on( 'comments_toggle resize fv_cache_for_users_loaded fv_measure_comments_on_scroll', decounced_measure_comments );
76
77		$( window ).on( 'comments_toggle', function() {
78			respond_position = false;
79		} );
80
81		var decounced_scroll_check = debounce( scroll_check, 100 );
82		$( window ).on( 'scroll', decounced_scroll_check );
83
84		function scroll_check() {
85
86			/**
87			 * Initial actions
88			 */
89
90			// Intial check of comment form position
91			if ( ! respond_position && respond_wrap && comments_list_offset ) {
92				if ( respond_wrap.offset().top < comments_list_offset.top ) {
93					// console.log( 'DEBUG: Initial position of comment form is above comments...');
94
95					respond_position = 'top';
96
97					respond_placeholder = calculate_placeholder();
98
99					comments_wrap.append( respond_placeholder );
100
101				} else {
102					// console.log( 'DEBUG: Initial position of comment form is below comments, nothing to do!');
103					//console.log( comments_list, respond_wrap, comments_list_offset.top, respond_wrap.offset().top );
104
105					return;
106				}
107			}
108
109			/**
110			 * Recurring actions
111			 */
112	
113			if ( cancel_reply && ! cancel_reply.is( ':hidden') ) {
114				// console.log( 'DEBUG: Reply is open, nothing to do!' );
115				return;
116			}
117
118			var breaking_point = comments_list_offset.top + comments_list_height / 2,
119				scroll_position = $( window ).scrollTop();
120
121			// Avoid moving comment form if the user did not scroll since the last time
122			if ( last_scroll_position == scroll_position ) {
123				return;
124			}
125
126			if (
127				'top' == respond_position &&
128				comments_list_height > window_height &&
129				scroll_position > breaking_point
130			) {
131				console.log( 'DEBUG: Move comments form down' );
132
133				respond_placeholder = calculate_placeholder();
134				respond_wrap.replaceWith( respond_placeholder );
135				comments_wrap.append( respond_wrap );
136	
137				respond_position = 'bottom';
138
139				last_scroll_position = $( window ).scrollTop();
140
141			} else if (
142				'bottom' == respond_position &&
143				scroll_position < breaking_point
144			) {
145				console.log( 'DEBUG: Move comments form up' );
146
147				respond_placeholder.replaceWith( respond_wrap );
148				respond_placeholder = calculate_placeholder();
149				comments_wrap.append( respond_placeholder );
150
151				respond_position = 'top';
152
153				last_scroll_position = $( window ).scrollTop();
154
155			} else {
156				last_scroll_position = scroll_position;
157			}
158	
159		}
160
161		function debounce( func, wait) {
162			var timeout;
163			return function() {
164				clearTimeout(timeout);
165				timeout = setTimeout(func, wait);
166			};
167		}
168
169	});
170
171});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.