Skip to content

Instantly share code, notes, and snippets.

@superhero
Last active December 20, 2015 01:59
Show Gist options
  • Save superhero/6052935 to your computer and use it in GitHub Desktop.
Save superhero/6052935 to your computer and use it in GitHub Desktop.
This is a module for the shift framework that allows interaction between the view layer of the DOM to trigger events in the framework.jQuery dependent..
Shift.EventAttacher = function(sl)
{
this.router =
{
'shift.ready' : 'attachEvents',
'attach-events': 'attachEvents'
};
this.view =
{
attachEvents: function()
{
$('*')
.filter(function()
{
return $(this).data('routes') || $(this).data('route');
})
.each(function()
{
var $this = $(this),
routes = $this.data('routes')
? $this.data('routes')
: $this.data('route'),
type = $this.data('on')
? $this.data('on')
: 'click';
$this.on(type, function($event)
{
$.each(routes.split(' '), function(i, route)
{
sl.get('event-bus').trigger(route, $event);
});
});
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment