var EventController = Backbone.Model.extend({ options: {}, events: { 'map.underground.draw.success': [], 'map.underground.draw.end': [], 'map.routing.draw.success': [], 'map.modal.editor-routing-choose.close': [], 'map.tour.draw': [], 'map.marker.click': [], 'map.marker.hover': [], 'map.tour.click' : [] }, initialize: function(options) { var that = this; $.extend(true, that.options, options); }, trigger: function(key, data) { var that = this; if (that.events[key]) { $.each(that.events[key], function(i, event) { if (data) { event.callback(data); } else { event.callback(); } if (event.once) { that.events[key].splice(i); } }); } }, add: function(key, callback, once) { var that = this; if (that.events[key]) { that.events[key].push({ callback: callback, once: once }); } }, remove: function(key, callback) { var that = this; if (that.events[key]) { $.each(that.events[key], function(i, event) { if (event.callback !== callback) { delete that.events[key][i]; } }); } } });