Last active
December 20, 2015 01:59
-
-
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..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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