Backport mobile fixes to 1.8

Backport of https://bugs.dojotoolkit.org/ticket/16730 and https://bugs.dojotoolkit.org/ticket/17388 to 1.8 branch.