あなたはこれらの線に沿って何かを試すことができます:
window.createEventManager = (function() {
var Event = function(manager, name) {
this.name = name;
this._manager = manager;
this._listeners = [];
};
Event.prototype = {
listen: function(fn) {
if (!$.isFunction(fn)) {
throw "fn is not a function.";
}
this._listeners.push(fn);
},
fire: function(args) {
args = args || {};
args.name = this.name;
var ls = this._listeners;
for (var i = 0, l = ls.length; i < l; ++i) {
ls[i](args);
}
this._manager.fire(args);
}
};
var EventManager = function(eventNames) {
for (var n in eventNames) {
this[eventNames[n]] = new Event(this, eventNames[n]);
}
this._listeners = [];
};
EventManager.prototype = {
/**
* Listen to all events
* @param fn
*/
listen: function(fn) {
if (!$.isFunction(fn)) {
throw "fn is not a function.";
}
this._listeners.push(fn);
},
fire: function(args) {
var ls = this._listeners;
for (var i = 0, l = ls.length; i < l; ++i) {
ls[i](args);
}
},
getEvent: function(name){
return this[name];
}
};
return function(eventNames) {
return new EventManager(eventNames);
};
})();
マップコントローラー内:
init : function(){
events = createEventManager(["mapTrigger"]);
},
そしてブラウザでそれを聞いてください:
$('#map').app_map().events.getEvent("mapTrigger").listen(function(){
// Logic to perform on trigger.
});