1module Element.Events exposing
2 ( onClick, onDoubleClick, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseMove
6 -- , onClickScreenCoords
9 -- , onMouseScreenCoords
17@docs onClick, onDoubleClick, onMouseDown, onMouseUp, onMouseEnter, onMouseLeave, onMouseMove
22@docs onFocus, onLoseFocus
26import Element exposing (Attribute)
28import Internal.Model as Internal
29import Json.Decode as Json
38onMouseDown : msg -> Attribute msg
40 Internal.Attr << Html.Events.onMouseDown
44onMouseUp : msg -> Attribute msg
46 Internal.Attr << Html.Events.onMouseUp
50onClick : msg -> Attribute msg
52 Internal.Attr << Html.Events.onClick
56onDoubleClick : msg -> Attribute msg
58 Internal.Attr << Html.Events.onDoubleClick
62onMouseEnter : msg -> Attribute msg
64 Internal.Attr << Html.Events.onMouseEnter
68onMouseLeave : msg -> Attribute msg
70 Internal.Attr << Html.Events.onMouseLeave
74onMouseMove : msg -> Attribute msg
76 on "mousemove" (Json.succeed msg)
82-- , send = localCoords Button
88-- type Button = Primary | Secondary
97onClickCoords : (Coords -> msg) -> Attribute msg
99 on "click" (Json.map msg localCoords)
103onClickScreenCoords : (Coords -> msg) -> Attribute msg
104onClickScreenCoords msg =
105 on "click" (Json.map msg screenCoords)
109onClickPageCoords : (Coords -> msg) -> Attribute msg
110onClickPageCoords msg =
111 on "click" (Json.map msg pageCoords)
115onMouseCoords : (Coords -> msg) -> Attribute msg
117 on "mousemove" (Json.map msg localCoords)
121onMouseScreenCoords : (Coords -> msg) -> Attribute msg
122onMouseScreenCoords msg =
123 on "mousemove" (Json.map msg screenCoords)
127onMousePageCoords : (Coords -> msg) -> Attribute msg
128onMousePageCoords msg =
129 on "mousemove" (Json.map msg pageCoords)
138screenCoords : Json.Decoder Coords
141 (Json.field "screenX" Json.int)
142 (Json.field "screenY" Json.int)
146localCoords : Json.Decoder Coords
149 (Json.field "offsetX" Json.int)
150 (Json.field "offsetY" Json.int)
153pageCoords : Json.Decoder Coords
156 (Json.field "pageX" Json.int)
157 (Json.field "pageY" Json.int)
165onLoseFocus : msg -> Attribute msg
167 Internal.Attr << Html.Events.onBlur
171onFocus : msg -> Attribute msg
173 Internal.Attr << Html.Events.onFocus
180{-| Create a custom event listener. Normally this will not be necessary, but
181you have the power! Here is how `onClick` is defined for example:
183 import Json.Decode as Json
185 onClick : msg -> Attribute msg
187 on "click" (Json.succeed message)
189The first argument is the event name in the same format as with JavaScript's
190[`addEventListener`][aEL] function.
191The second argument is a JSON decoder. Read more about these [here][decoder].
192When an event occurs, the decoder tries to turn the event object into an Elm
193value. If successful, the value is routed to your `update` function. In the
194case of `onClick` we always just succeed with the given `message`.
195If this is confusing, work through the [Elm Architecture Tutorial][tutorial].
197[aEL]: <https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener>
198[decoder]: <http://package.elm-lang.org/packages/elm-lang/core/latest/Json-Decode>
199[tutorial]: <https://github.com/evancz/elm-architecture-tutorial/>
202on : String -> Json.Decoder msg -> Attribute msg
204 Internal.Attr <| Html.Events.on event decode
208-- {-| Same as `on` but you can set a few options.
210-- onWithOptions : String -> Html.Events.Options -> Json.Decoder msg -> Attribute msg
211-- onWithOptions event options decode =
212-- Internal.Attr <| Html.Events.onWithOptions event options decode
216{-| A `Json.Decoder` for grabbing `event.target.value`. We use this to define
219 import Json.Decode as Json
221 onInput : (String -> msg) -> Attribute msg
223 on "input" (Json.map tagger targetValue)
225You probably will never need this, but hopefully it gives some insights into
226how to make custom event handlers.
229targetValue : Json.Decoder String
231 Json.at [ "target", "value" ] Json.string
234{-| A `Json.Decoder` for grabbing `event.target.checked`. We use this to define
237 import Json.Decode as Json
239 onCheck : (Bool -> msg) -> Attribute msg
241 on "input" (Json.map tagger targetChecked)
244targetChecked : Json.Decoder Bool
246 Json.at [ "target", "checked" ] Json.bool
249{-| A `Json.Decoder` for grabbing `event.keyCode`. This helps you define
250keyboard listeners like this:
252 import Json.Decode as Json
254 onKeyUp : (Int -> msg) -> Attribute msg
256 on "keyup" (Json.map tagger keyCode)
258**Note:** It looks like the spec is moving away from `event.keyCode` and
259towards `event.key`. Once this is supported in more browsers, we may add
260helpers here for `onKeyUp`, `onKeyDown`, `onKeyPress`, etc.
263keyCode : Json.Decoder Int
265 Json.field "keyCode" Json.int
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list