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

1 line
4.3 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{};(function(a){var b=function(){var s=this,e,c,p=typeof pagenow!="undefined"?pagenow:"",h=typeof ajaxurl!="undefined"?ajaxurl:"",B,A=0,w={},C,i,q=0,z=0,x,f=true,o,j,g,v=-1;this.autostart=true;this.connectionLost=false;if(typeof(window.heartbeatSettings)=="object"){B=a.extend({},window.heartbeatSettings);h=B.ajaxurl||h;delete B.ajaxurl;delete B.nonce;C=B.interval||15;delete B.interval;if(C<15){C=15}else{if(C>60){C=60}}C=C*1000;p=p||B.screenId||"front";delete B.screenId;a.extend(this,B)}function k(E){if(E){return parseInt((new Date()).getTime()/1000)}return(new Date()).getTime()}function y(H){var E,G=H.src;if(G&&/^https?:\/\//.test(G)){E=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.host;if(G.indexOf(E)!==0){return false}}try{if(H.contentWindow.document){return true}}catch(F){}return false}function u(F){var E;if(F){switch(F){case"abort":break;case"timeout":E=true;break;case"parsererror":case"error":case"empty":case"unknown":z++;if(z>2){E=true}break}if(E&&!s.connectionLost){s.connectionLost=true;a(document).trigger("heartbeat-connection-lost")}}else{if(s.connectionLost){z=0;s.connectionLost=false;a(document).trigger("heartbeat-connection-restored")}}}function d(){var I={},H,E,G=true,F=typeof window.heartbeatSettings=="object"?window.heartbeatSettings.nonce:"";A=k();H=a.extend({},w);w={};a(document).trigger("heartbeat-send",[H]);for(E in H){if(H.hasOwnProperty(E)){G=false;break}}if(G){i=false;t();return}I.data=H;I.interval=C/1000;I._nonce=F;I.action="heartbeat";I.screen_id=p;I.has_focus=f;i=true;s.xhr=a.ajax({url:h,type:"post",timeout:30000,data:I,dataType:"json"}).done(function(J,M,K){var L;if(!J){return u("empty")}if(s.connectionLost){u()}if(J.nonces_expired){a(document).trigger("heartbeat-nonces-expired");return}if(J.heartbeat_interval){L=J.heartbeat_interval;delete J.heartbeat_interval}s.tick(J,M,K);if(L){s.interval.call(s,L)}}).always(function(){i=false;t()}).fail(function(K,L,J){u(L||"unknown");s.error(K,L,J)})}function t(){var F=k()-A,E=C;if(!e){return}if(!f){E=120000}else{if(q>0&&x){E=x;q--}}window.clearTimeout(c);if(F<E){c=window.setTimeout(function(){if(e){d()}},E-F)}else{d()}}function n(){window.clearTimeout(g);window.clearTimeout(v);g=v=0;f=false}function m(){window.clearTimeout(g);window.clearTimeout(v);g=v=0;o=k();if(f){return}f=true;window.clearTimeout(c);if(!i){t()}}function r(){a("iframe").each(function(E,F){if(!y(F)){return}if(a.data(F,"wp-heartbeat-focus")){return}a.data(F,"wp-heartbeat-focus",1);a(F.contentWindow).on("focus.wp-heartbeat-focus",function(G){m()}).on("blur.wp-heartbeat-focus",function(G){r();v=window.setTimeout(function(){n()},500)})})}a(window).on("blur.wp-heartbeat-focus",function(E){r();g=window.setTimeout(function(){n()},500)}).on("focus.wp-heartbeat-focus",function(){a("iframe").each(function(E,F){if(!y(F)){return}a.removeData(F,"wp-heartbeat-focus");a(F.contentWindow).off(".wp-heartbeat-focus")});m()});function D(){j=false;a(document).off(".wp-heartbeat-active");a("iframe").each(function(E,F){if(!y(F)){return}a(F.contentWindow).off(".wp-heartbeat-active")});m()}function l(){var E=o?k()-o:0;if(E>300000&&f){n()}if(!j){a(document).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){D()});a("iframe").each(function(F,G){if(!y(G)){return}a(G.contentWindow).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){D()})});j=true}}window.setInterval(function(){l()},30000);if(this.autostart){a(document).ready(function(){e=true;A=k();t()})}this.hasFocus=function(){return f};this.interval=function(G,F){var E,H;F=parseInt(F,10)||30;F=F<1||F>30?30:F;if(G){switch(G){case"fast":H=5;q=F;break;case"slow":H=60;q=0;break;case"long-polling":C=0;return 0;break;default:H=15;q=0}E=H*1000<C;if(q>0){x=H*1000}else{C=H*1000;x=0}if(E){t()}}if(!f){return 120}return x?x/1000:C/1000};this.start=function(){if(e){return false}e=true;d();return true};this.stop=function(){if(s.xhr&&s.xhr.readyState!=4){s.xhr.abort()}u();e=false;return true};this.enqueue=function(G,F,E){if(G){if(w.hasOwnProperty(G)&&E){return false}w[G]