(fn, time, context)
| 79 | // function, followed by any arguments passed when invoking the bound function. |
| 80 | // Has an `L.throttle` shortcut. |
| 81 | function throttle(fn, time, context) { |
| 82 | var lock, args, wrapperFn, later; |
| 83 | |
| 84 | later = function () { |
| 85 | // reset lock and call if queued |
| 86 | lock = false; |
| 87 | if (args) { |
| 88 | wrapperFn.apply(context, args); |
| 89 | args = false; |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | wrapperFn = function () { |
| 94 | if (lock) { |
| 95 | // called too soon, queue to call later |
| 96 | args = arguments; |
| 97 | |
| 98 | } else { |
| 99 | // call and lock until later |
| 100 | fn.apply(context, arguments); |
| 101 | setTimeout(later, time); |
| 102 | lock = true; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | return wrapperFn; |
| 107 | } |
| 108 | |
| 109 | // @function wrapNum(num: Number, range: Number[], includeMax?: Boolean): Number |
| 110 | // Returns the number `num` modulo `range` in such a way so it lies within |
no outgoing calls
no test coverage detected