|
19 | 19 | var tasks = [];
|
20 | 20 | var runAttempts = 0;
|
21 | 21 | var isRunning = false;
|
22 |
| - var remainingTime = 25; |
23 |
| - var minThrottle = 0; |
24 |
| - var throttle = 0; |
| 22 | + var remainingTime = 7; |
| 23 | + var minThrottle = 35; |
| 24 | + var throttle = 125; |
25 | 25 | var index = 0;
|
26 | 26 | var taskStart = 0;
|
27 | 27 | var tasklength = 0;
|
|
36 | 36 | };
|
37 | 37 | var setInacitve = debounce(function(){
|
38 | 38 | remainingTime = 25;
|
39 |
| - throttle = 0; |
| 39 | + throttle = 33; |
40 | 40 | minThrottle = 0;
|
41 | 41 | });
|
42 | 42 |
|
|
110 | 110 | throttleDelay = minThrottle;
|
111 | 111 | }
|
112 | 112 |
|
113 |
| - if(throttleDelay > 0){ |
| 113 | + if(throttleDelay > 9){ |
114 | 114 | lazytimer = setTimeout(scheduleRaf, throttleDelay);
|
115 | 115 | } else {
|
116 | 116 | throttleDelay = 0;
|
|
142 | 142 | }
|
143 | 143 | }
|
144 | 144 |
|
145 |
| - function requestIdleCallback(task){ |
| 145 | + function requestIdleCallbackShim(task){ |
146 | 146 | index++;
|
147 | 147 | tasks.push(task);
|
148 | 148 | scheduleLazy();
|
149 | 149 | return index;
|
150 | 150 | }
|
151 | 151 |
|
152 |
| - function cancelIdleCallback(id){ |
| 152 | + function cancelIdleCallbackShim(id){ |
153 | 153 | var index = id - 1 - tasklength;
|
154 | 154 | if(tasks[index]){
|
155 | 155 | tasks[index] = null;
|
156 | 156 | }
|
157 | 157 | }
|
158 | 158 |
|
159 | 159 | if(!root.requestIdleCallback || !root.cancelIdleCallback){
|
160 |
| - root.requestIdleCallback = requestIdleCallback; |
161 |
| - root.cancelIdleCallback = cancelIdleCallback; |
| 160 | + root.requestIdleCallback = requestIdleCallbackShim; |
| 161 | + root.cancelIdleCallback = cancelIdleCallbackShim; |
162 | 162 |
|
163 | 163 | window.addEventListener('scroll', onInputorMutation, true);
|
164 | 164 | window.addEventListener('resize', onInputorMutation);
|
|
170 | 170 | if(window.MutationObserver){
|
171 | 171 | new MutationObserver( onInputorMutation ).observe( document.documentElement, {childList: true, subtree: true, attributes: true} );
|
172 | 172 | }
|
| 173 | + } else { |
| 174 | + try{ |
| 175 | + root.requestIdleCallback(function(){}, {timeout: 0}); |
| 176 | + } catch(e){ |
| 177 | + (function(rIC){ |
| 178 | + var timeRemainingProto, timeRemaining; |
| 179 | + root.requestIdleCallback = function(fn, timeout){ |
| 180 | + if(timeout && typeof timeout.timeout == 'number'){ |
| 181 | + return rIC(fn, timeout.timeout); |
| 182 | + } |
| 183 | + return rIC(fn); |
| 184 | + }; |
| 185 | + if(root.IdleCallbackDeadline && (timeRemainingProto = IdleCallbackDeadline.prototype)){ |
| 186 | + timeRemaining = Object.getOwnPropertyDescriptor(timeRemainingProto, 'timeRemaining'); |
| 187 | + if(!timeRemaining.configurable || !timeRemaining.get){return;} |
| 188 | + Object.defineProperty(timeRemainingProto, 'timeRemaining', { |
| 189 | + value: function(){ |
| 190 | + return timeRemaining.get.call(this); |
| 191 | + }, |
| 192 | + enumerable: true, |
| 193 | + configurable: true, |
| 194 | + }); |
| 195 | + } |
| 196 | + })(root.requestIdleCallback) |
| 197 | + } |
173 | 198 | }
|
174 | 199 |
|
175 | 200 | return {
|
176 |
| - request: requestIdleCallback, |
177 |
| - cancel: cancelIdleCallback, |
| 201 | + request: requestIdleCallbackShim, |
| 202 | + cancel: cancelIdleCallbackShim, |
178 | 203 | };
|
179 | 204 | }));
|
0 commit comments