Events

HaQuery events separated to DOM-related and component-related.

DOM element events

DOM events is pre-defined: click, mousedown, mouseup, mousemove, focus, blur, load and etc. To use them give ID to DOM element in your template.html file:

<input type="button" id="mybt" value="Press me!" />

After that you have two way to attach handlers: static and dynamic.

Static way to attach handlers

Simple define method with a magick name:

// for client class
function mybt_click(t, e) // t will be autotyped to haquery.client.HaqComponent, e to js.JqEvent
{
    // event handler code
}

// for server class
function mybt_click(t, e) // t will be autotyped to haquery.server.HaqComponent, e is reserved
{
    // event handler code
}

As you understand, you only need to create method with right name (DOM element id + event name).

Dynamic way to attach handlers

This is a dynamic way to attach handler (client only):

q('#mybt').click(function(e:js.JqEvent)
{
    // event handler code
});

Component events


First you need to define event. After that you may attach handler to it.

Define event


Component events are user-defined. They may be server and client. Server and client events are fully independent. You may create any event by adding event_* variable to your server or client class. After this, you may add code to call handlers attached to component event. For example, look at the mybutton component.

mybutton/template.html file:

<input type="button" id="bt" value="OK" />

mybutton/Server.hx file:

class Server extends haquery.server.HaqComponent
{
    var event_clicked : haquery.server.HaqEvent<Dynamic>;
    
    function bt_click()
    {
        event_clicked.call(null); // when need, call attached handlers
    }
}

Attach handler

To attach a handler to the component event you can use static way only.

template.html file:

<haq:mybutton id="mybt" />

Server.hx file:

class Server extends BaseServer
{
    function mybt_clicked(t, e)
    {
        // handler code
    }
}

version #177, modified 2013-01-29 12:10:02 by yar3333