[javascript] Calculate text width with JavaScript