()
| 260 | } |
| 261 | |
| 262 | func rafPolyfill() { |
| 263 | vendors := []string{"ms", "moz", "webkit", "o"} |
| 264 | if window.Get("requestAnimationFrame").Type() == js.TypeUndefined { |
| 265 | for i := 0; i < len(vendors) && window.Get("requestAnimationFrame").Type() == js.TypeUndefined; i++ { |
| 266 | vendor := vendors[i] |
| 267 | window.Set("requestAnimationFrame", window.Get(vendor+"RequestAnimationFrame")) |
| 268 | window.Set("cancelAnimationFrame", window.Get(vendor+"CancelAnimationFrame")) |
| 269 | if window.Get("cancelAnimationFrame").Type() == js.TypeUndefined { |
| 270 | window.Set("cancelAnimationFrame", window.Get(vendor+"CancelRequestAnimationFrame")) |
| 271 | } |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | lastTime := 0.0 |
| 276 | if window.Get("requestAnimationFrame").Type() == js.TypeUndefined { |
| 277 | window.Set("requestAnimationFrame", js.FuncOf(func(this js.Value, args []js.Value) interface{} { |
| 278 | currTime := js.Global().Get("Date").New().Call("getTime").Float() |
| 279 | timeToCall := math.Max(0, 16-(currTime-lastTime)) |
| 280 | window.Call("setTimeout", js.FuncOf(func(this js.Value, args []js.Value) interface{} { |
| 281 | args[0].Invoke(currTime + timeToCall) |
| 282 | return nil |
| 283 | }), timeToCall) |
| 284 | lastTime = currTime + timeToCall |
| 285 | return nil |
| 286 | })) |
| 287 | } |
| 288 | |
| 289 | if window.Get("cancelAnimationFrame").Type() == js.TypeUndefined { |
| 290 | window.Set("cancelAnimationFrame", js.FuncOf(func(this js.Value, args []js.Value) interface{} { |
| 291 | js.Global().Get("clearTimeout").Invoke(args[0]) |
| 292 | return nil |
| 293 | })) |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // RunIteration runs one iteration per frame |
| 298 | func RunIteration() { |
no test coverage detected