Refactor title JavaScript

The jQuery chaining makes it hard to follow and to hook into.

Change-Id: I2f4be293f20432a49dfbffd98bc0af40fdd9caef
Merge "Refactor title JavaScript"