129 |
129 |
130 // Used to limit the number of AJAX requests. Overrides all other intervals if they are shorter. |
130 // Used to limit the number of AJAX requests. Overrides all other intervals if they are shorter. |
131 // Needed for some hosts that cannot handle frequent requests and the user may exceed the allocated server CPU time, etc. |
131 // Needed for some hosts that cannot handle frequent requests and the user may exceed the allocated server CPU time, etc. |
132 // The minimal interval can be up to 600 sec. however setting it to longer than 120 sec. will limit or disable |
132 // The minimal interval can be up to 600 sec. however setting it to longer than 120 sec. will limit or disable |
133 // some of the functionality (like post locks). |
133 // some of the functionality (like post locks). |
134 // Once set at initialization, minimalInterval cannot be changed/overriden. |
134 // Once set at initialization, minimalInterval cannot be changed/overridden. |
135 if ( options.minimalInterval ) { |
135 if ( options.minimalInterval ) { |
136 options.minimalInterval = parseInt( options.minimalInterval, 10 ); |
136 options.minimalInterval = parseInt( options.minimalInterval, 10 ); |
137 settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval * 1000 : 0; |
137 settings.minimalInterval = options.minimalInterval > 0 && options.minimalInterval <= 600 ? options.minimalInterval * 1000 : 0; |
138 } |
138 } |
139 |
139 |
140 if ( settings.minimalInterval && settings.mainInterval < settings.minimalInterval ) { |
140 if ( settings.minimalInterval && settings.mainInterval < settings.minimalInterval ) { |
141 settings.mainInterval = settings.minimalInterval; |
141 settings.mainInterval = settings.minimalInterval; |
142 } |
142 } |
143 |
143 |
144 // 'screenId' can be added from settings on the front-end where the JS global 'pagenow' is not set |
144 // 'screenId' can be added from settings on the front end where the JS global 'pagenow' is not set |
145 if ( ! settings.screenId ) { |
145 if ( ! settings.screenId ) { |
146 settings.screenId = options.screenId || 'front'; |
146 settings.screenId = options.screenId || 'front'; |
147 } |
147 } |
148 |
148 |
149 if ( options.suspension === 'disable' ) { |
149 if ( options.suspension === 'disable' ) { |
365 action: 'heartbeat', |
365 action: 'heartbeat', |
366 screen_id: settings.screenId, |
366 screen_id: settings.screenId, |
367 has_focus: settings.hasFocus |
367 has_focus: settings.hasFocus |
368 }; |
368 }; |
369 |
369 |
|
370 if ( 'customize' === settings.screenId ) { |
|
371 ajaxData.wp_customize = 'on'; |
|
372 } |
|
373 |
370 settings.connecting = true; |
374 settings.connecting = true; |
371 settings.xhr = $.ajax({ |
375 settings.xhr = $.ajax({ |
372 url: settings.url, |
376 url: settings.url, |
373 type: 'post', |
377 type: 'post', |
374 timeout: 30000, // throw an error if not completed after 30 sec. |
378 timeout: 30000, // throw an error if not completed after 30 sec. |
387 |
391 |
388 clearErrorState(); |
392 clearErrorState(); |
389 |
393 |
390 if ( response.nonces_expired ) { |
394 if ( response.nonces_expired ) { |
391 $document.trigger( 'heartbeat-nonces-expired' ); |
395 $document.trigger( 'heartbeat-nonces-expired' ); |
392 return; |
|
393 } |
396 } |
394 |
397 |
395 // Change the interval from PHP |
398 // Change the interval from PHP |
396 if ( response.heartbeat_interval ) { |
399 if ( response.heartbeat_interval ) { |
397 newInterval = response.heartbeat_interval; |
400 newInterval = response.heartbeat_interval; |
741 isQueued: isQueued, |
744 isQueued: isQueued, |
742 getQueuedItem: getQueuedItem |
745 getQueuedItem: getQueuedItem |
743 }; |
746 }; |
744 }; |
747 }; |
745 |
748 |
746 // Ensure the global `wp` object exists. |
749 /** |
|
750 * Ensure the global `wp` object exists. |
|
751 * |
|
752 * @namespace wp |
|
753 */ |
747 window.wp = window.wp || {}; |
754 window.wp = window.wp || {}; |
748 window.wp.heartbeat = new Heartbeat(); |
755 window.wp.heartbeat = new Heartbeat(); |
749 |
756 |
750 }( jQuery, window )); |
757 }( jQuery, window )); |