tooty/src/View/Events.elm
Nicolas Perriault bf09b87215 Modularize views (#117)
* Part 1: Refactor views.

I'm in the middle of nowhere. It's cold, but I distinguish
lights.

It's dark, but my good ol' Elm keeps barking when something
looks wrong or dangerous.

I'm not afraid.

* Part 2: More views refactoring.

The night is deep, but I can see clear. The truth is
at the end of this path.

Perhaps.

* Part 3: The sun is rising.

The darkness is gently fading over, dawn is near. I can
now see mountains drawing in the horizon.

Elm is rather quiet, but keeps scrutating the shadows.

* Part 4: Moaar view splitting.

I follow some wrong path, but I'm back on track.

The sun is shining.

* Epilogue

That was actually fun.
2017-05-02 08:27:01 +02:00

56 lines
1.4 KiB
Elm

module View.Events
exposing
( onClickInformation
, onInputInformation
, decodePositionInformation
, onClickWithPreventAndStop
, onClickWithPrevent
, onClickWithStop
)
import Html exposing (..)
import Html.Events exposing (on, onWithOptions)
import Json.Decode as Decode
import Types exposing (..)
onClickInformation : (InputInformation -> msg) -> Attribute msg
onClickInformation msg =
on "mouseup" (Decode.map msg decodePositionInformation)
onInputInformation : (InputInformation -> msg) -> Attribute msg
onInputInformation msg =
on "input" (Decode.map msg decodePositionInformation)
decodePositionInformation : Decode.Decoder InputInformation
decodePositionInformation =
Decode.map2 InputInformation
(Decode.at [ "target", "value" ] Decode.string)
(Decode.at [ "target", "selectionStart" ] Decode.int)
onClickWithPreventAndStop : msg -> Attribute msg
onClickWithPreventAndStop msg =
onWithOptions
"click"
{ preventDefault = True, stopPropagation = True }
(Decode.succeed msg)
onClickWithPrevent : msg -> Attribute msg
onClickWithPrevent msg =
onWithOptions
"click"
{ preventDefault = True, stopPropagation = False }
(Decode.succeed msg)
onClickWithStop : msg -> Attribute msg
onClickWithStop msg =
onWithOptions
"click"
{ preventDefault = False, stopPropagation = True }
(Decode.succeed msg)