javascript events?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

javascript events?

Raoul Duke
hi,

i'm trying to learn what the latest is for handling events in
haXe->js, like checking keycodes. when i google around it seems like
there are the to-be-expected troubles and tribulations with
cross-browser success. what is the current best practice as they say?

thanks.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

Lars Madson
Hi Raoul,

The simplest way for me was to extend the Dom, mostly to make it work
with IE as it works same on all other browsers:


typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
typedef WindowIe = { > js.Window, public var event : EventIe; };

class LibIE extends js.Lib{
     public static var windowIE : WindowIe;

     static function __init__() untyped {
         windowIE = untyped __js__("window");
     }
}

## this is not necessary but just so you can understand the rest of my
exemple:
typedef Ln = { >js.Link,
     public var targetDom : HtmlDom;
     public var action : String;
     public var kallback : Dynamic -> Void;
     public var calldata : CallData;
     public var cbTarget : HtmlDom;
     public var method : Bool;
     public var params : Dynamic;
     public var klass : String;
     public var hashit : Bool;
}
##
So then I would call a getTarget method on an event object which makes
the Haxe/Js events work everywhere:

     /**
      * Return the target element of an Event
      * @param    e : The Event object
      * @return    A js.Ln object
      */
     function getEventTarget( e : Event ) : js.Ln {
         if ( js.Lib.isIE )
             if ( js.LibIE.windowIE.event.srcElement == null )
                 return untyped e.target;
             else
                 return untyped js.LibIE.windowIE.event.srcElement;
         var t : js.Ln = null;
         if ( e.target != null ) t = untyped e.target;
         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this
is in case of texte node or somethin
         return t;
     }



     /**
      * Create an minimal Event object, mainly to call an element action
without user input.
      * @param    l : a js.Ln object
      * @return    A dynamic object
      */
     function mkEvent( l : js.Ln ) : Dynamic{
         var e : Dynamic = { };
         e.target = untyped l;
         return e;
     }

hope it helps ;)
Laurent


Le 05/04/2011 21:49, Raoul Duke a écrit :
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

Tony Polinelli
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:

> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

tom rhodes
which jquery is bundled? the one by Andy Li? so you don't have to install it via haxelib any more?

i don't see it in the autocomplete in flashdevelop with 2.07, is it under js?


On 6 April 2011 00:53, Tony Polinelli <[hidden email]> wrote:
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:
> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

John Plsek
not bundled in 2.07

only in the SVN - jQuery 1.5

On 6 April 2011 09:08, tom rhodes <[hidden email]> wrote:
which jquery is bundled? the one by Andy Li? so you don't have to install it via haxelib any more?

i don't see it in the autocomplete in flashdevelop with 2.07, is it under js?



On 6 April 2011 00:53, Tony Polinelli <[hidden email]> wrote:
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:
> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Coming soon - BravoStudio, a complete internet radio/tv solution

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

tom rhodes
interesting, is it the same syntax/usage as the haxelib version?


On 6 April 2011 01:48, John Plsek <[hidden email]> wrote:
not bundled in 2.07

only in the SVN - jQuery 1.5


On 6 April 2011 09:08, tom rhodes <[hidden email]> wrote:
which jquery is bundled? the one by Andy Li? so you don't have to install it via haxelib any more?

i don't see it in the autocomplete in flashdevelop with 2.07, is it under js?



On 6 April 2011 00:53, Tony Polinelli <[hidden email]> wrote:
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:
> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Coming soon - BravoStudio, a complete internet radio/tv solution

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

Justin Donaldson-3
In reply to this post by tom rhodes
It's on svn, and I don't think it's Andy's.

http://haxe.1354130.n2.nabble.com/Multitypes-amp-JQuery-td6035378.html

-Justin

On Tue, Apr 5, 2011 at 4:08 PM, tom rhodes <[hidden email]> wrote:
which jquery is bundled? the one by Andy Li? so you don't have to install it via haxelib any more?

i don't see it in the autocomplete in flashdevelop with 2.07, is it under js?



On 6 April 2011 00:53, Tony Polinelli <[hidden email]> wrote:
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:
> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

MarcWeber
In reply to this post by Raoul Duke
Excerpts from Raoul Duke's message of Tue Apr 05 21:49:39 +0200 2011:
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?

use jquery, mootools or the like.
Its not only about attaching handlers - but also about preventing
memory leaks and cleaning up. Read jquery or mootools code to understand
how to do it properly.

Also IE and the rest have two different event models (unless you use
.click = function() only)

both: jquery and mootools abstract over things like bubbling, stopping
events etc nicely.

Marc Weber

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: javascript events?

Andy Li
In reply to this post by tom rhodes
jQuery in haxe SVN and jQueryExtern is largely the same, both use jQuery 1.5.
But jQueryExtern is made 100% reflecting the original jQuery API, which jQuery in haxe SVN made some changes to make it more type safe.
I think jQuery in haxe SVN also embeds jQuery for you, while jQueryExtern does not.

best,
Andy

On Wed, Apr 6, 2011 at 7:55 AM, tom rhodes <[hidden email]> wrote:
interesting, is it the same syntax/usage as the haxelib version?



On 6 April 2011 01:48, John Plsek <[hidden email]> wrote:
not bundled in 2.07

only in the SVN - jQuery 1.5


On 6 April 2011 09:08, tom rhodes <[hidden email]> wrote:
which jquery is bundled? the one by Andy Li? so you don't have to install it via haxelib any more?

i don't see it in the autocomplete in flashdevelop with 2.07, is it under js?



On 6 April 2011 00:53, Tony Polinelli <[hidden email]> wrote:
Jquery is bundled with the latest haxe-js isn't it? Maybe repo. I
think this is still the preferred cross browser approach

On Wednesday, April 6, 2011, Laurent Kappler <[hidden email]> wrote:
> Hi Raoul,
>
> The simplest way for me was to extend the Dom, mostly to make it work with IE as it works same on all other browsers:
>
>
> typedef EventIe = { > js.Event, public var srcElement : HtmlDom; };
> typedef WindowIe = { > js.Window, public var event : EventIe; };
>
> class LibIE extends js.Lib{
>     public static var windowIE : WindowIe;
>
>     static function __init__() untyped {
>         windowIE = untyped __js__("window");
>     }
> }
>
> ## this is not necessary but just so you can understand the rest of my exemple:
> typedef Ln = { >js.Link,
>     public var targetDom : HtmlDom;
>     public var action : String;
>     public var kallback : Dynamic -> Void;
>     public var calldata : CallData;
>     public var cbTarget : HtmlDom;
>     public var method : Bool;
>     public var params : Dynamic;
>     public var klass : String;
>     public var hashit : Bool;
> }
> ##
> So then I would call a getTarget method on an event object which makes the Haxe/Js events work everywhere:
>
>     /**
>      * Return the target element of an Event
>      * @param    e : The Event object
>      * @return    A js.Ln object
>      */
>     function getEventTarget( e : Event ) : js.Ln {
>         if ( js.Lib.isIE )
>             if ( js.LibIE.windowIE.event.srcElement == null )
>                 return untyped e.target;
>             else
>                 return untyped js.LibIE.windowIE.event.srcElement;
>         var t : js.Ln = null;
>         if ( e.target != null ) t = untyped e.target;
>         if ( t.nodeType == 3 ) t = untyped t.parentNode; //I think this is in case of texte node or somethin
>         return t;
>     }
>
>
>
>     /**
>      * Create an minimal Event object, mainly to call an element action without user input.
>      * @param    l : a js.Ln object
>      * @return    A dynamic object
>      */
>     function mkEvent( l : js.Ln ) : Dynamic{
>         var e : Dynamic = { };
>         e.target = untyped l;
>         return e;
>     }
>
> hope it helps ;)
> Laurent
>
>
> Le 05/04/2011 21:49, Raoul Duke a écrit :
>
> hi,
>
> i'm trying to learn what the latest is for handling events in
> haXe->js, like checking keycodes. when i google around it seems like
> there are the to-be-expected troubles and tribulations with
> cross-browser success. what is the current best practice as they say?
>
> thanks.
>
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>

--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org



--
Coming soon - BravoStudio, a complete internet radio/tv solution

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org