<commit_before>// $begin{copyright}
//
// This file is part of WebSharper
//
// Copyright (c) 2008-2014 IntelliFactory
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License.  You may
// obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.  See the License for the specific language governing
// permissions and limitations under the License.
//
// $end{copyright}

namespace WebSharper.Html.Client

/// Provides the event interfaces and the default event support.
module Events =
    open WebSharper
    open WebSharper.JavaScript
    open WebSharper.JQuery

    /// Represents mouse event data.
    type MouseEvent =
        {
            X : int
            Y : int
        }

    /// Represents character code data.
    type CharacterCode =
        {
            CharacterCode : int
        }

    /// Represents key code data
    type KeyCode =
        {
            KeyCode : int
        }

    /// Interface for event handling implementation
    type IEventSupport =

        // Mouse
        abstract member OnClick<'T when 'T :> Pagelet>         : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnDoubleClick<'T when 'T :> Pagelet>   : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseDown<'T when 'T :> Pagelet>     : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseEnter<'T when 'T :> Pagelet>    : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseLeave<'T when 'T :> Pagelet>    : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseMove<'T when 'T :> Pagelet>     : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseOut<'T when 'T :> Pagelet>      : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseUp<'T when 'T :> Pagelet>      : ('T -> MouseEvent -> unit) -> 'T -> unit

        // Keys
        abstract member OnKeyDown<'T when 'T :> Pagelet>       : ('T -> KeyCode -> unit) -> 'T ->  unit
        abstract member OnKeyPress<'T when 'T :> Pagelet>      : ('T -> CharacterCode -> unit) -> 'T ->  unit
        abstract member OnKeyUp<'T when 'T :> Pagelet>         : ('T -> KeyCode -> unit) -> 'T ->  unit

        // Other
        abstract member OnBlur<'T when 'T :> Pagelet>          : ('T -> unit) -> 'T -> unit
        abstract member OnChange<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnFocus<'T when 'T :> Pagelet>         : ('T -> unit) -> 'T -> unit
        abstract member OnError<'T when 'T :> Pagelet>         : ('T -> unit) -> 'T -> unit
        abstract member OnLoad<'T when 'T :> Pagelet>          : ('T -> unit) -> 'T -> unit
        abstract member OnUnLoad<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnResize<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnScroll<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnSelect<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnSubmit<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit

    type internal JE = WebSharper.JQuery.Event

    type internal JQueryEventSupport [<JavaScript>] () =

        [<JavaScript>]
        member private this.OnMouse<'T when 'T :> Pagelet> name (f: 'T -> MouseEvent -> unit) (el: 'T)  =
            JQuery.Of(el.Body).Bind(name, fun _ (ev: JE) ->
                f el {X = ev.PageX; Y = ev.PageY}
            ).Ignore

        interface IEventSupport with

            [<JavaScript>]
            member this.OnBlur f el  =
                JQuery.Of(el.Body).Bind("blur", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnChange f el =
                JQuery.Of(el.Body).Bind("change", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnClick f el =
                this.OnMouse "click" f el

            [<JavaScript>]
            member this.OnDoubleClick f el =
                this.OnMouse "dblclick" f el

            [<JavaScript>]
            member this.OnMouseDown f el =
                this.OnMouse "mousedown" f el

            [<JavaScript>]
            member this.OnMouseEnter f el =
                this.OnMouse "mouseenter" f el

            [<JavaScript>]
            member this.OnMouseLeave f el =
                this.OnMouse "mouseleave" f el

            [<JavaScript>]
            member this.OnMouseMove f el =
                this.OnMouse "mousemove" f el

            [<JavaScript>]
            member this.OnMouseOut f el =
                this.OnMouse "mouseout" f el

            [<JavaScript>]
            member this.OnMouseUp f el =
                this.OnMouse "mouseup" f el

            [<JavaScript>]
            member this.OnKeyDown f el =
                JQuery.Of(el.Body).Bind("keydown", fun _ (ev: JE) ->
                    f el {KeyCode = ev?keyCode}
                ).Ignore

            [<JavaScript>]
            member this.OnKeyPress f el =
                JQuery.Of(el.Body)
                    .Keypress(fun _ (arg: JE) -> f el ({ CharacterCode = arg.Which }))
                    .Ignore

            [<JavaScript>]
            member this.OnKeyUp f el  =
                JQuery.Of(el.Body).Bind("keyup", fun _ (ev: JE) ->
                    f el {KeyCode = ev?keyCode}
                ).Ignore

            [<JavaScript>]
            member this.OnFocus f el =
                JQuery.Of(el.Body).Bind("focus", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnLoad f el =
                JQuery.Of(el.Body).Bind("load", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnUnLoad f el =
                JQuery.Of(el.Body).Bind("unload", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnResize f el =<commit_msg>Add field to access the Dom.Event in Html.Client events (#174)<commit_after>// $begin{copyright}
//
// This file is part of WebSharper
//
// Copyright (c) 2008-2014 IntelliFactory
//
// Licensed under the Apache License, Version 2.0 (the "License"); you
// may not use this file except in compliance with the License.  You may
// obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied.  See the License for the specific language governing
// permissions and limitations under the License.
//
// $end{copyright}

namespace WebSharper.Html.Client

/// Provides the event interfaces and the default event support.
module Events =
    open WebSharper
    open WebSharper.JavaScript
    open WebSharper.JQuery

    /// Represents mouse event data.
    type MouseEvent =
        {
            X : int
            Y : int
            Event : Dom.MouseEvent
        }

    /// Represents character code data.
    type CharacterCode =
        {
            CharacterCode : int
            Event : Dom.KeyboardEvent
        }

    /// Represents key code data
    type KeyCode =
        {
            KeyCode : int
            Event : Dom.KeyboardEvent
        }

    /// Interface for event handling implementation
    type IEventSupport =

        // Mouse
        abstract member OnClick<'T when 'T :> Pagelet>         : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnDoubleClick<'T when 'T :> Pagelet>   : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseDown<'T when 'T :> Pagelet>     : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseEnter<'T when 'T :> Pagelet>    : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseLeave<'T when 'T :> Pagelet>    : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseMove<'T when 'T :> Pagelet>     : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseOut<'T when 'T :> Pagelet>      : ('T -> MouseEvent -> unit) -> 'T -> unit
        abstract member OnMouseUp<'T when 'T :> Pagelet>      : ('T -> MouseEvent -> unit) -> 'T -> unit

        // Keys
        abstract member OnKeyDown<'T when 'T :> Pagelet>       : ('T -> KeyCode -> unit) -> 'T ->  unit
        abstract member OnKeyPress<'T when 'T :> Pagelet>      : ('T -> CharacterCode -> unit) -> 'T ->  unit
        abstract member OnKeyUp<'T when 'T :> Pagelet>         : ('T -> KeyCode -> unit) -> 'T ->  unit

        // Other
        abstract member OnBlur<'T when 'T :> Pagelet>          : ('T -> unit) -> 'T -> unit
        abstract member OnChange<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnFocus<'T when 'T :> Pagelet>         : ('T -> unit) -> 'T -> unit
        abstract member OnError<'T when 'T :> Pagelet>         : ('T -> unit) -> 'T -> unit
        abstract member OnLoad<'T when 'T :> Pagelet>          : ('T -> unit) -> 'T -> unit
        abstract member OnUnLoad<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnResize<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnScroll<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnSelect<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit
        abstract member OnSubmit<'T when 'T :> Pagelet>        : ('T -> unit) -> 'T -> unit

    type internal JE = WebSharper.JQuery.Event

    type internal JQueryEventSupport [<JavaScript>] () =

        [<JavaScript>]
        member private this.OnMouse<'T when 'T :> Pagelet> name (f: 'T -> MouseEvent -> unit) (el: 'T)  =
            JQuery.Of(el.Body).Bind(name, fun _ (ev: JE) ->
                f el {X = ev.PageX; Y = ev.PageY; Event = ev.AsDomEvent :?> _}
            ).Ignore

        interface IEventSupport with

            [<JavaScript>]
            member this.OnBlur f el  =
                JQuery.Of(el.Body).Bind("blur", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnChange f el =
                JQuery.Of(el.Body).Bind("change", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnClick f el =
                this.OnMouse "click" f el

            [<JavaScript>]
            member this.OnDoubleClick f el =
                this.OnMouse "dblclick" f el

            [<JavaScript>]
            member this.OnMouseDown f el =
                this.OnMouse "mousedown" f el

            [<JavaScript>]
            member this.OnMouseEnter f el =
                this.OnMouse "mouseenter" f el

            [<JavaScript>]
            member this.OnMouseLeave f el =
                this.OnMouse "mouseleave" f el

            [<JavaScript>]
            member this.OnMouseMove f el =
                this.OnMouse "mousemove" f el

            [<JavaScript>]
            member this.OnMouseOut f el =
                this.OnMouse "mouseout" f el

            [<JavaScript>]
            member this.OnMouseUp f el =
                this.OnMouse "mouseup" f el

            [<JavaScript>]
            member this.OnKeyDown f el =
                JQuery.Of(el.Body).Bind("keydown", fun _ (ev: JE) ->
                    f el {KeyCode = ev?keyCode; Event = ev.AsDomEvent :?> _}
                ).Ignore

            [<JavaScript>]
            member this.OnKeyPress f el =
                JQuery.Of(el.Body)
                    .Keypress(fun _ (ev: JE) -> f el ({ CharacterCode = ev.Which; Event = ev.AsDomEvent :?> _ }))
                    .Ignore

            [<JavaScript>]
            member this.OnKeyUp f el  =
                JQuery.Of(el.Body).Bind("keyup", fun _ (ev: JE) ->
                    f el {KeyCode = ev?keyCode; Event = ev.AsDomEvent :?> _}
                ).Ignore

            [<JavaScript>]
            member this.OnFocus f el =
                JQuery.Of(el.Body).Bind("focus", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnLoad f el =
                JQuery.Of(el.Body).Bind("load", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnUnLoad f el =
                JQuery.Of(el.Body).Bind("unload", fun _ _ -> f el).Ignore

            [<JavaScript>]
            member this.OnResize f el =
{'fraction_non_alphanumeric': 0.1291824494949495, 'fraction_numerical': 0.002130681818181818, 'mean_word_length': 1.6391087047063724, 'pattern_counts': {'":': 0, '<': 85, '<?xml version=': 0, '>': 303, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4323030', 'n_tokens_mistral': 3768, 'n_tokens_neox': 3595, 'n_words': 1157}