วิวัฒนาการ-จัดการ
แก้ไขไฟล์: heartbeat.min.js
/*! This file is auto-generated */ !function(w,g){g.wp=g.wp||{},g.wp.heartbeat=new function(){var e,t,n,a,i=w(document),r={suspend:!1,suspendEnabled:!0,screenId:"",url:"",lastTick:0,queue:{},mainInterval:60,tempInterval:0,originalInterval:0,minimalInterval:0,countdown:0,connecting:!1,connectionError:!1,errorcount:0,hasConnected:!1,hasFocus:!0,userActivity:0,userActivityEvents:!1,checkFocusTimer:0,beatTimer:0};function o(){return(new Date).getTime()}function c(e){var t,n=e.src;if(!n||!/^https?:\/\//.test(n)||(t=g.location.origin||g.location.protocol+"//"+g.location.host,0===n.indexOf(t)))try{if(e.contentWindow.document)return 1}catch(e){}}function s(){r.hasFocus&&!document.hasFocus()?v():!r.hasFocus&&document.hasFocus()&&d()}function u(e,t){var n;if(e){switch(e){case"abort":break;case"timeout":n=!0;break;case"error":if(503===t&&r.hasConnected){n=!0;break}case"parsererror":case"empty":case"unknown":r.errorcount++,2<r.errorcount&&r.hasConnected&&(n=!0)}n&&!b()&&(r.connectionError=!0,i.trigger("heartbeat-connection-lost",[e,t]),wp.hooks.doAction("heartbeat.connection-lost",e,t))}}function l(){var e;r.connecting||r.suspend||(r.lastTick=o(),e=w.extend({},r.queue),r.queue={},i.trigger("heartbeat-send",[e]),wp.hooks.doAction("heartbeat.send",e),e={data:e,interval:r.tempInterval?r.tempInterval/1e3:r.mainInterval/1e3,_nonce:"object"==typeof g.heartbeatSettings?g.heartbeatSettings.nonce:"",action:"heartbeat",screen_id:r.screenId,has_focus:r.hasFocus},"customize"===r.screenId&&(e.wp_customize="on"),r.connecting=!0,r.xhr=w.ajax({url:r.url,type:"post",timeout:3e4,data:e,dataType:"json"}).always(function(){r.connecting=!1,m()}).done(function(e,t,n){var a;e?(r.hasConnected=!0,b()&&(r.errorcount=0,r.connectionError=!1,i.trigger("heartbeat-connection-restored"),wp.hooks.doAction("heartbeat.connection-restored")),e.nonces_expired&&(i.trigger("heartbeat-nonces-expired"),wp.hooks.doAction("heartbeat.nonces-expired")),e.heartbeat_interval&&(a=e.heartbeat_interval,delete e.heartbeat_interval),e.heartbeat_nonce&&"object"==typeof g.heartbeatSettings&&(g.heartbeatSettings.nonce=e.heartbeat_nonce,delete e.heartbeat_nonce),e.rest_nonce&&"object"==typeof g.wpApiSettings&&(g.wpApiSettings.nonce=e.rest_nonce),i.trigger("heartbeat-tick",[e,t,n]),wp.hooks.doAction("heartbeat.tick",e,t,n),a&&f(a)):u("empty")}).fail(function(e,t,n){u(t||"unknown",e.status),i.trigger("heartbeat-error",[e,t,n]),wp.hooks.doAction("heartbeat.error",e,t,n)}))}function m(){var e=o()-r.lastTick,t=r.mainInterval;r.suspend||(r.hasFocus?0<r.countdown&&r.tempInterval&&(t=r.tempInterval,r.countdown--,r.countdown<1)&&(r.tempInterval=0):t=12e4,r.minimalInterval&&t<r.minimalInterval&&(t=r.minimalInterval),g.clearTimeout(r.beatTimer),e<t?r.beatTimer=g.setTimeout(function(){l()},t-e):l())}function v(){r.hasFocus=!1}function d(){r.userActivity=o(),r.suspend=!1,r.hasFocus||(r.hasFocus=!0,m())}function h(){r.suspend=!0}function p(){r.userActivityEvents=!1,i.off(".wp-heartbeat-active"),w("iframe").each(function(e,t){c(t)&&w(t.contentWindow).off(".wp-heartbeat-active")}),d()}function I(){var e=r.userActivity?o()-r.userActivity:0;3e5<e&&r.hasFocus&&v(),(r.suspendEnabled&&6e5<e||36e5<e)&&h(),r.userActivityEvents||(i.on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active",function(){p()}),w("iframe").each(function(e,t){c(t)&&w(t.contentWindow).on("mouseover.wp-heartbeat-active keyup.wp-heartbeat-active touchend.wp-heartbeat-active",function(){p()})}),r.userActivityEvents=!0)}function b(){return r.connectionError}function f(e,t){var n,a=r.tempInterval||r.mainInterval;if(e){if("fast"===e)n=5e3;else{if("long-polling"===e)return r.mainInterval=0;n=1<=(e=parseInt(e,10))&&e<=3600?1e3*e:r.originalInterval}5e3===(n=r.minimalInterval&&n<r.minimalInterval?r.minimalInterval:n)?(t=parseInt(t,10)||30,r.countdown=t=t<1||30<t?30:t,r.tempInterval=n):(r.countdown=0,r.tempInterval=0,r.mainInterval=n),n!==a&&m()}return r.tempInterval?r.tempInterval/1e3:r.mainInterval/1e3}return"string"==typeof g.pagenow&&(r.screenId=g.pagenow),"string"==typeof g.ajaxurl&&(r.url=g.ajaxurl),"object"==typeof g.heartbeatSettings&&(e=g.heartbeatSettings,!r.url&&e.ajaxurl&&(r.url=e.ajaxurl),e.interval&&(r.mainInterval=e.interval,r.mainInterval<1?r.mainInterval=1:3600<r.mainInterval&&(r.mainInterval=3600)),e.minimalInterval&&(e.minimalInterval=parseInt(e.minimalInterval,10),r.minimalInterval=0<e.minimalInterval&&e.minimalInterval<=600?e.minimalInterval:0),r.minimalInterval&&r.mainInterval<r.minimalInterval&&(r.mainInterval=r.minimalInterval),r.screenId||(r.screenId=e.screenId||"front"),"disable"===e.suspension)&&(r.suspendEnabled=!1),r.mainInterval=1e3*r.mainInterval,r.originalInterval=r.mainInterval,r.minimalInterval&&(r.minimalInterval=1e3*r.minimalInterval),void 0!==document.hidden?(t="hidden",a="visibilitychange",n="visibilityState"):void 0!==document.msHidden?(t="msHidden",a="msvisibilitychange",n="msVisibilityState"):void 0!==document.webkitHidden&&(t="webkitHidden",a="webkitvisibilitychange",n="webkitVisibilityState"),t&&(document[t]&&(r.hasFocus=!1),i.on(a+".wp-heartbeat",function(){"hidden"===document[n]?(v(),g.clearInterval(r.checkFocusTimer)):(d(),document.hasFocus&&(r.checkFocusTimer=g.setInterval(s,1e4)))})),document.hasFocus&&(r.checkFocusTimer=g.setInterval(s,1e4)),w(g).on("pagehide.wp-heartbeat",function(){h(),r.xhr&&4!==r.xhr.readyState&&r.xhr.abort()}),w(g).on("pageshow.wp-heartbeat",function(e){e.originalEvent.persisted&&d()}),g.setInterval(I,3e4),w(function(){r.lastTick=o(),m()}),{hasFocus:function(){return r.hasFocus},connectNow:function(){r.lastTick=0,m()},disableSuspend:function(){r.suspendEnabled=!1},interval:f,hasConnectionError:b,enqueue:function(e,t,n){return!!e&&!(n&&this.isQueued(e)||(r.queue[e]=t,0))},dequeue:function(e){e&&delete r.queue[e]},isQueued:function(e){if(e)return r.queue.hasOwnProperty(e)},getQueuedItem:function(e){return e&&this.isQueued(e)?r.queue[e]:void 0}}}}(jQuery,window);