Take a look at the ol3 API here
this will get you the point of the line closest to the given coordinate. Otherwise you have to calculate the perpendicular distance. There's a few ways to accomplish that, see Wikipedia for reference. But with the function I pointed out in the API you are already halfway done. You just have to figure out the second point (it's either the one before or after the point the API call returns). Imagine a line between those two points and calculate the perpendicular distance using one of the ways described in the Wikipedia article.
So, to answer the question directly: You have to code it yourself if you need the shortest distance to the line itself and not to one point within the line.
To clarify it a litte see this picture
Given a line consisting of two points and a point from which you want to know the shortest distance to the line, the perpendicular distance is displayed as the pink line. It is the shortest distance to the line itself, even though there might be no actual point. The API call would return the distance towards the closest point of the line, which would, in this case, be P1 (green line).Depending on what you need, you have to choose between those two, as they are obviously not the same.