fix(list): Fix for sticky titles in Chrome/Android. Currently broken

This commit is contained in:
jbavari
2015-10-02 12:40:22 -06:00
parent e9615191a8
commit 82ef03b346
4 changed files with 230 additions and 7 deletions

View File

@ -180,3 +180,35 @@ export function getQuerystring(url, key) {
}
return queryParams;
}
/**
* Throttle the given fun, only allowing it to be
* called at most every `wait` ms.
*/
export function throttle(func, wait, options) {
var context, args, result;
var timeout = null;
var previous = 0;
options || (options = {});
var later = function() {
previous = options.leading === false ? 0 : Date.now();
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = Date.now();
if (!previous && options.leading === false) previous = now;
var remaining = wait - (now - previous);
context = this;
args = arguments;
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
previous = now;
result = func.apply(context, args);
} else if (!timeout && options.trailing !== false) {
timeout = setTimeout(later, remaining);
}
return result;
};
}