jasonkneen / nl.fokkezb.drawer

[UNMAINTAINED] An Alloy widget wrapping the NappDrawer module for Facebook-like sliding side menus.
84 stars 36 forks source link

expose Window events when using DrawerLayout #73

Open dulmandakh opened 8 years ago

dulmandakh commented 8 years ago

Currently, we cannot attach handlers to 'open' and 'close' events when using DrawerLayout because we're attaching handlers to $.instance instead of $.window

FokkeZB commented 8 years ago

Do you mean this is a bug and the following lines should bind to $.window when you use DrawerLayout?

https://github.com/FokkeZB/nl.fokkezb.drawer/blob/master/nl.fokkezb.drawer/controllers/widget.js#L295-L301

dulmandakh commented 8 years ago

I would propose change something like below

$.on = function (event, callback, context) {
    if (mod !== 'dk.napp.drawer' && (event === 'open' || event === 'close')) {
        return $.window.addEventListener(translateEvent(event), callback);
    }
    return $.instance.addEventListener(translateEvent(event), callback);
};

$.off = function (event, callback, context) {
    if (mod !== 'dk.napp.drawer' && (event === 'open' || event === 'close')) {
        return $.window.addEventListener(translateEvent(event), callback);
    }
    return $.instance.removeEventListener(translateEvent(event), callback);
};
FokkeZB commented 8 years ago

That looks like a good fix. Could you do a PR?