Browse Source

Replaced hom cooked event emitter with emitter-component module

css_transitions
josdejong 11 years ago
parent
commit
b0366f9cbc
2 changed files with 11 additions and 49 deletions
  1. +3
    -38
      src/graph/Graph.js
  2. +8
    -11
      src/graph/SelectionMixin.js

+ 3
- 38
src/graph/Graph.js View File

@ -197,6 +197,9 @@ function Graph (container, data, options) {
}
}
// Extend Graph with an Emitter mixin
Emitter(Graph.prototype);
/**
* Get the script path where the vis.js library is located
*
@ -508,44 +511,6 @@ Graph.prototype.setOptions = function (options) {
this._redraw();
};
/**
* Add event listener
* @param {String} event Event name. Available events:
* 'select'
* @param {function} callback Callback function, invoked as callback(properties)
* where properties is an optional object containing
* event specific properties.
*/
Graph.prototype.on = function on (event, callback) {
var available = ['select'];
if (available.indexOf(event) == -1) {
throw new Error('Unknown event "' + event + '". Choose from ' + available.join());
}
events.addListener(this, event, callback);
};
/**
* Remove an event listener
* @param {String} event Event name
* @param {function} callback Callback function
*/
Graph.prototype.off = function off (event, callback) {
events.removeListener(this, event, callback);
};
/**
* fire an event
* @param {String} event The name of an event, for example 'select'
* @param {Object} params Optional object with event parameters
* @private
*/
Graph.prototype._trigger = function (event, params) {
events.trigger(this, event, params);
};
/**
* Create the main frame for the Graph.
* This function is executed once when a Graph object is created. The frame

+ 8
- 11
src/graph/SelectionMixin.js View File

@ -213,9 +213,7 @@ var SelectionMixin = {
this.selectionObj = {};
if (doNotTrigger == false) {
this._trigger('select', {
nodes: this.getSelection()
});
this.emit('select', this.getSelection());
}
},
@ -242,9 +240,7 @@ var SelectionMixin = {
}
if (doNotTrigger == false) {
this._trigger('select', {
nodes: this.getSelection()
});
this.emit('select', this.getSelection());
}
},
@ -399,9 +395,7 @@ var SelectionMixin = {
this._removeFromSelection(object);
}
if (doNotTrigger == false) {
this._trigger('select', {
nodes: this.getSelection()
});
this.emit('select', this.getSelection());
}
},
@ -512,7 +506,10 @@ var SelectionMixin = {
getSelection : function() {
var nodeIds = this.getSelectedNodes();
var edgeIds = this.getSelectedEdges();
return {nodes:nodeIds, edges:edgeIds};
return {
nodes: nodeIds,
edges: edgeIds
};
},
/**
@ -636,7 +633,7 @@ var SelectionMixin = {
=======
if (changed) {
// fire the select event
this._trigger('select', {
this.emit('select', {
nodes: this.getSelection()
});
}

Loading…
Cancel
Save