From cf5b2d4f35d0941c6f08c6db12ed7243154ffd7f Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 14 Sep 2020 19:57:48 -0400 Subject: [PATCH 1/2] Remove extraneous imports --- src/Html/Parser/Util.elm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Html/Parser/Util.elm b/src/Html/Parser/Util.elm index 2fd3d18..27f8a00 100644 --- a/src/Html/Parser/Util.elm +++ b/src/Html/Parser/Util.elm @@ -9,10 +9,9 @@ module Html.Parser.Util exposing (toVirtualDom) -} -import Html exposing (..) -import Html.Attributes exposing (..) +import Html exposing (Attribute, Html, text) +import Html.Attributes exposing (attribute) import Html.Parser exposing (Node(..)) -import VirtualDom {-| Converts nodes to virtual dom nodes. From 384fad826a591ff5ac7578a53ec86f12b170a054 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Mon, 14 Sep 2020 20:06:14 -0400 Subject: [PATCH 2/2] Set "muted" as a property on videos for autoplay in Chrome --- elm.json | 1 + src/Html/Parser/Util.elm | 41 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/elm.json b/elm.json index 245387b..dcae2b6 100644 --- a/elm.json +++ b/elm.json @@ -12,6 +12,7 @@ "dependencies": { "elm/core": "1.0.0 <= v < 2.0.0", "elm/html": "1.0.0 <= v < 2.0.0", + "elm/json": "1.1.3 <= v < 2.0.0", "elm/parser": "1.0.0 <= v < 2.0.0", "elm/virtual-dom": "1.0.2 <= v < 2.0.0", "rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0" diff --git a/src/Html/Parser/Util.elm b/src/Html/Parser/Util.elm index 27f8a00..b698ca0 100644 --- a/src/Html/Parser/Util.elm +++ b/src/Html/Parser/Util.elm @@ -10,8 +10,9 @@ module Html.Parser.Util exposing (toVirtualDom) -} import Html exposing (Attribute, Html, text) -import Html.Attributes exposing (attribute) +import Html.Attributes exposing (attribute, property) import Html.Parser exposing (Node(..)) +import Json.Encode as Encode {-| Converts nodes to virtual dom nodes. @@ -25,7 +26,18 @@ toVirtualDomEach : Node -> Html msg toVirtualDomEach node = case node of Element name attrs children -> - Html.node name (List.map toAttribute attrs) (toVirtualDom children) + Html.node name + (List.map + (case name of + "video" -> + toVideoAttribute + + _ -> + toAttribute + ) + attrs + ) + (toVirtualDom children) Text s -> text s @@ -37,3 +49,28 @@ toVirtualDomEach node = toAttribute : ( String, String ) -> Attribute msg toAttribute ( name, value ) = attribute name value + + +toVideoAttribute : ( String, String ) -> Attribute msg +toVideoAttribute ( name, value ) = + case name of + "muted" -> + stringToBool value + |> Encode.bool + |> property name + + _ -> + attribute name value + + +stringToBool : String -> Bool +stringToBool str = + case (String.trim >> String.toLower) str of + "false" -> + False + + "no" -> + False + + _ -> + True