wp/wp-includes/js/heartbeat.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   130 				if ( ! settings.url && options.ajaxurl ) {
   130 				if ( ! settings.url && options.ajaxurl ) {
   131 					settings.url = options.ajaxurl;
   131 					settings.url = options.ajaxurl;
   132 				}
   132 				}
   133 
   133 
   134 				/*
   134 				/*
   135 				 * The interval can be from 15 to 120 seconds and can be set temporarily to 5 seconds.
   135 				 * Logic check: the interval can be from 1 to 3600 seconds and can be set temporarily
   136 				 * It can be set in the initial options or changed later through JS and/or through PHP.
   136 				 * to 5 seconds. It can be set in the initial options or changed later from JS
       
   137 				 * or from PHP through the AJAX responses.
   137 				 */
   138 				 */
   138 				if ( options.interval ) {
   139 				if ( options.interval ) {
   139 					settings.mainInterval = options.interval;
   140 					settings.mainInterval = options.interval;
   140 
   141 
   141 					if ( settings.mainInterval < 15 ) {
   142 					if ( settings.mainInterval < 1 ) {
   142 						settings.mainInterval = 15;
   143 						settings.mainInterval = 1;
   143 					} else if ( settings.mainInterval > 120 ) {
   144 					} else if ( settings.mainInterval > 3600 ) {
   144 						settings.mainInterval = 120;
   145 						settings.mainInterval = 3600;
   145 					}
   146 					}
   146 				}
   147 				}
   147 
   148 
   148 				/*
   149 				/*
   149 				 * Used to limit the number of Ajax requests. Overrides all other intervals
   150 				 * Used to limit the number of Ajax requests. Overrides all other intervals
   719 		 *
   720 		 *
   720 		 * @since 3.6.0
   721 		 * @since 3.6.0
   721 		 *
   722 		 *
   722 		 * @memberOf wp.heartbeat.prototype
   723 		 * @memberOf wp.heartbeat.prototype
   723 		 *
   724 		 *
   724 		 * @param {string|number} speed Interval: 'fast' or 5, 15, 30, 60, 120.
   725 		 * @param {string|number} speed Interval: 'fast' or integer between 1 and 3600 (seconds).
   725 		 *                              Fast equals 5.
   726 		 *                              Fast equals 5.
   726 		 * @param {string}        ticks Tells how many ticks before the interval reverts
   727 		 * @param {number}        ticks Tells how many ticks before the interval reverts back.
   727 		 *                              back. Used with speed = 'fast' or 5.
   728 		 *                              Value must be between 1 and 30. Used with speed = 'fast' or 5.
   728 		 *
   729 		 *
   729 		 * @return {number} Current interval in seconds.
   730 		 * @return {number} Current interval in seconds.
   730 		 */
   731 		 */
   731 		function interval( speed, ticks ) {
   732 		function interval( speed, ticks ) {
   732 			var newInterval,
   733 			var newInterval,
   733 				oldInterval = settings.tempInterval ? settings.tempInterval : settings.mainInterval;
   734 				oldInterval = settings.tempInterval ? settings.tempInterval : settings.mainInterval;
   734 
   735 
   735 			if ( speed ) {
   736 			if ( speed ) {
   736 				switch ( speed ) {
   737 				if ( 'fast' === speed ) {
   737 					case 'fast':
   738 					// Special case, see below.
   738 					case 5:
   739 					newInterval = 5000;
   739 						newInterval = 5000;
   740 				} else if ( 'long-polling' === speed ) {
   740 						break;
   741 					// Allow long polling (experimental).
   741 					case 15:
   742 					settings.mainInterval = 0;
   742 						newInterval = 15000;
   743 					return 0;
   743 						break;
   744 				} else {
   744 					case 30:
   745 					speed = parseInt( speed, 10 );
   745 						newInterval = 30000;
   746 
   746 						break;
   747 					if ( speed >= 1 && speed <= 3600 ) {
   747 					case 60:
   748 						newInterval = speed * 1000;
   748 						newInterval = 60000;
   749 					} else {
   749 						break;
       
   750 					case 120:
       
   751 						newInterval = 120000;
       
   752 						break;
       
   753 					case 'long-polling':
       
   754 						// Allow long polling (experimental).
       
   755 						settings.mainInterval = 0;
       
   756 						return 0;
       
   757 					default:
       
   758 						newInterval = settings.originalInterval;
   750 						newInterval = settings.originalInterval;
       
   751 					}
   759 				}
   752 				}
   760 
   753 
   761 				if ( settings.minimalInterval && newInterval < settings.minimalInterval ) {
   754 				if ( settings.minimalInterval && newInterval < settings.minimalInterval ) {
   762 					newInterval = settings.minimalInterval;
   755 					newInterval = settings.minimalInterval;
   763 				}
   756 				}
   764 
   757 
       
   758 				// Special case, runs for a number of ticks then reverts to the previous interval.
   765 				if ( 5000 === newInterval ) {
   759 				if ( 5000 === newInterval ) {
   766 					ticks = parseInt( ticks, 10 ) || 30;
   760 					ticks = parseInt( ticks, 10 ) || 30;
   767 					ticks = ticks < 1 || ticks > 30 ? 30 : ticks;
   761 					ticks = ticks < 1 || ticks > 30 ? 30 : ticks;
   768 
   762 
   769 					settings.countdown = ticks;
   763 					settings.countdown = ticks;