intelligent javascript text truncation