Define sourceX before use in touchAngle function
Try to add docPointerUp listeners to window.parent

If for example in an iFrame, end when there is a mouse up in the window
above.