Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set video "muted" attribute as property in Parser.Util.toVirtualDom #16

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
44 changes: 40 additions & 4 deletions src/Html/Parser/Util.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module Html.Parser.Util exposing (toVirtualDom)

-}

import Html exposing (..)
import Html.Attributes exposing (..)
import Html exposing (Attribute, Html, text)
import Html.Attributes exposing (attribute, property)
import Html.Parser exposing (Node(..))
import VirtualDom
import Json.Encode as Encode


{-| Converts nodes to virtual dom nodes.
Expand All @@ -26,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
Expand All @@ -38,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