WordPress/wp-includes/js/heartbeat.min.js
Bot (Assets) ea4aa44ed1 Compress scripts/styles: 3.6-beta3-24407.
git-svn-id: http://core.svn.wordpress.org/trunk@24407 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2013-06-05 00:59:01 +00:00

1 line
4.1 KiB
JavaScript

window.wp=window.wp||{};(function(a){var b=function(){var s=this,e,c,B,p=typeof pagenow!="undefined"?pagenow:"",h=typeof ajaxurl!="undefined"?ajaxurl:"",C,A=0,w={},D,i,q=0,z=0,x,f=true,o,j,g,v=-1;this.autostart=true;this.connectionLost=false;if(typeof(window.heartbeatSettings)!="undefined"){C=window.heartbeatSettings;B=C.nonce||"";delete C.nonce;h=C.ajaxurl||h;delete C.ajaxurl;D=C.interval||15;delete C.interval;if(D<15){D=15}else{if(D>60){D=60}}D=D*1000;p=p||C.screenId||"front";delete C.screenId;a.extend(this,C)}function k(F){if(F){return parseInt((new Date()).getTime()/1000)}return(new Date()).getTime()}function y(I){var F,H=I.src;if(H&&/^https?:\/\//.test(H)){F=window.location.origin?window.location.origin:window.location.protocol+"//"+window.location.host;if(H.indexOf(F)!==0){return false}}try{if(I.contentWindow.document){return true}}catch(G){}return false}function u(G){var F;if(G){switch(G){case"abort":break;case"timeout":F=true;break;case"parsererror":case"error":case"empty":case"unknown":z++;if(z>2){F=true}break}if(F&&!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,F,G=true;A=k();H=a.extend({},w);w={};a(document).trigger("heartbeat-send",[H]);for(F in H){if(H.hasOwnProperty(F)){G=false;break}}if(G){i=false;t();return}I.data=H;I.interval=D/1000;I._nonce=B;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.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 G=k()-A,F=D;if(!e){return}if(!f){F=120000}else{if(q>0&&x){F=x;q--}}window.clearTimeout(c);if(G<F){c=window.setTimeout(function(){if(e){d()}},F-G)}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(F,G){if(!y(G)){return}if(a.data(G,"wp-heartbeat-focus")){return}a.data(G,"wp-heartbeat-focus",1);a(G.contentWindow).on("focus.wp-heartbeat-focus",function(H){m()}).on("blur.wp-heartbeat-focus",function(H){r();v=window.setTimeout(function(){n()},500)})})}a(window).on("blur.wp-heartbeat-focus",function(F){r();g=window.setTimeout(function(){n()},500)}).on("focus.wp-heartbeat-focus",function(){a("iframe").each(function(F,G){if(!y(G)){return}a.removeData(G,"wp-heartbeat-focus");a(G.contentWindow).off(".wp-heartbeat-focus")});m()});function E(){j=false;a(document).off(".wp-heartbeat-active");a("iframe").each(function(F,G){if(!y(G)){return}a(G.contentWindow).off(".wp-heartbeat-active")});m()}function l(){var F=o?k()-o:0;if(F>300000&&f){n()}if(!j){a(document).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){E()});a("iframe").each(function(G,H){if(!y(H)){return}a(H.contentWindow).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active",function(){E()})});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){var F,H;if(G){switch(G){case"fast":H=5;q=30;break;case"slow":H=60;q=0;break;case"long-polling":D=0;return 0;break;default:H=15;q=0}F=H*1000<D;if(q>0){x=H*1000}else{D=H*1000;x=0}if(F){t()}}if(!f){return 120}return x?x/1000:D/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(H,G,F){if(H){if(w.hasOwnProperty(H)&&F){return false}w[H]=G;return true}return false};this.isQueued=function(F){return w[F]}};a.extend(b.prototype,{tick:function(d,e,c){a(document).trigger("heartbeat-tick",[d,e,c])},error:function(d,e,c){a(document).trigger("heartbeat-error",[d,e,c])}});wp.heartbeat=new b()}(jQuery));