author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* Heartbeat API |
|
3 |
* |
|
5 | 4 |
* Heartbeat is a simple server polling API that sends XHR requests to |
5 |
* the server every 15 - 60 seconds and triggers events (or callbacks) upon |
|
6 |
* receiving data. Currently these 'ticks' handle transports for post locking, |
|
7 |
* login-expiration warnings, autosave, and related tasks while a user is logged in. |
|
0 | 8 |
* |
5 | 9 |
* Available PHP filters (in ajax-actions.php): |
0 | 10 |
* - heartbeat_received |
11 |
* - heartbeat_send |
|
12 |
* - heartbeat_tick |
|
13 |
* - heartbeat_nopriv_received |
|
14 |
* - heartbeat_nopriv_send |
|
15 |
* - heartbeat_nopriv_tick |
|
16 |
* @see wp_ajax_nopriv_heartbeat(), wp_ajax_heartbeat() |
|
17 |
* |
|
5 | 18 |
* Custom jQuery events: |
19 |
* - heartbeat-send |
|
20 |
* - heartbeat-tick |
|
21 |
* - heartbeat-error |
|
22 |
* - heartbeat-connection-lost |
|
23 |
* - heartbeat-connection-restored |
|
24 |
* - heartbeat-nonces-expired |
|
25 |
* |
|
0 | 26 |
* @since 3.6.0 |
9 | 27 |
* @output wp-includes/js/heartbeat.js |
0 | 28 |
*/ |
29 |
||
5 | 30 |
( function( $, window, undefined ) { |
9 | 31 |
|
32 |
/** |
|
33 |
* Constructs the Heartbeat API. |
|
34 |
* |
|
35 |
* @since 3.6.0 |
|
36 |
* |
|
16 | 37 |
* @return {Object} An instance of the Heartbeat class. |
9 | 38 |
* @constructor |
39 |
*/ |
|
0 | 40 |
var Heartbeat = function() { |
5 | 41 |
var $document = $(document), |
42 |
settings = { |
|
9 | 43 |
// Suspend/resume. |
5 | 44 |
suspend: false, |
45 |
||
9 | 46 |
// Whether suspending is enabled. |
5 | 47 |
suspendEnabled: true, |
48 |
||
9 | 49 |
// Current screen id, defaults to the JS global 'pagenow' when present |
50 |
// (in the admin) or 'front'. |
|
5 | 51 |
screenId: '', |
52 |
||
9 | 53 |
// XHR request URL, defaults to the JS global 'ajaxurl' when present. |
5 | 54 |
url: '', |
55 |
||
9 | 56 |
// Timestamp, start of the last connection request. |
5 | 57 |
lastTick: 0, |
58 |
||
9 | 59 |
// Container for the enqueued items. |
5 | 60 |
queue: {}, |
61 |
||
9 | 62 |
// Connect interval (in seconds). |
5 | 63 |
mainInterval: 60, |
64 |
||
16 | 65 |
// Used when the interval is set to 5 seconds temporarily. |
5 | 66 |
tempInterval: 0, |
67 |
||
9 | 68 |
// Used when the interval is reset. |
5 | 69 |
originalInterval: 0, |
70 |
||
16 | 71 |
// Used to limit the number of Ajax requests. |
5 | 72 |
minimalInterval: 0, |
73 |
||
9 | 74 |
// Used together with tempInterval. |
5 | 75 |
countdown: 0, |
76 |
||
9 | 77 |
// Whether a connection is currently in progress. |
5 | 78 |
connecting: false, |
79 |
||
9 | 80 |
// Whether a connection error occurred. |
5 | 81 |
connectionError: false, |
82 |
||
9 | 83 |
// Used to track non-critical errors. |
5 | 84 |
errorcount: 0, |
85 |
||
9 | 86 |
// Whether at least one connection has been completed successfully. |
5 | 87 |
hasConnected: false, |
88 |
||
9 | 89 |
// Whether the current browser window is in focus and the user is active. |
5 | 90 |
hasFocus: true, |
91 |
||
16 | 92 |
// Timestamp, last time the user was active. Checked every 30 seconds. |
5 | 93 |
userActivity: 0, |
94 |
||
9 | 95 |
// Flag whether events tracking user activity were set. |
5 | 96 |
userActivityEvents: false, |
97 |
||
9 | 98 |
// Timer that keeps track of how long a user has focus. |
5 | 99 |
checkFocusTimer: 0, |
9 | 100 |
|
101 |
// Timer that keeps track of how long needs to be waited before connecting to |
|
102 |
// the server again. |
|
5 | 103 |
beatTimer: 0 |
104 |
}; |
|
0 | 105 |
|
106 |
/** |
|
9 | 107 |
* Sets local variables and events, then starts the heartbeat. |
0 | 108 |
* |
16 | 109 |
* @since 3.8.0 |
5 | 110 |
* @access private |
111 |
* |
|
16 | 112 |
* @return {void} |
0 | 113 |
*/ |
5 | 114 |
function initialize() { |
115 |
var options, hidden, visibilityState, visibilitychange; |
|
116 |
||
117 |
if ( typeof window.pagenow === 'string' ) { |
|
118 |
settings.screenId = window.pagenow; |
|
119 |
} |
|
120 |
||
121 |
if ( typeof window.ajaxurl === 'string' ) { |
|
122 |
settings.url = window.ajaxurl; |
|
123 |
} |
|
124 |
||
9 | 125 |
// Pull in options passed from PHP. |
5 | 126 |
if ( typeof window.heartbeatSettings === 'object' ) { |
127 |
options = window.heartbeatSettings; |
|
128 |
||
9 | 129 |
// The XHR URL can be passed as option when window.ajaxurl is not set. |
5 | 130 |
if ( ! settings.url && options.ajaxurl ) { |
131 |
settings.url = options.ajaxurl; |
|
132 |
} |
|
133 |
||
9 | 134 |
/* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
135 |
* Logic check: the interval can be from 1 to 3600 seconds and can be set temporarily |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
136 |
* to 5 seconds. It can be set in the initial options or changed later from JS |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
137 |
* or from PHP through the AJAX responses. |
9 | 138 |
*/ |
5 | 139 |
if ( options.interval ) { |
140 |
settings.mainInterval = options.interval; |
|
0 | 141 |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
142 |
if ( settings.mainInterval < 1 ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
143 |
settings.mainInterval = 1; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
144 |
} else if ( settings.mainInterval > 3600 ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
145 |
settings.mainInterval = 3600; |
5 | 146 |
} |
147 |
} |
|
0 | 148 |
|
9 | 149 |
/* |
16 | 150 |
* Used to limit the number of Ajax requests. Overrides all other intervals |
151 |
* if they are shorter. Needed for some hosts that cannot handle frequent requests |
|
152 |
* and the user may exceed the allocated server CPU time, etc. The minimal interval |
|
153 |
* can be up to 600 seconds, however setting it to longer than 120 seconds |
|
154 |
* will limit or disable some of the functionality (like post locks). |
|
155 |
* Once set at initialization, minimalInterval cannot be changed/overridden. |
|
9 | 156 |
*/ |
5 | 157 |
if ( options.minimalInterval ) { |
158 |
options.minimalInterval = parseInt( options.minimalInterval, 10 ); |
|
19 | 159 |
settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval : 0; |
5 | 160 |
} |
161 |
||
162 |
if ( settings.minimalInterval && settings.mainInterval < settings.minimalInterval ) { |
|
163 |
settings.mainInterval = settings.minimalInterval; |
|
164 |
} |
|
165 |
||
9 | 166 |
// 'screenId' can be added from settings on the front end where the JS global |
167 |
// 'pagenow' is not set. |
|
5 | 168 |
if ( ! settings.screenId ) { |
169 |
settings.screenId = options.screenId || 'front'; |
|
170 |
} |
|
171 |
||
172 |
if ( options.suspension === 'disable' ) { |
|
173 |
settings.suspendEnabled = false; |
|
174 |
} |
|
175 |
} |
|
0 | 176 |
|
9 | 177 |
// Convert to milliseconds. |
5 | 178 |
settings.mainInterval = settings.mainInterval * 1000; |
179 |
settings.originalInterval = settings.mainInterval; |
|
19 | 180 |
if ( settings.minimalInterval ) { |
181 |
settings.minimalInterval = settings.minimalInterval * 1000; |
|
182 |
} |
|
5 | 183 |
|
9 | 184 |
/* |
185 |
* Switch the interval to 120 seconds by using the Page Visibility API. |
|
186 |
* If the browser doesn't support it (Safari < 7, Android < 4.4, IE < 10), the |
|
187 |
* interval will be increased to 120 seconds after 5 minutes of mouse and keyboard |
|
188 |
* inactivity. |
|
189 |
*/ |
|
5 | 190 |
if ( typeof document.hidden !== 'undefined' ) { |
191 |
hidden = 'hidden'; |
|
192 |
visibilitychange = 'visibilitychange'; |
|
193 |
visibilityState = 'visibilityState'; |
|
16 | 194 |
} else if ( typeof document.msHidden !== 'undefined' ) { // IE10. |
5 | 195 |
hidden = 'msHidden'; |
196 |
visibilitychange = 'msvisibilitychange'; |
|
197 |
visibilityState = 'msVisibilityState'; |
|
16 | 198 |
} else if ( typeof document.webkitHidden !== 'undefined' ) { // Android. |
5 | 199 |
hidden = 'webkitHidden'; |
200 |
visibilitychange = 'webkitvisibilitychange'; |
|
201 |
visibilityState = 'webkitVisibilityState'; |
|
202 |
} |
|
203 |
||
204 |
if ( hidden ) { |
|
205 |
if ( document[hidden] ) { |
|
206 |
settings.hasFocus = false; |
|
207 |
} |
|
0 | 208 |
|
5 | 209 |
$document.on( visibilitychange + '.wp-heartbeat', function() { |
210 |
if ( document[visibilityState] === 'hidden' ) { |
|
211 |
blurred(); |
|
212 |
window.clearInterval( settings.checkFocusTimer ); |
|
213 |
} else { |
|
214 |
focused(); |
|
215 |
if ( document.hasFocus ) { |
|
216 |
settings.checkFocusTimer = window.setInterval( checkFocus, 10000 ); |
|
217 |
} |
|
218 |
} |
|
219 |
}); |
|
220 |
} |
|
221 |
||
222 |
// Use document.hasFocus() if available. |
|
223 |
if ( document.hasFocus ) { |
|
224 |
settings.checkFocusTimer = window.setInterval( checkFocus, 10000 ); |
|
225 |
} |
|
0 | 226 |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
227 |
$(window).on( 'pagehide.wp-heartbeat', function() { |
9 | 228 |
// Don't connect anymore. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
229 |
suspend(); |
0 | 230 |
|
9 | 231 |
// Abort the last request if not completed. |
5 | 232 |
if ( settings.xhr && settings.xhr.readyState !== 4 ) { |
233 |
settings.xhr.abort(); |
|
234 |
} |
|
235 |
}); |
|
236 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
237 |
$(window).on( |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
238 |
'pageshow.wp-heartbeat', |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
239 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
240 |
* Handles pageshow event, specifically when page navigation is restored from back/forward cache. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
241 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
242 |
* @param {jQuery.Event} event |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
243 |
* @param {PageTransitionEvent} event.originalEvent |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
244 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
245 |
function ( event ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
246 |
if ( event.originalEvent.persisted ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
247 |
/* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
248 |
* When page navigation is stored via bfcache (Back/Forward Cache), consider this the same as |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
249 |
* if the user had just switched to the tab since the behavior is similar. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
250 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
251 |
focused(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
252 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
253 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
254 |
); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
255 |
|
5 | 256 |
// Check for user activity every 30 seconds. |
257 |
window.setInterval( checkUserActivity, 30000 ); |
|
258 |
||
9 | 259 |
// Start one tick after DOM ready. |
18 | 260 |
$( function() { |
5 | 261 |
settings.lastTick = time(); |
262 |
scheduleNextTick(); |
|
263 |
}); |
|
0 | 264 |
} |
265 |
||
5 | 266 |
/** |
9 | 267 |
* Returns the current time according to the browser. |
5 | 268 |
* |
16 | 269 |
* @since 3.6.0 |
5 | 270 |
* @access private |
271 |
* |
|
16 | 272 |
* @return {number} Returns the current time. |
5 | 273 |
*/ |
274 |
function time() { |
|
0 | 275 |
return (new Date()).getTime(); |
276 |
} |
|
277 |
||
5 | 278 |
/** |
9 | 279 |
* Checks if the iframe is from the same origin. |
5 | 280 |
* |
16 | 281 |
* @since 3.6.0 |
5 | 282 |
* @access private |
283 |
* |
|
16 | 284 |
* @return {boolean} Returns whether or not the iframe is from the same origin. |
5 | 285 |
*/ |
0 | 286 |
function isLocalFrame( frame ) { |
287 |
var origin, src = frame.src; |
|
288 |
||
9 | 289 |
/* |
290 |
* Need to compare strings as WebKit doesn't throw JS errors when iframes have |
|
291 |
* different origin. It throws uncatchable exceptions. |
|
292 |
*/ |
|
0 | 293 |
if ( src && /^https?:\/\//.test( src ) ) { |
294 |
origin = window.location.origin ? window.location.origin : window.location.protocol + '//' + window.location.host; |
|
295 |
||
5 | 296 |
if ( src.indexOf( origin ) !== 0 ) { |
0 | 297 |
return false; |
5 | 298 |
} |
0 | 299 |
} |
300 |
||
301 |
try { |
|
5 | 302 |
if ( frame.contentWindow.document ) { |
0 | 303 |
return true; |
5 | 304 |
} |
0 | 305 |
} catch(e) {} |
306 |
||
307 |
return false; |
|
308 |
} |
|
309 |
||
5 | 310 |
/** |
9 | 311 |
* Checks if the document's focus has changed. |
5 | 312 |
* |
16 | 313 |
* @since 4.1.0 |
5 | 314 |
* @access private |
315 |
* |
|
16 | 316 |
* @return {void} |
5 | 317 |
*/ |
318 |
function checkFocus() { |
|
319 |
if ( settings.hasFocus && ! document.hasFocus() ) { |
|
320 |
blurred(); |
|
321 |
} else if ( ! settings.hasFocus && document.hasFocus() ) { |
|
322 |
focused(); |
|
323 |
} |
|
324 |
} |
|
325 |
||
326 |
/** |
|
9 | 327 |
* Sets error state and fires an event on XHR errors or timeout. |
5 | 328 |
* |
16 | 329 |
* @since 3.8.0 |
5 | 330 |
* @access private |
331 |
* |
|
9 | 332 |
* @param {string} error The error type passed from the XHR. |
333 |
* @param {number} status The HTTP status code passed from jqXHR |
|
334 |
* (200, 404, 500, etc.). |
|
335 |
* |
|
16 | 336 |
* @return {void} |
5 | 337 |
*/ |
338 |
function setErrorState( error, status ) { |
|
0 | 339 |
var trigger; |
340 |
||
341 |
if ( error ) { |
|
342 |
switch ( error ) { |
|
343 |
case 'abort': |
|
9 | 344 |
// Do nothing. |
0 | 345 |
break; |
346 |
case 'timeout': |
|
16 | 347 |
// No response for 30 seconds. |
0 | 348 |
trigger = true; |
349 |
break; |
|
5 | 350 |
case 'error': |
351 |
if ( 503 === status && settings.hasConnected ) { |
|
352 |
trigger = true; |
|
353 |
break; |
|
354 |
} |
|
355 |
/* falls through */ |
|
0 | 356 |
case 'parsererror': |
357 |
case 'empty': |
|
358 |
case 'unknown': |
|
5 | 359 |
settings.errorcount++; |
0 | 360 |
|
5 | 361 |
if ( settings.errorcount > 2 && settings.hasConnected ) { |
0 | 362 |
trigger = true; |
5 | 363 |
} |
0 | 364 |
|
365 |
break; |
|
366 |
} |
|
367 |
||
5 | 368 |
if ( trigger && ! hasConnectionError() ) { |
369 |
settings.connectionError = true; |
|
370 |
$document.trigger( 'heartbeat-connection-lost', [error, status] ); |
|
9 | 371 |
wp.hooks.doAction( 'heartbeat.connection-lost', error, status ); |
0 | 372 |
} |
5 | 373 |
} |
374 |
} |
|
0 | 375 |
|
5 | 376 |
/** |
9 | 377 |
* Clears the error state and fires an event if there is a connection error. |
5 | 378 |
* |
16 | 379 |
* @since 3.8.0 |
5 | 380 |
* @access private |
381 |
* |
|
16 | 382 |
* @return {void} |
5 | 383 |
*/ |
384 |
function clearErrorState() { |
|
9 | 385 |
// Has connected successfully. |
5 | 386 |
settings.hasConnected = true; |
387 |
||
388 |
if ( hasConnectionError() ) { |
|
389 |
settings.errorcount = 0; |
|
390 |
settings.connectionError = false; |
|
391 |
$document.trigger( 'heartbeat-connection-restored' ); |
|
9 | 392 |
wp.hooks.doAction( 'heartbeat.connection-restored' ); |
0 | 393 |
} |
394 |
} |
|
395 |
||
5 | 396 |
/** |
9 | 397 |
* Gathers the data and connects to the server. |
5 | 398 |
* |
16 | 399 |
* @since 3.6.0 |
5 | 400 |
* @access private |
401 |
* |
|
16 | 402 |
* @return {void} |
5 | 403 |
*/ |
0 | 404 |
function connect() { |
5 | 405 |
var ajaxData, heartbeatData; |
0 | 406 |
|
5 | 407 |
// If the connection to the server is slower than the interval, |
408 |
// heartbeat connects as soon as the previous connection's response is received. |
|
409 |
if ( settings.connecting || settings.suspend ) { |
|
0 | 410 |
return; |
411 |
} |
|
412 |
||
5 | 413 |
settings.lastTick = time(); |
414 |
||
415 |
heartbeatData = $.extend( {}, settings.queue ); |
|
9 | 416 |
// Clear the data queue. Anything added after this point will be sent on the next tick. |
5 | 417 |
settings.queue = {}; |
418 |
||
419 |
$document.trigger( 'heartbeat-send', [ heartbeatData ] ); |
|
9 | 420 |
wp.hooks.doAction( 'heartbeat.send', heartbeatData ); |
0 | 421 |
|
5 | 422 |
ajaxData = { |
423 |
data: heartbeatData, |
|
424 |
interval: settings.tempInterval ? settings.tempInterval / 1000 : settings.mainInterval / 1000, |
|
425 |
_nonce: typeof window.heartbeatSettings === 'object' ? window.heartbeatSettings.nonce : '', |
|
426 |
action: 'heartbeat', |
|
427 |
screen_id: settings.screenId, |
|
428 |
has_focus: settings.hasFocus |
|
429 |
}; |
|
430 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
431 |
if ( 'customize' === settings.screenId ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
432 |
ajaxData.wp_customize = 'on'; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
433 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
434 |
|
5 | 435 |
settings.connecting = true; |
436 |
settings.xhr = $.ajax({ |
|
437 |
url: settings.url, |
|
0 | 438 |
type: 'post', |
16 | 439 |
timeout: 30000, // Throw an error if not completed after 30 seconds. |
5 | 440 |
data: ajaxData, |
0 | 441 |
dataType: 'json' |
5 | 442 |
}).always( function() { |
443 |
settings.connecting = false; |
|
444 |
scheduleNextTick(); |
|
0 | 445 |
}).done( function( response, textStatus, jqXHR ) { |
5 | 446 |
var newInterval; |
0 | 447 |
|
5 | 448 |
if ( ! response ) { |
449 |
setErrorState( 'empty' ); |
|
450 |
return; |
|
451 |
} |
|
0 | 452 |
|
5 | 453 |
clearErrorState(); |
0 | 454 |
|
455 |
if ( response.nonces_expired ) { |
|
5 | 456 |
$document.trigger( 'heartbeat-nonces-expired' ); |
9 | 457 |
wp.hooks.doAction( 'heartbeat.nonces-expired' ); |
0 | 458 |
} |
459 |
||
16 | 460 |
// Change the interval from PHP. |
0 | 461 |
if ( response.heartbeat_interval ) { |
5 | 462 |
newInterval = response.heartbeat_interval; |
0 | 463 |
delete response.heartbeat_interval; |
464 |
} |
|
465 |
||
9 | 466 |
// Update the heartbeat nonce if set. |
467 |
if ( response.heartbeat_nonce && typeof window.heartbeatSettings === 'object' ) { |
|
468 |
window.heartbeatSettings.nonce = response.heartbeat_nonce; |
|
469 |
delete response.heartbeat_nonce; |
|
470 |
} |
|
0 | 471 |
|
9 | 472 |
// Update the Rest API nonce if set and wp-api loaded. |
473 |
if ( response.rest_nonce && typeof window.wpApiSettings === 'object' ) { |
|
474 |
window.wpApiSettings.nonce = response.rest_nonce; |
|
475 |
// This nonce is required for api-fetch through heartbeat.tick. |
|
476 |
// delete response.rest_nonce; |
|
477 |
} |
|
478 |
||
479 |
$document.trigger( 'heartbeat-tick', [response, textStatus, jqXHR] ); |
|
480 |
wp.hooks.doAction( 'heartbeat.tick', response, textStatus, jqXHR ); |
|
481 |
||
16 | 482 |
// Do this last. Can trigger the next XHR if connection time > 5 seconds and newInterval == 'fast'. |
5 | 483 |
if ( newInterval ) { |
484 |
interval( newInterval ); |
|
485 |
} |
|
0 | 486 |
}).fail( function( jqXHR, textStatus, error ) { |
5 | 487 |
setErrorState( textStatus || 'unknown', jqXHR.status ); |
488 |
$document.trigger( 'heartbeat-error', [jqXHR, textStatus, error] ); |
|
9 | 489 |
wp.hooks.doAction( 'heartbeat.error', jqXHR, textStatus, error ); |
0 | 490 |
}); |
491 |
} |
|
492 |
||
5 | 493 |
/** |
9 | 494 |
* Schedules the next connection. |
5 | 495 |
* |
496 |
* Fires immediately if the connection time is longer than the interval. |
|
497 |
* |
|
16 | 498 |
* @since 3.8.0 |
5 | 499 |
* @access private |
500 |
* |
|
16 | 501 |
* @return {void} |
5 | 502 |
*/ |
503 |
function scheduleNextTick() { |
|
504 |
var delta = time() - settings.lastTick, |
|
505 |
interval = settings.mainInterval; |
|
0 | 506 |
|
5 | 507 |
if ( settings.suspend ) { |
508 |
return; |
|
0 | 509 |
} |
510 |
||
5 | 511 |
if ( ! settings.hasFocus ) { |
16 | 512 |
interval = 120000; // 120 seconds. Post locks expire after 150 seconds. |
5 | 513 |
} else if ( settings.countdown > 0 && settings.tempInterval ) { |
514 |
interval = settings.tempInterval; |
|
515 |
settings.countdown--; |
|
516 |
||
517 |
if ( settings.countdown < 1 ) { |
|
518 |
settings.tempInterval = 0; |
|
519 |
} |
|
520 |
} |
|
0 | 521 |
|
5 | 522 |
if ( settings.minimalInterval && interval < settings.minimalInterval ) { |
523 |
interval = settings.minimalInterval; |
|
524 |
} |
|
525 |
||
526 |
window.clearTimeout( settings.beatTimer ); |
|
527 |
||
528 |
if ( delta < interval ) { |
|
529 |
settings.beatTimer = window.setTimeout( |
|
530 |
function() { |
|
531 |
connect(); |
|
0 | 532 |
}, |
5 | 533 |
interval - delta |
0 | 534 |
); |
535 |
} else { |
|
536 |
connect(); |
|
537 |
} |
|
538 |
} |
|
539 |
||
5 | 540 |
/** |
9 | 541 |
* Sets the internal state when the browser window becomes hidden or loses focus. |
5 | 542 |
* |
16 | 543 |
* @since 3.6.0 |
5 | 544 |
* @access private |
545 |
* |
|
16 | 546 |
* @return {void} |
5 | 547 |
*/ |
0 | 548 |
function blurred() { |
5 | 549 |
settings.hasFocus = false; |
0 | 550 |
} |
551 |
||
5 | 552 |
/** |
9 | 553 |
* Sets the internal state when the browser window becomes visible or is in focus. |
5 | 554 |
* |
16 | 555 |
* @since 3.6.0 |
5 | 556 |
* @access private |
557 |
* |
|
16 | 558 |
* @return {void} |
5 | 559 |
*/ |
560 |
function focused() { |
|
561 |
settings.userActivity = time(); |
|
0 | 562 |
|
16 | 563 |
// Resume if suspended. |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
564 |
resume(); |
0 | 565 |
|
5 | 566 |
if ( ! settings.hasFocus ) { |
567 |
settings.hasFocus = true; |
|
568 |
scheduleNextTick(); |
|
569 |
} |
|
0 | 570 |
} |
571 |
||
5 | 572 |
/** |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
573 |
* Suspends connecting. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
574 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
575 |
function suspend() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
576 |
settings.suspend = true; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
577 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
578 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
579 |
/** |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
580 |
* Resumes connecting. |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
581 |
*/ |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
582 |
function resume() { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
583 |
settings.suspend = false; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
584 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
585 |
|
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
586 |
/** |
9 | 587 |
* Runs when the user becomes active after a period of inactivity. |
5 | 588 |
* |
16 | 589 |
* @since 3.6.0 |
5 | 590 |
* @access private |
591 |
* |
|
16 | 592 |
* @return {void} |
5 | 593 |
*/ |
594 |
function userIsActive() { |
|
595 |
settings.userActivityEvents = false; |
|
596 |
$document.off( '.wp-heartbeat-active' ); |
|
0 | 597 |
|
598 |
$('iframe').each( function( i, frame ) { |
|
5 | 599 |
if ( isLocalFrame( frame ) ) { |
600 |
$( frame.contentWindow ).off( '.wp-heartbeat-active' ); |
|
601 |
} |
|
0 | 602 |
}); |
603 |
||
604 |
focused(); |
|
605 |
} |
|
606 |
||
5 | 607 |
/** |
9 | 608 |
* Checks for user activity. |
5 | 609 |
* |
16 | 610 |
* Runs every 30 seconds. Sets 'hasFocus = true' if user is active and the window |
611 |
* is in the background. Sets 'hasFocus = false' if the user has been inactive |
|
612 |
* (no mouse or keyboard activity) for 5 minutes even when the window has focus. |
|
5 | 613 |
* |
16 | 614 |
* @since 3.8.0 |
5 | 615 |
* @access private |
616 |
* |
|
16 | 617 |
* @return {void} |
5 | 618 |
*/ |
619 |
function checkUserActivity() { |
|
620 |
var lastActive = settings.userActivity ? time() - settings.userActivity : 0; |
|
0 | 621 |
|
16 | 622 |
// Throttle down when no mouse or keyboard activity for 5 minutes. |
5 | 623 |
if ( lastActive > 300000 && settings.hasFocus ) { |
624 |
blurred(); |
|
625 |
} |
|
0 | 626 |
|
16 | 627 |
// Suspend after 10 minutes of inactivity when suspending is enabled. |
628 |
// Always suspend after 60 minutes of inactivity. This will release the post lock, etc. |
|
5 | 629 |
if ( ( settings.suspendEnabled && lastActive > 600000 ) || lastActive > 3600000 ) { |
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
630 |
suspend(); |
5 | 631 |
} |
632 |
||
633 |
if ( ! settings.userActivityEvents ) { |
|
634 |
$document.on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active', function() { |
|
635 |
userIsActive(); |
|
636 |
}); |
|
0 | 637 |
|
638 |
$('iframe').each( function( i, frame ) { |
|
5 | 639 |
if ( isLocalFrame( frame ) ) { |
640 |
$( frame.contentWindow ).on( 'mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active', function() { |
|
641 |
userIsActive(); |
|
642 |
}); |
|
643 |
} |
|
0 | 644 |
}); |
645 |
||
5 | 646 |
settings.userActivityEvents = true; |
0 | 647 |
} |
648 |
} |
|
649 |
||
9 | 650 |
// Public methods. |
5 | 651 |
|
652 |
/** |
|
9 | 653 |
* Checks whether the window (or any local iframe in it) has focus, or the user |
654 |
* is active. |
|
5 | 655 |
* |
9 | 656 |
* @since 3.6.0 |
657 |
* @memberOf wp.heartbeat.prototype |
|
658 |
* |
|
16 | 659 |
* @return {boolean} True if the window or the user is active. |
5 | 660 |
*/ |
661 |
function hasFocus() { |
|
662 |
return settings.hasFocus; |
|
663 |
} |
|
664 |
||
665 |
/** |
|
9 | 666 |
* Checks whether there is a connection error. |
667 |
* |
|
668 |
* @since 3.6.0 |
|
5 | 669 |
* |
9 | 670 |
* @memberOf wp.heartbeat.prototype |
671 |
* |
|
16 | 672 |
* @return {boolean} True if a connection error was found. |
5 | 673 |
*/ |
674 |
function hasConnectionError() { |
|
675 |
return settings.connectionError; |
|
676 |
} |
|
0 | 677 |
|
5 | 678 |
/** |
9 | 679 |
* Connects as soon as possible regardless of 'hasFocus' state. |
5 | 680 |
* |
681 |
* Will not open two concurrent connections. If a connection is in progress, |
|
682 |
* will connect again immediately after the current connection completes. |
|
683 |
* |
|
9 | 684 |
* @since 3.8.0 |
685 |
* |
|
686 |
* @memberOf wp.heartbeat.prototype |
|
687 |
* |
|
16 | 688 |
* @return {void} |
5 | 689 |
*/ |
690 |
function connectNow() { |
|
691 |
settings.lastTick = 0; |
|
692 |
scheduleNextTick(); |
|
693 |
} |
|
694 |
||
695 |
/** |
|
9 | 696 |
* Disables suspending. |
5 | 697 |
* |
9 | 698 |
* Should be used only when Heartbeat is performing critical tasks like |
16 | 699 |
* autosave, post-locking, etc. Using this on many screens may overload |
700 |
* the user's hosting account if several browser windows/tabs are left open |
|
701 |
* for a long time. |
|
5 | 702 |
* |
9 | 703 |
* @since 3.8.0 |
704 |
* |
|
705 |
* @memberOf wp.heartbeat.prototype |
|
706 |
* |
|
16 | 707 |
* @return {void} |
5 | 708 |
*/ |
709 |
function disableSuspend() { |
|
710 |
settings.suspendEnabled = false; |
|
711 |
} |
|
0 | 712 |
|
713 |
/** |
|
9 | 714 |
* Gets/Sets the interval. |
715 |
* |
|
716 |
* When setting to 'fast' or 5, the interval is 5 seconds for the next 30 ticks |
|
717 |
* (for 2 minutes and 30 seconds) by default. In this case the number of 'ticks' |
|
16 | 718 |
* can be passed as second argument. If the window doesn't have focus, |
719 |
* the interval slows down to 2 minutes. |
|
9 | 720 |
* |
721 |
* @since 3.6.0 |
|
0 | 722 |
* |
9 | 723 |
* @memberOf wp.heartbeat.prototype |
0 | 724 |
* |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
725 |
* @param {string|number} speed Interval: 'fast' or integer between 1 and 3600 (seconds). |
16 | 726 |
* Fast equals 5. |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
727 |
* @param {number} ticks Tells how many ticks before the interval reverts back. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
728 |
* Value must be between 1 and 30. Used with speed = 'fast' or 5. |
9 | 729 |
* |
16 | 730 |
* @return {number} Current interval in seconds. |
0 | 731 |
*/ |
5 | 732 |
function interval( speed, ticks ) { |
733 |
var newInterval, |
|
734 |
oldInterval = settings.tempInterval ? settings.tempInterval : settings.mainInterval; |
|
0 | 735 |
|
736 |
if ( speed ) { |
|
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
737 |
if ( 'fast' === speed ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
738 |
// Special case, see below. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
739 |
newInterval = 5000; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
740 |
} else if ( 'long-polling' === speed ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
741 |
// Allow long polling (experimental). |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
742 |
settings.mainInterval = 0; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
743 |
return 0; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
744 |
} else { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
745 |
speed = parseInt( speed, 10 ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
746 |
|
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
747 |
if ( speed >= 1 && speed <= 3600 ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
748 |
newInterval = speed * 1000; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
749 |
} else { |
5 | 750 |
newInterval = settings.originalInterval; |
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
751 |
} |
5 | 752 |
} |
753 |
||
754 |
if ( settings.minimalInterval && newInterval < settings.minimalInterval ) { |
|
755 |
newInterval = settings.minimalInterval; |
|
0 | 756 |
} |
757 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
758 |
// Special case, runs for a number of ticks then reverts to the previous interval. |
5 | 759 |
if ( 5000 === newInterval ) { |
760 |
ticks = parseInt( ticks, 10 ) || 30; |
|
761 |
ticks = ticks < 1 || ticks > 30 ? 30 : ticks; |
|
0 | 762 |
|
5 | 763 |
settings.countdown = ticks; |
764 |
settings.tempInterval = newInterval; |
|
0 | 765 |
} else { |
5 | 766 |
settings.countdown = 0; |
767 |
settings.tempInterval = 0; |
|
768 |
settings.mainInterval = newInterval; |
|
0 | 769 |
} |
770 |
||
16 | 771 |
/* |
772 |
* Change the next connection time if new interval has been set. |
|
773 |
* Will connect immediately if the time since the last connection |
|
774 |
* is greater than the new interval. |
|
775 |
*/ |
|
5 | 776 |
if ( newInterval !== oldInterval ) { |
777 |
scheduleNextTick(); |
|
778 |
} |
|
0 | 779 |
} |
780 |
||
5 | 781 |
return settings.tempInterval ? settings.tempInterval / 1000 : settings.mainInterval / 1000; |
782 |
} |
|
0 | 783 |
|
784 |
/** |
|
9 | 785 |
* Enqueues data to send with the next XHR. |
0 | 786 |
* |
9 | 787 |
* As the data is send asynchronously, this function doesn't return the XHR |
788 |
* response. To see the response, use the custom jQuery event 'heartbeat-tick' |
|
789 |
* on the document, example: |
|
0 | 790 |
* $(document).on( 'heartbeat-tick.myname', function( event, data, textStatus, jqXHR ) { |
791 |
* // code |
|
792 |
* }); |
|
9 | 793 |
* If the same 'handle' is used more than once, the data is not overwritten when |
794 |
* the third argument is 'true'. Use `wp.heartbeat.isQueued('handle')` to see if |
|
795 |
* any data is already queued for that handle. |
|
796 |
* |
|
797 |
* @since 3.6.0 |
|
0 | 798 |
* |
9 | 799 |
* @memberOf wp.heartbeat.prototype |
800 |
* |
|
801 |
* @param {string} handle Unique handle for the data, used in PHP to |
|
802 |
* receive the data. |
|
803 |
* @param {*} data The data to send. |
|
804 |
* @param {boolean} noOverwrite Whether to overwrite existing data in the queue. |
|
805 |
* |
|
16 | 806 |
* @return {boolean} True if the data was queued. |
0 | 807 |
*/ |
5 | 808 |
function enqueue( handle, data, noOverwrite ) { |
0 | 809 |
if ( handle ) { |
5 | 810 |
if ( noOverwrite && this.isQueued( handle ) ) { |
0 | 811 |
return false; |
5 | 812 |
} |
0 | 813 |
|
5 | 814 |
settings.queue[handle] = data; |
0 | 815 |
return true; |
816 |
} |
|
817 |
return false; |
|
5 | 818 |
} |
0 | 819 |
|
820 |
/** |
|
9 | 821 |
* Checks if data with a particular handle is queued. |
822 |
* |
|
823 |
* @since 3.6.0 |
|
0 | 824 |
* |
9 | 825 |
* @param {string} handle The handle for the data. |
826 |
* |
|
16 | 827 |
* @return {boolean} True if the data is queued with this handle. |
0 | 828 |
*/ |
5 | 829 |
function isQueued( handle ) { |
830 |
if ( handle ) { |
|
831 |
return settings.queue.hasOwnProperty( handle ); |
|
832 |
} |
|
833 |
} |
|
0 | 834 |
|
835 |
/** |
|
9 | 836 |
* Removes data with a particular handle from the queue. |
837 |
* |
|
838 |
* @since 3.7.0 |
|
0 | 839 |
* |
9 | 840 |
* @memberOf wp.heartbeat.prototype |
841 |
* |
|
842 |
* @param {string} handle The handle for the data. |
|
843 |
* |
|
16 | 844 |
* @return {void} |
0 | 845 |
*/ |
5 | 846 |
function dequeue( handle ) { |
847 |
if ( handle ) { |
|
848 |
delete settings.queue[handle]; |
|
849 |
} |
|
850 |
} |
|
0 | 851 |
|
852 |
/** |
|
9 | 853 |
* Gets data that was enqueued with a particular handle. |
854 |
* |
|
855 |
* @since 3.7.0 |
|
0 | 856 |
* |
9 | 857 |
* @memberOf wp.heartbeat.prototype |
858 |
* |
|
859 |
* @param {string} handle The handle for the data. |
|
860 |
* |
|
16 | 861 |
* @return {*} The data or undefined. |
0 | 862 |
*/ |
5 | 863 |
function getQueuedItem( handle ) { |
864 |
if ( handle ) { |
|
865 |
return this.isQueued( handle ) ? settings.queue[handle] : undefined; |
|
866 |
} |
|
867 |
} |
|
868 |
||
869 |
initialize(); |
|
870 |
||
9 | 871 |
// Expose public methods. |
5 | 872 |
return { |
873 |
hasFocus: hasFocus, |
|
874 |
connectNow: connectNow, |
|
875 |
disableSuspend: disableSuspend, |
|
876 |
interval: interval, |
|
877 |
hasConnectionError: hasConnectionError, |
|
878 |
enqueue: enqueue, |
|
879 |
dequeue: dequeue, |
|
880 |
isQueued: isQueued, |
|
881 |
getQueuedItem: getQueuedItem |
|
0 | 882 |
}; |
883 |
}; |
|
884 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
885 |
/** |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
886 |
* Ensure the global `wp` object exists. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
887 |
* |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
888 |
* @namespace wp |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
889 |
*/ |
5 | 890 |
window.wp = window.wp || {}; |
9 | 891 |
|
892 |
/** |
|
893 |
* Contains the Heartbeat API. |
|
894 |
* |
|
895 |
* @namespace wp.heartbeat |
|
896 |
* @type {Heartbeat} |
|
897 |
*/ |
|
5 | 898 |
window.wp.heartbeat = new Heartbeat(); |
0 | 899 |
|
5 | 900 |
}( jQuery, window )); |