diff --git a/lib/philomena_web/templates/layout/app.html.slime b/lib/philomena_web/templates/layout/app.html.slime index 7d388074..c97f2161 100644 --- a/lib/philomena_web/templates/layout/app.html.slime +++ b/lib/philomena_web/templates/layout/app.html.slime @@ -3,7 +3,8 @@ html lang="en" head meta charset="utf-8" meta http-equiv="X-UA-Compatible" content="IE=edge" - meta name="viewport" content="width=device-width, initial-scale=1" + = viewport_meta_tag(@conn) + title = if assigns[:title] do => assigns[:title] diff --git a/lib/philomena_web/views/layout_view.ex b/lib/philomena_web/views/layout_view.ex index e9107e40..9c9715f0 100644 --- a/lib/philomena_web/views/layout_view.ex +++ b/lib/philomena_web/views/layout_view.ex @@ -117,4 +117,20 @@ defmodule PhilomenaWeb.LayoutView do def manages_bans?(conn), do: can?(conn, :create, Philomena.Bans.User) + + def viewport_meta_tag(conn) do + ua = get_user_agent(conn) + + case String.contains?(ua, ["Mobile", "webOS"]) do + true -> tag(:meta, name: "viewport", content: "width=device-width, initial-scale=1") + _false -> tag(:meta, name: "viewport", content: "width=1024, initial-scale=1") + end + end + + defp get_user_agent(conn) do + case Plug.Conn.get_req_header(conn, "user-agent") do + [ua] -> ua + _ -> "" + end + end end