pointer lock polyfill that presents an eventemitter / stream api
pointer-lock api exposed as an event emitter that emits readable streams of mouse movement data. automatically handles adding appropriate mousedown/up event listeners on the targeted element. tries to reuse objects instead of creating new objects, to keep garbage generation low. may sing you songs, if you're nice enough to it.
var lock = require'pointer-lock'my_element = documentgetElementById'element'if!lockavailablereturn alert'not available!'var pointer = lockmy_elementpointeron'attain'var initial = x: movementsx y: movements: y// movements is a readable streammovementson'data'// be sure to copy the data *out of* move,// as the move object is reused.initialx += movedxinitialy += movedymovementson'close'// no more movements from this pointer-lock session.pointeron'release'// pointer has been releasedpointeron'error'// user denied pointer lock OR it's not availablepointeron'needs-fullscreen'// some browsers require you to be in fullscreen mode// for pointer lock.// this lets you catch that case and request it after// you've requested fullscreen.var fullscreen = require'fullscreen'fs = fullscreenmy_elementfsonce'attain'// manually re-request pointer lockpointerrequest// request fullscreen!fsrequest// releases the pointer lock session, if any.pointerrelease// current pointer lock element, if any.pointertarget