From 40debb9634c9e3f77b9958cb20bf0c89a9465704 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Fri, 20 Dec 2019 09:19:43 -0500 Subject: [PATCH] add viewport meta hook --- .../templates/layout/app.html.slime | 3 ++- lib/philomena_web/views/layout_view.ex | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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