WordPress/wp-includes/js/heartbeat.min.js

1 line
4.7 KiB
JavaScript
Raw Normal View History

!function(a,b,c){var d=function(){function d(){if("string"==typeof b.pagenow&&(A.screenId=b.pagenow),"string"==typeof b.ajaxurl&&(A.url=b.ajaxurl),"object"==typeof b.heartbeatSettings){var c=b.heartbeatSettings;!A.url&&c.ajaxurl&&(A.url=c.ajaxurl),c.interval&&(A.mainInterval=c.interval,A.mainInterval<15?A.mainInterval=15:A.mainInterval>60&&(A.mainInterval=60)),A.screenId||(A.screenId=c.screenId||"front")}A.mainInterval=1e3*A.mainInterval,A.originalInterval=A.mainInterval,a(b).on("blur.wp-heartbeat-focus",function(){m(),A.winBlurTimer=b.setTimeout(function(){k()},500)}).on("focus.wp-heartbeat-focus",function(){n(),l()}).on("unload.wp-heartbeat",function(){A.isRunning=!1}),b.setInterval(function(){q()},3e4),z.ready(function(){A.lastTick=e(),j()})}function e(){return(new Date).getTime()}function f(a){var c,d=a.src;if(d&&/^https?:\/\//.test(d)&&(c=b.location.origin?b.location.origin:b.location.protocol+"//"+b.location.host,0!==d.indexOf(c)))return!1;try{if(a.contentWindow.document)return!0}catch(e){}return!1}function g(a,b){var c;if(a){switch(a){case"abort":break;case"timeout":c=!0;break;case"error":if(503===b&&A.hasConnected){c=!0;break}case"parsererror":case"empty":case"unknown":A.errorcount++,A.errorcount>2&&A.hasConnected&&(c=!0)}c&&!s()&&(A.connectionError=!0,z.trigger("heartbeat-connection-lost",[a,b]))}}function h(){A.hasConnected=!0,s()&&(A.errorcount=0,A.connectionError=!1,z.trigger("heartbeat-connection-restored"))}function i(){var c,d;A.connecting||(A.lastTick=e(),d=a.extend({},A.queue),A.queue={},z.trigger("heartbeat-send",[d]),c={data:d,interval:A.tempInterval?A.tempInterval/1e3:A.mainInterval/1e3,_nonce:"object"==typeof b.heartbeatSettings?b.heartbeatSettings.nonce:"",action:"heartbeat",screen_id:A.screenId,has_focus:A.hasFocus},A.connecting=!0,A.xhr=a.ajax({url:A.url,type:"post",timeout:3e4,data:c,dataType:"json"}).always(function(){A.connecting=!1,j()}).done(function(a,b,c){var d;return a?(h(),a.nonces_expired?(z.trigger("heartbeat-nonces-expired"),void 0):(a.heartbeat_interval&&(d=a.heartbeat_interval,delete a.heartbeat_interval),z.trigger("heartbeat-tick",[a,b,c]),d&&u(d),void 0)):(g("empty"),void 0)}).fail(function(a,b,c){g(b||"unknown",a.status),z.trigger("heartbeat-error",[a,b,c])}))}function j(){var a=e()-A.lastTick,c=A.mainInterval;A.isRunning&&(A.hasFocus?A.countdown>0&&A.tempInterval&&(c=A.tempInterval,A.countdown--,A.countdown<1&&(A.tempInterval=0)):c=12e4,b.clearTimeout(A.beatTimer),c>a?A.beatTimer=b.setTimeout(function(){i()},c-a):i())}function k(){o(),A.hasFocus=!1}function l(){o(),A.userActivity=e(),A.hasFocus||(A.hasFocus=!0,j())}function m(){a("iframe").each(function(c,d){f(d)&&(a.data(d,"wp-heartbeat-focus")||(a.data(d,"wp-heartbeat-focus",1),a(d.contentWindow).on("focus.wp-heartbeat-focus",function(){l()}).on("blur.wp-heartbeat-focus",function(){m(),A.frameBlurTimer=b.setTimeout(function(){k()},500)})))})}function n(){a("iframe").each(function(b,c){f(c)&&(a.removeData(c,"wp-heartbeat-focus"),a(c.contentWindow).off(".wp-heartbeat-focus"))})}function o(){b.clearTimeout(A.winBlurTimer),b.clearTimeout(A.frameBlurTimer)}function p(){A.userActivityEvents=!1,z.off(".wp-heartbeat-active"),a("iframe").each(function(b,c){f(c)&&a(c.contentWindow).off(".wp-heartbeat-active")}),l()}function q(){var b=A.userActivity?e()-A.userActivity:0;b>3e5&&A.hasFocus&&k(),A.userActivityEvents||(z.on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){p()}),a("iframe").each(function(b,c){f(c)&&a(c.contentWindow).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){p()})}),A.userActivityEvents=!0)}function r(){return A.hasFocus}function s(){return A.connectionError}function t(){A.lastTick=0,j()}function u(a,b){var c,d=A.tempInterval?A.tempInterval:A.mainInterval;if(a){switch(a){case"fast":case 5:c=5e3;break;case 15:c=15e3;break;case 30:c=3e4;break;case 60:c=6e4;break;case"long-polling":return A.mainInterval=0,0;default:c=A.originalInterval}5e3===c?(b=parseInt(b,10)||30,b=1>b||b>30?30:b,A.countdown=b,A.tempInterval=c):(A.countdown=0,A.tempInterval=0,A.mainInterval=c),c!==d&&j()}return